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();
}
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();
}
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]
}
Aggregations