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());
}
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations