use of io.pravega.controller.stream.api.grpc.v1.Controller.SuccessorResponse in project pravega by pravega.
the class ControllerServiceImplTest method getSegmentsImmediatlyFollowingTest.
@Test
public void getSegmentsImmediatlyFollowingTest() {
scaleTest();
ResultObserver<SuccessorResponse> result = new ResultObserver<>();
this.controllerService.getSegmentsImmediatlyFollowing(ModelHelper.createSegmentId(SCOPE1, STREAM1, 1), result);
final SuccessorResponse successorResponse = result.get();
Assert.assertEquals(2, successorResponse.getSegmentsCount());
ResultObserver<SuccessorResponse> result2 = new ResultObserver<>();
this.controllerService.getSegmentsImmediatlyFollowing(ModelHelper.createSegmentId(SCOPE1, STREAM1, 0), result2);
final SuccessorResponse successorResponse2 = result2.get();
Assert.assertEquals(0, successorResponse2.getSegmentsCount());
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.SuccessorResponse in project pravega by pravega.
the class ControllerServiceImpl method getSegmentsImmediatelyFollowing.
@Override
public void getSegmentsImmediatelyFollowing(SegmentId segmentId, StreamObserver<SuccessorResponse> responseObserver) {
String segment = NameUtils.getQualifiedStreamSegmentName(segmentId.getStreamInfo().getScope(), segmentId.getStreamInfo().getStream(), segmentId.getSegmentId());
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), GET_SEGMENTS_IMMEDIATELY_FOLLOWING, segment);
log.info(requestTag.getRequestId(), "getSegmentsImmediatelyFollowing called for segment {} ", segment);
authenticateExecuteAndProcessResults(() -> this.grpcAuthHelper.checkAuthorization(authorizationResource.ofStreamInScope(segmentId.getStreamInfo().getScope(), segmentId.getStreamInfo().getStream()), AuthHandler.Permissions.READ), delegationToken -> controllerService.getSegmentsImmediatelyFollowing(segmentId, requestTag.getRequestId()).thenApply(ModelHelper::createSuccessorResponse).thenApply(response -> {
response.setDelegationToken(delegationToken);
return response.build();
}), responseObserver);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.SuccessorResponse in project pravega by pravega.
the class ControllerImpl method getSuccessors.
@Override
public CompletableFuture<StreamSegmentsWithPredecessors> getSuccessors(Segment segment) {
Exceptions.checkNotClosed(closed.get(), this);
final long requestId = requestIdGenerator.get();
long traceId = LoggerHelpers.traceEnter(log, "getSuccessors", segment, requestId);
final CompletableFuture<SuccessorResponse> resultFuture = this.retryConfig.runAsync(() -> {
RPCAsyncCallback<SuccessorResponse> callback = new RPCAsyncCallback<>(requestId, "getSuccessors", segment);
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, GET_SEGMENTS_IMMEDIATELY_FOLLOWING, segment.getScopedName()).getSegmentsImmediatelyFollowing(ModelHelper.decode(segment), callback);
return callback.getFuture();
}, this.executor);
return resultFuture.thenApplyAsync(successors -> {
log.debug(requestId, "Received the following data from the controller {}", successors.getSegmentsList());
Map<SegmentWithRange, List<Long>> result = new HashMap<>();
for (SuccessorResponse.SegmentEntry entry : successors.getSegmentsList()) {
result.put(encode(entry.getSegment()), entry.getValueList());
}
return new StreamSegmentsWithPredecessors(result, successors.getDelegationToken());
}, this.executor).whenComplete((x, e) -> {
if (e != null) {
log.warn(requestId, "getSuccessors of segment {} failed: ", segment.getSegmentId(), e);
}
LoggerHelpers.traceLeave(log, "getSuccessors", traceId, requestId);
});
}
Aggregations