Search in sources :

Example 6 with SuccessResponse

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

the class TestNetworkClasses method getPackageTypeFromResponse1.

/**
 * Get the package type from the response
 * @throws PackageEncodeException
 * @throws IOException
 */
@Test(timeout = 60000)
public void getPackageTypeFromResponse1() throws PackageEncodeException, IOException {
    final SuccessResponse response = new SuccessResponse((short) 2);
    final byte[] encodedPackage = networkPackageToByte(response);
    Assert.assertNotNull(encodedPackage);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    Assert.assertEquals(NetworkConst.RESPONSE_TYPE_SUCCESS, NetworkPackageDecoder.getPackageTypeFromResponse(bb));
}
Also used : SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 7 with SuccessResponse

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

the class TestNetworkClasses method testGetResultBodyLength2.

/**
 * Read the body length from a result package
 * @throws PackageEncodeException
 * @throws IOException
 */
@Test(timeout = 60000)
public void testGetResultBodyLength2() throws PackageEncodeException, IOException {
    final SuccessResponse response = new SuccessResponse((short) 2, "abc");
    final byte[] encodedPackage = networkPackageToByte(response);
    Assert.assertNotNull(encodedPackage);
    // 2 Byte (short) data length
    int calculatedBodyLength = 5;
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    long bodyLength = NetworkPackageDecoder.getBodyLengthFromResponsePackage(bb);
    Assert.assertEquals(calculatedBodyLength, bodyLength);
}
Also used : SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 8 with SuccessResponse

use of org.bboxdb.network.packages.response.SuccessResponse 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)

Example 9 with SuccessResponse

use of org.bboxdb.network.packages.response.SuccessResponse 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 10 with SuccessResponse

use of org.bboxdb.network.packages.response.SuccessResponse 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)

Aggregations

SuccessResponse (org.bboxdb.network.packages.response.SuccessResponse)12 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)7 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)6 IOException (java.io.IOException)4 ByteBuffer (java.nio.ByteBuffer)4 Test (org.junit.Test)4 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)2 TupleStoreAdapter (org.bboxdb.distribution.zookeeper.TupleStoreAdapter)2 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)2 ExceptionSafeRunnable (org.bboxdb.commons.concurrent.ExceptionSafeRunnable)1 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)1 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)1 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)1 CancelQueryRequest (org.bboxdb.network.packages.request.CancelQueryRequest)1 CreateDistributionGroupRequest (org.bboxdb.network.packages.request.CreateDistributionGroupRequest)1 CreateTableRequest (org.bboxdb.network.packages.request.CreateTableRequest)1 DeleteDistributionGroupRequest (org.bboxdb.network.packages.request.DeleteDistributionGroupRequest)1 DeleteTableRequest (org.bboxdb.network.packages.request.DeleteTableRequest)1 KeepAliveRequest (org.bboxdb.network.packages.request.KeepAliveRequest)1 ClientQuery (org.bboxdb.network.server.ClientQuery)1