wiki:ComputeStartExample4

Tasks distribution over different computational resources

Tasks distribution is implemented using GridGain GridTaskAdapter. In this scenario, a cloud should have several segments. Workers in the cloud can belong to one or more segments (Worker settings example). Every script should contain information about execution environment or cloud segment, where it should be executed. First, We found all Worker nodes from this segment. Then, a script is sent to one of them

public Map<? extends GridJob, GridNode> map(List<GridNode> subgrid, Script script) throws GridException
{
    Map<ExecuteCommandLineJob, GridNode> jobs = new HashMap<ExecuteCommandLineJob, GridNode>(1);

    //get the id of the execution environment
    String eeID = script.getExecutionEnvironmentID();

    //list of worker nodes
    List<GridNode> workerNodes = new ArrayList<GridNode>();

    //find worker nodes for the job execution
    for (Iterator it = subgrid.iterator(); it.hasNext();)
    {
       GridNode node = (GridNode) it.next();
       String segment = node.getAttribute(eeID);

       if (segment != null)
       {
          if (segment.equals("true"))
          {
             workerNodes.add(node);
          }
       }
    }
 
    if(workerNodes.size() == 0)
    {
        ...
        return null;
    }

    ...
    ExecuteCommandLineJob myJob = new ExecuteCommandLineJob(script);

    //the worker can be pick-up randomly
    //int i = rand.nextInt(workerNodes.size());

    ... 
    jobs.put(myJob, workerNodes.get(i));
    return jobs;
}

Back to Examples

Last modified 13 years ago Last modified on 2010-11-12T10:31:45+01:00