use of org.apache.hadoop.hdfs.server.diskbalancer.planner.Planner in project hadoop by apache.
the class DiskBalancerCluster method computePlan.
/**
* Compute plan takes a node and constructs a planner that creates a plan that
* we would like to follow.
* <p/>
* This function creates a thread pool and executes a planner on each node
* that we are supposed to plan for. Each of these planners return a NodePlan
* that we can persist or schedule for execution with a diskBalancer
* Executor.
*
* @param thresholdPercent - in percentage
* @return list of NodePlans
*/
public List<NodePlan> computePlan(double thresholdPercent) {
List<NodePlan> planList = new LinkedList<>();
if (nodesToProcess == null) {
LOG.warn("Nodes to process is null. No nodes processed.");
return planList;
}
int poolSize = computePoolSize(nodesToProcess.size());
ExecutorService executorService = Executors.newFixedThreadPool(poolSize);
List<Future<NodePlan>> futureList = new LinkedList<>();
for (int x = 0; x < nodesToProcess.size(); x++) {
final DiskBalancerDataNode node = nodesToProcess.get(x);
final Planner planner = PlannerFactory.getPlanner(PlannerFactory.GREEDY_PLANNER, node, thresholdPercent);
futureList.add(executorService.submit(new Callable<NodePlan>() {
@Override
public NodePlan call() throws Exception {
assert planner != null;
return planner.plan(node);
}
}));
}
for (Future<NodePlan> f : futureList) {
try {
planList.add(f.get());
} catch (InterruptedException e) {
LOG.error("Compute Node plan was cancelled or interrupted : ", e);
} catch (ExecutionException e) {
LOG.error("Unable to compute plan : ", e);
}
}
return planList;
}
Aggregations