Search in sources :

Example 1 with UpdateInstanceMetadata

use of com.google.spanner.admin.instance.v1.UpdateInstanceMetadata 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 UpdateInstanceMetadata

use of com.google.spanner.admin.instance.v1.UpdateInstanceMetadata in project google-cloud-java by GoogleCloudPlatform.

the class ITInstanceAdminTest method updateInstanceViaEntity.

@Test
public void updateInstanceViaEntity() throws Exception {
    Instance instance = instanceClient.getInstance(env.getTestHelper().getInstanceId().getInstance());
    String rand = new Random().nextInt() + "";
    String newDisplayName = "instance test" + rand;
    Instance toUpdate = instance.toBuilder().setDisplayName(newDisplayName).setNodeCount(instance.getNodeCount() + 1).build();
    // Only update display name
    Operation<Instance, UpdateInstanceMetadata> op = toUpdate.update(InstanceInfo.InstanceField.DISPLAY_NAME);
    Instance newInstance = op.waitFor().getResult();
    assertThat(newInstance.getNodeCount()).isEqualTo(instance.getNodeCount());
    assertThat(newInstance.getDisplayName()).isEqualTo(newDisplayName);
    Instance newInstanceFromGet = instance.reload();
    assertThat(newInstanceFromGet).isEqualTo(newInstance);
    toUpdate = newInstance.toBuilder().setDisplayName(instance.getDisplayName()).build();
    toUpdate.update(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) Test(org.junit.Test) IntegrationTest(com.google.cloud.spanner.IntegrationTest)

Example 3 with UpdateInstanceMetadata

use of com.google.spanner.admin.instance.v1.UpdateInstanceMetadata 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)3 UpdateInstanceMetadata (com.google.spanner.admin.instance.v1.UpdateInstanceMetadata)3 InstanceInfo (com.google.cloud.spanner.InstanceInfo)2 IntegrationTest (com.google.cloud.spanner.IntegrationTest)2 Random (java.util.Random)2 Test (org.junit.Test)2 ExecutionException (java.util.concurrent.ExecutionException)1