use of com.google.spanner.admin.database.v1.InstanceName in project java-spanner by googleapis.
the class InstanceAdminClientTest method deleteInstanceExceptionTest.
@Test
public void deleteInstanceExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockInstanceAdmin.addException(exception);
try {
InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
client.deleteInstance(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.spanner.admin.database.v1.InstanceName in project java-spanner by googleapis.
the class InstanceAdminClientTest method deleteInstanceTest.
@Test
public void deleteInstanceTest() throws Exception {
Empty expectedResponse = Empty.newBuilder().build();
mockInstanceAdmin.addResponse(expectedResponse);
InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
client.deleteInstance(name);
List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteInstanceRequest actualRequest = ((DeleteInstanceRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.admin.database.v1.InstanceName in project java-spanner by googleapis.
the class GapicSpannerRpc method listDatabaseOperations.
@Override
public Paginated<Operation> listDatabaseOperations(String instanceName, int pageSize, @Nullable String filter, @Nullable String pageToken) {
acquireAdministrativeRequestsRateLimiter();
ListDatabaseOperationsRequest.Builder requestBuilder = ListDatabaseOperationsRequest.newBuilder().setParent(instanceName).setPageSize(pageSize);
if (filter != null) {
requestBuilder.setFilter(filter);
}
if (pageToken != null) {
requestBuilder.setPageToken(pageToken);
}
final ListDatabaseOperationsRequest request = requestBuilder.build();
final GrpcCallContext context = newCallContext(null, instanceName, request, DatabaseAdminGrpc.getListDatabaseOperationsMethod());
ListDatabaseOperationsResponse response = runWithRetryOnAdministrativeRequestsExceeded(() -> get(databaseAdminStub.listDatabaseOperationsCallable().futureCall(request, context)));
return new Paginated<>(response.getOperationsList(), response.getNextPageToken());
}
use of com.google.spanner.admin.database.v1.InstanceName in project java-spanner by googleapis.
the class GapicSpannerRpc method createDatabase.
@Override
public OperationFuture<Database, CreateDatabaseMetadata> createDatabase(final String instanceName, String createDatabaseStatement, Iterable<String> additionalStatements, com.google.cloud.spanner.Database databaseInfo) throws SpannerException {
final String databaseId = databaseInfo.getId().getDatabase();
CreateDatabaseRequest.Builder requestBuilder = CreateDatabaseRequest.newBuilder().setParent(instanceName).setCreateStatement(createDatabaseStatement).addAllExtraStatements(additionalStatements);
if (databaseInfo.getEncryptionConfig() != null) {
requestBuilder.setEncryptionConfig(EncryptionConfigProtoMapper.encryptionConfig(databaseInfo.getEncryptionConfig()));
}
if (databaseInfo.getDialect() != null) {
requestBuilder.setDatabaseDialect(databaseInfo.getDialect().toProto());
}
final CreateDatabaseRequest request = requestBuilder.build();
OperationFutureCallable<CreateDatabaseRequest, Database, CreateDatabaseMetadata> callable = new OperationFutureCallable<>(databaseAdminStub.createDatabaseOperationCallable(), request, DatabaseAdminGrpc.getCreateDatabaseMethod(), instanceName, nextPageToken -> listDatabaseOperations(instanceName, 0, String.format("(metadata.@type:type.googleapis.com/%s) AND (name:%s/operations/)", CreateDatabaseMetadata.getDescriptor().getFullName(), String.format("%s/databases/%s", instanceName, databaseId)), nextPageToken), input -> {
if (input.getDone() && input.hasResponse()) {
try {
Timestamp createTime = input.getResponse().unpack(Database.class).getCreateTime();
if (Timestamp.getDefaultInstance().equals(createTime)) {
// method to indicate that there is no known create time.
return null;
}
} catch (InvalidProtocolBufferException e) {
return null;
}
}
return null;
});
return RetryHelper.runWithRetries(callable, databaseAdminStubSettings.createDatabaseOperationSettings().getInitialCallSettings().getRetrySettings(), new OperationFutureRetryAlgorithm<>(), NanoClock.getDefaultClock());
}
use of com.google.spanner.admin.database.v1.InstanceName in project java-spanner by googleapis.
the class GapicSpannerRpc method listDatabases.
@Override
public Paginated<Database> listDatabases(String instanceName, int pageSize, @Nullable String pageToken) throws SpannerException {
acquireAdministrativeRequestsRateLimiter();
ListDatabasesRequest.Builder requestBuilder = ListDatabasesRequest.newBuilder().setParent(instanceName).setPageSize(pageSize);
if (pageToken != null) {
requestBuilder.setPageToken(pageToken);
}
final ListDatabasesRequest request = requestBuilder.build();
final GrpcCallContext context = newCallContext(null, instanceName, request, DatabaseAdminGrpc.getListDatabasesMethod());
ListDatabasesResponse response = runWithRetryOnAdministrativeRequestsExceeded(() -> get(databaseAdminStub.listDatabasesCallable().futureCall(request, context)));
return new Paginated<>(response.getDatabasesList(), response.getNextPageToken());
}
Aggregations