Search in sources :

Example 1 with Planner

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;
}
Also used : NodePlan(org.apache.hadoop.hdfs.server.diskbalancer.planner.NodePlan) LinkedList(java.util.LinkedList) Callable(java.util.concurrent.Callable) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Planner(org.apache.hadoop.hdfs.server.diskbalancer.planner.Planner) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

LinkedList (java.util.LinkedList)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 NodePlan (org.apache.hadoop.hdfs.server.diskbalancer.planner.NodePlan)1 Planner (org.apache.hadoop.hdfs.server.diskbalancer.planner.Planner)1