use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class SegmentHelper method createTransaction.
public CompletableFuture<UUID> createTransaction(final String scope, final String stream, final int segmentNumber, final UUID txId, final HostControllerStore hostControllerStore, final ConnectionFactory clientCF, String delegationToken) {
final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
final CompletableFuture<UUID> result = new CompletableFuture<>();
final WireCommandType type = WireCommandType.CREATE_TRANSACTION;
final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {
@Override
public void connectionDropped() {
log.warn("createTransaction {}/{}/{} connectionDropped", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.ConnectionDropped));
}
@Override
public void wrongHost(WireCommands.WrongHost wrongHost) {
log.warn("createTransaction {}/{}/{} wrong host", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.UnknownHost));
}
@Override
public void transactionCreated(WireCommands.TransactionCreated transactionCreated) {
log.debug("createTransaction {}/{}/{} TransactionCreated", scope, stream, segmentNumber);
result.complete(txId);
}
@Override
public void segmentAlreadyExists(WireCommands.SegmentAlreadyExists segmentAlreadyExists) {
log.debug("createTransaction {}/{}/{} TransactionCreated", scope, stream, segmentNumber);
result.complete(txId);
}
@Override
public void processingFailure(Exception error) {
log.error("createTransaction {}/{}/{} failed", scope, stream, segmentNumber, error);
result.completeExceptionally(error);
}
@Override
public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
result.completeExceptionally(new WireCommandFailedException(new AuthenticationException(authTokenCheckFailed.toString()), type, WireCommandFailedException.Reason.AuthFailed));
}
};
WireCommands.CreateTransaction request = new WireCommands.CreateTransaction(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), txId, delegationToken);
sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri));
return result;
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class SegmentHelper method abortTransaction.
public CompletableFuture<TxnStatus> abortTransaction(final String scope, final String stream, final int segmentNumber, final UUID txId, final HostControllerStore hostControllerStore, final ConnectionFactory clientCF, String delegationToken) {
final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
final CompletableFuture<TxnStatus> result = new CompletableFuture<>();
final WireCommandType type = WireCommandType.ABORT_TRANSACTION;
final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {
@Override
public void connectionDropped() {
log.warn("abortTransaction {}/{}/{} connectionDropped", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.ConnectionDropped));
}
@Override
public void wrongHost(WireCommands.WrongHost wrongHost) {
log.warn("abortTransaction {}/{}/{} wrongHost", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.UnknownHost));
}
@Override
public void transactionCommitted(WireCommands.TransactionCommitted transactionCommitted) {
log.warn("abortTransaction {}/{}/{} TransactionCommitted", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.PreconditionFailed));
}
@Override
public void transactionAborted(WireCommands.TransactionAborted transactionDropped) {
log.debug("abortTransaction {}/{}/{} transactionAborted", scope, stream, segmentNumber);
result.complete(TxnStatus.newBuilder().setStatus(TxnStatus.Status.SUCCESS).build());
}
@Override
public void noSuchSegment(WireCommands.NoSuchSegment noSuchSegment) {
log.info("abortTransaction {}/{}/{} NoSuchSegment", scope, stream, segmentNumber);
result.complete(TxnStatus.newBuilder().setStatus(TxnStatus.Status.SUCCESS).build());
}
@Override
public void processingFailure(Exception error) {
log.info("abortTransaction {}/{}/{} failed", scope, stream, segmentNumber, error);
result.completeExceptionally(error);
}
@Override
public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
result.completeExceptionally(new WireCommandFailedException(new AuthenticationException(authTokenCheckFailed.toString()), type, WireCommandFailedException.Reason.AuthFailed));
}
};
WireCommands.AbortTransaction request = new WireCommands.AbortTransaction(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), txId, delegationToken);
sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri));
return result;
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class SegmentHelper method commitTransaction.
public CompletableFuture<TxnStatus> commitTransaction(final String scope, final String stream, final int segmentNumber, final UUID txId, final HostControllerStore hostControllerStore, final ConnectionFactory clientCF, String delegationToken) {
final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
final CompletableFuture<TxnStatus> result = new CompletableFuture<>();
final WireCommandType type = WireCommandType.COMMIT_TRANSACTION;
final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {
@Override
public void connectionDropped() {
log.warn("commitTransaction {}/{}/{} connection dropped", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.ConnectionDropped));
}
@Override
public void wrongHost(WireCommands.WrongHost wrongHost) {
log.warn("commitTransaction {}/{}/{} wrongHost", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.UnknownHost));
}
@Override
public void transactionCommitted(WireCommands.TransactionCommitted transactionCommitted) {
log.debug("commitTransaction {}/{}/{} TransactionCommitted", scope, stream, segmentNumber);
result.complete(TxnStatus.newBuilder().setStatus(TxnStatus.Status.SUCCESS).build());
}
@Override
public void transactionAborted(WireCommands.TransactionAborted transactionAborted) {
log.warn("commitTransaction {}/{}/{} Transaction aborted", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.PreconditionFailed));
}
@Override
public void noSuchSegment(WireCommands.NoSuchSegment noSuchSegment) {
log.info("commitTransaction {}/{}/{} NoSuchSegment", scope, stream, segmentNumber);
result.complete(TxnStatus.newBuilder().setStatus(TxnStatus.Status.SUCCESS).build());
}
@Override
public void processingFailure(Exception error) {
log.error("commitTransaction {}/{}/{} failed", scope, stream, segmentNumber, error);
result.completeExceptionally(error);
}
@Override
public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
result.completeExceptionally(new WireCommandFailedException(new AuthenticationException(authTokenCheckFailed.toString()), type, WireCommandFailedException.Reason.AuthFailed));
}
};
WireCommands.CommitTransaction request = new WireCommands.CommitTransaction(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), txId, delegationToken);
sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri));
return result;
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class SegmentHelper method updatePolicy.
public CompletableFuture<Void> updatePolicy(String scope, String stream, ScalingPolicy policy, int segmentNumber, HostControllerStore hostControllerStore, ConnectionFactory clientCF, String delegationToken) {
final CompletableFuture<Void> result = new CompletableFuture<>();
final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
final WireCommandType type = WireCommandType.UPDATE_SEGMENT_POLICY;
final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {
@Override
public void connectionDropped() {
log.warn("updatePolicy {}/{}/{} connectionDropped", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.ConnectionDropped));
}
@Override
public void wrongHost(WireCommands.WrongHost wrongHost) {
log.warn("updatePolicy {}/{}/{} wrongHost", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.UnknownHost));
}
@Override
public void segmentPolicyUpdated(WireCommands.SegmentPolicyUpdated policyUpdated) {
log.info("updatePolicy {}/{}/{} SegmentPolicyUpdated", scope, stream, segmentNumber);
result.complete(null);
}
@Override
public void processingFailure(Exception error) {
log.info("updatePolicy {}/{}/{} failed", scope, stream, segmentNumber, error);
result.completeExceptionally(error);
}
@Override
public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
result.completeExceptionally(new WireCommandFailedException(new AuthenticationException(authTokenCheckFailed.toString()), type, WireCommandFailedException.Reason.AuthFailed));
}
};
Pair<Byte, Integer> extracted = extractFromPolicy(policy);
WireCommands.UpdateSegmentPolicy request = new WireCommands.UpdateSegmentPolicy(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), extracted.getLeft(), extracted.getRight(), delegationToken);
sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri));
return result;
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class SegmentHelper method sealSegment.
/**
* This method sends segment sealed message for the specified segment.
*
* @param scope stream scope
* @param stream stream name
* @param segmentId number of segment to be sealed
* @param delegationToken the token to be presented to segmentstore.
* @param clientRequestId client-generated id for end-to-end tracing
* @return void
*/
public CompletableFuture<Void> sealSegment(final String scope, final String stream, final long segmentId, final String delegationToken, final long clientRequestId) {
final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentId);
final String qualifiedName = getQualifiedStreamSegmentName(scope, stream, segmentId);
final WireCommandType type = WireCommandType.SEAL_SEGMENT;
RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
final long requestId = connection.getFlow().asLong();
return sendRequest(connection, clientRequestId, new WireCommands.SealSegment(requestId, qualifiedName, delegationToken)).thenAccept(r -> handleReply(clientRequestId, r, connection, qualifiedName, WireCommands.SealSegment.class, type));
}
Aggregations