无法从 java sdk 创建实例

Can't create instance from java sdk

我正在尝试使用 Java SDK 创建一个 OCI 实例。我在 routeRules 中遇到错误。

当我评论下一行时,我能够创建一个实例。但是在那台机器上没有启用路由。

addInternetGatewayToRouteTable(vcnClient, compartmentId, vcn.getDefaultRouteTableId(), internetGateway);

https://github.com/oracle/oci-java-sdk/blob/master/bmc-examples/src/main/java/CreateInstanceExample.java

Exception in thread "main" com.oracle.bmc.model.BmcException: (400, InvalidParameter, false) routeRules[0].networkEntityId may not be null (opc-request-id: 6BC8A182852240F8AFFD1EB279CFF901/AD5BF82603D64DA298976FCFE83871F6/9398B04078B0435A8FA68FEA7307CC99)
        at com.oracle.bmc.http.internal.ResponseHelper.throwIfNotSuccessful(ResponseHelper.java:120)
        at com.oracle.bmc.http.internal.ResponseConversionFunctionFactory$ValidatingParseResponseFunction.apply(ResponseConversionFunctionFactory.java:86)
        at com.oracle.bmc.http.internal.ResponseConversionFunctionFactory$ValidatingParseResponseFunction.apply(ResponseConversionFunctionFactory.java:82)
        at com.oracle.bmc.core.internal.http.UpdateRouteTableConverter.apply(UpdateRouteTableConverter.java:70)
        at com.oracle.bmc.core.internal.http.UpdateRouteTableConverter.apply(UpdateRouteTableConverter.java:55)
        at com.oracle.bmc.core.VirtualNetworkClient.updateRouteTable(VirtualNetworkClient.java:3325)
        at CreateInstanceExample.addInternetGatewayToRouteTable(CreateInstanceExample.java:295)
        at CreateInstanceExample.main(CreateInstanceExample.java:146)

代码有bug,可以在addInternetGatewayToRouteTable(..)方法中替换destination

        RouteRule internetAccessRoute =
                RouteRule.builder()
                        .cidrBlock("0.0.0.0/0")
                        .destination(internetGateway.getId())
                        .build();

第 295 行 networkEntityId:

        RouteRule internetAccessRoute =
                RouteRule.builder()
                        .cidrBlock("0.0.0.0/0")
                        .networkEntityId(internetGateway.getId())
                        .build();

REST APIs here可以看出在路由table中创建路由规则需要哪些参数。

该示例似乎基于调用 RouteRule 生成器的已弃用版本。