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));
}
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);
}
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;
}
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;
}
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;
}
Aggregations