use of com.google.spanner.admin.database.v1.InstanceName in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method createTableFromSnapshotTest2.
@Test
public void createTableFromSnapshotTest2() throws Exception {
Table expectedResponse = Table.newBuilder().setName(TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString()).putAllClusterStates(new HashMap<String, Table.ClusterState>()).putAllColumnFamilies(new HashMap<String, ColumnFamily>()).setRestoreInfo(RestoreInfo.newBuilder().build()).build();
Operation resultOperation = Operation.newBuilder().setName("createTableFromSnapshotTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockBigtableTableAdmin.addResponse(resultOperation);
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
String tableId = "tableId-1552905847";
String sourceSnapshot = "sourceSnapshot-1078634753";
Table actualResponse = client.createTableFromSnapshotAsync(parent, tableId, sourceSnapshot).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateTableFromSnapshotRequest actualRequest = ((CreateTableFromSnapshotRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(tableId, actualRequest.getTableId());
Assert.assertEquals(sourceSnapshot, actualRequest.getSourceSnapshot());
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 listBackups.
@Override
public Paginated<Backup> listBackups(String instanceName, int pageSize, @Nullable String filter, @Nullable String pageToken) throws SpannerException {
acquireAdministrativeRequestsRateLimiter();
ListBackupsRequest.Builder requestBuilder = ListBackupsRequest.newBuilder().setParent(instanceName).setPageSize(pageSize);
if (filter != null) {
requestBuilder.setFilter(filter);
}
if (pageToken != null) {
requestBuilder.setPageToken(pageToken);
}
final ListBackupsRequest request = requestBuilder.build();
final GrpcCallContext context = newCallContext(null, instanceName, request, DatabaseAdminGrpc.getListBackupsMethod());
ListBackupsResponse response = runWithRetryOnAdministrativeRequestsExceeded(() -> get(databaseAdminStub.listBackupsCallable().futureCall(request, context)));
return new Paginated<>(response.getBackupsList(), response.getNextPageToken());
}
use of com.google.spanner.admin.database.v1.InstanceName 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.InstanceName in project java-spanner by googleapis.
the class GapicSpannerRpc method listBackupOperations.
@Override
public Paginated<Operation> listBackupOperations(String instanceName, int pageSize, @Nullable String filter, @Nullable String pageToken) {
acquireAdministrativeRequestsRateLimiter();
ListBackupOperationsRequest.Builder requestBuilder = ListBackupOperationsRequest.newBuilder().setParent(instanceName).setPageSize(pageSize);
if (filter != null) {
requestBuilder.setFilter(filter);
}
if (pageToken != null) {
requestBuilder.setPageToken(pageToken);
}
final ListBackupOperationsRequest request = requestBuilder.build();
final GrpcCallContext context = newCallContext(null, instanceName, request, DatabaseAdminGrpc.getListBackupOperationsMethod());
ListBackupOperationsResponse response = runWithRetryOnAdministrativeRequestsExceeded(() -> get(databaseAdminStub.listBackupOperationsCallable().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 DatabaseAdminGaxTest method listDatabasesTest.
@Test
public void listDatabasesTest() {
Exception exception = setupException();
String nextPageToken = "token%d";
List<com.google.spanner.admin.database.v1.Database> databases = new ArrayList<>(2);
for (int i = 0; i < 2; i++) {
databases.add(com.google.spanner.admin.database.v1.Database.newBuilder().setName(String.format("projects/%s/instances/%s/databases/test%d", PROJECT, INSTANCE, i)).build());
}
if (exceptionAtCall == 0) {
mockDatabaseAdmin.addException(exception);
}
for (int i = 0; i < 2; i++) {
ListDatabasesResponse.Builder builder = ListDatabasesResponse.newBuilder().addAllDatabases(Collections.singletonList(databases.get(i)));
if (i < (databases.size() - 1)) {
builder.setNextPageToken(String.format(nextPageToken, i));
}
if (exceptionAtCall == (i + 1)) {
mockDatabaseAdmin.addException(exception);
}
mockDatabaseAdmin.addResponse(builder.build());
}
InstanceName parent = InstanceName.of(PROJECT, INSTANCE);
Page<Database> pagedListResponse = client.listDatabases(INSTANCE);
List<Database> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(2, resources.size());
List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
Assert.assertEquals(2, actualRequests.size());
ListDatabasesRequest actualRequest = (ListDatabasesRequest) actualRequests.get(0);
Assert.assertEquals(parent, InstanceName.parse(actualRequest.getParent()));
}
Aggregations