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