stopInstanceRequest google java library

49 views Asked by At

I am trying to implement a method to programmatically start and stop google compute instances using com.google.cloud.compute.v1 library.

The issue I am currently fighting is this:

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

The function is:

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
      }
}

My question is these: 1- From where is hasDiscardLocalSsd() called? 2- where in the library should this function be located.

I am using google-cloud-compute v 1.18.0

I hav tried reading the reference.

1

There are 1 answers

0
Faux_Clef On

To get this to work you need the right version of the library and libraries-bom from 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>