/** * Deletes a specific Redis instance. Instance stops serving and data is deleted. * * <p>Sample code: * * <pre><code> * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { * InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); * DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder() * .setName(name.toString()) * .build(); * Empty response = cloudRedisClient.deleteInstanceAsync(request).get(); * } * </code></pre> * * @param request The request object containing all of the parameters for the API call. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @BetaApi( "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Empty, Any> deleteInstanceAsync(DeleteInstanceRequest request) { return deleteInstanceOperationCallable().futureCall(request); }
@Override public OperationFuture<Empty, UpdateDatabaseDdlMetadata> updateDatabaseDdl( String databaseName, Iterable<String> updateDatabaseStatements, @Nullable String updateId) throws SpannerException { UpdateDatabaseDdlRequest request = UpdateDatabaseDdlRequest.newBuilder() .setDatabase(databaseName) .addAllStatements(updateDatabaseStatements) .setOperationId(MoreObjects.firstNonNull(updateId, "")) .build(); GrpcCallContext context = newCallContext(null, databaseName); OperationCallable<UpdateDatabaseDdlRequest, Empty, UpdateDatabaseDdlMetadata> callable = databaseAdminStub.updateDatabaseDdlOperationCallable(); OperationFuture<Empty, UpdateDatabaseDdlMetadata> operationFuture = callable.futureCall(request, context); try { operationFuture.getInitialFuture().get(); } catch (InterruptedException e) { throw newSpannerException(e); } catch (ExecutionException e) { Throwable t = e.getCause(); if (t instanceof AlreadyExistsException) { String operationName = OPERATION_NAME_TEMPLATE.instantiate("database", databaseName, "operation", updateId); return callable.resumeFutureCall(operationName, context); } } return operationFuture; }
@Test public void callCancel() throws Exception { ApiCallContext defaultCallContext = FakeCallContext.createDefault(); OperationStashCallable stashCallable = new OperationStashCallable(); OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(defaultCallContext); OperationFuture<String, Long> operationFuture = callable.futureCall(45); callable.cancel(operationFuture.getName()).get(); Truth.assertThat(stashCallable.wasCancelCalled()).isTrue(); Truth.assertThat(stashCallable.getCancelContext()).isSameAs(defaultCallContext); }
/** * Creates a new {@link OperationFuture} to watch an operation that has been initiated previously. * Note: This is not type-safe at static time; the result type can only be checked once the * operation finishes. * * @param operationName The name of the operation to resume. * @return {@link OperationFuture} for the call result. */ public OperationFuture<ResponseT, MetadataT> resumeFutureCall(String operationName) { return resumeFutureCall(operationName, null); }
/** * Sends a cancellation request to the server for the operation with name {@code operationName}. * * @param operationName The name of the operation to cancel. * @return the future which completes once the operation is canceled on the server side. */ public ApiFuture<Void> cancel(String operationName) { return cancel(operationName, null); }
/** * Creates a callable object that represents a long-running operation. Designed for use by * generated code. * * @param grpcCallSettings the gRPC call settings * @param operationCallSettings {@link OperationCallSettings} to configure the method-level * settings with. * @param clientContext {@link ClientContext} to use to connect to the service. * @param operationsStub {@link OperationsStub} to use to poll for updates on the Operation. * @return {@link com.google.api.gax.rpc.OperationCallable} callable object. */ @BetaApi( "The surface for long-running operations is not stable yet and may change in the future.") public static <RequestT, ResponseT, MetadataT> OperationCallable<RequestT, ResponseT, MetadataT> createOperationCallable( GrpcCallSettings<RequestT, Operation> grpcCallSettings, OperationCallSettings<RequestT, ResponseT, MetadataT> operationCallSettings, ClientContext clientContext, OperationsStub operationsStub) { UnaryCallable<RequestT, Operation> initialGrpcCallable = createBaseUnaryCallable( grpcCallSettings, operationCallSettings.getInitialCallSettings(), clientContext); UnaryCallable<RequestT, OperationSnapshot> initialCallable = new GrpcOperationSnapshotCallable<>(initialGrpcCallable); LongRunningClient longRunningClient = new GrpcLongRunningClient(operationsStub); OperationCallable<RequestT, ResponseT, MetadataT> operationCallable = Callables.longRunningOperation( initialCallable, operationCallSettings, clientContext, longRunningClient); return operationCallable.withDefaultCallContext(clientContext.getDefaultCallContext()); }
@Test public void call() throws Exception { ApiCallContext defaultCallContext = FakeCallContext.createDefault(); OperationStashCallable stashCallable = new OperationStashCallable(); OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(defaultCallContext); String response = callable.call(1); Truth.assertThat(response).isEqualTo("1"); Truth.assertThat(stashCallable.getContext()).isSameAs(defaultCallContext); }
@Override public OperationFuture<Empty, UpdateDatabaseDdlMetadata> updateDatabaseDdl( String databaseName, Iterable<String> updateDatabaseStatements, @Nullable String updateId) throws SpannerException { UpdateDatabaseDdlRequest request = UpdateDatabaseDdlRequest.newBuilder() .setDatabase(databaseName) .addAllStatements(updateDatabaseStatements) .setOperationId(MoreObjects.firstNonNull(updateId, "")) .build(); GrpcCallContext context = newCallContext(null, databaseName); OperationCallable<UpdateDatabaseDdlRequest, Empty, UpdateDatabaseDdlMetadata> callable = databaseAdminStub.updateDatabaseDdlOperationCallable(); OperationFuture<Empty, UpdateDatabaseDdlMetadata> operationFuture = callable.futureCall(request, context); try { operationFuture.getInitialFuture().get(); } catch (InterruptedException e) { throw newSpannerException(e); } catch (ExecutionException e) { Throwable t = e.getCause(); if (t instanceof AlreadyExistsException) { String operationName = OPERATION_NAME_TEMPLATE.instantiate("database", databaseName, "operation", updateId); return callable.resumeFutureCall(operationName, context); } } return operationFuture; }
@Test public void callCancelWithContext() throws Exception { FakeChannel channel = new FakeChannel(); Credentials credentials = Mockito.mock(Credentials.class); ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials); OperationStashCallable stashCallable = new OperationStashCallable(); OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault()); OperationFuture<String, Long> operationFuture = callable.futureCall(45); callable.cancel(operationFuture.getName(), context).get(); Truth.assertThat(stashCallable.wasCancelCalled()).isTrue(); FakeCallContext actualContext = (FakeCallContext) stashCallable.getCancelContext(); Truth.assertThat(actualContext.getChannel()).isSameAs(channel); Truth.assertThat(actualContext.getCredentials()).isSameAs(credentials); }
/** * Creates a new {@link OperationFuture} to watch an operation that has been initiated previously. * Note: This is not type-safe at static time; the result type can only be checked once the * operation finishes. * * @param operationName The name of the operation to resume. * @return {@link OperationFuture} for the call result. */ public OperationFuture<ResponseT, MetadataT> resumeFutureCall(String operationName) { return resumeFutureCall(operationName, null); }
/** * Sends a cancellation request to the server for the operation with name {@code operationName}. * * @param operationName The name of the operation to cancel. * @return the future which completes once the operation is canceled on the server side. */ public ApiFuture<Void> cancel(String operationName) { return cancel(operationName, null); }
/** * Creates a callable object that represents a long-running operation. Designed for use by * generated code. * * @param grpcCallSettings the gRPC call settings * @param operationCallSettings {@link OperationCallSettings} to configure the method-level * settings with. * @param clientContext {@link ClientContext} to use to connect to the service. * @param operationsStub {@link OperationsStub} to use to poll for updates on the Operation. * @return {@link com.google.api.gax.rpc.OperationCallable} callable object. */ @BetaApi( "The surface for long-running operations is not stable yet and may change in the future.") public static <RequestT, ResponseT, MetadataT> OperationCallable<RequestT, ResponseT, MetadataT> createOperationCallable( GrpcCallSettings<RequestT, Operation> grpcCallSettings, OperationCallSettings<RequestT, ResponseT, MetadataT> operationCallSettings, ClientContext clientContext, OperationsStub operationsStub) { UnaryCallable<RequestT, Operation> initialGrpcCallable = createBaseUnaryCallable( grpcCallSettings, operationCallSettings.getInitialCallSettings(), clientContext); UnaryCallable<RequestT, OperationSnapshot> initialCallable = new GrpcOperationSnapshotCallable<>(initialGrpcCallable); LongRunningClient longRunningClient = new GrpcLongRunningClient(operationsStub); OperationCallable<RequestT, ResponseT, MetadataT> operationCallable = Callables.longRunningOperation( initialCallable, operationCallSettings, clientContext, longRunningClient); return operationCallable.withDefaultCallContext(clientContext.getDefaultCallContext()); }
@Test public void testCall() { Color resp = getColor(1.0f); Currency meta = Currency.getInstance("UAH"); OperationSnapshot resultOperation = getOperation("testCall", resp, null, meta, true); UnaryCallable<Integer, OperationSnapshot> initialCallable = mockGetOpSnapshotCallable(StatusCode.Code.OK, resultOperation); LongRunningClient longRunningClient = new UnsupportedOperationApi(); OperationCallable<Integer, Color, Currency> callable = FakeCallableFactory.createOperationCallable( initialCallable, callSettings, initialContext, longRunningClient); Color response = callable.call(2, FakeCallContext.createDefault()); Truth.assertThat(response).isEqualTo(resp); assertThat(executor.getIterationsCount()).isEqualTo(0); }
/** * Deletes a specific Redis instance. Instance stops serving and data is deleted. * * <p>Sample code: * * <pre><code> * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { * InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); * DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder() * .setName(name.toString()) * .build(); * Empty response = cloudRedisClient.deleteInstanceAsync(request).get(); * } * </code></pre> * * @param request The request object containing all of the parameters for the API call. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @BetaApi( "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Empty, OperationMetadata> deleteInstanceAsync( DeleteInstanceRequest request) { return deleteInstanceOperationCallable().futureCall(request); }
@Test public void callResume() throws Exception { ApiCallContext defaultCallContext = FakeCallContext.createDefault(); OperationStashCallable stashCallable = new OperationStashCallable(); OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(defaultCallContext); OperationFuture<String, Long> operationFuture = callable.futureCall(45); String response = callable.resumeFutureCall(operationFuture.getName()).get(); Truth.assertThat(response).isEqualTo("45"); Truth.assertThat(stashCallable.getResumeContext()).isSameAs(defaultCallContext); }
@Override public OperationFuture<ResponseT, MetadataT> resumeFutureCall( String operationName, ApiCallContext thisCallContext) { return OperationCallable.this.resumeFutureCall( operationName, defaultCallContext.merge(thisCallContext)); }
@Override public ApiFuture<Void> cancel(String operationName, ApiCallContext thisCallContext) { return OperationCallable.this.cancel( operationName, defaultCallContext.merge(thisCallContext)); } };
/** * Creates a callable object that represents a long-running operation. Designed for use by * generated code. * * @param innerCallable the callable that starts the operation * @param operationCallSettings {@link OperationCallSettings} to configure the method-level * settings with. * @param clientContext {@link ClientContext} to use to connect to the service. * @param longRunningClient {@link LongRunningClient} to use to poll for updates on the Operation. * @return {@link com.google.api.gax.rpc.OperationCallable} callable object. */ public static <RequestT, ResponseT, MetadataT> OperationCallable<RequestT, ResponseT, MetadataT> createOperationCallable( UnaryCallable<RequestT, OperationSnapshot> innerCallable, OperationCallSettings<RequestT, ResponseT, MetadataT> operationCallSettings, ClientContext clientContext, LongRunningClient longRunningClient) { UnaryCallable<RequestT, OperationSnapshot> initialCallable = createBaseUnaryCallable( innerCallable, operationCallSettings.getInitialCallSettings(), clientContext); OperationCallable<RequestT, ResponseT, MetadataT> operationCallable = Callables.longRunningOperation( initialCallable, operationCallSettings, clientContext, longRunningClient); return operationCallable.withDefaultCallContext(FakeCallContext.create(clientContext)); }
@Test public void callWithContext() throws Exception { FakeChannel channel = new FakeChannel(); Credentials credentials = Mockito.mock(Credentials.class); ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials); OperationStashCallable stashCallable = new OperationStashCallable(); OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault()); String response = callable.call(2, context); Truth.assertThat(response).isEqualTo("2"); FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext(); Truth.assertThat(actualContext.getChannel()).isSameAs(channel); Truth.assertThat(actualContext.getCredentials()).isSameAs(credentials); }
/** * Updates an app profile within an instance. * * <p>Sample code: * * <pre><code> * try (BaseBigtableInstanceAdminClient baseBigtableInstanceAdminClient = BaseBigtableInstanceAdminClient.create()) { * AppProfile appProfile = AppProfile.newBuilder().build(); * FieldMask updateMask = FieldMask.newBuilder().build(); * UpdateAppProfileRequest request = UpdateAppProfileRequest.newBuilder() * .setAppProfile(appProfile) * .setUpdateMask(updateMask) * .build(); * AppProfile response = baseBigtableInstanceAdminClient.updateAppProfileAsync(request).get(); * } * </code></pre> * * @param request The request object containing all of the parameters for the API call. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @BetaApi( "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<AppProfile, UpdateAppProfileMetadata> updateAppProfileAsync( UpdateAppProfileRequest request) { return updateAppProfileOperationCallable().futureCall(request); }