无法从Java SDK创建实例

时间:2019-04-09 08:59:14

标签: oracle-cloud-infrastructure oci-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$1.apply(UpdateRouteTableConverter.java:70)
        at com.oracle.bmc.core.internal.http.UpdateRouteTableConverter$1.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)

1 个答案:

答案 0 :(得分:4)

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

        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中看到在路由表中创建路由规则所需的参数。

该示例似乎基于不推荐使用的调用RouteRule构建器的版本。