diff --git a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/InstanceAdminClient.java b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/InstanceAdminClient.java
index 520d5b048815..4a046cc40c9f 100644
--- a/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/InstanceAdminClient.java
+++ b/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/InstanceAdminClient.java
@@ -25,9 +25,23 @@
public interface InstanceAdminClient {
/** Gets an instance config. */
+ /*
+ *
{@code
+ * final String configId = my_config_id;
+ * InstanceConfig instanceConfig = instanceAdminClient.getInstanceConfig(configId);
+ * }
+ *
+ */
InstanceConfig getInstanceConfig(String configId) throws SpannerException;
/** Lists the supported instance configs for current project. */
+ /*
+ * {@code
+ * List configs =
+ * Lists.newArrayList(instanceAdminClient.listInstanceConfigs(Options.pageSize(1)).iterateAll());
+ * }
+ *
+ */
Page listInstanceConfigs(ListOption... options) throws SpannerException;
/**
@@ -58,11 +72,35 @@ public interface InstanceAdminClient {
* Databases can be created in the instance.
* The instance's allocated resource levels are readable via the
*
+ *
+ *
+ * {@code
+ * final String instanceId = my_instance_id;
+ * final String configId = my_config_id;
+ * final String clientProject = my_client_project;
+ *
+ * Operation op =
+ * instanceAdminClient.createInstance(InstanceInfo
+ * .newBuilder(InstanceId.of(clientProject, instanceId))
+ * .setInstanceConfigId(InstanceConfigId.of(clientProject, configId))
+ * .setDisplayName(instanceId)
+ * .setNodeCount(1)
+ * .build());
+ * op.waitFor();
+ * }
+ *
*/
Operation createInstance(InstanceInfo instance)
throws SpannerException;
/** Gets an instance. */
+ /*
+ * {@code
+ * final String instanceId = my_instance_id;
+ * Instance ins = instanceAdminClient.getInstance(instanceId);
+ * }
+ *
+ */
Instance getInstance(String instanceId) throws SpannerException;
/**
@@ -75,10 +113,25 @@ Operation createInstance(InstanceInfo instance
* display_name
* labels.key where key is the name of a label
*
+ *
+ *
+ * {@code
+ * List instances =
+ * Lists.newArrayList(
+ * instanceAdminClient.listInstances(Options.pageSize(1)).iterateAll());
+ * }
+ *
*/
Page listInstances(ListOption... options) throws SpannerException;
/** Deletes an instance. */
+ /*
+ * {@code
+ * final String instanceId = my_instance_id;
+ * instanceAdminClient.deleteInstance(instanceId);
+ * }
+ *
+ */
void deleteInstance(String instanceId) throws SpannerException;
/**
@@ -112,6 +165,26 @@ Operation createInstance(InstanceInfo instance
* All newly-reserved resources are available for serving the instance's tables.
* The instance's new resource levels are readable via the API.
*
+ *
+ *
+ * {@code
+ * 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
+ * Operation op =
+ * instanceAdminClient.updateInstance(toUpdate, InstanceInfo.InstanceField.DISPLAY_NAME);
+ * op.waitFor().getResult();
+ * }
+ *
*/
Operation updateInstance(
InstanceInfo instance, InstanceInfo.InstanceField... fieldsToUpdate);
diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriberSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriberSnippets.java
index 642d571f67d0..b31862a690b5 100644
--- a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriberSnippets.java
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/SubscriberSnippets.java
@@ -184,7 +184,7 @@ private Subscriber createSubscriberWithCustomCredentials() throws Exception {
Subscriber.newBuilder(subscriptionName, receiver)
.setCredentialsProvider(credentialsProvider)
.build();
- // [START pubsub_subscriber_custom_credentials]
+ // [END pubsub_subscriber_custom_credentials]
return subscriber;
}
diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/InstanceAdminClientSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/InstanceAdminClientSnippets.java
new file mode 100644
index 000000000000..501a28fc7280
--- /dev/null
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/InstanceAdminClientSnippets.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright 2018 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * EDITING INSTRUCTIONS
+ * This file is referenced in spanner/InstanceAdminClient's javadoc. Any change
+ * to this file should be reflected in spanner/InstanceAdminClient's javadoc.
+ */
+
+package com.google.cloud.examples.spanner.snippets;
+
+import com.google.cloud.spanner.Instance;
+import com.google.cloud.spanner.InstanceAdminClient;
+import com.google.cloud.spanner.InstanceConfig;
+import com.google.cloud.spanner.InstanceConfigId;
+import com.google.cloud.spanner.InstanceId;
+import com.google.cloud.spanner.InstanceInfo;
+import com.google.cloud.spanner.Operation;
+import com.google.cloud.spanner.Options;
+import com.google.common.collect.Lists;
+import com.google.spanner.admin.instance.v1.CreateInstanceMetadata;
+import com.google.spanner.admin.instance.v1.UpdateInstanceMetadata;
+import java.util.List;
+
+/**
+ * This class contains snippets for {@link InstanceAdminClient} interface.
+ */
+public class InstanceAdminClientSnippets {
+
+ private final InstanceAdminClient instanceAdminClient;
+
+ public InstanceAdminClientSnippets(InstanceAdminClient instanceAdminClient) {
+ this.instanceAdminClient = instanceAdminClient;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Example to list instance configs.
+ */
+ public List listInstanceConfigs() {
+ // [START instance_admin_client_list_configs]
+ List configs =
+ Lists.newArrayList(instanceAdminClient.listInstanceConfigs(Options.pageSize(1)).iterateAll());
+ // [END instance_admin_client_list_configs]
+ return configs;
+ }
+
+ /**
+ * Example to create an instance.
+ */
+ public void createInstance(
+ final String my_instance_id,
+ final String my_config_id,
+ final String my_client_project) {
+ // [START instance_admin_client_create_instance]
+ final String instanceId = my_instance_id;
+ final String configId = my_config_id;
+ final String clientProject = my_client_project;
+
+ Operation op =
+ instanceAdminClient.createInstance(InstanceInfo
+ .newBuilder(InstanceId.of(clientProject, instanceId))
+ .setInstanceConfigId(InstanceConfigId.of(clientProject, configId))
+ .setDisplayName(instanceId)
+ .setNodeCount(1)
+ .build());
+ op.waitFor();
+ // [END instance_admin_client_create_instance]
+ }
+
+ /**
+ * Example to get an instance.
+ */
+ public Instance getInstance(final String my_instance_id) {
+ // [START instance_admin_client_get_instance]
+ final String instanceId = my_instance_id;
+ Instance ins = instanceAdminClient.getInstance(instanceId);
+ // [END instance_admin_client_get_instance]
+ return ins;
+ }
+
+ /**
+ * Example to list instances.
+ */
+ public List listInstances() {
+ // [START instance_admin_client_list_instances]
+ List instances =
+ Lists.newArrayList(
+ instanceAdminClient.listInstances(Options.pageSize(1)).iterateAll());
+ // [END instance_admin_client_list_instances]
+ return instances;
+ }
+
+ /**
+ * Example to delete an instance.
+ */
+ public void deleteInstance(final String my_instance_id) {
+ // [START instance_admin_client_delete_instance]
+ final String instanceId = my_instance_id;
+ instanceAdminClient.deleteInstance(instanceId);
+ // [END instance_admin_client_delete_instance]
+ }
+
+ /**
+ * 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
+ Operation op =
+ instanceAdminClient.updateInstance(toUpdate, InstanceInfo.InstanceField.DISPLAY_NAME);
+ op.waitFor().getResult();
+ // [END instance_admin_client_update_instance]
+ }
+}
+