use of io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRange in project pravega by pravega.
the class ControllerImpl method convert.
private TxnSegments convert(CreateTxnResponse response) {
NavigableMap<Double, Segment> rangeMap = new TreeMap<>();
for (SegmentRange r : response.getActiveSegmentsList()) {
rangeMap.put(r.getMaxKey(), ModelHelper.encode(r.getSegmentId()));
}
StreamSegments segments = new StreamSegments(rangeMap, response.getDelegationToken());
return new TxnSegments(segments, ModelHelper.encode(response.getTxnId()));
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRange in project pravega by pravega.
the class ModelHelperTest method createSuccessorResponse.
@Test
public void createSuccessorResponse() {
Controller.SegmentRange segmentRange = createSegmentRange(0.1, 0.5);
Map<Controller.SegmentRange, List<Integer>> inputMap = new HashMap<>(1);
inputMap.put(segmentRange, Arrays.asList(1));
Controller.SuccessorResponse successorResponse = ModelHelper.createSuccessorResponse(inputMap).build();
Assert.assertEquals(1, successorResponse.getSegmentsCount());
final SegmentId resultSegmentID = successorResponse.getSegments(0).getSegment().getSegmentId();
assertEquals("testScope", resultSegmentID.getStreamInfo().getScope());
assertEquals("testStream", resultSegmentID.getStreamInfo().getStream());
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRange in project pravega by pravega.
the class ControllerService method getSegmentsImmediatelyFollowing.
public CompletableFuture<Map<SegmentRange, List<Integer>>> getSegmentsImmediatelyFollowing(SegmentId segment) {
Preconditions.checkNotNull(segment, "segment");
OperationContext context = streamStore.createContext(segment.getStreamInfo().getScope(), segment.getStreamInfo().getStream());
return streamStore.getSuccessors(segment.getStreamInfo().getScope(), segment.getStreamInfo().getStream(), segment.getSegmentNumber(), context, executor).thenComposeAsync(successors -> Futures.keysAllOfWithResults(successors.entrySet().stream().collect(Collectors.toMap(entry -> streamStore.getSegment(segment.getStreamInfo().getScope(), segment.getStreamInfo().getStream(), entry.getKey(), context, executor).thenApply(seg -> ModelHelper.createSegmentRange(segment.getStreamInfo().getScope(), segment.getStreamInfo().getStream(), seg.getNumber(), seg.getKeyStart(), seg.getKeyEnd())), Map.Entry::getValue))), executor);
}
Aggregations