Search in sources :

Example 16 with InstanceName

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.
    }
}
Also used : InstanceName(com.google.spanner.admin.instance.v1.InstanceName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 17 with InstanceName

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()));
}
Also used : InstanceName(com.google.spanner.admin.instance.v1.InstanceName) Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DeleteInstanceRequest(com.google.spanner.admin.instance.v1.DeleteInstanceRequest) Test(org.junit.Test)

Example 18 with InstanceName

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

Example 19 with InstanceName

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());
}
Also used : CreateDatabaseRequest(com.google.spanner.admin.database.v1.CreateDatabaseRequest) Database(com.google.spanner.admin.database.v1.Database) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) CreateDatabaseMetadata(com.google.spanner.admin.database.v1.CreateDatabaseMetadata) Timestamp(com.google.protobuf.Timestamp)

Example 20 with InstanceName

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

Aggregations

Test (org.junit.Test)44 AbstractMessage (com.google.protobuf.AbstractMessage)24 StatusRuntimeException (io.grpc.StatusRuntimeException)24 ByteString (com.google.protobuf.ByteString)21 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)20 InstanceName (com.google.bigtable.admin.v2.InstanceName)20 InstanceName (com.google.spanner.admin.database.v1.InstanceName)16 ExecutionException (java.util.concurrent.ExecutionException)11 Operation (com.google.longrunning.Operation)9 InstanceName (com.google.spanner.admin.instance.v1.InstanceName)9 ArrayList (java.util.ArrayList)7 Table (com.google.bigtable.admin.v2.Table)5 Database (com.google.spanner.admin.database.v1.Database)5 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)4 Backup (com.google.spanner.admin.database.v1.Backup)4 InstanceConfigName (com.google.spanner.admin.instance.v1.InstanceConfigName)4 IOException (java.io.IOException)4 ExpectedException (org.junit.rules.ExpectedException)4 AppProfile (com.google.bigtable.admin.v2.AppProfile)3 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)3