Search in sources :

Example 1 with InstanceInfo

use of com.google.cloud.spanner.InstanceInfo in project google-cloud-java by GoogleCloudPlatform.

the class ITInstanceAdminTest method updateInstance.

@Test
public void updateInstance() throws Exception {
    Instance instance = instanceClient.getInstance(env.getTestHelper().getInstanceId().getInstance());
    String rand = new Random().nextInt() + "";
    String newDisplayName = "instance test" + rand;
    InstanceInfo toUpdate = InstanceInfo.newBuilder(env.getTestHelper().getInstanceId()).setDisplayName(newDisplayName).setNodeCount(instance.getNodeCount() + 1).build();
    // Only update display name
    Operation<Instance, UpdateInstanceMetadata> op = instanceClient.updateInstance(toUpdate, InstanceInfo.InstanceField.DISPLAY_NAME);
    Instance newInstance = op.waitFor().getResult();
    assertThat(newInstance.getNodeCount()).isEqualTo(instance.getNodeCount());
    assertThat(newInstance.getDisplayName()).isEqualTo(newDisplayName);
    Instance newInstanceFromGet = instanceClient.getInstance(env.getTestHelper().getInstanceId().getInstance());
    assertThat(newInstanceFromGet).isEqualTo(newInstance);
    toUpdate = InstanceInfo.newBuilder(instance.getId()).setDisplayName(instance.getDisplayName()).build();
    instanceClient.updateInstance(toUpdate, InstanceInfo.InstanceField.DISPLAY_NAME).waitFor();
}
Also used : Random(java.util.Random) Instance(com.google.cloud.spanner.Instance) UpdateInstanceMetadata(com.google.spanner.admin.instance.v1.UpdateInstanceMetadata) InstanceInfo(com.google.cloud.spanner.InstanceInfo) Test(org.junit.Test) IntegrationTest(com.google.cloud.spanner.IntegrationTest)

Example 2 with InstanceInfo

use of com.google.cloud.spanner.InstanceInfo in project google-cloud-java by GoogleCloudPlatform.

the class InstanceAdminClientSnippets method updateInstance.

/**
 * Example to update an instance.
 */
public void updateInstance(Instance my_instance, final String my_client_project, final String my_instance_id, final String my_display_name) {
    // [START instance_admin_client_update_instance]
    Instance instance = my_instance;
    final String clientProject = my_client_project;
    final String instanceId = my_instance_id;
    final String newDisplayName = my_display_name;
    InstanceInfo toUpdate = InstanceInfo.newBuilder(InstanceId.of(clientProject, instanceId)).setDisplayName(newDisplayName).setNodeCount(instance.getNodeCount() + 1).build();
    // Only update display name
    OperationFuture<Instance, UpdateInstanceMetadata> op = instanceAdminClient.updateInstance(toUpdate, InstanceInfo.InstanceField.DISPLAY_NAME);
    try {
        op.get();
    } catch (ExecutionException e) {
        throw (SpannerException) e.getCause();
    } catch (InterruptedException e) {
        throw SpannerExceptionFactory.propagateInterrupt(e);
    }
// [END instance_admin_client_update_instance]
}
Also used : Instance(com.google.cloud.spanner.Instance) UpdateInstanceMetadata(com.google.spanner.admin.instance.v1.UpdateInstanceMetadata) ExecutionException(java.util.concurrent.ExecutionException) InstanceInfo(com.google.cloud.spanner.InstanceInfo)

Aggregations

Instance (com.google.cloud.spanner.Instance)2 InstanceInfo (com.google.cloud.spanner.InstanceInfo)2 UpdateInstanceMetadata (com.google.spanner.admin.instance.v1.UpdateInstanceMetadata)2 IntegrationTest (com.google.cloud.spanner.IntegrationTest)1 Random (java.util.Random)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1