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