/** * Waits for an operation like cluster resizing to complete. * @param operationName The fully qualified name of the operation * @param maxSeconds The maximum amount of seconds to wait for the operation to complete. * @throws InterruptedException if a user interrupts the process, usually with a ^C. */ public void waitForOperation(String operationName, int maxSeconds) throws InterruptedException { long endTimeMillis = TimeUnit.SECONDS.toMillis(maxSeconds) + System.currentTimeMillis(); GetOperationRequest request = GetOperationRequest.newBuilder().setName(operationName).build(); do { Thread.sleep(500); Operation response = client.getOperation(request); if (response.getDone()) { switch (response.getResultCase()) { case RESPONSE: return; case ERROR: throw new RuntimeException("Cluster could not be resized: " + response.getError()); case RESULT_NOT_SET: throw new IllegalStateException( "System returned invalid response for Operation check: " + response); } } } while (System.currentTimeMillis() < endTimeMillis); throw new IllegalStateException( String.format("Waited %d seconds and cluster was not resized yet.", maxSeconds)); }
throws TimeoutException, IOException { GetOperationRequest request = GetOperationRequest.newBuilder() .setName(operation.getName()) .build();
/** * Gets the latest state of a long-running operation. Clients can use this method to poll the * operation result at intervals as recommended by the API service. * * <p>Sample code: * * <pre><code> * try (OperationsClient operationsClient = OperationsClient.create()) { * String name = ""; * Operation response = operationsClient.getOperation(name); * } * </code></pre> * * @param name The name of the operation resource. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Operation getOperation(String name) { GetOperationRequest request = GetOperationRequest.newBuilder().setName(name).build(); return getOperation(request); }
/** * Gets the latest state of a long-running operation. Clients can use this method to poll the * operation result at intervals as recommended by the API service. * * <p>Sample code: * * <pre><code> * try (OperationsClient operationsClient = OperationsClient.create()) { * String name = ""; * Operation response = operationsClient.getOperation(name); * } * </code></pre> * * @param name The name of the operation resource. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Operation getOperation(String name) { GetOperationRequest request = GetOperationRequest.newBuilder().setName(name).build(); return getOperation(request); }
@Override public GetOperationRequest apply(String request) { return GetOperationRequest.newBuilder().setName(request).build(); } },
@Override public Operation getOperation(String name) throws SpannerException { GetOperationRequest request = GetOperationRequest.newBuilder().setName(name).build(); GrpcCallContext context = newCallContext(null, name); return get( databaseAdminStub.getOperationsStub().getOperationCallable().futureCall(request, context)); }
@Override public GetOperationRequest apply(String request) { return GetOperationRequest.newBuilder().setName(request).build(); } },
@Override public Operation getOperation(String name) throws SpannerException { GetOperationRequest request = GetOperationRequest.newBuilder().setName(name).build(); GrpcCallContext context = newCallContext(null, name); return get( databaseAdminStub.getOperationsStub().getOperationCallable().futureCall(request, context)); }