Search in sources :

Example 6 with DistributionGroupAdapter

use of org.bboxdb.distribution.zookeeper.DistributionGroupAdapter in project bboxdb by jnidzwetzki.

the class CreateInitialPartitioning method doesGroupExist.

/**
 * Does the group exist?
 * @param distributionGroup
 * @throws ZookeeperException
 * @throws ZookeeperNotFoundException
 */
private static void doesGroupExist(final String distributionGroup) throws ZookeeperException, ZookeeperNotFoundException {
    final DistributionGroupAdapter adapter = ZookeeperClientFactory.getZookeeperClient().getDistributionGroupAdapter();
    final List<String> knownGroups = adapter.getDistributionGroups();
    if (!knownGroups.contains(distributionGroup)) {
        System.err.format("Distribution group %s does not exist%n", distributionGroup);
        System.exit(-1);
    }
}
Also used : DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)

Example 7 with DistributionGroupAdapter

use of org.bboxdb.distribution.zookeeper.DistributionGroupAdapter 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 8 with DistributionGroupAdapter

use of org.bboxdb.distribution.zookeeper.DistributionGroupAdapter 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)

Example 9 with DistributionGroupAdapter

use of org.bboxdb.distribution.zookeeper.DistributionGroupAdapter in project bboxdb by jnidzwetzki.

the class DistributedRecoveryService method checkGroupVersion.

/**
 * Check the group version
 * @param storage
 * @param distributionGroupName
 * @param zookeeperClient
 */
protected void checkGroupVersion(final DiskStorage storage, final String distributionGroupName, final ZookeeperClient zookeeperClient) {
    try {
        final DistributionGroupMetadata metaData = DistributionGroupMetadataHelper.getMedatadaForGroup(storage.getBasedir().getAbsolutePath(), distributionGroupName);
        if (metaData == null) {
            logger.debug("Metadata for storage {} and group {} is null, skipping check", storage.getBasedir(), distributionGroupName);
            return;
        }
        final DistributionGroupAdapter distributionGroupZookeeperAdapter = new DistributionGroupAdapter(zookeeperClient);
        final String path = distributionGroupZookeeperAdapter.getDistributionGroupPath(distributionGroupName);
        final long remoteVersion = NodeMutationHelper.getNodeMutationVersion(zookeeperClient, path, null);
        final long localVersion = metaData.getVersion();
        if (remoteVersion != localVersion) {
            logger.error("Local version {} of dgroup {} does not match remtote version {}", localVersion, distributionGroupName, remoteVersion);
            System.exit(-1);
        }
    } catch (ZookeeperException | ZookeeperNotFoundException e) {
        logger.error("Got an exception while checking group version");
    }
}
Also used : DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) DistributionGroupMetadata(org.bboxdb.storage.entity.DistributionGroupMetadata)

Aggregations

DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)9 ZookeeperClient (org.bboxdb.distribution.zookeeper.ZookeeperClient)3 IOException (java.io.IOException)2 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)2 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)2 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)2 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)2 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)2 SuccessResponse (org.bboxdb.network.packages.response.SuccessResponse)2 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)2 DistributionGroupMetadata (org.bboxdb.storage.entity.DistributionGroupMetadata)2 ImmutableMultiset (com.google.common.collect.ImmutableMultiset)1 InputParseException (org.bboxdb.commons.InputParseException)1 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)1 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)1 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)1 CreateDistributionGroupRequest (org.bboxdb.network.packages.request.CreateDistributionGroupRequest)1 DeleteDistributionGroupRequest (org.bboxdb.network.packages.request.DeleteDistributionGroupRequest)1 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)1 BeforeClass (org.junit.BeforeClass)1