public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (streamInfo_ != null) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(1, getStreamInfo()); } if (lease_ != 0L) { size += com.google.protobuf.CodedOutputStream .computeInt64Size(2, lease_); } if (scaleGracePeriod_ != 0L) { size += com.google.protobuf.CodedOutputStream .computeInt64Size(3, scaleGracePeriod_); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
@Override public CompletableFuture<TxnSegments> createTransaction(final Stream stream, final long lease) { Exceptions.checkNotClosed(closed.get(), this); Preconditions.checkNotNull(stream, "stream"); long traceId = LoggerHelpers.traceEnter(log, "createTransaction", stream, lease); final CompletableFuture<CreateTxnResponse> result = this.retryConfig.runAsync(() -> { RPCAsyncCallback<CreateTxnResponse> callback = new RPCAsyncCallback<>(traceId, "createTransaction"); client.createTransaction( CreateTxnRequest.newBuilder() .setStreamInfo(ModelHelper.createStreamInfo(stream.getScope(), stream.getStreamName())) .setLease(lease) .build(), callback); return callback.getFuture(); }, this.executor); return result.thenApply(this::convert) .whenComplete((x, e) -> { if (e != null) { log.warn("createTransaction failed: ", e); } LoggerHelpers.traceLeave(log, "createTransaction", traceId); }); }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (hasStreamInfo()) { hash = (37 * hash) + STREAMINFO_FIELD_NUMBER; hash = (53 * hash) + getStreamInfo().hashCode(); } hash = (37 * hash) + LEASE_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( getLease()); hash = (37 * hash) + SCALEGRACEPERIOD_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( getScaleGracePeriod()); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@io.grpc.stub.annotations.RpcMethod( fullMethodName = SERVICE_NAME + '/' + "createTransaction", requestType = io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest.class, responseType = io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnResponse.class, methodType = io.grpc.MethodDescriptor.MethodType.UNARY) public static io.grpc.MethodDescriptor<io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest, io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnResponse> getCreateTransactionMethod() { io.grpc.MethodDescriptor<io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest, io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnResponse> getCreateTransactionMethod; if ((getCreateTransactionMethod = ControllerServiceGrpc.getCreateTransactionMethod) == null) { synchronized (ControllerServiceGrpc.class) { if ((getCreateTransactionMethod = ControllerServiceGrpc.getCreateTransactionMethod) == null) { ControllerServiceGrpc.getCreateTransactionMethod = getCreateTransactionMethod = io.grpc.MethodDescriptor.<io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest, io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnResponse>newBuilder() .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "io.pravega.controller.stream.api.grpc.v1.ControllerService", "createTransaction")) .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnResponse.getDefaultInstance())) .setSchemaDescriptor(new ControllerServiceMethodDescriptorSupplier("createTransaction")) .build(); } } } return getCreateTransactionMethod; }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest)) { return super.equals(obj); } io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest other = (io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest) obj; boolean result = true; result = result && (hasStreamInfo() == other.hasStreamInfo()); if (hasStreamInfo()) { result = result && getStreamInfo() .equals(other.getStreamInfo()); } result = result && (getLease() == other.getLease()); result = result && (getScaleGracePeriod() == other.getScaleGracePeriod()); result = result && unknownFields.equals(other.unknownFields); return result; }
@Override public void createTransaction(CreateTxnRequest request, StreamObserver<Controller.CreateTxnResponse> responseObserver) { Controller.CreateTxnResponse.Builder builder = Controller.CreateTxnResponse.newBuilder(); if (request.getStreamInfo().getStream().equals("stream1")) { builder.setTxnId(TxnId.newBuilder().setHighBits(11L).setLowBits(22L).build()); builder.addActiveSegments(ModelHelper.createSegmentRange("scope1", "stream1", 0, 0.0, 0.5)); builder.addActiveSegments(ModelHelper.createSegmentRange("scope1", "stream1", 1, 0.5, 1.0)); responseObserver.onNext(builder.build()); responseObserver.onCompleted(); } else if (request.getStreamInfo().getStream().equals("stream2")) { builder.addActiveSegments(ModelHelper.createSegmentRange("scope1", "stream2", 0, 0.0, 1.0)); builder.setTxnId(TxnId.newBuilder().setHighBits(33L).setLowBits(44L).build()); responseObserver.onNext(builder.build()); responseObserver.onCompleted(); } else { responseObserver.onError(Status.INTERNAL.withDescription("Server error").asRuntimeException()); } }
@Override public void createTransaction(CreateTxnRequest request, StreamObserver<Controller.CreateTxnResponse> responseObserver) { log.info("createTransaction called for stream {}/{}.", request.getStreamInfo().getScope(), request.getStreamInfo().getStream()); authenticateExecuteAndProcessResults(() -> this.authHelper.checkAuthorizationAndCreateToken(request.getStreamInfo().getScope() + "/" + request.getStreamInfo().getStream(), AuthHandler.Permissions.READ_UPDATE), delegationToken -> controllerService.createTransaction(request.getStreamInfo().getScope(), request.getStreamInfo().getStream(), request.getLease()) .thenApply(pair -> Controller.CreateTxnResponse.newBuilder() .setDelegationToken(delegationToken) .setTxnId(ModelHelper.decode(pair.getKey())) .addAllActiveSegments(pair.getValue()) .build()), responseObserver); }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
public io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest getDefaultInstanceForType() { return io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest.getDefaultInstance(); }
@Test public void createTransactionFailureTest() { createScopeAndStream(SCOPE1, STREAM1, ScalingPolicy.fixed(4)); StreamInfo streamInfo = ModelHelper.createStreamInfo(SCOPE1, STREAM1); // Invalid lease CreateTxnRequest request = CreateTxnRequest.newBuilder() .setStreamInfo(streamInfo) .setLease(-1) .build(); ResultObserver<CreateTxnResponse> resultObserver = new ResultObserver<>(); this.controllerService.createTransaction(request, resultObserver); AssertExtensions.assertThrows("Lease lower bound violated ", resultObserver::get, e -> checkGRPCException(e, IllegalArgumentException.class)); }
public Builder mergeFrom(io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest other) { if (other == io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest.getDefaultInstance()) return this; if (other.hasStreamInfo()) { mergeStreamInfo(other.getStreamInfo()); } if (other.getLease() != 0L) { setLease(other.getLease()); } if (other.getScaleGracePeriod() != 0L) { setScaleGracePeriod(other.getScaleGracePeriod()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (streamInfo_ != null) { output.writeMessage(1, getStreamInfo()); } if (lease_ != 0L) { output.writeInt64(2, lease_); } if (scaleGracePeriod_ != 0L) { output.writeInt64(3, scaleGracePeriod_); } unknownFields.writeTo(output); }
private Controller.CreateTxnResponse createTransaction(final String scope, final String stream, final long lease) { Controller.StreamInfo streamInfo = ModelHelper.createStreamInfo(scope, stream); Controller.CreateTxnRequest request = Controller.CreateTxnRequest.newBuilder() .setStreamInfo(streamInfo) .setLease(lease) .build(); ResultObserver<Controller.CreateTxnResponse> resultObserver = new ResultObserver<>(); this.controllerService.createTransaction(request, resultObserver); Controller.CreateTxnResponse response = resultObserver.get(); Assert.assertTrue(response != null); return response; } }
/** * <code>.io.pravega.controller.stream.api.grpc.v1.StreamInfo streamInfo = 1;</code> */ public io.pravega.controller.stream.api.grpc.v1.Controller.StreamInfoOrBuilder getStreamInfoOrBuilder() { return getStreamInfo(); }
public io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest buildPartial() { io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest result = new io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest(this); if (streamInfoBuilder_ == null) { result.streamInfo_ = streamInfo_; } else { result.streamInfo_ = streamInfoBuilder_.build(); } result.lease_ = lease_; result.scaleGracePeriod_ = scaleGracePeriod_; onBuilt(); return result; }
public io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest build() { io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }