| 3 |  | Tasks distribution is implemented using [http://www.gridgain.com/javadoc/org/gridgain/grid/GridTaskAdapter.html GridGain GridTaskAdapter]. In this scenario, a cloud should have several segments. Workers in the cloud can belong to one or more segments (Worker [http://www.molgenis.org/wiki/ComputeStartExample8 settings example]). | 
                      
                        |  | 3 | Tasks distribution is implemented using [http://www.gridgain.com/javadoc/org/gridgain/grid/GridTaskAdapter.html GridGain GridTaskAdapter]. In this scenario, a cloud should have several segments. Workers in the cloud can belong to one or more segments (Worker [http://www.molgenis.org/wiki/ComputeStartExample8 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 | 
                        |  | 4 |  | 
                        |  | 5 | {{{ | 
                        |  | 6 | public Map<? extends GridJob, GridNode> map(List<GridNode> subgrid, Script script) throws GridException | 
                        |  | 7 | { | 
                        |  | 8 |  | 
                        |  | 9 | Map<ExecuteCommandLineJob, GridNode> jobs = new HashMap<ExecuteCommandLineJob, GridNode>(1); | 
                        |  | 10 |  | 
                        |  | 11 | //get the id of the execution environment | 
                        |  | 12 | String eeID = script.getExecutionEnvironmentID(); | 
                        |  | 13 |  | 
                        |  | 14 | //list of worker nodes | 
                        |  | 15 | List<GridNode> workerNodes = new ArrayList<GridNode>(); | 
                        |  | 16 |  | 
                        |  | 17 | //find worker nodes for the job execution | 
                        |  | 18 | for (Iterator it = subgrid.iterator(); it.hasNext();) | 
                        |  | 19 | { | 
                        |  | 20 | GridNode node = (GridNode) it.next(); | 
                        |  | 21 | String segment = node.getAttribute(eeID); | 
                        |  | 22 |  | 
                        |  | 23 | if (segment != null) | 
                        |  | 24 | { | 
                        |  | 25 | if (segment.equals("true")) | 
                        |  | 26 | { | 
                        |  | 27 | workerNodes.add(node); | 
                        |  | 28 | } | 
                        |  | 29 | } | 
                        |  | 30 | } | 
                        |  | 31 |  | 
                        |  | 32 | if(workerNodes.size() == 0) | 
                        |  | 33 | { | 
                        |  | 34 | ... | 
                        |  | 35 | return null; | 
                        |  | 36 | } | 
                        |  | 37 |  | 
                        |  | 38 | ... | 
                        |  | 39 | ExecuteCommandLineJob myJob = new ExecuteCommandLineJob(script); | 
                        |  | 40 |  | 
                        |  | 41 | //the worker can be pick-up randomly | 
                        |  | 42 | //int i = rand.nextInt(workerNodes.size()); | 
                        |  | 43 |  | 
                        |  | 44 | ... | 
                        |  | 45 | jobs.put(myJob, workerNodes.get(i)); | 
                        |  | 46 | return jobs; | 
                        |  | 47 | } | 
                        |  | 48 |  | 
                        |  | 49 | }}} | 
                        |  | 50 |  |