Search in sources :

Example 1 with CreateBackupRequest

use of com.google.spanner.admin.database.v1.CreateBackupRequest in project java-spanner by googleapis.

the class DatabaseAdminClientTest method createBackupTest.

@Test
public void createBackupTest() throws Exception {
    Backup expectedResponse = Backup.newBuilder().setDatabase(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString()).setVersionTime(Timestamp.newBuilder().build()).setExpireTime(Timestamp.newBuilder().build()).setName(BackupName.of("[PROJECT]", "[INSTANCE]", "[BACKUP]").toString()).setCreateTime(Timestamp.newBuilder().build()).setSizeBytes(-1796325715).addAllReferencingDatabases(new ArrayList<String>()).setEncryptionInfo(EncryptionInfo.newBuilder().build()).setDatabaseDialect(DatabaseDialect.forNumber(0)).build();
    Operation resultOperation = Operation.newBuilder().setName("createBackupTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockDatabaseAdmin.addResponse(resultOperation);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    Backup backup = Backup.newBuilder().build();
    String backupId = "backupId2121930365";
    Backup actualResponse = client.createBackupAsync(parent, backup, backupId).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateBackupRequest actualRequest = ((CreateBackupRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(backup, actualRequest.getBackup());
    Assert.assertEquals(backupId, actualRequest.getBackupId());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) CreateBackupRequest(com.google.spanner.admin.database.v1.CreateBackupRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Backup(com.google.spanner.admin.database.v1.Backup) ArrayList(java.util.ArrayList) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 2 with CreateBackupRequest

use of com.google.spanner.admin.database.v1.CreateBackupRequest in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method createBackupTest2.

@Test
public void createBackupTest2() throws Exception {
    Backup expectedResponse = Backup.newBuilder().setName(BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]").toString()).setSourceTable("sourceTable-95372173").setExpireTime(Timestamp.newBuilder().build()).setStartTime(Timestamp.newBuilder().build()).setEndTime(Timestamp.newBuilder().build()).setSizeBytes(-1796325715).setEncryptionInfo(EncryptionInfo.newBuilder().build()).build();
    Operation resultOperation = Operation.newBuilder().setName("createBackupTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableTableAdmin.addResponse(resultOperation);
    String parent = "parent-995424086";
    String backupId = "backupId2121930365";
    Backup backup = Backup.newBuilder().build();
    Backup actualResponse = client.createBackupAsync(parent, backupId, backup).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateBackupRequest actualRequest = ((CreateBackupRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(backupId, actualRequest.getBackupId());
    Assert.assertEquals(backup, actualRequest.getBackup());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : CreateBackupRequest(com.google.bigtable.admin.v2.CreateBackupRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Backup(com.google.bigtable.admin.v2.Backup) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 3 with CreateBackupRequest

use of com.google.spanner.admin.database.v1.CreateBackupRequest in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method createBackupTest.

@Test
public void createBackupTest() throws Exception {
    Backup expectedResponse = Backup.newBuilder().setName(BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]").toString()).setSourceTable("sourceTable-95372173").setExpireTime(Timestamp.newBuilder().build()).setStartTime(Timestamp.newBuilder().build()).setEndTime(Timestamp.newBuilder().build()).setSizeBytes(-1796325715).setEncryptionInfo(EncryptionInfo.newBuilder().build()).build();
    Operation resultOperation = Operation.newBuilder().setName("createBackupTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableTableAdmin.addResponse(resultOperation);
    ClusterName parent = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
    String backupId = "backupId2121930365";
    Backup backup = Backup.newBuilder().build();
    Backup actualResponse = client.createBackupAsync(parent, backupId, backup).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateBackupRequest actualRequest = ((CreateBackupRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(backupId, actualRequest.getBackupId());
    Assert.assertEquals(backup, actualRequest.getBackup());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : CreateBackupRequest(com.google.bigtable.admin.v2.CreateBackupRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Backup(com.google.bigtable.admin.v2.Backup) ClusterName(com.google.bigtable.admin.v2.ClusterName) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 4 with CreateBackupRequest

use of com.google.spanner.admin.database.v1.CreateBackupRequest 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 5 with CreateBackupRequest

use of com.google.spanner.admin.database.v1.CreateBackupRequest in project java-spanner by googleapis.

the class MockDatabaseAdminServiceImpl method createBackup.

@Override
public void createBackup(CreateBackupRequest request, StreamObserver<Operation> responseObserver) {
    requests.add(request);
    try {
        createBackupStartupExecutionTime.simulateExecutionTime(exceptions, false, freezeLock);
        String name = String.format("%s/backups/%s", request.getParent(), request.getBackupId());
        MockDatabase db = databases.get(request.getBackup().getDatabase());
        if (db == null) {
            responseObserver.onError(Status.NOT_FOUND.withDescription(String.format("Database with name %s not found", request.getBackup().getDatabase())).asRuntimeException());
            return;
        }
        MockBackup bck = new MockBackup(name, request.getBackup(), db);
        if (backups.putIfAbsent(name, bck) == null) {
            CreateBackupMetadata metadata = CreateBackupMetadata.newBuilder().setName(name).setDatabase(bck.database).setProgress(OperationProgress.newBuilder().setStartTime(Timestamp.newBuilder().setSeconds(System.currentTimeMillis() / 1000L).build()).setProgressPercent(0)).build();
            Operation operation = Operation.newBuilder().setMetadata(Any.pack(metadata)).setResponse(Any.pack(bck.toProto())).setName(operations.generateOperationName(name)).build();
            operations.addOperation(operation, new CreateBackupCallable(operation.getName(), name));
            createBackupResponseExecutionTime.simulateExecutionTime(exceptions, false, freezeLock);
            responseObserver.onNext(operation);
            responseObserver.onCompleted();
        } else {
            responseObserver.onError(Status.ALREADY_EXISTS.withDescription(String.format("Backup with name %s already exists", name)).asRuntimeException());
        }
    } catch (Throwable t) {
        responseObserver.onError(t);
    }
}
Also used : CreateBackupMetadata(com.google.spanner.admin.database.v1.CreateBackupMetadata) Operation(com.google.longrunning.Operation)

Aggregations

Operation (com.google.longrunning.Operation)5 AbstractMessage (com.google.protobuf.AbstractMessage)4 ByteString (com.google.protobuf.ByteString)4 Backup (com.google.spanner.admin.database.v1.Backup)4 CreateBackupRequest (com.google.spanner.admin.database.v1.CreateBackupRequest)4 Test (org.junit.Test)4 CreateBackupMetadata (com.google.spanner.admin.database.v1.CreateBackupMetadata)3 Backup (com.google.bigtable.admin.v2.Backup)2 CreateBackupRequest (com.google.bigtable.admin.v2.CreateBackupRequest)2 ArrayList (java.util.ArrayList)2 CancelledException (com.google.api.gax.rpc.CancelledException)1 ClusterName (com.google.bigtable.admin.v2.ClusterName)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 InstanceName (com.google.spanner.admin.database.v1.InstanceName)1 ExecutionException (java.util.concurrent.ExecutionException)1