Search in sources :

Example 1 with DeleteDistributionGroupRequest

use of org.bboxdb.network.packages.request.DeleteDistributionGroupRequest in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method encodeAndDecodeDeleteDistributionGroup.

/**
 * The the encoding and decoding of an create distribution group package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void encodeAndDecodeDeleteDistributionGroup() throws IOException, PackageEncodeException {
    final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
    final DeleteDistributionGroupRequest groupPackage = new DeleteDistributionGroupRequest(sequenceNumber, "test");
    byte[] encodedVersion = networkPackageToByte(groupPackage);
    Assert.assertNotNull(encodedVersion);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
    final DeleteDistributionGroupRequest decodedPackage = DeleteDistributionGroupRequest.decodeTuple(bb);
    Assert.assertEquals(groupPackage.getDistributionGroup(), decodedPackage.getDistributionGroup());
    Assert.assertEquals(groupPackage, decodedPackage);
    Assert.assertEquals(groupPackage.hashCode(), decodedPackage.hashCode());
    Assert.assertEquals(groupPackage.toString(), decodedPackage.toString());
}
Also used : DeleteDistributionGroupRequest(org.bboxdb.network.packages.request.DeleteDistributionGroupRequest) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with DeleteDistributionGroupRequest

use of org.bboxdb.network.packages.request.DeleteDistributionGroupRequest 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

DeleteDistributionGroupRequest (org.bboxdb.network.packages.request.DeleteDistributionGroupRequest)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)1 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)1 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)1 SuccessResponse (org.bboxdb.network.packages.response.SuccessResponse)1 Test (org.junit.Test)1