Search in sources :

Example 6 with UpdateStreamStatus

use of io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus in project pravega by pravega.

the class ControllerServiceImplTest method updateStreamTests.

@Test
public void updateStreamTests() {
    createScopeAndStream(SCOPE1, STREAM1, ScalingPolicy.fixed(2));
    final StreamConfiguration configuration2 = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build();
    ResultObserver<UpdateStreamStatus> result2 = new ResultObserver<>();
    this.controllerService.updateStream(ModelHelper.decode(SCOPE1, STREAM1, configuration2), result2);
    UpdateStreamStatus updateStreamStatus = result2.get();
    Assert.assertEquals(updateStreamStatus.getStatus(), UpdateStreamStatus.Status.SUCCESS);
    // Update stream for non-existent stream.
    ResultObserver<UpdateStreamStatus> result3 = new ResultObserver<>();
    final StreamConfiguration configuration3 = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
    this.controllerService.updateStream(ModelHelper.decode(SCOPE1, "unknownstream", configuration3), result3);
    updateStreamStatus = result3.get();
    Assert.assertEquals(UpdateStreamStatus.Status.STREAM_NOT_FOUND, updateStreamStatus.getStatus());
}
Also used : UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Test(org.junit.Test)

Example 7 with UpdateStreamStatus

use of io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus in project pravega by pravega.

the class ControllerServiceImplTest method sealStreamTests.

@Test
public void sealStreamTests() {
    CreateScopeStatus createScopeStatus;
    CreateStreamStatus createStreamStatus;
    UpdateStreamStatus updateStreamStatus;
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE1).streamName(STREAM1).scalingPolicy(ScalingPolicy.fixed(4)).build();
    // Create a test scope.
    ResultObserver<CreateScopeStatus> result1 = new ResultObserver<>();
    this.controllerService.createScope(ModelHelper.createScopeInfo(SCOPE1), result1);
    createScopeStatus = result1.get();
    assertEquals("Create Scope", CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
    // Create a test stream.
    ResultObserver<CreateStreamStatus> result2 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration1), result2);
    createStreamStatus = result2.get();
    assertEquals("Create stream", CreateStreamStatus.Status.SUCCESS, createStreamStatus.getStatus());
    // Seal a test stream.
    ResultObserver<UpdateStreamStatus> result3 = new ResultObserver<>();
    this.controllerService.sealStream(ModelHelper.createStreamInfo(SCOPE1, STREAM1), result3);
    updateStreamStatus = result3.get();
    assertEquals("Seal Stream", UpdateStreamStatus.Status.SUCCESS, updateStreamStatus.getStatus());
    // Seal a non-existent stream.
    ResultObserver<UpdateStreamStatus> result4 = new ResultObserver<>();
    this.controllerService.sealStream(ModelHelper.createStreamInfo(SCOPE1, "dummyStream"), result4);
    updateStreamStatus = result4.get();
    assertEquals("Seal non-existent stream", UpdateStreamStatus.Status.STREAM_NOT_FOUND, updateStreamStatus.getStatus());
    // Seal a non-existent stream.
    ResultObserver<UpdateStreamStatus> result5 = new ResultObserver<>();
    this.controllerService.sealStream(ModelHelper.createStreamInfo("dummyScope", STREAM1), result5);
    updateStreamStatus = result5.get();
    assertEquals("Seal non-existent stream", UpdateStreamStatus.Status.STREAM_NOT_FOUND, updateStreamStatus.getStatus());
}
Also used : UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Test(org.junit.Test)

Example 8 with UpdateStreamStatus

use of io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus in project pravega by pravega.

the class ControllerServiceImplTest method deleteStreamTests.

@Test
public void deleteStreamTests() {
    CreateScopeStatus createScopeStatus;
    CreateStreamStatus createStreamStatus;
    DeleteStreamStatus deleteStreamStatus;
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE1).streamName(STREAM1).scalingPolicy(ScalingPolicy.fixed(4)).build();
    // Create a test scope.
    ResultObserver<CreateScopeStatus> result1 = new ResultObserver<>();
    this.controllerService.createScope(ModelHelper.createScopeInfo(SCOPE1), result1);
    createScopeStatus = result1.get();
    assertEquals("Create Scope", CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
    // Try deleting a non-existent stream.
    ResultObserver<DeleteStreamStatus> result2 = new ResultObserver<>();
    this.controllerService.deleteStream(ModelHelper.createStreamInfo(SCOPE3, "dummyStream"), result2);
    deleteStreamStatus = result2.get();
    assertEquals("Delete Non-existent stream", DeleteStreamStatus.Status.STREAM_NOT_FOUND, deleteStreamStatus.getStatus());
    // Try deleting a non-existent stream.
    ResultObserver<DeleteStreamStatus> result3 = new ResultObserver<>();
    this.controllerService.deleteStream(ModelHelper.createStreamInfo("dummyScope", "dummyStream"), result3);
    deleteStreamStatus = result3.get();
    assertEquals("Delete Non-existent stream", DeleteStreamStatus.Status.STREAM_NOT_FOUND, deleteStreamStatus.getStatus());
    // Create a test stream.
    ResultObserver<CreateStreamStatus> result4 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(configuration1), result4);
    createStreamStatus = result4.get();
    Assert.assertEquals("Create stream", CreateStreamStatus.Status.SUCCESS, createStreamStatus.getStatus());
    // Try deleting the test stream without sealing it first.
    ResultObserver<DeleteStreamStatus> result5 = new ResultObserver<>();
    this.controllerService.deleteStream(ModelHelper.createStreamInfo(SCOPE1, STREAM1), result5);
    deleteStreamStatus = result5.get();
    assertEquals("Delete non-sealed stream", DeleteStreamStatus.Status.STREAM_NOT_SEALED, deleteStreamStatus.getStatus());
    // Seal the test stream.
    ResultObserver<UpdateStreamStatus> result6 = new ResultObserver<>();
    this.controllerService.sealStream(ModelHelper.createStreamInfo(SCOPE1, STREAM1), result6);
    UpdateStreamStatus updateStreamStatus = result6.get();
    assertEquals("Seal stream", UpdateStreamStatus.Status.SUCCESS, updateStreamStatus.getStatus());
    // Delete the sealed stream.
    ResultObserver<DeleteStreamStatus> result7 = new ResultObserver<>();
    this.controllerService.deleteStream(ModelHelper.createStreamInfo(SCOPE1, STREAM1), result7);
    deleteStreamStatus = result7.get();
    assertEquals("Delete sealed stream", DeleteStreamStatus.Status.SUCCESS, deleteStreamStatus.getStatus());
}
Also used : UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) DeleteStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteStreamStatus) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Test(org.junit.Test)

Example 9 with UpdateStreamStatus

use of io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus in project pravega by pravega.

the class ControllerImpl method sealStream.

@Override
public CompletableFuture<Boolean> sealStream(final String scope, final String streamName) {
    Exceptions.checkNotClosed(closed.get(), this);
    Exceptions.checkNotNullOrEmpty(scope, "scope");
    Exceptions.checkNotNullOrEmpty(streamName, "streamName");
    long traceId = LoggerHelpers.traceEnter(log, "sealStream", scope, streamName);
    final CompletableFuture<UpdateStreamStatus> result = this.retryConfig.runAsync(() -> {
        RPCAsyncCallback<UpdateStreamStatus> callback = new RPCAsyncCallback<>();
        client.sealStream(ModelHelper.createStreamInfo(scope, streamName), callback);
        return callback.getFuture();
    }, this.executor);
    return result.thenApply(x -> {
        switch(x.getStatus()) {
            case FAILURE:
                log.warn("Failed to seal stream: {}", streamName);
                throw new ControllerFailureException("Failed to seal stream: " + streamName);
            case SCOPE_NOT_FOUND:
                log.warn("Scope not found: {}", scope);
                throw new InvalidStreamException("Scope does not exist: " + scope);
            case STREAM_NOT_FOUND:
                log.warn("Stream does not exist: {}", streamName);
                throw new InvalidStreamException("Stream does not exist: " + streamName);
            case SUCCESS:
                log.info("Successfully sealed stream: {}", streamName);
                return true;
            case UNRECOGNIZED:
            default:
                throw new ControllerFailureException("Unknown return status scealing stream " + streamName + " " + x.getStatus());
        }
    }).whenComplete((x, e) -> {
        if (e != null) {
            log.warn("sealStream failed: ", e);
        }
        LoggerHelpers.traceLeave(log, "sealStream", traceId);
    });
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) ManagedChannel(io.grpc.ManagedChannel) Retry(io.pravega.common.util.Retry) NegotiationType(io.grpc.netty.NegotiationType) MoreCallCredentials(io.grpc.auth.MoreCallCredentials) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) PingTxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnRequest) SegmentRanges(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRanges) GetSegmentsRequest(io.pravega.controller.stream.api.grpc.v1.Controller.GetSegmentsRequest) StreamObserver(io.grpc.stub.StreamObserver) Stream(io.pravega.client.stream.Stream) Map(java.util.Map) Collectors.summarizingInt(java.util.stream.Collectors.summarizingInt) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) Transaction(io.pravega.client.stream.Transaction) DeleteScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) Collection(java.util.Collection) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) NavigableMap(java.util.NavigableMap) Collectors(java.util.stream.Collectors) List(java.util.List) SSLException(javax.net.ssl.SSLException) Slf4j(lombok.extern.slf4j.Slf4j) CreateTxnResponse(io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnResponse) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Futures(io.pravega.common.concurrent.Futures) Segment(io.pravega.client.segment.impl.Segment) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) ScaleStatusRequest(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusRequest) Exceptions(io.pravega.common.Exceptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ScaleStatusResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse) ScopeInfo(io.pravega.controller.stream.api.grpc.v1.Controller.ScopeInfo) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SuccessorResponse(io.pravega.controller.stream.api.grpc.v1.Controller.SuccessorResponse) PingFailedException(io.pravega.client.stream.PingFailedException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) NodeUri(io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri) ScaleRequest(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleRequest) CreateTxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest) StreamInfo(io.pravega.controller.stream.api.grpc.v1.Controller.StreamInfo) DeleteStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteStreamStatus) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ControllerServiceGrpc(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc) ScaleResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse) LoggerHelpers(io.pravega.common.LoggerHelpers) Futures.getAndHandleExceptions(io.pravega.common.concurrent.Futures.getAndHandleExceptions) lombok.val(lombok.val) SegmentRange(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRange) File(java.io.File) StatusRuntimeException(io.grpc.StatusRuntimeException) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) TimeUnit(java.util.concurrent.TimeUnit) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) TreeMap(java.util.TreeMap) UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) TxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Preconditions(com.google.common.base.Preconditions) RoundRobinLoadBalancerFactory(io.grpc.util.RoundRobinLoadBalancerFactory) SegmentsAtTime(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentsAtTime) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TxnFailedException(io.pravega.client.stream.TxnFailedException) TxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.TxnRequest) ArrayDeque(java.util.ArrayDeque) SegmentValidityResponse(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentValidityResponse) Collections(java.util.Collections) GrpcSslContexts(io.grpc.netty.GrpcSslContexts) UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) InvalidStreamException(io.pravega.client.stream.InvalidStreamException)

Example 10 with UpdateStreamStatus

use of io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus in project pravega by pravega.

the class ControllerServiceImplTest method truncateSealedStreamTest.

@Test
public void truncateSealedStreamTest() {
    CreateScopeStatus createScopeStatus;
    CreateStreamStatus createStreamStatus;
    UpdateStreamStatus truncateStreamStatus;
    final StreamConfiguration configuration1 = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(4)).build();
    // Create a test scope.
    ResultObserver<CreateScopeStatus> result1 = new ResultObserver<>();
    this.controllerService.createScope(ModelHelper.createScopeInfo(SCOPE1), result1);
    createScopeStatus = result1.get();
    assertEquals("Create Scope", CreateScopeStatus.Status.SUCCESS, createScopeStatus.getStatus());
    // Create a test stream.
    ResultObserver<CreateStreamStatus> result2 = new ResultObserver<>();
    this.controllerService.createStream(ModelHelper.decode(SCOPE1, STREAM1, configuration1), result2);
    createStreamStatus = result2.get();
    Assert.assertEquals("Create stream", CreateStreamStatus.Status.SUCCESS, createStreamStatus.getStatus());
    // Seal the test stream.
    ResultObserver<UpdateStreamStatus> result3 = new ResultObserver<>();
    this.controllerService.sealStream(ModelHelper.createStreamInfo(SCOPE1, STREAM1), result3);
    UpdateStreamStatus updateStreamStatus = result3.get();
    assertEquals("Seal stream", UpdateStreamStatus.Status.SUCCESS, updateStreamStatus.getStatus());
    // Truncate the sealed test stream
    ResultObserver<UpdateStreamStatus> result4 = new ResultObserver<>();
    this.controllerService.truncateStream(Controller.StreamCut.newBuilder().setStreamInfo(StreamInfo.newBuilder().setScope(SCOPE1).setStream(STREAM1).build()).putCut(0, 0).putCut(1, 0).putCut(2, 0).putCut(3, 0).build(), result4);
    truncateStreamStatus = result4.get();
    assertEquals("Truncate sealed stream", UpdateStreamStatus.Status.STREAM_SEALED, truncateStreamStatus.getStatus());
}
Also used : UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Test(org.junit.Test)

Aggregations

UpdateStreamStatus (io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus)15 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)14 CreateScopeStatus (io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus)12 CreateStreamStatus (io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus)12 Test (org.junit.Test)11 DeleteStreamStatus (io.pravega.controller.stream.api.grpc.v1.Controller.DeleteStreamStatus)6 CreateTxnRequest (io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest)4 DeleteScopeStatus (io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus)4 GetSegmentsRequest (io.pravega.controller.stream.api.grpc.v1.Controller.GetSegmentsRequest)4 NodeUri (io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri)4 PingTxnRequest (io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnRequest)4 PingTxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus)4 ScaleRequest (io.pravega.controller.stream.api.grpc.v1.Controller.ScaleRequest)4 ScaleResponse (io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse)4 Segment (io.pravega.client.segment.impl.Segment)3 ScaleStatusRequest (io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusRequest)3 ScaleStatusResponse (io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse)3 ScopeInfo (io.pravega.controller.stream.api.grpc.v1.Controller.ScopeInfo)3 SegmentId (io.pravega.controller.stream.api.grpc.v1.Controller.SegmentId)3 SegmentRanges (io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRanges)3