.setResponseMarshaller( io.grpc.protobuf.ProtoUtils.marshaller( com.google.longrunning.Operation.getDefaultInstance())) .setSchemaDescriptor(new CloudRedisMethodDescriptorSupplier("UpdateInstance")) .build();
@Test public void reload() { com.google.longrunning.Operation proto = newBuilder().setName("op1").setDone(false).build(); Operation<Database, String> op = Operation.create(rpc, proto, new ParserImpl()); com.google.spanner.admin.database.v1.Database db = com.google.spanner.admin.database.v1.Database.newBuilder() .setName(NAME) .setState(com.google.spanner.admin.database.v1.Database.State.READY) .build(); proto = newBuilder().setName("op1").setDone(true).setResponse(Any.pack(db)).build(); when(rpc.getOperation("op1")).thenReturn(proto); op = op.reload(); assertThat(op.getName()).isEqualTo("op1"); assertThat(op.isDone()).isTrue(); assertThat(op.isSuccessful()).isTrue(); assertThat(op.getMetadata()).isNull(); assertThat(op.getResult().getId().getName()).isEqualTo(NAME); }
static <R, M> Operation<R, M> create( SpannerRpc rpc, com.google.longrunning.Operation proto, Parser<R, M> parser, ApiClock clock) { M metadata = proto.hasMetadata() ? parser.parseMetadata(proto.getMetadata()) : null; String name = proto.getName(); if (proto.getDone()) { if (proto.getResultCase() == ResultCase.ERROR) { return Operation.<R, M>failed(rpc, name, proto.getError(), metadata, parser, clock); } else { return Operation.<R, M>successful( rpc, name, metadata, parser.parseResult(proto.getResponse()), parser, clock); } } else { return Operation.<R, M>pending(rpc, name, metadata, parser, clock); } }
/** * <pre> * The server-assigned name, which is only unique within the same service that * originally returns it. If you use the default HTTP mapping, the * `name` should have the format of `operations/some/unique/name`. * </pre> * * <code>string name = 1;</code> */ public Builder clearName() { name_ = getDefaultInstance().getName(); onChanged(); return this; } /**
hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + NAME_FIELD_NUMBER; hash = (53 * hash) + getName().hashCode(); if (hasMetadata()) { hash = (37 * hash) + METADATA_FIELD_NUMBER; hash = (53 * hash) + getMetadata().hashCode(); getDone()); switch (resultCase_) { case 4: hash = (37 * hash) + ERROR_FIELD_NUMBER; hash = (53 * hash) + getError().hashCode(); break; case 5: hash = (37 * hash) + RESPONSE_FIELD_NUMBER; hash = (53 * hash) + getResponse().hashCode(); break; case 0:
throws TimeoutException, IOException { GetOperationRequest request = GetOperationRequest.newBuilder() .setName(operation.getName()) .build(); if (currentOperationState.getDone()) { switch (currentOperationState.getResultCase()) { case RESPONSE: return; case ERROR: throw StatusProto.toStatusRuntimeException(currentOperationState.getError()); case RESULT_NOT_SET: throw new IllegalStateException(
/** * 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)); }
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (!getNameBytes().isEmpty()) { com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); } if (metadata_ != null) { output.writeMessage(2, getMetadata()); } if (done_ != false) { output.writeBool(3, done_); } if (resultCase_ == 4) { output.writeMessage(4, (com.google.rpc.Status) result_); } if (resultCase_ == 5) { output.writeMessage(5, (com.google.protobuf.Any) result_); } }
@Override public boolean shouldRetry( Throwable prevThrowable, com.google.longrunning.Operation prevResponse) { if (prevResponse != null) { return !prevResponse.getDone(); } if (prevThrowable instanceof SpannerException) { SpannerException spannerException = (SpannerException) prevThrowable; return spannerException.getErrorCode() != ErrorCode.NOT_FOUND && spannerException.isRetryable(); } return false; } },
@Override public String getErrorMessage() { return operation.getError().getMessage(); }
@Override public String getName() { return operation.getName(); }
/** * <pre> * Service-specific metadata associated with the operation. It typically * contains progress information and common metadata such as create time. * Some services might not provide such metadata. Any method that returns a * long-running operation should document the metadata type, if any. * </pre> * * <code>.google.protobuf.Any metadata = 2;</code> */ public com.google.protobuf.AnyOrBuilder getMetadataOrBuilder() { return getMetadata(); }
/** * <pre> * The server-assigned name, which is only unique within the same service that * originally returns it. If you use the default HTTP mapping, the * `name` should have the format of `operations/some/unique/name`. * </pre> * * <code>string name = 1;</code> */ public Builder clearName() { name_ = getDefaultInstance().getName(); onChanged(); return this; } /**
hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + NAME_FIELD_NUMBER; hash = (53 * hash) + getName().hashCode(); if (hasMetadata()) { hash = (37 * hash) + METADATA_FIELD_NUMBER; hash = (53 * hash) + getMetadata().hashCode(); getDone()); switch (resultCase_) { case 4: hash = (37 * hash) + ERROR_FIELD_NUMBER; hash = (53 * hash) + getError().hashCode(); break; case 5: hash = (37 * hash) + RESPONSE_FIELD_NUMBER; hash = (53 * hash) + getResponse().hashCode(); break; case 0:
public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (!getNameBytes().isEmpty()) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); } if (metadata_ != null) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(2, getMetadata()); } if (done_ != false) { size += com.google.protobuf.CodedOutputStream .computeBoolSize(3, done_); } if (resultCase_ == 4) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(4, (com.google.rpc.Status) result_); } if (resultCase_ == 5) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(5, (com.google.protobuf.Any) result_); } memoizedSize = size; return size; }
@Override public boolean isDone() { return operation.getDone(); }
@Override public String getErrorMessage() { return operation.getError().getMessage(); }
@Override public String getName() { return operation.getName(); }
@Override public Object getMetadata() { return operation.getMetadata(); }
.setResponseMarshaller( io.grpc.protobuf.ProtoUtils.marshaller( com.google.longrunning.Operation.getDefaultInstance())) .setSchemaDescriptor(new AutoMlMethodDescriptorSupplier("ImportData")) .build();