Search in sources :

Example 1 with ListBackupOperationsResponse

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

the class MockDatabaseAdminServiceImpl method listBackupOperations.

@Override
public void listBackupOperations(ListBackupOperationsRequest request, StreamObserver<ListBackupOperationsResponse> responseObserver) {
    requests.add(request);
    ListBackupOperationsResponse.Builder builder = ListBackupOperationsResponse.newBuilder();
    try {
        for (Operation op : operations.iterable()) {
            if (op.getName().matches(".*?/backups/.*?/operations/.*?") && op.getName().startsWith(request.getParent())) {
                if (matchesFilter(op, request.getFilter())) {
                    builder.addOperations(op);
                }
            }
        }
        responseObserver.onNext(builder.build());
        responseObserver.onCompleted();
    } catch (Exception e) {
        responseObserver.onError(e);
    }
}
Also used : ListBackupOperationsResponse(com.google.spanner.admin.database.v1.ListBackupOperationsResponse) Operation(com.google.longrunning.Operation)

Example 2 with ListBackupOperationsResponse

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

the class DatabaseAdminClientTest method listBackupOperationsTest.

@Test
public void listBackupOperationsTest() throws Exception {
    Operation responsesElement = Operation.newBuilder().build();
    ListBackupOperationsResponse expectedResponse = ListBackupOperationsResponse.newBuilder().setNextPageToken("").addAllOperations(Arrays.asList(responsesElement)).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    ListBackupOperationsPagedResponse pagedListResponse = client.listBackupOperations(parent);
    List<Operation> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getOperationsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListBackupOperationsRequest actualRequest = ((ListBackupOperationsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) ListBackupOperationsResponse(com.google.spanner.admin.database.v1.ListBackupOperationsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Operation(com.google.longrunning.Operation) ListBackupOperationsRequest(com.google.spanner.admin.database.v1.ListBackupOperationsRequest) ListBackupOperationsPagedResponse(com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupOperationsPagedResponse) Test(org.junit.Test)

Example 3 with ListBackupOperationsResponse

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

Example 4 with ListBackupOperationsResponse

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

the class DatabaseAdminClientTest method listBackupOperationsTest2.

@Test
public void listBackupOperationsTest2() throws Exception {
    Operation responsesElement = Operation.newBuilder().build();
    ListBackupOperationsResponse expectedResponse = ListBackupOperationsResponse.newBuilder().setNextPageToken("").addAllOperations(Arrays.asList(responsesElement)).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListBackupOperationsPagedResponse pagedListResponse = client.listBackupOperations(parent);
    List<Operation> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getOperationsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListBackupOperationsRequest actualRequest = ((ListBackupOperationsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListBackupOperationsResponse(com.google.spanner.admin.database.v1.ListBackupOperationsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) ListBackupOperationsRequest(com.google.spanner.admin.database.v1.ListBackupOperationsRequest) ListBackupOperationsPagedResponse(com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupOperationsPagedResponse) Test(org.junit.Test)

Aggregations

ListBackupOperationsResponse (com.google.spanner.admin.database.v1.ListBackupOperationsResponse)4 Operation (com.google.longrunning.Operation)3 ListBackupOperationsRequest (com.google.spanner.admin.database.v1.ListBackupOperationsRequest)3 ListBackupOperationsPagedResponse (com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupOperationsPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)1 ByteString (com.google.protobuf.ByteString)1 InstanceName (com.google.spanner.admin.database.v1.InstanceName)1