use of com.google.spanner.admin.instance.v1.InstanceConfig in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerClient method initializeInstance.
private void initializeInstance(InstanceId instanceId) {
InstanceConfig instanceConfig = Iterators.get(spClient.getInstanceAdminClient().listInstanceConfigs().iterateAll().iterator(), // us-east1
32, null);
checkState(instanceConfig != null, "No instance configs found");
InstanceConfigId configId = instanceConfig.getId();
logger.log(Level.INFO, "Creating instance using config {0}", configId);
InstanceInfo instance = InstanceInfo.newBuilder(instanceId).setNodeCount(1).setDisplayName("Test instance").setInstanceConfigId(configId).build();
OperationFuture<Instance, CreateInstanceMetadata> op = spClient.getInstanceAdminClient().createInstance(instance);
Instance createdInstance;
try {
createdInstance = op.get();
} catch (Exception e) {
boolean cancelled = false;
try {
// Try to cancel the createInstance operation.
spClient.getInstanceAdminClient().cancelOperation(op.getName());
com.google.longrunning.Operation createOperation = spClient.getInstanceAdminClient().getOperation(op.getName());
cancelled = createOperation.hasError() && createOperation.getError().getCode() == Status.CANCELLED.getCode().value();
if (cancelled) {
logger.info("Cancelled the createInstance operation because the operation failed");
} else {
logger.info("Tried to cancel the createInstance operation because the operation failed, but the" + " operation could not be cancelled. Current status: " + createOperation.getError().getCode());
}
} catch (Throwable t) {
logger.log(Level.WARNING, "Failed to cancel the createInstance operation", t);
}
if (!cancelled) {
try {
spClient.getInstanceAdminClient().deleteInstance(instanceId.getInstance());
logger.info("Deleted the test instance because the createInstance operation failed and" + " cancelling the operation did not succeed");
} catch (Throwable t) {
logger.log(Level.WARNING, "Failed to delete the test instance", t);
}
}
throw SpannerExceptionFactory.newSpannerException(e);
}
logger.log(Level.INFO, "Created test instance: {0}", createdInstance.getId());
}
use of com.google.spanner.admin.instance.v1.InstanceConfig in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerIntegrationTest method initializeInstance.
private static void initializeInstance(InstanceAdminClient instanceAdminClient, InstanceId instanceId) {
InstanceConfig instanceConfig = Iterators.get(instanceAdminClient.listInstanceConfigs().iterateAll().iterator(), 0, null);
checkState(instanceConfig != null, "No instance configs found");
InstanceConfigId configId = instanceConfig.getId();
InstanceInfo instance = InstanceInfo.newBuilder(instanceId).setNodeCount(1).setDisplayName("grpc-gcp test instance").setInstanceConfigId(configId).build();
OperationFuture<Instance, CreateInstanceMetadata> op = instanceAdminClient.createInstance(instance);
try {
op.get();
} catch (Exception e) {
throw SpannerExceptionFactory.newSpannerException(e);
}
}
use of com.google.spanner.admin.instance.v1.InstanceConfig in project google-cloud-java by GoogleCloudPlatform.
the class GrpcSpannerRpc method listInstanceConfigs.
@Override
public Paginated<InstanceConfig> listInstanceConfigs(int pageSize, @Nullable String pageToken) throws SpannerException {
ListInstanceConfigsRequest.Builder request = ListInstanceConfigsRequest.newBuilder().setParent(projectName()).setPageSize(0);
if (pageToken != null) {
request.setPageToken(pageToken);
}
ListInstanceConfigsResponse response = get(doUnaryCall(InstanceAdminGrpc.METHOD_LIST_INSTANCE_CONFIGS, request.build(), projectName(), null));
return new Paginated<>(response.getInstanceConfigsList(), response.getNextPageToken());
}
use of com.google.spanner.admin.instance.v1.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();
}
use of com.google.spanner.admin.instance.v1.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();
}
Aggregations