use of org.bboxdb.network.packages.request.CreateDistributionGroupRequest in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method encodeAndDecodeCreateDistributionGroup.
/**
* The the encoding and decoding of an create distribution group package
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void encodeAndDecodeCreateDistributionGroup() throws IOException, PackageEncodeException {
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final DistributionGroupConfiguration distributionGroupConfiguration = DistributionGroupConfigurationBuilder.create(4).withPlacementStrategy("abc", "def").withSpacePartitioner("efg", "ijh").withMaximumRegionSize(33333).withMinimumRegionSize(1111).withReplicationFactor((short) 11).build();
final CreateDistributionGroupRequest groupPackage = new CreateDistributionGroupRequest(sequenceNumber, "test", distributionGroupConfiguration);
byte[] encodedVersion = networkPackageToByte(groupPackage);
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
final CreateDistributionGroupRequest decodedPackage = CreateDistributionGroupRequest.decodeTuple(bb);
Assert.assertEquals(groupPackage.getDistributionGroup(), decodedPackage.getDistributionGroup());
Assert.assertEquals(groupPackage.getDistributionGroupConfiguration(), distributionGroupConfiguration);
Assert.assertEquals(groupPackage.hashCode(), decodedPackage.hashCode());
Assert.assertEquals(groupPackage.toString(), decodedPackage.toString());
}
use of org.bboxdb.network.packages.request.CreateDistributionGroupRequest 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;
}
Aggregations