Search in sources :

Example 11 with DatabaseName

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) DatabaseName(com.google.firestore.admin.v1.DatabaseName) ExportDocumentsRequest(com.google.firestore.admin.v1.ExportDocumentsRequest) ExportDocumentsResponse(com.google.firestore.admin.v1.ExportDocumentsResponse) Operation(com.google.longrunning.Operation) Test(org.junit.Test)

Example 12 with DatabaseName

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());
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) GetDatabaseDdlRequest(com.google.spanner.admin.database.v1.GetDatabaseDdlRequest)

Example 13 with DatabaseName

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());
}
Also used : CreateBackupRequest(com.google.spanner.admin.database.v1.CreateBackupRequest) Backup(com.google.spanner.admin.database.v1.Backup) CreateBackupMetadata(com.google.spanner.admin.database.v1.CreateBackupMetadata) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

Example 14 with DatabaseName

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;
    });
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) DropDatabaseRequest(com.google.spanner.admin.database.v1.DropDatabaseRequest)

Example 15 with DatabaseName

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)));
}
Also used : GetDatabaseRequest(com.google.spanner.admin.database.v1.GetDatabaseRequest) GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext)

Aggregations

Test (org.junit.Test)19 AbstractMessage (com.google.protobuf.AbstractMessage)10 DatabaseName (com.google.spanner.admin.database.v1.DatabaseName)10 StatusRuntimeException (io.grpc.StatusRuntimeException)10 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)9 DatabaseName (com.google.spanner.v1.DatabaseName)7 ArrayList (java.util.ArrayList)6 Empty (com.google.protobuf.Empty)5 ExecutionException (java.util.concurrent.ExecutionException)5 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)4 DatabaseName (com.google.firestore.admin.v1.DatabaseName)4 Operation (com.google.longrunning.Operation)3 DropDatabaseRequest (com.google.spanner.admin.database.v1.DropDatabaseRequest)3 Session (com.google.spanner.v1.Session)3 ByteString (com.google.protobuf.ByteString)2 Database (com.google.spanner.admin.database.v1.Database)2 GetDatabaseDdlRequest (com.google.spanner.admin.database.v1.GetDatabaseDdlRequest)2 GetDatabaseRequest (com.google.spanner.admin.database.v1.GetDatabaseRequest)2 UpdateDatabaseDdlRequest (com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest)2 ListSessionsRequest (com.google.spanner.v1.ListSessionsRequest)2