Search in sources :

Example 11 with ErrorResponse

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;
}
Also used : SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) CreateTableRequest(org.bboxdb.network.packages.request.CreateTableRequest) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 12 with ErrorResponse

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;
}
Also used : DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) DeleteDistributionGroupRequest(org.bboxdb.network.packages.request.DeleteDistributionGroupRequest) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 13 with ErrorResponse

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;
    }
}
Also used : HelloResponse(org.bboxdb.network.packages.response.HelloResponse) HelloRequest(org.bboxdb.network.packages.request.HelloRequest) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 14 with ErrorResponse

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;
}
Also used : RejectedException(org.bboxdb.commons.RejectedException) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) RoutingHop(org.bboxdb.network.routing.RoutingHop) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 15 with ErrorResponse

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;
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) NextPageRequest(org.bboxdb.network.packages.request.NextPageRequest) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Aggregations

ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)20 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)16 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)9 SuccessResponse (org.bboxdb.network.packages.response.SuccessResponse)7 IOException (java.io.IOException)6 List (java.util.List)5 StreamClientQuery (org.bboxdb.network.server.StreamClientQuery)5 OperatorTreeBuilder (org.bboxdb.storage.queryprocessor.OperatorTreeBuilder)5 BoundingBox (org.bboxdb.commons.math.BoundingBox)4 Operator (org.bboxdb.storage.queryprocessor.operator.Operator)4 ExceptionSafeRunnable (org.bboxdb.commons.concurrent.ExceptionSafeRunnable)3 TupleStoreAdapter (org.bboxdb.distribution.zookeeper.TupleStoreAdapter)3 ClientQuery (org.bboxdb.network.server.ClientQuery)3 SpatialIndexReadOperator (org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator)3 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)2 FullTablescanOperator (org.bboxdb.storage.queryprocessor.operator.FullTablescanOperator)2 NewerAsInsertTimeSeclectionOperator (org.bboxdb.storage.queryprocessor.operator.NewerAsInsertTimeSeclectionOperator)2 RejectedException (org.bboxdb.commons.RejectedException)1 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)1 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)1