Search in sources :

Example 16 with DistributionGroupConfiguration

use of org.bboxdb.storage.entity.DistributionGroupConfiguration in project bboxdb by jnidzwetzki.

the class DistributionGroupConfigurationCache method getDistributionGroupConfiguration.

/**
 * Get the distribution group configuration
 * @param distributionGroupName
 * @return
 * @throws ZookeeperNotFoundException
 */
public synchronized DistributionGroupConfiguration getDistributionGroupConfiguration(final String distributionGroupName) throws ZookeeperNotFoundException {
    if (!cache.containsKey(distributionGroupName)) {
        try {
            final ZookeeperClient zookeeperClient = ZookeeperClientFactory.getZookeeperClient();
            final DistributionGroupAdapter distributionGroupZookeeperAdapter = new DistributionGroupAdapter(zookeeperClient);
            final DistributionGroupConfiguration configuration = distributionGroupZookeeperAdapter.getDistributionGroupConfiguration(distributionGroupName);
            addNewConfiguration(distributionGroupName, configuration);
        } catch (InputParseException | ZookeeperException e) {
            logger.error("Exception while reading zokeeper data", e);
            return new DistributionGroupConfiguration();
        }
    }
    return cache.get(distributionGroupName);
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) InputParseException(org.bboxdb.commons.InputParseException) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration)

Example 17 with DistributionGroupConfiguration

use of org.bboxdb.storage.entity.DistributionGroupConfiguration in project bboxdb by jnidzwetzki.

the class DistributionGroupAdapter method getSpaceparitioner.

/**
 * Get the space partitioner of a distribution group
 * @param mapper
 * @param callback
 * @return
 * @throws ZookeeperException
 * @throws ZookeeperNotFoundException
 */
public SpacePartitioner getSpaceparitioner(final String distributionGroup, final Set<DistributionRegionCallback> callback, final DistributionRegionIdMapper mapper) throws ZookeeperException, ZookeeperNotFoundException {
    final String path = getDistributionGroupPath(distributionGroup);
    if (!zookeeperClient.exists(path)) {
        final String exceptionMessage = MessageFormat.format("Unable to read {0}. Path {1} does not exist", distributionGroup, path);
        throw new ZookeeperException(exceptionMessage);
    }
    final DistributionGroupConfiguration config = DistributionGroupConfigurationCache.getInstance().getDistributionGroupConfiguration(distributionGroup);
    final SpacePartitionerContext spacePartitionerContext = new SpacePartitionerContext(config.getSpacePartitionerConfig(), distributionGroup, zookeeperClient, callback, mapper);
    return SpacePartitionerFactory.getSpacePartitionerForDistributionGroup(spacePartitionerContext);
}
Also used : SpacePartitionerContext(org.bboxdb.distribution.partitioner.SpacePartitionerContext) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration)

Example 18 with DistributionGroupConfiguration

use of org.bboxdb.storage.entity.DistributionGroupConfiguration in project bboxdb by jnidzwetzki.

the class DistributionGroupAdapter method getDistributionGroupConfiguration.

/**
 * Get the distribution group configuration
 * @param distributionGroup
 * @return
 * @throws ZookeeperException
 * @throws ZookeeperNotFoundException
 * @throws InputParseException
 */
public DistributionGroupConfiguration getDistributionGroupConfiguration(final String distributionGroup) throws ZookeeperException, ZookeeperNotFoundException, InputParseException {
    final String path = getDistributionGroupPath(distributionGroup);
    final String placementConfigPath = path + "/" + ZookeeperNodeNames.NAME_PLACEMENT_CONFIG;
    final String placementConfig = zookeeperClient.readPathAndReturnString(placementConfigPath);
    final String placementPath = path + "/" + ZookeeperNodeNames.NAME_PLACEMENT_STRATEGY;
    final String placementStrategy = zookeeperClient.readPathAndReturnString(placementPath);
    final String spacePartitionerConfigPath = path + "/" + ZookeeperNodeNames.NAME_SPACEPARTITIONER_CONFIG;
    final String spacePartitionerConfig = zookeeperClient.readPathAndReturnString(spacePartitionerConfigPath);
    final String spacePartitionerPath = path + "/" + ZookeeperNodeNames.NAME_SPACEPARTITIONER;
    final String spacePartitoner = zookeeperClient.readPathAndReturnString(spacePartitionerPath);
    final String replicationFactorPath = path + "/" + ZookeeperNodeNames.NAME_REPLICATION;
    final String replicationFactorString = zookeeperClient.getData(replicationFactorPath);
    final short replicationFactor = (short) MathUtil.tryParseInt(replicationFactorString, () -> "Unable to parse: " + replicationFactorString);
    final String dimensionsPath = path + "/" + ZookeeperNodeNames.NAME_DIMENSIONS;
    final String dimensionsString = zookeeperClient.getData(dimensionsPath);
    final int dimensions = MathUtil.tryParseInt(dimensionsString, () -> "Unable to parse: " + dimensionsString);
    final String regionMinSizePath = path + "/" + ZookeeperNodeNames.NAME_MIN_REGION_SIZE;
    final String sizeStrinMin = zookeeperClient.readPathAndReturnString(regionMinSizePath);
    final int minRegionSize = MathUtil.tryParseInt(sizeStrinMin, () -> "Unable to parse: " + sizeStrinMin);
    final String regionMaxSizePath = path + "/" + ZookeeperNodeNames.NAME_MAX_REGION_SIZE;
    final String sizeStringMax = zookeeperClient.readPathAndReturnString(regionMaxSizePath);
    final int maxRegionSize = MathUtil.tryParseInt(sizeStringMax, () -> "Unable to parse: " + sizeStringMax);
    final DistributionGroupConfiguration configuration = new DistributionGroupConfiguration();
    configuration.setPlacementStrategyConfig(placementConfig);
    configuration.setPlacementStrategy(placementStrategy);
    configuration.setSpacePartitionerConfig(spacePartitionerConfig);
    configuration.setSpacePartitioner(spacePartitoner);
    configuration.setReplicationFactor(replicationFactor);
    configuration.setMaximumRegionSize(maxRegionSize);
    configuration.setMinimumRegionSize(minRegionSize);
    configuration.setDimensions(dimensions);
    return configuration;
}
Also used : DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration)

Example 19 with DistributionGroupConfiguration

use of org.bboxdb.storage.entity.DistributionGroupConfiguration in project bboxdb by jnidzwetzki.

the class SpacePartitionerHelper method allocateSystemsToRegion.

/**
 * Allocate the required amount of systems to the given region
 *
 * @param region
 * @param zookeeperClient
 * @throws ZookeeperException
 * @throws ResourceAllocationException
 * @throws ZookeeperNotFoundException
 */
public static void allocateSystemsToRegion(final String regionPath, final String distributionGroupName, final Collection<BBoxDBInstance> blacklist, final ZookeeperClient zookeeperClient) throws ZookeeperException, ResourceAllocationException, ZookeeperNotFoundException {
    final DistributionGroupConfiguration config = DistributionGroupConfigurationCache.getInstance().getDistributionGroupConfiguration(distributionGroupName);
    final short replicationFactor = config.getReplicationFactor();
    final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
    final List<BBoxDBInstance> availableSystems = distributedInstanceManager.getInstances();
    final String placementStrategy = config.getPlacementStrategy();
    final ResourcePlacementStrategy resourcePlacementStrategy = ResourcePlacementStrategyFactory.getInstance(placementStrategy);
    if (resourcePlacementStrategy == null) {
        throw new ResourceAllocationException("Unable to instanciate the ressource " + "placement strategy");
    }
    // The blacklist, to prevent duplicate allocations
    final Set<BBoxDBInstance> allocationSystems = new HashSet<>();
    final Set<BBoxDBInstance> blacklistedSystems = new HashSet<>();
    blacklistedSystems.addAll(blacklist);
    for (short i = 0; i < replicationFactor; i++) {
        final BBoxDBInstance instance = resourcePlacementStrategy.getInstancesForNewRessource(availableSystems, blacklistedSystems);
        allocationSystems.add(instance);
        blacklistedSystems.add(instance);
    }
    logger.info("Allocated new ressource to {} with blacklist {}", allocationSystems, blacklist);
    zookeeperClient.getDistributionRegionAdapter().allocateSystemsToRegion(regionPath, allocationSystems);
}
Also used : BBoxDBInstanceManager(org.bboxdb.distribution.membership.BBoxDBInstanceManager) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) ResourceAllocationException(org.bboxdb.distribution.placement.ResourceAllocationException) ResourcePlacementStrategy(org.bboxdb.distribution.placement.ResourcePlacementStrategy) HashSet(java.util.HashSet)

Example 20 with DistributionGroupConfiguration

use of org.bboxdb.storage.entity.DistributionGroupConfiguration in project bboxdb by jnidzwetzki.

the class SpacePartitionerFactory method getSpacePartitionerForDistributionGroup.

/**
 * Return the space partitioner for the distribution group
 * @param mapper
 * @param callback
 * @throws ZookeeperNotFoundException
 */
public static SpacePartitioner getSpacePartitionerForDistributionGroup(final SpacePartitionerContext spacePartitionerContext) throws ZookeeperException {
    try {
        final String distributionGroup = spacePartitionerContext.getDistributionGroupName();
        final DistributionGroupConfiguration config = DistributionGroupConfigurationCache.getInstance().getDistributionGroupConfiguration(distributionGroup);
        final String spacePartitionerString = config.getSpacePartitioner();
        // Instance the classname
        final Class<?> classObject = Class.forName(spacePartitionerString);
        if (classObject == null) {
            throw new ClassNotFoundException("Unable to locate class: " + spacePartitionerString);
        }
        final Object factoryObject = classObject.newInstance();
        if (!(factoryObject instanceof SpacePartitioner)) {
            throw new ClassNotFoundException(spacePartitionerString + " is not a instance of SpacePartitioner");
        }
        final SpacePartitioner spacePartitioner = (SpacePartitioner) factoryObject;
        spacePartitioner.init(spacePartitionerContext);
        return spacePartitioner;
    } catch (Exception e) {
        logger.warn("Unable to instance space partitioner for group: " + spacePartitionerContext.getDistributionGroupName(), e);
        throw new RuntimeException(e);
    }
}
Also used : DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)

Aggregations

DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)43 Test (org.junit.Test)12 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)9 Before (org.junit.Before)7 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)4 BeforeClass (org.junit.BeforeClass)4 BoundingBox (org.bboxdb.commons.math.BoundingBox)3 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)3 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)3 BBoxDBException (org.bboxdb.misc.BBoxDBException)3 Tuple (org.bboxdb.storage.entity.Tuple)3 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)2 ZookeeperClient (org.bboxdb.distribution.zookeeper.ZookeeperClient)2 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)2 Cursor (java.awt.Cursor)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 InputParseException (org.bboxdb.commons.InputParseException)1