Search in sources :

Example 1 with WrongHost

use of io.pravega.shared.protocol.netty.WireCommands.WrongHost in project pravega by pravega.

the class AppendProcessor method handleException.

private void handleException(UUID writerId, long requestId, String segment, String doingWhat, Throwable u) {
    if (u == null) {
        IllegalStateException exception = new IllegalStateException("No exception to handle.");
        log.error("Append processor: Error {} on segment = '{}'", doingWhat, segment, exception);
        throw exception;
    }
    u = Exceptions.unwrap(u);
    if (u instanceof StreamSegmentExistsException) {
        log.warn("Segment '{}' already exists and {} cannot perform operation '{}'.", segment, writerId, doingWhat);
        connection.send(new SegmentAlreadyExists(requestId, segment));
    } else if (u instanceof StreamSegmentNotExistsException) {
        log.warn("Segment '{}' does not exist and {} cannot perform operation '{}'.", segment, writerId, doingWhat);
        connection.send(new NoSuchSegment(requestId, segment));
    } else if (u instanceof StreamSegmentSealedException) {
        log.info("Segment '{}' is sealed and {} cannot perform operation '{}'.", segment, writerId, doingWhat);
        connection.send(new SegmentIsSealed(requestId, segment));
    } else if (u instanceof ContainerNotFoundException) {
        int containerId = ((ContainerNotFoundException) u).getContainerId();
        log.warn("Wrong host. Segment '{}' (Container {}) is not owned and {} cannot perform operation '{}'.", segment, containerId, writerId, doingWhat);
        connection.send(new WrongHost(requestId, segment, ""));
    } else if (u instanceof BadAttributeUpdateException) {
        log.warn("Bad attribute update by {} on segment {}.", writerId, segment, u);
        connection.send(new InvalidEventNumber(writerId, requestId));
        connection.close();
    } else if (u instanceof TooManyAttributesException) {
        log.warn("Attribute limit would be exceeded by {} on segment {}.", writerId, segment, u);
        connection.send(new InvalidEventNumber(writerId, requestId));
        connection.close();
    } else if (u instanceof AuthenticationException) {
        log.warn("Token check failed while being written by {} on segment {}.", writerId, segment, u);
        connection.send(new WireCommands.AuthTokenCheckFailed(requestId));
        connection.close();
    } else if (u instanceof UnsupportedOperationException) {
        log.warn("Unsupported Operation '{}'.", doingWhat, u);
        connection.send(new OperationUnsupported(requestId, doingWhat));
    } else {
        log.error("Error (Segment = '{}', Operation = 'append')", segment, u);
        // Closing connection should reinitialize things, and hopefully fix the problem
        connection.close();
    }
}
Also used : TooManyAttributesException(io.pravega.segmentstore.contracts.TooManyAttributesException) OperationUnsupported(io.pravega.shared.protocol.netty.WireCommands.OperationUnsupported) AuthenticationException(io.pravega.common.auth.AuthenticationException) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) StreamSegmentExistsException(io.pravega.segmentstore.contracts.StreamSegmentExistsException) SegmentAlreadyExists(io.pravega.shared.protocol.netty.WireCommands.SegmentAlreadyExists) StreamSegmentSealedException(io.pravega.segmentstore.contracts.StreamSegmentSealedException) SegmentIsSealed(io.pravega.shared.protocol.netty.WireCommands.SegmentIsSealed) BadAttributeUpdateException(io.pravega.segmentstore.contracts.BadAttributeUpdateException) InvalidEventNumber(io.pravega.shared.protocol.netty.WireCommands.InvalidEventNumber) NoSuchSegment(io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ContainerNotFoundException(io.pravega.segmentstore.contracts.ContainerNotFoundException)

Example 2 with WrongHost

use of io.pravega.shared.protocol.netty.WireCommands.WrongHost in project pravega by pravega.

the class MockController method createSegmentTx.

private CompletableFuture<Void> createSegmentTx(UUID txId, Segment segment) {
    CompletableFuture<Void> result = new CompletableFuture<>();
    FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

        @Override
        public void connectionDropped() {
            result.completeExceptionally(new ConnectionClosedException());
        }

        @Override
        public void wrongHost(WrongHost wrongHost) {
            result.completeExceptionally(new UnsupportedOperationException());
        }

        @Override
        public void transactionCreated(TransactionCreated transactionCreated) {
            result.complete(null);
        }

        @Override
        public void processingFailure(Exception error) {
            result.completeExceptionally(error);
        }

        @Override
        public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
            result.completeExceptionally(new AuthenticationException(authTokenCheckFailed.toString()));
        }
    };
    sendRequestOverNewConnection(new CreateTransaction(idGenerator.get(), segment.getScopedName(), txId, ""), replyProcessor, result);
    return result;
}
Also used : CreateTransaction(io.pravega.shared.protocol.netty.WireCommands.CreateTransaction) CompletableFuture(java.util.concurrent.CompletableFuture) TransactionCreated(io.pravega.shared.protocol.netty.WireCommands.TransactionCreated) AuthenticationException(io.pravega.common.auth.AuthenticationException) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) AuthenticationException(io.pravega.common.auth.AuthenticationException) TxnFailedException(io.pravega.client.stream.TxnFailedException) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException)

Example 3 with WrongHost

use of io.pravega.shared.protocol.netty.WireCommands.WrongHost in project pravega by pravega.

the class MockController method deleteSegment.

private boolean deleteSegment(String name, PravegaNodeUri uri) {
    CompletableFuture<Boolean> result = new CompletableFuture<>();
    FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

        @Override
        public void connectionDropped() {
            result.completeExceptionally(new ConnectionClosedException());
        }

        @Override
        public void wrongHost(WireCommands.WrongHost wrongHost) {
            result.completeExceptionally(new UnsupportedOperationException());
        }

        @Override
        public void segmentDeleted(WireCommands.SegmentDeleted segmentDeleted) {
            result.complete(true);
        }

        @Override
        public void noSuchSegment(WireCommands.NoSuchSegment noSuchSegment) {
            result.complete(false);
        }

        @Override
        public void processingFailure(Exception error) {
            result.completeExceptionally(error);
        }

        @Override
        public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
            result.completeExceptionally(new AuthenticationException(authTokenCheckFailed.toString()));
        }
    };
    DeleteSegment command = new WireCommands.DeleteSegment(idGenerator.get(), name, "");
    sendRequestOverNewConnection(command, replyProcessor, result);
    return getAndHandleExceptions(result, RuntimeException::new);
}
Also used : AuthenticationException(io.pravega.common.auth.AuthenticationException) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) DeleteSegment(io.pravega.shared.protocol.netty.WireCommands.DeleteSegment) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) AuthenticationException(io.pravega.common.auth.AuthenticationException) TxnFailedException(io.pravega.client.stream.TxnFailedException) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) CompletableFuture(java.util.concurrent.CompletableFuture)

Example 4 with WrongHost

use of io.pravega.shared.protocol.netty.WireCommands.WrongHost in project pravega by pravega.

the class MockController method createSegment.

private boolean createSegment(String name, PravegaNodeUri uri) {
    CompletableFuture<Boolean> result = new CompletableFuture<>();
    FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

        @Override
        public void connectionDropped() {
            result.completeExceptionally(new ConnectionClosedException());
        }

        @Override
        public void wrongHost(WireCommands.WrongHost wrongHost) {
            result.completeExceptionally(new UnsupportedOperationException());
        }

        @Override
        public void segmentAlreadyExists(WireCommands.SegmentAlreadyExists segmentAlreadyExists) {
            result.complete(false);
        }

        @Override
        public void segmentCreated(WireCommands.SegmentCreated segmentCreated) {
            result.complete(true);
        }

        @Override
        public void processingFailure(Exception error) {
            result.completeExceptionally(error);
        }

        @Override
        public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
            result.completeExceptionally(new AuthenticationException(authTokenCheckFailed.toString()));
        }
    };
    CreateSegment command = new WireCommands.CreateSegment(idGenerator.get(), name, WireCommands.CreateSegment.NO_SCALE, 0, "");
    sendRequestOverNewConnection(command, replyProcessor, result);
    return getAndHandleExceptions(result, RuntimeException::new);
}
Also used : AuthenticationException(io.pravega.common.auth.AuthenticationException) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) AuthenticationException(io.pravega.common.auth.AuthenticationException) TxnFailedException(io.pravega.client.stream.TxnFailedException) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) CompletableFuture(java.util.concurrent.CompletableFuture) CreateSegment(io.pravega.shared.protocol.netty.WireCommands.CreateSegment)

Example 5 with WrongHost

use of io.pravega.shared.protocol.netty.WireCommands.WrongHost in project pravega by pravega.

the class MockController method commitTxSegment.

private CompletableFuture<Void> commitTxSegment(UUID txId, Segment segment) {
    CompletableFuture<Void> result = new CompletableFuture<>();
    FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

        @Override
        public void connectionDropped() {
            result.completeExceptionally(new ConnectionClosedException());
        }

        @Override
        public void wrongHost(WrongHost wrongHost) {
            result.completeExceptionally(new UnsupportedOperationException());
        }

        @Override
        public void transactionCommitted(TransactionCommitted transactionCommitted) {
            result.complete(null);
        }

        @Override
        public void transactionAborted(TransactionAborted transactionAborted) {
            result.completeExceptionally(new TxnFailedException("Transaction already aborted."));
        }

        @Override
        public void processingFailure(Exception error) {
            result.completeExceptionally(error);
        }

        @Override
        public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
            result.completeExceptionally(new AuthenticationException(authTokenCheckFailed.toString()));
        }
    };
    sendRequestOverNewConnection(new CommitTransaction(idGenerator.get(), segment.getScopedName(), txId, ""), replyProcessor, result);
    return result;
}
Also used : AuthenticationException(io.pravega.common.auth.AuthenticationException) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) TransactionAborted(io.pravega.shared.protocol.netty.WireCommands.TransactionAborted) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) AuthenticationException(io.pravega.common.auth.AuthenticationException) TxnFailedException(io.pravega.client.stream.TxnFailedException) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) TransactionCommitted(io.pravega.shared.protocol.netty.WireCommands.TransactionCommitted) CommitTransaction(io.pravega.shared.protocol.netty.WireCommands.CommitTransaction) CompletableFuture(java.util.concurrent.CompletableFuture) TxnFailedException(io.pravega.client.stream.TxnFailedException)

Aggregations

AuthenticationException (io.pravega.common.auth.AuthenticationException)7 WrongHost (io.pravega.shared.protocol.netty.WireCommands.WrongHost)7 TxnFailedException (io.pravega.client.stream.TxnFailedException)5 ConnectionClosedException (io.pravega.client.stream.impl.ConnectionClosedException)5 FailingReplyProcessor (io.pravega.shared.protocol.netty.FailingReplyProcessor)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 ContainerNotFoundException (io.pravega.segmentstore.contracts.ContainerNotFoundException)2 StreamSegmentExistsException (io.pravega.segmentstore.contracts.StreamSegmentExistsException)2 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)2 StreamSegmentSealedException (io.pravega.segmentstore.contracts.StreamSegmentSealedException)2 NoSuchSegment (io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment)2 OperationUnsupported (io.pravega.shared.protocol.netty.WireCommands.OperationUnsupported)2 SegmentAlreadyExists (io.pravega.shared.protocol.netty.WireCommands.SegmentAlreadyExists)2 SegmentIsSealed (io.pravega.shared.protocol.netty.WireCommands.SegmentIsSealed)2 TransactionAborted (io.pravega.shared.protocol.netty.WireCommands.TransactionAborted)2 TransactionCommitted (io.pravega.shared.protocol.netty.WireCommands.TransactionCommitted)2 BadAttributeUpdateException (io.pravega.segmentstore.contracts.BadAttributeUpdateException)1 BadOffsetException (io.pravega.segmentstore.contracts.BadOffsetException)1 TooManyAttributesException (io.pravega.segmentstore.contracts.TooManyAttributesException)1 WireCommands (io.pravega.shared.protocol.netty.WireCommands)1