Changeset 256
- Timestamp:
- 04/12/12 14:08:05 (13 years ago)
- Location:
- xssim/branches/tpiontek/src/example/localplugin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
xssim/branches/tpiontek/src/example/localplugin/BaseLocalPlugin.java
r163 r256 1 1 package example.localplugin; 2 2 3 import java.util.HashMap; 4 import java.util.List; 3 5 import java.util.Map; 4 6 … … 13 15 import schedframe.scheduling.utils.ResourceParameterName; 14 16 import test.rewolucja.GSSIMJobInterface; 17 import test.rewolucja.resources.ProcessingElements; 15 18 import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface; 19 import test.rewolucja.resources.physical.implementation.Processor; 16 20 import test.rewolucja.scheduling.JobRegistry; 17 21 import test.rewolucja.scheduling.plan.AllocationNew; … … 61 65 } 62 66 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 63 78 public void addToSchedulingPlan(SchedulingPlanNew plan, TaskInterface<?> task, Map<ResourceParameterName, ResourceUnit> choosenResources ){ 64 79 -
xssim/branches/tpiontek/src/example/localplugin/FCFSPreferedRandomClusterLocalPlugin.java
r252 r256 8 8 import java.util.Random; 9 9 10 import schedframe.resources.PowerState; 10 11 import schedframe.scheduling.TaskInterface; 11 12 import schedframe.scheduling.events.SchedulingEvent; … … 14 15 import test.rewolucja.energy.profile.PStateType; 15 16 import test.rewolucja.resources.ResourceStatus; 17 import test.rewolucja.resources.ResourceType; 16 18 import test.rewolucja.resources.manager.implementation.ClusterResourceManager; 17 19 import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface; … … 35 37 public SchedulingPlanInterfaceNew schedule(SchedulingEvent event, QueueList queues, JobRegistryInterface jobRegistry, 36 38 ResourceManagerInterface resManager, ModuleList modules) { 39 40 int scenario = 1; 37 41 38 42 ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; … … 66 70 // if status of the tasks in READY 67 71 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 72 92 } 73 93 } 74 94 75 int scenario = 0;76 95 switch( scenario) 77 96 { 78 97 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()) 85 101 { 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 92 121 default: break; 93 122 } … … 98 127 } 99 128 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){ 101 130 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); 105 140 } 106 141 } … … 108 143 } 109 144 110 private String chooseRandomProvider(ClusterResourceManager resourceManager, TaskInterface<?> task) {111 145 private int getCpuRequest( TaskInterface<?> task) 146 { 112 147 int cpuRequest; 148 113 149 try { 114 150 cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); … … 117 153 } 118 154 155 return cpuRequest; 156 } 157 158 private ComputingNode chooseRandomProvider(ClusterResourceManager resourceManager, TaskInterface<?> task) { 159 160 int cpuRequest = getCpuRequest(task); 161 119 162 List<ComputingNode> nodes = null; 120 163 121 164 String prefered = null; 122 165 123 nodes = findSuitableNodes(prefered, cpuRequest, resourceManager.getComputingNodes());166 nodes = findSuitableNodes(prefered, cpuRequest, ResourceStatus.FREE, resourceManager.getComputingNodes()); 124 167 if( nodes.size() > 0) 125 168 { 126 169 int nodeIdx = rand.nextInt(nodes.size()); 127 170 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); 134 177 } 135 178 … … 141 184 prefered = "A"; 142 185 143 nodes = findSuitableNodes(prefered, cpuRequest, resourceManager.getComputingNodes());186 nodes = findSuitableNodes(prefered, cpuRequest, ResourceStatus.FREE, resourceManager.getComputingNodes()); 144 187 if( nodes.size() > 0) 145 188 { 146 189 int nodeIdx = rand.nextInt(nodes.size()); 147 190 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; 154 193 } 155 194 } … … 165 204 // no extra initialization is expected. 166 205 } 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 } 167 216 168 217 }
Note: See TracChangeset
for help on using the changeset viewer.