Search in sources :

Example 1 with ResourcePlacementStrategy

use of org.bboxdb.distribution.placement.ResourcePlacementStrategy 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)

Aggregations

HashSet (java.util.HashSet)1 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)1 BBoxDBInstanceManager (org.bboxdb.distribution.membership.BBoxDBInstanceManager)1 ResourceAllocationException (org.bboxdb.distribution.placement.ResourceAllocationException)1 ResourcePlacementStrategy (org.bboxdb.distribution.placement.ResourcePlacementStrategy)1 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)1