package example.localplugin; import gridsim.Gridlet; import gridsim.gssim.SubmittedTask; import gssim.schedframe.scheduling.ExecTaskInterface; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; import schedframe.resources.units.Memory; import schedframe.resources.units.ResourceUnit; import schedframe.scheduling.TaskInterface; import schedframe.scheduling.events.SchedulingEvent; import schedframe.scheduling.plugin.grid.ModuleList; import schedframe.scheduling.utils.ResourceParameterName; import test.rewolucja.GSSIMJobInterface; import test.rewolucja.resources.ProcessingElements; import test.rewolucja.resources.ResourceStatus; import test.rewolucja.resources.ResourceType; import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface; import test.rewolucja.resources.physical.base.ComputingResource; import test.rewolucja.resources.physical.implementation.CPU; import test.rewolucja.resources.physical.implementation.ComputingNode; import test.rewolucja.scheduling.JobRegistryInterface; import test.rewolucja.scheduling.plan.SchedulingPlanInterfaceNew; import test.rewolucja.scheduling.plan.SchedulingPlanNew; import test.rewolucja.scheduling.queue.GSSIMQueue; import test.rewolucja.scheduling.queue.QueueList; public class FCFS_EBFLocalPlugin extends BaseLocalPlugin { public FCFS_EBFLocalPlugin() { } public SchedulingPlanInterfaceNew schedule(SchedulingEvent event, QueueList queues, JobRegistryInterface jobRegistry, ResourceManagerInterface resourceManager, ModuleList modules) { SchedulingPlanNew plan = new SchedulingPlanNew(); // chose the events types to serve. // Different actions for different events are possible. switch (event.getType()) { case START_TASK_EXECUTION: case TASK_FINISHED: // our tasks are placed only in first queue (see // BaseLocalPlugin.placeTasksInQueues() method) GSSIMQueue q = queues.get(0); // check all tasks in queue for (int i = 0; i < q.size(); i++) { GSSIMJobInterface job = q.get(i); TaskInterface task = (TaskInterface) job; // if status of the tasks in READY if (task.getStatus() == Gridlet.READY) { SubmittedTask subTask = (SubmittedTask) task; // DataCenterResourceManager dcrm = // (DataCenterResourceManager)unitsManager; // List cpus = dcrm.getProcessors(); // cpus.get(0).getPowerInterface().setFrequency(100); Map choosenResources = null; choosenResources = chooseResourcesForExecution(resourceManager, subTask); // String name = // chooseProviderForExecution(resourceManager); if (choosenResources != null) { // q.remove(i); // i--; addToSchedulingPlan(plan, task, choosenResources); } } } } return plan; } public HashMap chooseResourcesForExecution( ResourceManagerInterface unitsManager, ExecTaskInterface task) { HashMap map = new HashMap(); int cpuRequest; try { cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue(); } catch (NoSuchFieldException e) { cpuRequest = 1; } if (cpuRequest != 0) { List choosenResources = null; List processingElements = null; try { Properties properties = new Properties(); properties.setProperty("type", ResourceType.CPU.toString()); // properties.setProperty("status", // ResourceStatus.FREE.toString()); processingElements = (List) unitsManager.filterResources(properties); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if (processingElements.size() < cpuRequest) { // log.warn("Task requires more cpus than is availiable in this resource."); return null; } choosenResources = new ArrayList(); for (int i = 0; i < processingElements.size() && cpuRequest > 0; i++) { if (processingElements.get(i).getStatus() == ResourceStatus.FREE) { choosenResources.add(processingElements.get(i)); cpuRequest--; CPU cpu = (CPU)processingElements.get(i); //cpu.getParent().getPowerProfile().setPowerState(PowerState.OFF); } } if (cpuRequest > 0) { // log.info("Task " + task.getJobId() + "_" + task.getId() + // " requires more cpus than is availiable in this moment."); return null; } ProcessingElements result = new ProcessingElements(processingElements.get(0).getParent().getName()); result.addAll(choosenResources); map.put(ResourceParameterName.PROCESSINGELEMENTS, result); } int memoryRequest; try { memoryRequest = Double.valueOf(task.getMemoryRequest()).intValue(); } catch (NoSuchFieldException e) { memoryRequest = 0; } if (memoryRequest != 0) { List nodes = null; try { Properties properties = new Properties(); properties.setProperty("type", ResourceType.COMPUTING_NODE.toString()); nodes = (List) unitsManager.filterResources(properties); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Memory memory = null; for (ComputingNode node : nodes) { if (node.getFreeMemory() >= memoryRequest) { memory = new Memory(node.getMemory(), memoryRequest, memoryRequest); } else return null; } map.put(ResourceParameterName.MEMORY, memory); } return map; } public String getName() { return getClass().getName(); } public void init(Properties properties) { // no extra initialization is expected. } }