Search in sources :

Example 6 with ErrorResponse

use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.

the class PackageRouter method performInsertPackageRoutingAsync.

/**
 * Perform the routing task async
 * @param packageSequence
 * @param insertTupleRequest
 * @param boundingBox
 */
public void performInsertPackageRoutingAsync(final short packageSequence, final InsertTupleRequest insertTupleRequest) {
    final Runnable routeRunable = new ExceptionSafeRunnable() {

        @Override
        protected void runThread() {
            boolean operationSuccess = true;
            try {
                final RoutingHeader routingHeader = insertTupleRequest.getRoutingHeader();
                assert (routingHeader.isRoutedPackage()) : "Tuple is not a routed package";
                if (!routingHeader.reachedFinalInstance()) {
                    routingHeader.dispatchToNextHop();
                    operationSuccess = sendInsertPackage(insertTupleRequest);
                }
            } catch (InterruptedException e) {
                logger.error("Exception while routing package", e);
                Thread.currentThread().interrupt();
                operationSuccess = false;
            } catch (PackageEncodeException e) {
                logger.error("Exception while routing package", e);
                operationSuccess = false;
            }
            if (operationSuccess) {
                final SuccessResponse responsePackage = new SuccessResponse(packageSequence);
                clientConnectionHandler.writeResultPackageNE(responsePackage);
            } else {
                final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_ROUTING_FAILED);
                clientConnectionHandler.writeResultPackageNE(responsePackage);
            }
        }
    };
    // Submit the runnable to our pool
    if (threadPool.isShutdown()) {
        logger.warn("Thread pool is shutting down, don't route package: {}", packageSequence);
        final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_QUERY_SHUTDOWN);
        clientConnectionHandler.writeResultPackageNE(responsePackage);
    } else {
        threadPool.submit(routeRunable);
    }
}
Also used : SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) ExceptionSafeRunnable(org.bboxdb.commons.concurrent.ExceptionSafeRunnable) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) ExceptionSafeRunnable(org.bboxdb.commons.concurrent.ExceptionSafeRunnable) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 7 with ErrorResponse

use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.

the class DeleteTableHandler method handleRequest.

@Override
public /**
 * Handle the delete table call
 */
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    try {
        final DeleteTableRequest deletePackage = DeleteTableRequest.decodeTuple(encodedPackage);
        final TupleStoreName requestTable = deletePackage.getTable();
        logger.info("Got delete call for table: {}", requestTable);
        // Delete zookeeper configuration
        final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
        tupleStoreAdapter.deleteTable(requestTable);
        // Clear cached data
        TupleStoreConfigurationCache.getInstance().clear();
        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 : DeleteTableRequest(org.bboxdb.network.packages.request.DeleteTableRequest) SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 8 with ErrorResponse

use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.

the class KeepAliveHandler method handleRequest.

/**
 * Handle the keep alive package. Simply send a success response package back
 */
@Override
public boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    this.clientConnectionHandler = clientConnectionHandler;
    final KeepAliveRequest keepAliveRequst = KeepAliveRequest.decodeTuple(encodedPackage);
    boolean gossipResult = true;
    if (!keepAliveRequst.getTuples().isEmpty()) {
        gossipResult = handleGossip(keepAliveRequst, clientConnectionHandler);
    }
    if (gossipResult) {
        final SuccessResponse responsePackage = new SuccessResponse(packageSequence);
        clientConnectionHandler.writeResultPackage(responsePackage);
    } else {
        final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_OUTDATED_TUPLES);
        clientConnectionHandler.writeResultPackage(responsePackage);
    }
    return true;
}
Also used : SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) KeepAliveRequest(org.bboxdb.network.packages.request.KeepAliveRequest) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 9 with ErrorResponse

use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.

the class ClientConnectionHandler method handleQuery.

/**
 * Handle query package
 * @param bb
 * @param packageSequence
 * @return
 * @throws PackageEncodeException
 * @throws IOException
 */
protected boolean handleQuery(final ByteBuffer encodedPackage, final short packageSequence) throws IOException, PackageEncodeException {
    final byte queryType = NetworkPackageDecoder.getQueryTypeFromRequest(encodedPackage);
    if (!queryHandlerList.containsKey(queryType)) {
        logger.warn("Unsupported query type: {}", queryType);
        final ErrorResponse errorResponse = new ErrorResponse(packageSequence, ErrorMessages.ERROR_UNSUPPORTED_PACKAGE_TYPE);
        writeResultPackage(errorResponse);
        return false;
    }
    if (activeQueries.size() > MAX_RUNNING_QUERIES) {
        logger.warn("Client requested more than {} parallel queries", MAX_RUNNING_QUERIES);
        final ErrorResponse errorResponse = new ErrorResponse(packageSequence, ErrorMessages.ERROR_QUERY_TO_MUCH);
        writeResultPackage(errorResponse);
    } else {
        final QueryHandler queryHandler = queryHandlerList.get(queryType);
        queryHandler.handleQuery(encodedPackage, packageSequence, this);
    }
    return true;
}
Also used : QueryHandler(org.bboxdb.network.server.handler.query.QueryHandler) CancelQueryHandler(org.bboxdb.network.server.handler.request.CancelQueryHandler) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 10 with ErrorResponse

use of org.bboxdb.network.packages.response.ErrorResponse in project bboxdb by jnidzwetzki.

the class CreateDistributionGroupHandler method handleRequest.

@Override
public /**
 * Create a new distribution group
 */
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    try {
        final CreateDistributionGroupRequest createPackage = CreateDistributionGroupRequest.decodeTuple(encodedPackage);
        final String distributionGroup = createPackage.getDistributionGroup();
        logger.info("Create distribution group: {}", distributionGroup);
        final DistributionGroupAdapter distributionGroupAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionGroupAdapter();
        final DistributionRegionAdapter distributionRegionAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
        final List<String> knownGroups = distributionGroupAdapter.getDistributionGroups();
        if (knownGroups.contains(distributionGroup)) {
            logger.error("Untable to create distributon group {}, already exists", distributionGroup);
            final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_DGROUP_EXISTS);
            clientConnectionHandler.writeResultPackage(responsePackage);
            return true;
        }
        distributionGroupAdapter.createDistributionGroup(distributionGroup, createPackage.getDistributionGroupConfiguration());
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
        final DistributionRegion region = spacePartitioner.getRootNode();
        distributionRegionAdapter.setStateForDistributionRegion(region, DistributionRegionState.ACTIVE);
        clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
    } catch (Exception e) {
        logger.warn("Error while create 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) CreateDistributionGroupRequest(org.bboxdb.network.packages.request.CreateDistributionGroupRequest) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

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