Search in sources :

Example 1 with InstanceConfig

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

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

the class ITInstanceAdminTest method instanceConfigOperations.

@Test
public void instanceConfigOperations() {
    List<InstanceConfig> configs = new ArrayList<>();
    Iterators.addAll(configs, instanceClient.listInstanceConfigs().iterateAll().iterator());
    assertThat(configs.isEmpty()).isFalse();
    InstanceConfig config = instanceClient.getInstanceConfig(configs.get(0).getId().getInstanceConfig());
    assertThat(config.getId()).isEqualTo(configs.get(0).getId());
    config = config.reload();
    assertThat(config.getId()).isEqualTo(configs.get(0).getId());
}
Also used : InstanceConfig(com.google.cloud.spanner.InstanceConfig) ArrayList(java.util.ArrayList) Test(org.junit.Test) IntegrationTest(com.google.cloud.spanner.IntegrationTest)

Example 3 with InstanceConfig

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

the class InstanceAdminClientSnippets method getInstanceConfig.

/**
 * Example to get instance config.
 */
public InstanceConfig getInstanceConfig(final String my_config_id) {
    // [START instance_admin_client_get_instance_config]
    final String configId = my_config_id;
    InstanceConfig instanceConfig = instanceAdminClient.getInstanceConfig(configId);
    // [END instance_admin_client_get_instance_config]
    return instanceConfig;
}
Also used : InstanceConfig(com.google.cloud.spanner.InstanceConfig)

Example 4 with InstanceConfig

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

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

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