Search in sources :

Example 1 with DLException

use of com.twitter.distributedlog.exceptions.DLException in project distributedlog by twitter.

the class TestDistributedLogServer method testRequestDenied.

@Test(timeout = 60000)
public void testRequestDenied() throws Exception {
    String name = "request-denied";
    dlClient.routingService.addHost(name, dlServer.getAddress());
    AccessControlEntry ace = new AccessControlEntry();
    ace.setDenyWrite(true);
    ZooKeeperClient zkc = TestZooKeeperClientBuilder.newBuilder().uri(getUri()).connectionTimeoutMs(60000).sessionTimeoutMs(60000).build();
    DistributedLogNamespace dlNamespace = dlServer.dlServer.getLeft().getDistributedLogNamespace();
    BKDLConfig bkdlConfig = BKDLConfig.resolveDLConfig(zkc, getUri());
    String zkPath = getUri().getPath() + "/" + bkdlConfig.getACLRootPath() + "/" + name;
    ZKAccessControl accessControl = new ZKAccessControl(ace, zkPath);
    accessControl.create(zkc);
    AccessControlManager acm = dlNamespace.createAccessControlManager();
    while (acm.allowWrite(name)) {
        Thread.sleep(100);
    }
    try {
        Await.result(dlClient.dlClient.write(name, ByteBuffer.wrap("1".getBytes(UTF_8))));
        fail("Should fail with request denied exception");
    } catch (DLException dle) {
        assertEquals(StatusCode.REQUEST_DENIED, dle.getCode());
    }
}
Also used : AccessControlManager(com.twitter.distributedlog.acl.AccessControlManager) ZooKeeperClient(com.twitter.distributedlog.ZooKeeperClient) DistributedLogNamespace(com.twitter.distributedlog.namespace.DistributedLogNamespace) DLException(com.twitter.distributedlog.exceptions.DLException) AccessControlEntry(com.twitter.distributedlog.thrift.AccessControlEntry) BKDLConfig(com.twitter.distributedlog.metadata.BKDLConfig) ZKAccessControl(com.twitter.distributedlog.acl.ZKAccessControl) Test(org.junit.Test)

Example 2 with DLException

use of com.twitter.distributedlog.exceptions.DLException in project distributedlog by twitter.

the class StreamImpl method doExecuteOp.

private void doExecuteOp(final StreamOp op, boolean success) {
    final AsyncLogWriter writer;
    final Throwable lastException;
    synchronized (this) {
        writer = this.writer;
        lastException = this.lastException;
    }
    if (null != writer && success) {
        op.execute(writer, sequencer, txnLock).addEventListener(new FutureEventListener<Void>() {

            @Override
            public void onSuccess(Void value) {
            // nop
            }

            @Override
            public void onFailure(Throwable cause) {
                boolean countAsException = true;
                if (cause instanceof DLException) {
                    final DLException dle = (DLException) cause;
                    switch(dle.getCode()) {
                        case FOUND:
                            assert (cause instanceof OwnershipAcquireFailedException);
                            countAsException = false;
                            handleOwnershipAcquireFailedException(op, (OwnershipAcquireFailedException) cause);
                            break;
                        case ALREADY_CLOSED:
                            assert (cause instanceof AlreadyClosedException);
                            op.fail(cause);
                            handleAlreadyClosedException((AlreadyClosedException) cause);
                            break;
                        // exceptions that mostly from client (e.g. too large record)
                        case NOT_IMPLEMENTED:
                        case METADATA_EXCEPTION:
                        case LOG_EMPTY:
                        case LOG_NOT_FOUND:
                        case TRUNCATED_TRANSACTION:
                        case END_OF_STREAM:
                        case TRANSACTION_OUT_OF_ORDER:
                        case INVALID_STREAM_NAME:
                        case TOO_LARGE_RECORD:
                        case STREAM_NOT_READY:
                        case OVER_CAPACITY:
                            op.fail(cause);
                            break;
                        // exceptions that *could* / *might* be recovered by creating a new writer
                        default:
                            handleRecoverableDLException(op, cause);
                            break;
                    }
                } else {
                    handleUnknownException(op, cause);
                }
                if (countAsException) {
                    countException(cause, streamExceptionStatLogger);
                }
            }
        });
    } else {
        op.fail(lastException);
    }
}
Also used : OwnershipAcquireFailedException(com.twitter.distributedlog.exceptions.OwnershipAcquireFailedException) DLException(com.twitter.distributedlog.exceptions.DLException) AsyncLogWriter(com.twitter.distributedlog.AsyncLogWriter) AlreadyClosedException(com.twitter.distributedlog.exceptions.AlreadyClosedException)

Example 3 with DLException

use of com.twitter.distributedlog.exceptions.DLException in project distributedlog by twitter.

the class ResponseUtils method exceptionToHeader.

public static ResponseHeader exceptionToHeader(Throwable t) {
    ResponseHeader response = new ResponseHeader();
    if (t instanceof DLException) {
        DLException dle = (DLException) t;
        if (dle instanceof OwnershipAcquireFailedException) {
            response.setLocation(((OwnershipAcquireFailedException) dle).getCurrentOwner());
        }
        response.setCode(dle.getCode());
        response.setErrMsg(dle.getMessage());
    } else {
        response.setCode(StatusCode.INTERNAL_SERVER_ERROR);
        response.setErrMsg("Internal server error : " + t.getMessage());
    }
    return response;
}
Also used : OwnershipAcquireFailedException(com.twitter.distributedlog.exceptions.OwnershipAcquireFailedException) ResponseHeader(com.twitter.distributedlog.thrift.service.ResponseHeader) DLException(com.twitter.distributedlog.exceptions.DLException)

Example 4 with DLException

use of com.twitter.distributedlog.exceptions.DLException in project distributedlog by twitter.

the class TestDistributedLogServer method validateAllFailedAsCancelled.

int validateAllFailedAsCancelled(List<Future<DLSN>> futures, int start, int finish) {
    int failed = 0;
    for (int i = start; i < finish; i++) {
        Future<DLSN> future = futures.get(i);
        try {
            DLSN dlsn = Await.result(future, Duration.fromSeconds(10));
            fail("future should have failed!");
        } catch (DLException cre) {
            ++failed;
        } catch (Exception ex) {
            failDueToWrongException(ex);
        }
    }
    return failed;
}
Also used : DLSN(com.twitter.distributedlog.DLSN) LogRecordWithDLSN(com.twitter.distributedlog.LogRecordWithDLSN) DLException(com.twitter.distributedlog.exceptions.DLException) DLException(com.twitter.distributedlog.exceptions.DLException) NoBrokersAvailableException(com.twitter.finagle.NoBrokersAvailableException) LogNotFoundException(com.twitter.distributedlog.exceptions.LogNotFoundException)

Example 5 with DLException

use of com.twitter.distributedlog.exceptions.DLException in project distributedlog by twitter.

the class TestDistributedLogServer method validateFailedAsLogRecordTooLong.

void validateFailedAsLogRecordTooLong(Future<DLSN> future) {
    try {
        DLSN dlsn = Await.result(future, Duration.fromSeconds(10));
        fail("should have failed");
    } catch (DLException dle) {
        assertEquals(StatusCode.TOO_LARGE_RECORD, dle.getCode());
    } catch (Exception ex) {
        failDueToWrongException(ex);
    }
}
Also used : DLSN(com.twitter.distributedlog.DLSN) LogRecordWithDLSN(com.twitter.distributedlog.LogRecordWithDLSN) DLException(com.twitter.distributedlog.exceptions.DLException) DLException(com.twitter.distributedlog.exceptions.DLException) NoBrokersAvailableException(com.twitter.finagle.NoBrokersAvailableException) LogNotFoundException(com.twitter.distributedlog.exceptions.LogNotFoundException)

Aggregations

DLException (com.twitter.distributedlog.exceptions.DLException)5 DLSN (com.twitter.distributedlog.DLSN)2 LogRecordWithDLSN (com.twitter.distributedlog.LogRecordWithDLSN)2 LogNotFoundException (com.twitter.distributedlog.exceptions.LogNotFoundException)2 OwnershipAcquireFailedException (com.twitter.distributedlog.exceptions.OwnershipAcquireFailedException)2 NoBrokersAvailableException (com.twitter.finagle.NoBrokersAvailableException)2 AsyncLogWriter (com.twitter.distributedlog.AsyncLogWriter)1 ZooKeeperClient (com.twitter.distributedlog.ZooKeeperClient)1 AccessControlManager (com.twitter.distributedlog.acl.AccessControlManager)1 ZKAccessControl (com.twitter.distributedlog.acl.ZKAccessControl)1 AlreadyClosedException (com.twitter.distributedlog.exceptions.AlreadyClosedException)1 BKDLConfig (com.twitter.distributedlog.metadata.BKDLConfig)1 DistributedLogNamespace (com.twitter.distributedlog.namespace.DistributedLogNamespace)1 AccessControlEntry (com.twitter.distributedlog.thrift.AccessControlEntry)1 ResponseHeader (com.twitter.distributedlog.thrift.service.ResponseHeader)1 Test (org.junit.Test)1