Search in sources :

Example 1 with SegmentRange

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()));
}
Also used : SegmentRange(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRange) TreeMap(java.util.TreeMap) Segment(io.pravega.client.segment.impl.Segment)

Example 2 with SegmentRange

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());
}
Also used : HashMap(java.util.HashMap) SegmentId(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentId) List(java.util.List) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Test(org.junit.Test)

Example 3 with SegmentRange

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);
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) SegmentId(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentId) OperationContext(io.pravega.controller.store.stream.OperationContext) Getter(lombok.Getter) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) Exceptions(io.pravega.common.Exceptions) ScaleStatusResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) CompletableFuture(java.util.concurrent.CompletableFuture) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ArrayList(java.util.ArrayList) NodeUri(io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri) Cluster(io.pravega.common.cluster.Cluster) ScaleMetadata(io.pravega.controller.store.stream.ScaleMetadata) Pair(org.apache.commons.lang3.tuple.Pair) DeleteStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteStreamStatus) Map(java.util.Map) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Segment(io.pravega.controller.store.stream.Segment) ModelHelper(io.pravega.client.stream.impl.ModelHelper) DeleteScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus) ScaleResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) NameUtils(io.pravega.shared.NameUtils) Executor(java.util.concurrent.Executor) UUID(java.util.UUID) SegmentRange(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRange) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) TxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus) ClusterException(io.pravega.common.cluster.ClusterException) Preconditions(com.google.common.base.Preconditions) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Comparator(java.util.Comparator) AllArgsConstructor(lombok.AllArgsConstructor) Lombok(lombok.Lombok) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Futures(io.pravega.common.concurrent.Futures) Map(java.util.Map)

Aggregations

SegmentId (io.pravega.controller.stream.api.grpc.v1.Controller.SegmentId)2 SegmentRange (io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRange)2 List (java.util.List)2 Preconditions (com.google.common.base.Preconditions)1 Segment (io.pravega.client.segment.impl.Segment)1 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)1 ModelHelper (io.pravega.client.stream.impl.ModelHelper)1 Exceptions (io.pravega.common.Exceptions)1 Cluster (io.pravega.common.cluster.Cluster)1 ClusterException (io.pravega.common.cluster.ClusterException)1 Futures (io.pravega.common.concurrent.Futures)1 HostControllerStore (io.pravega.controller.store.host.HostControllerStore)1 OperationContext (io.pravega.controller.store.stream.OperationContext)1 ScaleMetadata (io.pravega.controller.store.stream.ScaleMetadata)1 Segment (io.pravega.controller.store.stream.Segment)1 StreamMetadataStore (io.pravega.controller.store.stream.StreamMetadataStore)1 VersionedTransactionData (io.pravega.controller.store.stream.VersionedTransactionData)1 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)1 CreateScopeStatus (io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus)1 CreateStreamStatus (io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus)1