Search in sources :

Example 1 with OperationUnsupported

use of io.pravega.shared.protocol.netty.WireCommands.OperationUnsupported 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 OperationUnsupported

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

the class AppendProcessorTest method testUnsupportedOperation.

@Test
public void testUnsupportedOperation() {
    String streamSegmentName = "testAppendSegment";
    UUID clientId = UUID.randomUUID();
    byte[] data = new byte[] { 1, 2, 3, 4, 6, 7, 8, 9 };
    StreamSegmentStore store = mock(StreamSegmentStore.class);
    ServerConnection connection = mock(ServerConnection.class);
    AppendProcessor processor = new AppendProcessor(store, connection, new FailingRequestProcessor(), null);
    setupGetStreamSegmentInfo(streamSegmentName, clientId, store);
    CompletableFuture<Void> result = Futures.failedFuture(new UnsupportedOperationException());
    when(store.append(streamSegmentName, data, updateEventNumber(clientId, data.length), AppendProcessor.TIMEOUT)).thenReturn(result);
    processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
    processor.append(new Append(streamSegmentName, clientId, data.length, Unpooled.wrappedBuffer(data), null));
    verify(store).getStreamSegmentInfo(anyString(), eq(true), eq(AppendProcessor.TIMEOUT));
    verify(store).append(streamSegmentName, data, updateEventNumber(clientId, data.length), AppendProcessor.TIMEOUT);
    verify(connection).send(new AppendSetup(1, streamSegmentName, clientId, 0));
    verify(connection, atLeast(0)).resumeReading();
    verify(connection).send(new OperationUnsupported(data.length, "appending data"));
    verifyNoMoreInteractions(connection);
    verifyNoMoreInteractions(store);
}
Also used : FailingRequestProcessor(io.pravega.shared.protocol.netty.FailingRequestProcessor) OperationUnsupported(io.pravega.shared.protocol.netty.WireCommands.OperationUnsupported) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Append(io.pravega.shared.protocol.netty.Append) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with OperationUnsupported

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

the class PravegaRequestProcessor method handleException.

private Void handleException(long requestId, String segment, String operation, Throwable u) {
    if (u == null) {
        IllegalStateException exception = new IllegalStateException("No exception to handle.");
        log.error("Error (Segment = '{}', Operation = '{}')", segment, operation, exception);
        throw exception;
    }
    u = Exceptions.unwrap(u);
    if (u instanceof StreamSegmentExistsException) {
        log.info("Segment '{}' already exists and cannot perform operation '{}'.", segment, operation);
        connection.send(new SegmentAlreadyExists(requestId, segment));
    } else if (u instanceof StreamSegmentNotExistsException) {
        log.warn("Segment '{}' does not exist and cannot perform operation '{}'.", segment, operation);
        connection.send(new NoSuchSegment(requestId, segment));
    } else if (u instanceof StreamSegmentSealedException) {
        log.info("Segment '{}' is sealed and cannot perform operation '{}'.", segment, operation);
        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. Operation = '{}').", segment, containerId, operation);
        connection.send(new WrongHost(requestId, segment, ""));
    } else if (u instanceof CancellationException) {
        log.info("Closing connection {} while performing {} due to {}.", connection, operation, u.getMessage());
        connection.close();
    } else if (u instanceof AuthenticationException) {
        log.warn("Authentication error during '{}'.", operation);
        connection.send(new WireCommands.AuthTokenCheckFailed(requestId));
        connection.close();
    } else if (u instanceof UnsupportedOperationException) {
        log.warn("Unsupported Operation '{}'.", operation, u);
        connection.send(new OperationUnsupported(requestId, operation));
    } else if (u instanceof BadOffsetException) {
        BadOffsetException badOffset = (BadOffsetException) u;
        connection.send(new SegmentIsTruncated(requestId, segment, badOffset.getExpectedOffset()));
    } else {
        log.error("Error (Segment = '{}', Operation = '{}')", segment, operation, u);
        // Closing connection should reinitialize things, and hopefully fix the problem
        connection.close();
        throw new IllegalStateException("Unknown exception.", u);
    }
    return null;
}
Also used : 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) CancellationException(java.util.concurrent.CancellationException) SegmentIsTruncated(io.pravega.shared.protocol.netty.WireCommands.SegmentIsTruncated) BadOffsetException(io.pravega.segmentstore.contracts.BadOffsetException) NoSuchSegment(io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment) ContainerNotFoundException(io.pravega.segmentstore.contracts.ContainerNotFoundException)

Aggregations

OperationUnsupported (io.pravega.shared.protocol.netty.WireCommands.OperationUnsupported)3 AuthenticationException (io.pravega.common.auth.AuthenticationException)2 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 SegmentAlreadyExists (io.pravega.shared.protocol.netty.WireCommands.SegmentAlreadyExists)2 SegmentIsSealed (io.pravega.shared.protocol.netty.WireCommands.SegmentIsSealed)2 WrongHost (io.pravega.shared.protocol.netty.WireCommands.WrongHost)2 BadAttributeUpdateException (io.pravega.segmentstore.contracts.BadAttributeUpdateException)1 BadOffsetException (io.pravega.segmentstore.contracts.BadOffsetException)1 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)1 TooManyAttributesException (io.pravega.segmentstore.contracts.TooManyAttributesException)1 Append (io.pravega.shared.protocol.netty.Append)1 FailingRequestProcessor (io.pravega.shared.protocol.netty.FailingRequestProcessor)1 WireCommands (io.pravega.shared.protocol.netty.WireCommands)1 AppendSetup (io.pravega.shared.protocol.netty.WireCommands.AppendSetup)1 InvalidEventNumber (io.pravega.shared.protocol.netty.WireCommands.InvalidEventNumber)1 SegmentIsTruncated (io.pravega.shared.protocol.netty.WireCommands.SegmentIsTruncated)1