Changeset 256


Ignore:
Timestamp:
04/12/12 14:08:05 (13 years ago)
Author:
piontek
Message:
 
Location:
xssim/branches/tpiontek/src/example/localplugin
Files:
2 edited

Legend:

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

    r163 r256  
    11package example.localplugin; 
    22 
     3import java.util.HashMap; 
     4import java.util.List; 
    35import java.util.Map; 
    46 
     
    1315import schedframe.scheduling.utils.ResourceParameterName; 
    1416import test.rewolucja.GSSIMJobInterface; 
     17import test.rewolucja.resources.ProcessingElements; 
    1518import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface; 
     19import test.rewolucja.resources.physical.implementation.Processor; 
    1620import test.rewolucja.scheduling.JobRegistry; 
    1721import test.rewolucja.scheduling.plan.AllocationNew; 
     
    6165        } 
    6266         
     67        public void addToSchedulingPlan(SchedulingPlanNew plan, TaskInterface<?> task,  List<Processor> cpus){ 
     68                 
     69                Map<ResourceParameterName, ResourceUnit> map = new HashMap<ResourceParameterName, ResourceUnit>(); 
     70                 
     71                ProcessingElements result = new ProcessingElements(); 
     72                result.addAll( cpus); 
     73                map.put(ResourceParameterName.PROCESSINGELEMENTS, result); 
     74                 
     75                addToSchedulingPlan(plan, task, map); 
     76        } 
     77         
    6378        public void addToSchedulingPlan(SchedulingPlanNew plan, TaskInterface<?> task, Map<ResourceParameterName, ResourceUnit> choosenResources ){ 
    6479                 
  • xssim/branches/tpiontek/src/example/localplugin/FCFSPreferedRandomClusterLocalPlugin.java

    r252 r256  
    88import java.util.Random; 
    99 
     10import schedframe.resources.PowerState; 
    1011import schedframe.scheduling.TaskInterface; 
    1112import schedframe.scheduling.events.SchedulingEvent; 
     
    1415import test.rewolucja.energy.profile.PStateType; 
    1516import test.rewolucja.resources.ResourceStatus; 
     17import test.rewolucja.resources.ResourceType; 
    1618import test.rewolucja.resources.manager.implementation.ClusterResourceManager; 
    1719import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface; 
     
    3537        public SchedulingPlanInterfaceNew schedule(SchedulingEvent event, QueueList queues, JobRegistryInterface jobRegistry, 
    3638                         ResourceManagerInterface resManager, ModuleList modules) { 
     39                 
     40                int scenario = 1; 
    3741                 
    3842                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; 
     
    6670                                // if status of the tasks in READY 
    6771                                if (task.getStatus() == Gridlet.READY) { 
    68                                         String nodeName = chooseRandomProvider(resourceManager, task); 
    69                                         if (nodeName != null) { 
    70                                                 addToSchedulingPlan(plan, task, nodeName); 
    71                                         } 
     72                                         
     73                                        ComputingNode node = chooseRandomProvider(resourceManager, task); 
     74                                         
     75                                        if (node != null) { 
     76                                                List<Processor> cpus = chooseProcessorsForExecution(node, ResourceStatus.FREE, task); 
     77                                                addToSchedulingPlan(plan, task, cpus); 
     78                                        } 
     79                                        else 
     80                                        { 
     81                                                switch( scenario) 
     82                                                { 
     83                                                case 0: break; 
     84                                                case 1: break; 
     85                                                case 2: 
     86                                                        findSuitableNodes( "", getCpuRequest(task), ResourceStatus.UNAVAILABLE, resourceManager.getComputingNodes()); 
     87                                                        break; 
     88                                                } 
     89                                        } 
     90                                         
     91                                         
    7292                                } 
    7393                        } 
    7494                         
    75                         int scenario = 0; 
    7695                        switch( scenario) 
    7796                        { 
    7897                                case 0: break; 
    79                                 case 1: ; 
    80                                  
    81                                 List<Processor> cpus = resourceManager.getProcessors(); 
    82                                 for( Processor cpu : cpus) 
    83                                 { 
    84                                         switch( cpu.getStatus()) 
     98                                case 1:  
     99                                 
     100                                        for( Processor cpu : resourceManager.getProcessors()) 
    85101                                        { 
    86                                                 case FREE: cpu.getPowerInterface().setPState( PStateType.P3); break; 
    87                                                 case PENDING: cpu.getPowerInterface().setPState( PStateType.P0); break; 
    88                                         } 
    89                                          
    90                                 } 
    91                                 break; 
     102                                                switch( cpu.getStatus()) 
     103                                                { 
     104                                                        case FREE: cpu.getPowerInterface().setPState( PStateType.P3); break; 
     105                                                        case PENDING: cpu.getPowerInterface().setPState( PStateType.P0); break; 
     106                                                } 
     107                                                 
     108                                        } 
     109                                        break; 
     110                                 
     111                                case 2: 
     112                                        for( Processor cpu : resourceManager.getProcessors()) 
     113                                        { 
     114                                                switch( cpu.getStatus()) 
     115                                                { 
     116                                                        case FREE: cpu.getPowerInterface().setPowerState( PowerState.OFF); break; 
     117                                                }        
     118                                        } 
     119                                        break; 
     120                                 
    92121                                default: break; 
    93122                        } 
     
    98127        } 
    99128 
    100         private List<ComputingNode> findSuitableNodes(String model, int cpuRequest, List<ComputingNode> nodes){ 
     129        private List<ComputingNode> findSuitableNodes(String model, int cpuRequest, ResourceStatus status, List<ComputingNode> nodes){ 
    101130                List<ComputingNode> avNodes = new ArrayList<ComputingNode>(); 
    102                 for(ComputingNode node: nodes){ 
    103                         if( (model == null || node.getCategory().getName().equals(model)) && node.getFreeProcessorsNumber() >= cpuRequest){ 
    104                                 avNodes.add(node); 
     131                for(ComputingNode node: nodes) 
     132                { 
     133                        if( (model == null || node.getCategory().getName().equals(model))) 
     134                        {        
     135                                @SuppressWarnings("unchecked") 
     136                                List<Processor> cpus = (List<Processor>)node.getDescendantsByTypeAndStatus( ResourceType.CPU, status); 
     137                                 
     138                                if( cpus.size() >= cpuRequest) 
     139                                        avNodes.add(node); 
    105140                        } 
    106141                } 
     
    108143        } 
    109144         
    110         private String chooseRandomProvider(ClusterResourceManager resourceManager, TaskInterface<?> task) { 
    111                  
     145        private int getCpuRequest( TaskInterface<?> task) 
     146        { 
    112147                int cpuRequest; 
     148                 
    113149                try { 
    114150                        cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); 
     
    117153                } 
    118154                 
     155                return cpuRequest; 
     156        } 
     157         
     158        private ComputingNode chooseRandomProvider(ClusterResourceManager resourceManager, TaskInterface<?> task) { 
     159                 
     160                int cpuRequest = getCpuRequest(task); 
     161                 
    119162                List<ComputingNode> nodes = null; 
    120163                 
    121164                String prefered = null; 
    122165                 
    123                 nodes = findSuitableNodes(prefered, cpuRequest, resourceManager.getComputingNodes()); 
     166                nodes = findSuitableNodes(prefered, cpuRequest, ResourceStatus.FREE, resourceManager.getComputingNodes()); 
    124167                if( nodes.size() > 0) 
    125168                {        
    126169                        int nodeIdx = rand.nextInt(nodes.size()); 
    127170                        ComputingNode node = nodes.get(nodeIdx); 
    128                          
    129                         //for( Processor cpu : node.getFreeProcessors()) 
    130                         //      if( cpu.getPowerInterface().getPState().getName() != PStateType.P0) 
    131                         //              cpu.getPowerInterface().setPState( PStateType.P0); 
    132                          
    133                         return node.getName(); 
     171                                                 
     172                        return node; 
     173                } 
     174                else 
     175                { 
     176                        System.out.println("NO resources: " + prefered); 
    134177                } 
    135178                 
     
    141184                                prefered = "A"; 
    142185                         
    143                         nodes = findSuitableNodes(prefered, cpuRequest, resourceManager.getComputingNodes()); 
     186                        nodes = findSuitableNodes(prefered, cpuRequest, ResourceStatus.FREE, resourceManager.getComputingNodes()); 
    144187                        if( nodes.size() > 0) 
    145188                        {        
    146189                                int nodeIdx = rand.nextInt(nodes.size()); 
    147190                                ComputingNode node = nodes.get(nodeIdx); 
    148                                  
    149                                 //for( Processor cpu : node.getFreeProcessors()) 
    150                                 //      if( cpu.getPowerInterface().getPState().getName() != PStateType.P0) 
    151                                 //              cpu.getPowerInterface().setPState( PStateType.P0); 
    152                                  
    153                                 return node.getName(); 
     191                                                         
     192                                return node; 
    154193                        } 
    155194                } 
     
    165204                // no extra initialization is expected. 
    166205        } 
     206         
     207        private List<Processor> chooseProcessorsForExecution(  
     208                        ComputingNode node, ResourceStatus status, TaskInterface<?> task) { 
     209                 
     210                int cpuRequest = getCpuRequest(task); 
     211 
     212                List<Processor> cpus = (List<Processor>)node.getDescendantsByTypeAndStatus( ResourceType.CPU, status); 
     213                 
     214                return cpus.subList(0, cpuRequest); 
     215        } 
    167216 
    168217} 
Note: See TracChangeset for help on using the changeset viewer.