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.PowerState; 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.implementation.ClusterResourceManager; 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 FCFSClusterLocalPlugin extends BaseLocalPlugin { public FCFSClusterLocalPlugin() { } public SchedulingPlanInterfaceNew schedule(SchedulingEvent event, QueueList queues, JobRegistryInterface jobRegistry, ResourceManagerInterface resManager, ModuleList modules) { ClusterResourceManager resourceManager = (ClusterResourceManager) resManager; 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: case TIMER: // 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; /****************3 ways to schedule task****************/ //1. Choosing particular resources to perform execution Map choosenResources = chooseResourcesForExecution(resourceManager, subTask); if (choosenResources != null) { addToSchedulingPlan(plan, task, choosenResources); } //2. Choosing resource scheduler/provider to submit task. If the given resource doesn't contains/isn't //a scheduler, random resources from the given resource will be chosen in order to perform execution /*String provName = chooseProviderForExecution(resourceManager); if (provName != null) { addToSchedulingPlan(plan, task, provName); }*/ //3. Scheduler will choose random resources to perform execution //addToSchedulingPlan(plan, task); } } break; } return plan; } private HashMap chooseResourcesForExecution( ClusterResourceManager resourceManager, 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 processors = null; processors = resourceManager.getProcessors(); if (processors.size() < cpuRequest) { // log.warn("Task requires more cpus than is availiable in this resource."); return null; } choosenResources = new ArrayList(); for (int i = 0; i < processors.size() && cpuRequest > 0; i++) { if (processors.get(i).getStatus() == ResourceStatus.FREE) { choosenResources.add(processors.get(i)); cpuRequest--; } } 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(processors.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 = resourceManager.getComputingNodes(); 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; } private String chooseProviderForExecution(ResourceManagerInterface unitsManager) { List processingElements; Properties properties = new Properties(); properties.setProperty("type", ResourceType.COMPUTING_NODE.toString()); // properties.setProperty("status", ResourceStatus.FREE.toString()); processingElements = (List) unitsManager.filterResources(properties); return processingElements.get(0).getName(); } public String getName() { return getClass().getName(); } public void init(Properties properties) { // no extra initialization is expected. } }