Ignore:
Timestamp:
04/11/12 16:30:38 (13 years ago)
Author:
piontek
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • xssim/branches/tpiontek/src/example/localplugin/FCFSRandomClusterLocalPlugin.java

    r192 r241  
    33import gridsim.Gridlet; 
    44 
     5import java.util.ArrayList; 
    56import java.util.List; 
    67import java.util.Properties; 
     
    1112import schedframe.scheduling.plugin.grid.ModuleList; 
    1213import test.rewolucja.GSSIMJobInterface; 
     14import test.rewolucja.energy.profile.PStateType; 
    1315import test.rewolucja.resources.manager.implementation.ClusterResourceManager; 
    1416import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface; 
    1517import test.rewolucja.resources.physical.implementation.ComputingNode; 
     18import test.rewolucja.resources.physical.implementation.Processor; 
    1619import test.rewolucja.scheduling.JobRegistryInterface; 
    1720import test.rewolucja.scheduling.plan.SchedulingPlanInterfaceNew; 
     
    2326 
    2427        private Random rand; 
     28        private boolean init = true; 
    2529         
    2630        public FCFSRandomClusterLocalPlugin() { 
     
    3034        public SchedulingPlanInterfaceNew schedule(SchedulingEvent event, QueueList queues, JobRegistryInterface jobRegistry, 
    3135                         ResourceManagerInterface resManager, ModuleList modules) { 
     36                 
     37                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; 
     38                 
     39                if( init) 
     40                { 
     41                        List<Processor> cpus = resourceManager.getProcessors(); 
     42                         
     43                        for( Processor cpu : cpus) 
     44                                cpu.getPowerInterface().setPState( PStateType.P3); 
     45                         
     46                        init = false; 
     47                } 
     48                 
    3249 
    33                 ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; 
     50                 
    3451                SchedulingPlanNew plan = new SchedulingPlanNew(); 
    3552                // chose the events types to serve. 
     
    4865                                // if status of the tasks in READY 
    4966                                if (task.getStatus() == Gridlet.READY) { 
    50                                         String nodeName = chooseRandomProvider(resourceManager); 
     67                                        String nodeName = chooseRandomProvider(resourceManager, task); 
    5168                                        if (nodeName != null) { 
    5269                                                addToSchedulingPlan(plan, task, nodeName); 
     
    5976        } 
    6077 
    61         private String chooseRandomProvider(ClusterResourceManager resourceManager) { 
     78        private List<ComputingNode> findSuitableNodes(int cpuRequest, List<ComputingNode> nodes){ 
     79                List<ComputingNode> avNodes = new ArrayList<ComputingNode>(); 
     80                for(ComputingNode node: nodes){ 
     81                        if(node.getFreeProcessorsNumber() >= cpuRequest){ 
     82                                avNodes.add(node); 
     83                        } 
     84                } 
     85                return avNodes; 
     86        } 
     87         
     88        private String chooseRandomProvider(ClusterResourceManager resourceManager, TaskInterface<?> task) { 
     89                 
     90                int cpuRequest; 
     91                try { 
     92                        cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); 
     93                } catch (NoSuchFieldException e) { 
     94                        cpuRequest = 1; 
     95                } 
     96                 
    6297                List<ComputingNode> nodes = resourceManager.getComputingNodes(); 
     98                 
     99                nodes = findSuitableNodes(cpuRequest, nodes); 
     100                 
    63101                int nodeIdx = rand.nextInt(nodes.size()); 
    64102                return nodes.get(nodeIdx).getName(); 
Note: See TracChangeset for help on using the changeset viewer.