Search in sources :

Example 21 with DatabaseName

use of com.google.firestore.admin.v1.DatabaseName in project cloud-spanner-r2dbc by GoogleCloudPlatform.

the class SessionCleanupUtils method getSessionNames.

private static List<String> getSessionNames() throws Exception {
    String databaseName = DatabaseName.format(ServiceOptions.getDefaultProjectId(), DatabaseProperties.INSTANCE, DatabaseProperties.DATABASE);
    String nextPageToken = null;
    List<String> sessionNames = new ArrayList<>();
    do {
        ListSessionsRequest.Builder requestBuilder = ListSessionsRequest.newBuilder().setDatabase(databaseName);
        if (nextPageToken != null) {
            requestBuilder.setPageToken(nextPageToken);
        }
        ListSessionsResponse listSessionsResponse = ObservableReactiveUtil.<ListSessionsResponse>unaryCall(obs -> spannerStub.listSessions(requestBuilder.build(), obs)).block();
        nextPageToken = listSessionsResponse.getNextPageToken();
        sessionNames.addAll(listSessionsResponse.getSessionsList().stream().map(Session::getName).collect(Collectors.toList()));
    } while (nextPageToken != null && !"".equals(nextPageToken));
    return sessionNames;
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) Session(com.google.spanner.v1.Session) SpannerStub(com.google.spanner.v1.SpannerGrpc.SpannerStub) ManagedChannel(io.grpc.ManagedChannel) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) DeleteSessionRequest(com.google.spanner.v1.DeleteSessionRequest) ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) MoreCallCredentials(io.grpc.auth.MoreCallCredentials) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ObservableReactiveUtil(com.google.cloud.spanner.r2dbc.util.ObservableReactiveUtil) Empty(com.google.protobuf.Empty) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) ListSessionsRequest(com.google.spanner.v1.ListSessionsRequest) List(java.util.List) StreamObserver(io.grpc.stub.StreamObserver) ServiceOptions(com.google.cloud.ServiceOptions) DatabaseName(com.google.spanner.v1.DatabaseName) SpannerGrpc(com.google.spanner.v1.SpannerGrpc) ArrayList(java.util.ArrayList) ListSessionsRequest(com.google.spanner.v1.ListSessionsRequest) Session(com.google.spanner.v1.Session)

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 DatabaseName (com.google.firestore.admin.v1.DatabaseName)4 Empty (com.google.protobuf.Empty)4 ExecutionException (java.util.concurrent.ExecutionException)4 Operation (com.google.longrunning.Operation)3 Session (com.google.spanner.v1.Session)3 ByteString (com.google.protobuf.ByteString)2 Database (com.google.spanner.admin.database.v1.Database)2 ListSessionsRequest (com.google.spanner.v1.ListSessionsRequest)2 ListSessionsResponse (com.google.spanner.v1.ListSessionsResponse)2 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)1 ServiceOptions (com.google.cloud.ServiceOptions)1 ObservableReactiveUtil (com.google.cloud.spanner.r2dbc.util.ObservableReactiveUtil)1 ListSessionsPagedResponse (com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse)1