use of com.google.spanner.admin.database.v1.DatabaseName in project java-firestore by googleapis.
the class FirestoreAdminClientTest method exportDocumentsTest.
@Test
public void exportDocumentsTest() throws Exception {
ExportDocumentsResponse expectedResponse = ExportDocumentsResponse.newBuilder().setOutputUriPrefix("outputUriPrefix499858205").build();
Operation resultOperation = Operation.newBuilder().setName("exportDocumentsTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockFirestoreAdmin.addResponse(resultOperation);
DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
ExportDocumentsResponse actualResponse = client.exportDocumentsAsync(name).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ExportDocumentsRequest actualRequest = ((ExportDocumentsRequest) 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.DatabaseName in project java-spanner by googleapis.
the class GapicSpannerRpc method getDatabaseDdl.
@Override
public List<String> getDatabaseDdl(String databaseName) throws SpannerException {
acquireAdministrativeRequestsRateLimiter();
final GetDatabaseDdlRequest request = GetDatabaseDdlRequest.newBuilder().setDatabase(databaseName).build();
final GrpcCallContext context = newCallContext(null, databaseName, request, DatabaseAdminGrpc.getGetDatabaseDdlMethod());
return runWithRetryOnAdministrativeRequestsExceeded(() -> get(databaseAdminStub.getDatabaseDdlCallable().futureCall(request, context)).getStatementsList());
}
use of com.google.spanner.admin.database.v1.DatabaseName in project java-spanner by googleapis.
the class GapicSpannerRpc method createBackup.
@Override
public OperationFuture<Backup, CreateBackupMetadata> createBackup(final com.google.cloud.spanner.Backup backupInfo) throws SpannerException {
final String instanceName = backupInfo.getInstanceId().getName();
final String databaseName = backupInfo.getDatabase().getName();
final String backupId = backupInfo.getId().getBackup();
final Backup.Builder backupBuilder = com.google.spanner.admin.database.v1.Backup.newBuilder().setDatabase(databaseName).setExpireTime(backupInfo.getExpireTime().toProto());
if (backupInfo.getVersionTime() != null) {
backupBuilder.setVersionTime(backupInfo.getVersionTime().toProto());
}
final Backup backup = backupBuilder.build();
final CreateBackupRequest.Builder requestBuilder = CreateBackupRequest.newBuilder().setParent(instanceName).setBackupId(backupId).setBackup(backup);
if (backupInfo.getEncryptionConfig() != null) {
requestBuilder.setEncryptionConfig(EncryptionConfigProtoMapper.createBackupEncryptionConfig(backupInfo.getEncryptionConfig()));
}
final CreateBackupRequest request = requestBuilder.build();
final OperationFutureCallable<CreateBackupRequest, Backup, CreateBackupMetadata> callable = new OperationFutureCallable<>(databaseAdminStub.createBackupOperationCallable(), request, DatabaseAdminGrpc.getCreateBackupMethod(), instanceName, nextPageToken -> listBackupOperations(instanceName, 0, String.format("(metadata.@type:type.googleapis.com/%s) AND (metadata.name:%s)", CreateBackupMetadata.getDescriptor().getFullName(), String.format("%s/backups/%s", instanceName, backupId)), nextPageToken), input -> {
try {
return input.getMetadata().unpack(CreateBackupMetadata.class).getProgress().getStartTime();
} catch (InvalidProtocolBufferException e) {
return null;
}
});
return RetryHelper.runWithRetries(callable, databaseAdminStubSettings.createBackupOperationSettings().getInitialCallSettings().getRetrySettings(), new OperationFutureRetryAlgorithm<>(), NanoClock.getDefaultClock());
}
use of com.google.spanner.admin.database.v1.DatabaseName in project java-spanner by googleapis.
the class GapicSpannerRpc method dropDatabase.
@Override
public void dropDatabase(String databaseName) throws SpannerException {
acquireAdministrativeRequestsRateLimiter();
final DropDatabaseRequest request = DropDatabaseRequest.newBuilder().setDatabase(databaseName).build();
final GrpcCallContext context = newCallContext(null, databaseName, request, DatabaseAdminGrpc.getDropDatabaseMethod());
runWithRetryOnAdministrativeRequestsExceeded(() -> {
get(databaseAdminStub.dropDatabaseCallable().futureCall(request, context));
return null;
});
}
use of com.google.spanner.admin.database.v1.DatabaseName in project java-spanner by googleapis.
the class GapicSpannerRpc method getDatabase.
@Override
public Database getDatabase(String databaseName) throws SpannerException {
acquireAdministrativeRequestsRateLimiter();
final GetDatabaseRequest request = GetDatabaseRequest.newBuilder().setName(databaseName).build();
final GrpcCallContext context = newCallContext(null, databaseName, request, DatabaseAdminGrpc.getGetDatabaseMethod());
return runWithRetryOnAdministrativeRequestsExceeded(() -> get(databaseAdminStub.getDatabaseCallable().futureCall(request, context)));
}
Aggregations