use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.
the class CreateTableHandler method handleRequest.
@Override
public /**
* Handle the create table call
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
final CreateTableRequest createPackage = CreateTableRequest.decodeTuple(encodedPackage);
final TupleStoreName requestTable = createPackage.getTable();
logger.info("Got create call for table: {}", requestTable.getFullname());
final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
if (tupleStoreAdapter.isTableKnown(requestTable)) {
logger.warn("Table name is already known {}", requestTable.getFullname());
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_TABLE_EXISTS);
clientConnectionHandler.writeResultPackage(responsePackage);
} else {
tupleStoreAdapter.writeTuplestoreConfiguration(requestTable, createPackage.getTupleStoreConfiguration());
clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
}
} catch (Exception e) {
logger.warn("Error while delete tuple", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.
the class DeleteDistributionGroupHandler method handleRequest.
@Override
public /**
* Delete an existing distribution group
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
final DeleteDistributionGroupRequest deletePackage = DeleteDistributionGroupRequest.decodeTuple(encodedPackage);
final String distributionGroup = deletePackage.getDistributionGroup();
logger.info("Delete distribution group: {}", distributionGroup);
// Delete in Zookeeper
final DistributionGroupAdapter distributionGroupZookeeperAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionGroupAdapter();
distributionGroupZookeeperAdapter.deleteDistributionGroup(distributionGroup);
// Delete local stored data
logger.info("Delete distribution group, delete local stored data");
clientConnectionHandler.getStorageRegistry().deleteAllTablesInDistributionGroup(distributionGroup);
// Clear cached data
TupleStoreConfigurationCache.getInstance().clear();
logger.info("Delete distribution group - DONE");
clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
} catch (Exception e) {
logger.warn("Error while delete distribution group", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.
the class HandshakeHandler method handleRequest.
/**
* Handle the handshake request
*/
@Override
public boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
logger.info("Handshaking with: {}", clientConnectionHandler.clientSocket.getInetAddress());
try {
final HelloRequest heloRequest = HelloRequest.decodeRequest(encodedPackage);
clientConnectionHandler.setConnectionCapabilities(heloRequest.getPeerCapabilities());
final HelloResponse responsePackage = new HelloResponse(packageSequence, NetworkConst.PROTOCOL_VERSION, clientConnectionHandler.getConnectionCapabilities());
clientConnectionHandler.writeResultPackage(responsePackage);
clientConnectionHandler.setConnectionStateToOpen();
return true;
} catch (Exception e) {
logger.warn("Error while reading network package", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
return false;
}
}
use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.
the class InsertTupleHandler method handleRequest.
@Override
public /**
* Handle the insert tuple request
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
if (logger.isDebugEnabled()) {
logger.debug("Got insert tuple request");
}
try {
final InsertTupleRequest insertTupleRequest = InsertTupleRequest.decodeTuple(encodedPackage);
final RoutingHeader routingHeader = insertTupleRequest.getRoutingHeader();
if (!routingHeader.isRoutedPackage()) {
final String errorMessage = "Error while inserting tuple - package is not routed";
logger.error(errorMessage);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, errorMessage);
clientConnectionHandler.writeResultPackage(responsePackage);
return true;
}
// Needs to be rerouted?
if (routingHeader.getHop() == -1) {
routingHeader.dispatchToNextHop();
final RoutingHop localHop = routingHeader.getRoutingHop();
if (PackageRouter.checkLocalSystemNameMatches(localHop)) {
processPackageLocally(packageSequence, clientConnectionHandler, insertTupleRequest);
} else {
logger.debug("Rerouting package {}", packageSequence);
forwardRoutedPackage(packageSequence, clientConnectionHandler, insertTupleRequest);
}
} else {
processPackageLocally(packageSequence, clientConnectionHandler, insertTupleRequest);
}
} catch (RejectedException e) {
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_LOCAL_OPERATION_REJECTED_RETRY + " " + e.getMessage());
clientConnectionHandler.writeResultPackage(responsePackage);
} catch (Throwable e) {
logger.error("Error while inserting tuple", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.
the class NextPageHandler method handleRequest.
@Override
public /**
* Handle the next page package
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
final NextPageRequest nextPagePackage = NextPageRequest.decodeTuple(encodedPackage);
logger.debug("Next page for query {} called", nextPagePackage.getQuerySequence());
// Send tuples as result for original query
clientConnectionHandler.sendNextResultsForQuery(packageSequence, nextPagePackage.getQuerySequence());
} catch (PackageEncodeException e) {
logger.warn("Error getting next page for a query", e);
final ErrorResponse errorResponse = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(errorResponse);
}
return true;
}
Aggregations