【问题标题】:stopInstanceRequest google java librarystopInstanceRequest 谷歌java库
【发布时间】:2023-01-17 17:03:45
【问题描述】:

我正在尝试实现一种使用com.google.cloud.compute.v1 库以编程方式启动和停止谷歌计算实例的方法。

我目前正在解决的问题是:

...
Caused by: java.lang.NoSuchMethodError: 'boolean com.google.cloud.compute.v1.StopInstanceRequest.hasDiscardLocalSsd()'
...

功能是:

private fun stopInstance( zone: String, instanceName: String) : Boolean{

            val project = Helpers.getProperties("PROJECT_ID")
            val instancesClient:InstancesClient = InstancesClient.create()
    
            val stopInstanceRequest = StopInstanceRequest.newBuilder()
                .setProject(project)
                .setZone(zone)
                .setInstance(instanceName)
                .build()
    
            val operation: OperationFuture<Operation, Operation> = instancesClient.stopAsync(
                stopInstanceRequest)
            val response = operation.get(3, TimeUnit.MINUTES)
    
            return if (operation.isDone && response.status == Operation.Status.DONE) {
                println("Instance stopped successfully! ${response.status}")
                true
            } else {
                println("Instance failed to stop. ${response.status}")
                false
      }
}

我的问题是: 1- 从哪里调用hasDiscardLocalSsd()? 2- 此函数应位于库中的什么位置。

我正在使用 google-cloud-compute v 1.18.0

我试过阅读参考资料。

【问题讨论】:

    标签: java kotlin google-cloud-compute-engine


    【解决方案1】:

    为了让它工作,你需要正确版本的库和 libraries-bom 来自 maven。

    <!-- https://mvnrepository.com/artifact/com.google.cloud/libraries-bom -->
    <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>libraries-bom</artifactId>
        <version>26.3.0</version>
        <type>pom</type>
    </dependency>
    ...
    <!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-compute -->
    <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>google-cloud-compute</artifactId>
        <version>1.18.0</version>
    </dependency>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-21
      • 1970-01-01
      • 2010-11-07
      • 2017-03-15
      • 1970-01-01
      相关资源
      最近更新 更多