Search in sources :

Example 1 with InvalidStreamException

use of io.pravega.client.stream.InvalidStreamException 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");
    final long requestId = requestIdGenerator.get();
    long traceId = LoggerHelpers.traceEnter(log, "sealStream", scope, streamName, requestId);
    final CompletableFuture<UpdateStreamStatus> result = this.retryConfig.runAsync(() -> {
        RPCAsyncCallback<UpdateStreamStatus> callback = new RPCAsyncCallback<>(requestId, "sealStream", scope, streamName);
        new ControllerClientTagger(client, timeoutMillis).withTag(requestId, SEAL_STREAM, scope, streamName).sealStream(ModelHelper.createStreamInfo(scope, streamName), callback);
        return callback.getFuture();
    }, this.executor);
    return result.thenApplyAsync(x -> {
        switch(x.getStatus()) {
            case FAILURE:
                log.warn(requestId, "Failed to seal stream: {}", streamName);
                throw new ControllerFailureException("Failed to seal stream: " + streamName);
            case SCOPE_NOT_FOUND:
                log.warn(requestId, "Scope not found: {}", scope);
                throw new InvalidStreamException("Scope does not exist: " + scope);
            case STREAM_NOT_FOUND:
                log.warn(requestId, "Stream does not exist: {}", streamName);
                throw new InvalidStreamException("Stream does not exist: " + streamName);
            case SUCCESS:
                log.info(requestId, "Successfully sealed stream: {}", streamName);
                return true;
            case UNRECOGNIZED:
            default:
                throw new ControllerFailureException("Unknown return status sealing stream " + streamName + " " + x.getStatus());
        }
    }, this.executor).whenComplete((x, e) -> {
        if (e != null) {
            log.warn(requestId, "sealStream {}/{} failed: ", scope, streamName, e);
        }
        LoggerHelpers.traceLeave(log, "sealStream", traceId, scope, streamName, requestId);
    });
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) StreamConfig(io.pravega.controller.stream.api.grpc.v1.Controller.StreamConfig) NegotiationType(io.grpc.netty.shaded.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) DELETE_STREAM(io.pravega.shared.controller.tracing.RPCTracingTags.DELETE_STREAM) SegmentRanges(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRanges) StreamSegments(io.pravega.client.stream.impl.StreamSegments) NoSuchScopeException(io.pravega.client.stream.NoSuchScopeException) TRUNCATE_STREAM(io.pravega.shared.controller.tracing.RPCTracingTags.TRUNCATE_STREAM) AccessOperation(io.pravega.shared.security.auth.AccessOperation) Map(java.util.Map) SubscriberStreamCut(io.pravega.controller.stream.api.grpc.v1.Controller.SubscriberStreamCut) LIST_SCOPES(io.pravega.shared.controller.tracing.RPCTracingTags.LIST_SCOPES) UPDATE_READER_GROUP(io.pravega.shared.controller.tracing.RPCTracingTags.UPDATE_READER_GROUP) UPDATE_TRUNCATION_STREAM_CUT(io.pravega.shared.controller.tracing.RPCTracingTags.UPDATE_TRUNCATION_STREAM_CUT) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) DeleteScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus) GET_SEGMENTS_IMMEDIATELY_FOLLOWING(io.pravega.shared.controller.tracing.RPCTracingTags.GET_SEGMENTS_IMMEDIATELY_FOLLOWING) ReaderGroupInfo(io.pravega.controller.stream.api.grpc.v1.Controller.ReaderGroupInfo) REMOVE_WRITER(io.pravega.shared.controller.tracing.RPCTracingTags.REMOVE_WRITER) GET_SEGMENTS_BETWEEN_STREAM_CUTS(io.pravega.shared.controller.tracing.RPCTracingTags.GET_SEGMENTS_BETWEEN_STREAM_CUTS) LIST_STREAMS_IN_SCOPE(io.pravega.shared.controller.tracing.RPCTracingTags.LIST_STREAMS_IN_SCOPE) SslContextBuilder(io.grpc.netty.shaded.io.netty.handler.ssl.SslContextBuilder) RequestTracker(io.pravega.common.tracing.RequestTracker) ScopesResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScopesResponse) SSLException(javax.net.ssl.SSLException) KVTablesInScopeRequest(io.pravega.controller.stream.api.grpc.v1.Controller.KVTablesInScopeRequest) GET_STREAM_CONFIGURATION(io.pravega.shared.controller.tracing.RPCTracingTags.GET_STREAM_CONFIGURATION) Futures(io.pravega.common.concurrent.Futures) KeyValueTableSegments(io.pravega.client.tables.impl.KeyValueTableSegments) SegmentId(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentId) StreamCutRangeResponse(io.pravega.controller.stream.api.grpc.v1.Controller.StreamCutRangeResponse) CreateReaderGroupResponse(io.pravega.controller.stream.api.grpc.v1.Controller.CreateReaderGroupResponse) LIST_KEY_VALUE_TABLES(io.pravega.shared.controller.tracing.RPCTracingTags.LIST_KEY_VALUE_TABLES) KeyValueTableConfig(io.pravega.controller.stream.api.grpc.v1.Controller.KeyValueTableConfig) GrpcSslContexts(io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts) Exceptions(io.pravega.common.Exceptions) ScopeInfo(io.pravega.controller.stream.api.grpc.v1.Controller.ScopeInfo) StreamsInScopeWithTagRequest(io.pravega.controller.stream.api.grpc.v1.Controller.StreamsInScopeWithTagRequest) ModelHelper.encode(io.pravega.client.control.impl.ModelHelper.encode) GET_KEY_VALUE_TABLE_CONFIGURATION(io.pravega.shared.controller.tracing.RPCTracingTags.GET_KEY_VALUE_TABLE_CONFIGURATION) Supplier(java.util.function.Supplier) UpdateSubscriberStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateSubscriberStatus) PingFailedException(io.pravega.client.stream.PingFailedException) Strings(com.google.common.base.Strings) Code(io.grpc.Status.Code) NodeUri(io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri) ReaderGroupConfiguration(io.pravega.controller.stream.api.grpc.v1.Controller.ReaderGroupConfiguration) StreamInfo(io.pravega.controller.stream.api.grpc.v1.Controller.StreamInfo) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) GET_SUCCESSORS_FROM_CUT(io.pravega.shared.controller.tracing.RPCTracingTags.GET_SUCCESSORS_FROM_CUT) ControllerServiceGrpc(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc) START_SCALE_STREAM(io.pravega.shared.controller.tracing.RPCTracingTags.START_SCALE_STREAM) StreamSegmentsWithPredecessors(io.pravega.client.stream.impl.StreamSegmentsWithPredecessors) ExistsResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ExistsResponse) RemoveWriterResponse(io.pravega.controller.stream.api.grpc.v1.Controller.RemoveWriterResponse) Callbacks(io.pravega.common.function.Callbacks) AsyncIterator(io.pravega.common.util.AsyncIterator) SegmentRange(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRange) WriterPosition(io.pravega.client.stream.impl.WriterPosition) File(java.io.File) StatusRuntimeException(io.grpc.StatusRuntimeException) CREATE_TRANSACTION(io.pravega.shared.controller.tracing.RPCTracingTags.CREATE_TRANSACTION) RPCTracingHelpers(io.pravega.shared.controller.tracing.RPCTracingHelpers) LIST_STREAMS_IN_SCOPE_FOR_TAG(io.pravega.shared.controller.tracing.RPCTracingTags.LIST_STREAMS_IN_SCOPE_FOR_TAG) TreeMap(java.util.TreeMap) TxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus) Preconditions(com.google.common.base.Preconditions) DeleteReaderGroupStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteReaderGroupStatus) SegmentsAtTime(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentsAtTime) TxnFailedException(io.pravega.client.stream.TxnFailedException) CreateKeyValueTableStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateKeyValueTableStatus) GET_CURRENT_SEGMENTS(io.pravega.shared.controller.tracing.RPCTracingTags.GET_CURRENT_SEGMENTS) CHECK_TRANSACTION_STATE(io.pravega.shared.controller.tracing.RPCTracingTags.CHECK_TRANSACTION_STATE) CREATE_STREAM(io.pravega.shared.controller.tracing.RPCTracingTags.CREATE_STREAM) ManagedChannel(io.grpc.ManagedChannel) Retry(io.pravega.common.util.Retry) LoggerFactory(org.slf4j.LoggerFactory) KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) StreamsInScopeResponse(io.pravega.controller.stream.api.grpc.v1.Controller.StreamsInScopeResponse) ContinuationToken(io.pravega.controller.stream.api.grpc.v1.Controller.ContinuationToken) GetSegmentsRequest(io.pravega.controller.stream.api.grpc.v1.Controller.GetSegmentsRequest) StreamObserver(io.grpc.stub.StreamObserver) TagLogger(io.pravega.common.tracing.TagLogger) ControllerServiceStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceStub) CREATE_KEY_VALUE_TABLE(io.pravega.shared.controller.tracing.RPCTracingTags.CREATE_KEY_VALUE_TABLE) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) Stream(io.pravega.client.stream.Stream) KVTablesInScopeResponse(io.pravega.controller.stream.api.grpc.v1.Controller.KVTablesInScopeResponse) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) SubscribersResponse(io.pravega.controller.stream.api.grpc.v1.Controller.SubscribersResponse) Transaction(io.pravega.client.stream.Transaction) DELETE_KEY_VALUE_TABLE(io.pravega.shared.controller.tracing.RPCTracingTags.DELETE_KEY_VALUE_TABLE) TxnSegments(io.pravega.client.stream.impl.TxnSegments) RetryAndThrowConditionally(io.pravega.common.util.Retry.RetryAndThrowConditionally) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) CHECK_SCOPE_EXISTS(io.pravega.shared.controller.tracing.RPCTracingTags.CHECK_SCOPE_EXISTS) LIST_SUBSCRIBERS(io.pravega.shared.controller.tracing.RPCTracingTags.LIST_SUBSCRIBERS) CHECK_STREAM_EXISTS(io.pravega.shared.controller.tracing.RPCTracingTags.CHECK_STREAM_EXISTS) CREATE_SCOPE(io.pravega.shared.controller.tracing.RPCTracingTags.CREATE_SCOPE) Collection(java.util.Collection) DelegationToken(io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) COMMIT_TRANSACTION(io.pravega.shared.controller.tracing.RPCTracingTags.COMMIT_TRANSACTION) NavigableMap(java.util.NavigableMap) Collectors(java.util.stream.Collectors) GET_SEGMENTS(io.pravega.shared.controller.tracing.RPCTracingTags.GET_SEGMENTS) GET_EPOCH_SEGMENTS(io.pravega.shared.controller.tracing.RPCTracingTags.GET_EPOCH_SEGMENTS) SEAL_STREAM(io.pravega.shared.controller.tracing.RPCTracingTags.SEAL_STREAM) SegmentWithRange(io.pravega.client.stream.impl.SegmentWithRange) List(java.util.List) ABORT_TRANSACTION(io.pravega.shared.controller.tracing.RPCTracingTags.ABORT_TRANSACTION) CreateTxnResponse(io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnResponse) GET_URI(io.pravega.shared.controller.tracing.RPCTracingTags.GET_URI) GetEpochSegmentsRequest(io.pravega.controller.stream.api.grpc.v1.Controller.GetEpochSegmentsRequest) DELETE_READER_GROUP(io.pravega.shared.controller.tracing.RPCTracingTags.DELETE_READER_GROUP) TimestampFromWriter(io.pravega.controller.stream.api.grpc.v1.Controller.TimestampFromWriter) DELETE_SCOPE(io.pravega.shared.controller.tracing.RPCTracingTags.DELETE_SCOPE) PING_TRANSACTION(io.pravega.shared.controller.tracing.RPCTracingTags.PING_TRANSACTION) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) DELETE_SCOPE_RECURSIVE(io.pravega.shared.controller.tracing.RPCTracingTags.DELETE_SCOPE_RECURSIVE) Segment(io.pravega.client.segment.impl.Segment) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) StreamImpl(io.pravega.client.stream.impl.StreamImpl) ScaleStatusRequest(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusRequest) KeyValueTableConfigResponse(io.pravega.controller.stream.api.grpc.v1.Controller.KeyValueTableConfigResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IS_SEGMENT_OPEN(io.pravega.shared.controller.tracing.RPCTracingTags.IS_SEGMENT_OPEN) ScaleStatusResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) SuccessorResponse(io.pravega.controller.stream.api.grpc.v1.Controller.SuccessorResponse) GET_OR_REFRESH_DELEGATION_TOKEN_FOR(io.pravega.shared.controller.tracing.RPCTracingTags.GET_OR_REFRESH_DELEGATION_TOKEN_FOR) ScaleRequest(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleRequest) DeleteKVTableStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteKVTableStatus) CreateTxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest) GET_CURRENT_SEGMENTS_KEY_VALUE_TABLE(io.pravega.shared.controller.tracing.RPCTracingTags.GET_CURRENT_SEGMENTS_KEY_VALUE_TABLE) ScopesRequest(io.pravega.controller.stream.api.grpc.v1.Controller.ScopesRequest) DeleteStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteStreamStatus) NOTE_TIMESTAMP_FROM_WRITER(io.pravega.shared.controller.tracing.RPCTracingTags.NOTE_TIMESTAMP_FROM_WRITER) CHECK_SCALE(io.pravega.shared.controller.tracing.RPCTracingTags.CHECK_SCALE) NettyChannelBuilder(io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder) UPDATE_STREAM(io.pravega.shared.controller.tracing.RPCTracingTags.UPDATE_STREAM) CREATE_READER_GROUP(io.pravega.shared.controller.tracing.RPCTracingTags.CREATE_READER_GROUP) ScaleResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse) SCALE_STREAM(io.pravega.shared.controller.tracing.RPCTracingTags.SCALE_STREAM) LoggerHelpers(io.pravega.common.LoggerHelpers) UpdateReaderGroupResponse(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateReaderGroupResponse) NameUtils(io.pravega.shared.NameUtils) TimestampResponse(io.pravega.controller.stream.api.grpc.v1.Controller.TimestampResponse) StreamsInScopeRequest(io.pravega.controller.stream.api.grpc.v1.Controller.StreamsInScopeRequest) RemoveWriterRequest(io.pravega.controller.stream.api.grpc.v1.Controller.RemoveWriterRequest) GET_READER_GROUP_CONFIG(io.pravega.shared.controller.tracing.RPCTracingTags.GET_READER_GROUP_CONFIG) StreamSegmentSuccessors(io.pravega.client.stream.impl.StreamSegmentSuccessors) TimeUnit(java.util.concurrent.TimeUnit) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) AbstractMap(java.util.AbstractMap) UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) ContinuationTokenAsyncIterator(io.pravega.common.util.ContinuationTokenAsyncIterator) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Credentials(io.pravega.shared.security.auth.Credentials) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RandomFactory(io.pravega.common.hash.RandomFactory) TxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.TxnRequest) ReaderGroupConfigResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ReaderGroupConfigResponse) SegmentValidityResponse(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentValidityResponse) Collections(java.util.Collections) UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) InvalidStreamException(io.pravega.client.stream.InvalidStreamException)

Example 2 with InvalidStreamException

use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.

the class ControllerImpl method commitTransaction.

@Override
public CompletableFuture<Void> commitTransaction(final Stream stream, final String writerId, final Long timestamp, final UUID txId) {
    Exceptions.checkNotClosed(closed.get(), this);
    Preconditions.checkNotNull(stream, "stream");
    Preconditions.checkNotNull(txId, "txId");
    long traceId = LoggerHelpers.traceEnter(log, "commitTransaction", stream, txId);
    final long requestId = requestIdGenerator.get();
    log.info(requestId, "Commit transaction {} invoked on Stream {} for writerId {} with timestamp {}", txId, stream, writerId, timestamp);
    final CompletableFuture<TxnStatus> result = this.retryConfig.runAsync(() -> {
        RPCAsyncCallback<TxnStatus> callback = new RPCAsyncCallback<>(traceId, "commitTransaction", stream, writerId, timestamp, txId);
        TxnRequest.Builder txnRequest = TxnRequest.newBuilder().setStreamInfo(ModelHelper.createStreamInfo(stream.getScope(), stream.getStreamName())).setWriterId(writerId).setTxnId(ModelHelper.decode(txId));
        if (timestamp != null) {
            txnRequest.setTimestamp(timestamp);
        } else {
            txnRequest.setTimestamp(Long.MIN_VALUE);
        }
        new ControllerClientTagger(client, timeoutMillis).withTag(requestId, COMMIT_TRANSACTION, stream.getScope(), stream.getStreamName(), txId.toString()).commitTransaction(txnRequest.build(), callback);
        return callback.getFuture();
    }, this.executor);
    return result.thenApplyAsync(txnStatus -> {
        LoggerHelpers.traceLeave(log, "commitTransaction", traceId, stream, txId);
        if (txnStatus.getStatus().equals(TxnStatus.Status.STREAM_NOT_FOUND)) {
            log.warn(requestId, "Stream {} not found while trying to commit transaction {}", stream.getStreamName(), txId);
            throw new InvalidStreamException("Stream no longer exists: " + stream);
        }
        if (txnStatus.getStatus().equals(TxnStatus.Status.TRANSACTION_NOT_FOUND)) {
            log.warn(requestId, "transaction not found: {} on stream {}", txId, stream);
            throw Exceptions.sneakyThrow(new TxnFailedException("Transaction was already either committed or aborted"));
        }
        if (txnStatus.getStatus().equals(TxnStatus.Status.SUCCESS)) {
            return null;
        }
        log.warn(requestId, "Unable to commit transaction {} on stream {}, commit status is {}", txId, stream, txnStatus.getStatus());
        throw Exceptions.sneakyThrow(new TxnFailedException("Commit transaction failed with status: " + txnStatus.getStatus()));
    }, this.executor);
}
Also used : PingTxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnRequest) CreateTxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest) TxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.TxnRequest) TxnFailedException(io.pravega.client.stream.TxnFailedException) TxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) InvalidStreamException(io.pravega.client.stream.InvalidStreamException)

Example 3 with InvalidStreamException

use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.

the class StreamManagerImpl method deleteScope.

/**
 * A new API is created hence this is going to be deprecated.
 *
 * @deprecated As of Pravega release 0.11.0, replaced by {@link #deleteScopeRecursive(String)}.
 */
@Override
@Deprecated
public boolean deleteScope(String scopeName, boolean forceDelete) throws DeleteScopeFailedException {
    NameUtils.validateUserScopeName(scopeName);
    if (forceDelete) {
        log.info("Deleting scope recursively: {}", scopeName);
        List<String> readerGroupList = new ArrayList<>();
        Iterator<Stream> iterator = listStreams(scopeName);
        while (iterator.hasNext()) {
            Stream stream = iterator.next();
            if (stream.getStreamName().startsWith(READER_GROUP_STREAM_PREFIX)) {
                readerGroupList.add(stream.getStreamName().substring(READER_GROUP_STREAM_PREFIX.length()));
            }
            try {
                Futures.getThrowingException(Futures.exceptionallyExpecting(controller.sealStream(stream.getScope(), stream.getStreamName()), e -> {
                    Throwable unwrap = Exceptions.unwrap(e);
                    // ignore failures if the stream doesn't exist or we are unable to seal it.
                    return unwrap instanceof InvalidStreamException || unwrap instanceof ControllerFailureException;
                }, false).thenCompose(sealed -> controller.deleteStream(stream.getScope(), stream.getStreamName())));
            } catch (Exception e) {
                String message = String.format("Failed to seal and delete stream %s", stream.getStreamName());
                throw new DeleteScopeFailedException(message, e);
            }
        }
        Iterator<KeyValueTableInfo> kvtIterator = controller.listKeyValueTables(scopeName).asIterator();
        while (kvtIterator.hasNext()) {
            KeyValueTableInfo kvt = kvtIterator.next();
            try {
                Futures.getThrowingException(controller.deleteKeyValueTable(scopeName, kvt.getKeyValueTableName()));
            } catch (Exception e) {
                String message = String.format("Failed to delete key-value table %s", kvt.getKeyValueTableName());
                throw new DeleteScopeFailedException(message, e);
            }
        }
        for (String groupName : readerGroupList) {
            try {
                Futures.getThrowingException(controller.getReaderGroupConfig(scopeName, groupName).thenCompose(conf -> controller.deleteReaderGroup(scopeName, groupName, conf.getReaderGroupId())));
            } catch (Exception e) {
                if (Exceptions.unwrap(e) instanceof ReaderGroupNotFoundException) {
                    continue;
                }
                String message = String.format("Failed to delete reader group %s", groupName);
                throw new DeleteScopeFailedException(message, e);
            }
        }
    }
    return Futures.getThrowingException(controller.deleteScope(scopeName));
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) Getter(lombok.Getter) StreamManager(io.pravega.client.admin.StreamManager) Exceptions(io.pravega.common.Exceptions) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ArrayList(java.util.ArrayList) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) AccessLevel(lombok.AccessLevel) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) Stream(io.pravega.client.stream.Stream) StreamCutImpl(io.pravega.client.stream.impl.StreamCutImpl) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) NameUtils(io.pravega.shared.NameUtils) Callbacks(io.pravega.common.function.Callbacks) Iterator(java.util.Iterator) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) Collection(java.util.Collection) AsyncIterator(io.pravega.common.util.AsyncIterator) StreamInfo(io.pravega.client.admin.StreamInfo) READER_GROUP_STREAM_PREFIX(io.pravega.shared.NameUtils.READER_GROUP_STREAM_PREFIX) ControllerImplConfig(io.pravega.client.control.impl.ControllerImplConfig) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Controller(io.pravega.client.control.impl.Controller) Futures(io.pravega.common.concurrent.Futures) ClientConfig(io.pravega.client.ClientConfig) ArrayList(java.util.ArrayList) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Stream(io.pravega.client.stream.Stream) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException)

Example 4 with InvalidStreamException

use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.

the class StreamManagerImplTest method testForceDeleteScope.

@Test(timeout = 10000)
public void testForceDeleteScope() throws ConnectionFailedException, DeleteScopeFailedException {
    // Setup Mocks
    ClientConnection connection = mock(ClientConnection.class);
    PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            WireCommands.CreateSegment request = (WireCommands.CreateSegment) invocation.getArgument(0);
            connectionFactory.getProcessor(location).process(new WireCommands.SegmentCreated(request.getRequestId(), request.getSegment()));
            return null;
        }
    }).when(connection).send(Mockito.any(WireCommands.CreateSegment.class));
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            WireCommands.GetStreamSegmentInfo request = (WireCommands.GetStreamSegmentInfo) invocation.getArgument(0);
            connectionFactory.getProcessor(location).process(new WireCommands.StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0));
            return null;
        }
    }).when(connection).send(Mockito.any(WireCommands.GetStreamSegmentInfo.class));
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            WireCommands.DeleteSegment request = (WireCommands.DeleteSegment) invocation.getArgument(0);
            connectionFactory.getProcessor(location).process(new WireCommands.SegmentDeleted(request.getRequestId(), request.getSegment()));
            return null;
        }
    }).when(connection).send(Mockito.any(WireCommands.DeleteSegment.class));
    connectionFactory.provideConnection(location, connection);
    MockController mockController = spy(new MockController(location.getEndpoint(), location.getPort(), connectionFactory, true));
    ConnectionPoolImpl pool = new ConnectionPoolImpl(ClientConfig.builder().maxConnectionsPerSegmentStore(1).build(), connectionFactory);
    @Cleanup final StreamManager streamManager = new StreamManagerImpl(mockController, pool);
    String scope = "scope";
    String stream1 = "stream1";
    String stream2 = "stream2";
    String stream3 = "stream3";
    streamManager.createScope(scope);
    streamManager.createStream(scope, stream1, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
    streamManager.createStream(scope, stream2, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
    streamManager.createStream(scope, stream3, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
    Set<Stream> streams = Sets.newHashSet(streamManager.listStreams(scope));
    assertEquals(3, streams.size());
    assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream1)));
    assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream2)));
    assertTrue(streams.stream().anyMatch(x -> x.getStreamName().equals(stream3)));
    // mock controller client to throw exceptions when attempting to seal and delete for stream 1.
    doAnswer(x -> Futures.failedFuture(new ControllerFailureException("Unable to seal stream"))).when(mockController).sealStream(scope, stream1);
    doAnswer(x -> Futures.failedFuture(new IllegalArgumentException("Stream not sealed"))).when(mockController).deleteStream(scope, stream1);
    AssertExtensions.assertThrows("Should have thrown exception", () -> streamManager.deleteScope(scope, true), e -> Exceptions.unwrap(e) instanceof DeleteScopeFailedException);
    // reset mock controller
    reset(mockController);
    // throw invalid stream for stream 2. Delete should happen despite invalid stream exception.
    doAnswer(x -> Futures.failedFuture(new InvalidStreamException("Stream does not exist"))).when(mockController).sealStream(scope, stream2);
    assertTrue(streamManager.deleteScope(scope, true));
}
Also used : Arrays(java.util.Arrays) AssertExtensions(io.pravega.test.common.AssertExtensions) Cleanup(lombok.Cleanup) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) KeyValueTableConfiguration(io.pravega.client.tables.KeyValueTableConfiguration) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) StreamSegments(io.pravega.client.stream.impl.StreamSegments) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.connection.impl.ClientConnection) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) Stream(io.pravega.client.stream.Stream) After(org.junit.After) Mockito.doAnswer(org.mockito.Mockito.doAnswer) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) URI(java.net.URI) Mockito.doReturn(org.mockito.Mockito.doReturn) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) Set(java.util.Set) StreamInfo(io.pravega.client.admin.StreamInfo) Sets(com.google.common.collect.Sets) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Assert.assertFalse(org.junit.Assert.assertFalse) TestUtils(io.pravega.test.common.TestUtils) Controller(io.pravega.client.control.impl.Controller) Futures(io.pravega.common.concurrent.Futures) Mockito.mock(org.mockito.Mockito.mock) StreamImpl(io.pravega.client.stream.impl.StreamImpl) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) StreamManager(io.pravega.client.admin.StreamManager) Exceptions(io.pravega.common.Exceptions) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) KeyValueTableManager(io.pravega.client.admin.KeyValueTableManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Lists(com.google.common.collect.Lists) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Before(org.junit.Before) NameUtils(io.pravega.shared.NameUtils) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) Assert.assertTrue(org.junit.Assert.assertTrue) AsyncIterator(io.pravega.common.util.AsyncIterator) Test(org.junit.Test) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Mockito(org.mockito.Mockito) TreeMap(java.util.TreeMap) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Assert(org.junit.Assert) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConfig(io.pravega.client.ClientConfig) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) Cleanup(lombok.Cleanup) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) ClientConnection(io.pravega.client.connection.impl.ClientConnection) Stream(io.pravega.client.stream.Stream) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException) WireCommands(io.pravega.shared.protocol.netty.WireCommands) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StreamManager(io.pravega.client.admin.StreamManager) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) MockController(io.pravega.client.stream.mock.MockController) Test(org.junit.Test)

Example 5 with InvalidStreamException

use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.

the class ReaderGroupManagerImplTest method testDeleteReaderGroupRGStreamDeleted.

@Test
public void testDeleteReaderGroupRGStreamDeleted() {
    ReaderGroupConfig config = ReaderGroupConfig.builder().startFromStreamCuts(ImmutableMap.<Stream, StreamCut>builder().put(createStream("s1"), createStreamCut("s1", 2)).put(createStream("s2"), createStreamCut("s2", 3)).build()).retentionType(ReaderGroupConfig.StreamDataRetention.MANUAL_RELEASE_AT_USER_STREAMCUT).build();
    when(clientFactory.createStateSynchronizer(anyString(), any(Serializer.class), any(Serializer.class), any(SynchronizerConfig.class))).thenThrow(new InvalidStreamException(""));
    when(controller.getReaderGroupConfig(SCOPE, GROUP_NAME)).thenReturn(CompletableFuture.completedFuture(config));
    when(controller.deleteReaderGroup(SCOPE, GROUP_NAME, config.getReaderGroupId())).thenReturn(CompletableFuture.completedFuture(true));
    // Delete ReaderGroup
    readerGroupManager.deleteReaderGroup(GROUP_NAME);
    verify(controller, times(1)).getReaderGroupConfig(SCOPE, GROUP_NAME);
    verify(controller, times(1)).deleteReaderGroup(SCOPE, GROUP_NAME, config.getReaderGroupId());
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamCut(io.pravega.client.stream.StreamCut) IntStream(java.util.stream.IntStream) Stream(io.pravega.client.stream.Stream) SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Serializer(io.pravega.client.stream.Serializer) Test(org.junit.Test)

Aggregations

InvalidStreamException (io.pravega.client.stream.InvalidStreamException)10 Stream (io.pravega.client.stream.Stream)6 Exceptions (io.pravega.common.Exceptions)6 Futures (io.pravega.common.concurrent.Futures)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Preconditions (com.google.common.base.Preconditions)4 KeyValueTableInfo (io.pravega.client.admin.KeyValueTableInfo)4 TxnFailedException (io.pravega.client.stream.TxnFailedException)4 PingTxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus)4 TxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus)4 Collection (java.util.Collection)4 List (java.util.List)4 ClientConfig (io.pravega.client.ClientConfig)3 ConnectionPoolImpl (io.pravega.client.connection.impl.ConnectionPoolImpl)3 Controller (io.pravega.client.control.impl.Controller)3 ControllerFailureException (io.pravega.client.control.impl.ControllerFailureException)3 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)3 ReaderGroupNotFoundException (io.pravega.client.stream.ReaderGroupNotFoundException)3 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)3