Search in sources :

Example 1 with Instance

use of com.google.cloud.spanner.Instance 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 Instance

use of com.google.cloud.spanner.Instance 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 Instance

use of com.google.cloud.spanner.Instance in project spanner-jdbc by olavloite.

the class AbstractSpecificIntegrationTest method createInstance.

private static void createInstance() {
    InstanceAdminClient instanceAdminClient = spanner.getInstanceAdminClient();
    InstanceConfig config = instanceAdminClient.getInstanceConfig("regional-europe-west1");
    Instance instance = instanceAdminClient.newInstanceBuilder(InstanceId.of(projectId, instanceId)).setDisplayName("Test Instance").setInstanceConfigId(config.getId()).setNodeCount(1).build();
    Operation<Instance, CreateInstanceMetadata> createInstance = instanceAdminClient.createInstance(instance);
    createInstance = createInstance.waitFor();
}
Also used : InstanceConfig(com.google.cloud.spanner.InstanceConfig) Instance(com.google.cloud.spanner.Instance) InstanceAdminClient(com.google.cloud.spanner.InstanceAdminClient) CreateInstanceMetadata(com.google.spanner.admin.instance.v1.CreateInstanceMetadata)

Example 4 with Instance

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

the class ITInstanceAdminTest method listInstances.

@Test
public void listInstances() throws Exception {
    Instance instance = Iterators.getOnlyElement(instanceClient.listInstances(Options.filter("name:instances/" + env.getTestHelper().getInstanceId().getInstance())).iterateAll().iterator());
    assertThat(instance.getId()).isEqualTo(env.getTestHelper().getInstanceId());
}
Also used : Instance(com.google.cloud.spanner.Instance) Test(org.junit.Test) IntegrationTest(com.google.cloud.spanner.IntegrationTest)

Example 5 with Instance

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