Search in sources :

Example 1 with InstanceAdminClient

use of com.google.cloud.spanner.InstanceAdminClient 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 2 with InstanceAdminClient

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

the class SpannerSnippets method getInstanceAdminClient.

InstanceAdminClient getInstanceAdminClient() {
    // [START get_instance_admin_client]
    SpannerOptions options = SpannerOptions.newBuilder().build();
    Spanner spanner = options.getService();
    InstanceAdminClient instanceAdminClient = spanner.getInstanceAdminClient();
    return instanceAdminClient;
}
Also used : InstanceAdminClient(com.google.cloud.spanner.InstanceAdminClient) SpannerOptions(com.google.cloud.spanner.SpannerOptions) Spanner(com.google.cloud.spanner.Spanner)

Example 3 with InstanceAdminClient

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

the class CloudSpannerIT method createInstance.

private void createInstance() {
    InstanceAdminClient instanceAdminClient = spanner.getInstanceAdminClient();
    InstanceConfig config = instanceAdminClient.getInstanceConfig("regional-europe-west1");
    Instance instance = instanceAdminClient.newInstanceBuilder(InstanceId.of(getProject(), 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 InstanceAdminClient

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

the class InstanceConfigIT method testEuropeWestSingleNodeConfig.

@Test
public void testEuropeWestSingleNodeConfig() {
    String credentialsPath = "cloudspanner-emulator-key.json";
    String projectId = "test-project";
    GoogleCredentials credentials = null;
    try {
        credentials = CloudSpannerConnection.getCredentialsFromFile(credentialsPath);
    } catch (IOException e) {
        throw new RuntimeException("Could not read key file " + credentialsPath, e);
    }
    Builder builder = SpannerOptions.newBuilder();
    builder.setProjectId(projectId);
    builder.setCredentials(credentials);
    builder.setHost(CloudSpannerIT.getHost());
    SpannerOptions options = builder.build();
    Spanner spanner = options.getService();
    InstanceAdminClient instanceAdminClient = spanner.getInstanceAdminClient();
    InstanceConfig config = instanceAdminClient.getInstanceConfig("regional-europe-west1");
    assertEquals("regional-europe-west1", config.getId().getInstanceConfig());
    spanner.close();
}
Also used : InstanceConfig(com.google.cloud.spanner.InstanceConfig) InstanceAdminClient(com.google.cloud.spanner.InstanceAdminClient) Builder(com.google.cloud.spanner.SpannerOptions.Builder) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) IOException(java.io.IOException) SpannerOptions(com.google.cloud.spanner.SpannerOptions) Spanner(com.google.cloud.spanner.Spanner) IntegrationTest(nl.topicus.jdbc.test.category.IntegrationTest) Test(org.junit.Test)

Aggregations

InstanceAdminClient (com.google.cloud.spanner.InstanceAdminClient)4 InstanceConfig (com.google.cloud.spanner.InstanceConfig)3 Instance (com.google.cloud.spanner.Instance)2 Spanner (com.google.cloud.spanner.Spanner)2 SpannerOptions (com.google.cloud.spanner.SpannerOptions)2 CreateInstanceMetadata (com.google.spanner.admin.instance.v1.CreateInstanceMetadata)2 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)1 Builder (com.google.cloud.spanner.SpannerOptions.Builder)1 IOException (java.io.IOException)1 IntegrationTest (nl.topicus.jdbc.test.category.IntegrationTest)1 Test (org.junit.Test)1