Search in sources :

Example 1 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 2 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 3 with ErrorResponse

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

the class ClientConnectionHandler method sendNextResultsForQuery.

/**
 * Send next results for the given query
 * @param packageSequence
 * @param
 * @throws PackageEncodeException
 * @throws IOException
 */
public void sendNextResultsForQuery(final short packageSequence, final short querySequence) throws IOException, PackageEncodeException {
    if (!getActiveQueries().containsKey(querySequence)) {
        logger.error("Unable to resume query {} - package {} - not found", querySequence, packageSequence);
        writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_QUERY_NOT_FOUND));
        return;
    }
    final Runnable queryRunable = new ExceptionSafeRunnable() {

        @Override
        protected void runThread() throws IOException, PackageEncodeException {
            final ClientQuery clientQuery = getActiveQueries().get(querySequence);
            clientQuery.fetchAndSendNextTuples(packageSequence);
            if (clientQuery.isQueryDone()) {
                logger.info("Query {} is done with {} tuples, removing iterator ", querySequence, clientQuery.getTotalSendTuples());
                clientQuery.close();
                getActiveQueries().remove(querySequence);
            }
        }

        @Override
        protected void afterExceptionHook() {
            try {
                writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
            } catch (IOException | PackageEncodeException e) {
                logger.error("Unable to send result package", e);
            }
        }
    };
    // Submit the runnable to our pool
    if (threadPool.isShutdown()) {
        logger.warn("Thread pool is shutting down, don't execute query: {}", querySequence);
        writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
    } else {
        getThreadPool().submit(queryRunable);
    }
}
Also used : ExceptionSafeRunnable(org.bboxdb.commons.concurrent.ExceptionSafeRunnable) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ExceptionSafeRunnable(org.bboxdb.commons.concurrent.ExceptionSafeRunnable) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 4 with ErrorResponse

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

the class QueryHelper method handleNonExstingTable.

/**
 * Handle a non existing table
 * @param requestTable
 * @param clientConnectionHandler
 * @return
 * @throws PackageEncodeException
 * @throws IOException
 */
public static boolean handleNonExstingTable(final TupleStoreName requestTable, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    // Table is locally known, prevent expensive zookeeper call
    final TupleStoreManagerRegistry storageRegistry = clientConnectionHandler.getStorageRegistry();
    if (storageRegistry.isStorageManagerKnown(requestTable)) {
        return true;
    }
    final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
    try {
        final boolean tableKnown = tupleStoreAdapter.isTableKnown(requestTable);
        if (!tableKnown) {
            clientConnectionHandler.writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_TABLE_NOT_EXIST));
            return false;
        }
    } catch (ZookeeperException e) {
        logger.error("Got an exception while query for table", e);
        return false;
    }
    return true;
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 5 with ErrorResponse

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

the class HandleBoundingBoxQuery method handleQuery.

@Override
public /**
 * Handle a bounding box query
 */
void handleQuery(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    try {
        if (clientConnectionHandler.getActiveQueries().containsKey(packageSequence)) {
            logger.error("Query sequence {} is already known, please close old query first", packageSequence);
            return;
        }
        final QueryBoundingBoxRequest queryRequest = QueryBoundingBoxRequest.decodeTuple(encodedPackage);
        final TupleStoreName requestTable = queryRequest.getTable();
        if (!QueryHelper.handleNonExstingTable(requestTable, packageSequence, clientConnectionHandler)) {
            return;
        }
        final OperatorTreeBuilder operatorTreeBuilder = new OperatorTreeBuilder() {

            @Override
            public Operator buildOperatorTree(final List<TupleStoreManager> storageManager) {
                if (storageManager.size() != 1) {
                    throw new IllegalArgumentException("This operator tree needs 1 storage manager");
                }
                final BoundingBox boundingBox = queryRequest.getBoundingBox();
                final SpatialIndexReadOperator operator = new SpatialIndexReadOperator(storageManager.get(0), boundingBox);
                return operator;
            }
        };
        final StreamClientQuery clientQuery = new StreamClientQuery(operatorTreeBuilder, queryRequest.isPagingEnabled(), queryRequest.getTuplesPerPage(), clientConnectionHandler, packageSequence, Arrays.asList(requestTable));
        clientConnectionHandler.getActiveQueries().put(packageSequence, clientQuery);
        clientConnectionHandler.sendNextResultsForQuery(packageSequence, packageSequence);
    } catch (PackageEncodeException e) {
        logger.warn("Got exception while decoding package", e);
        clientConnectionHandler.writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
    }
}
Also used : QueryBoundingBoxRequest(org.bboxdb.network.packages.request.QueryBoundingBoxRequest) SpatialIndexReadOperator(org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator) BoundingBox(org.bboxdb.commons.math.BoundingBox) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) OperatorTreeBuilder(org.bboxdb.storage.queryprocessor.OperatorTreeBuilder) StreamClientQuery(org.bboxdb.network.server.StreamClientQuery) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) List(java.util.List) 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