Index: /xssim/branches/tpiontek/src/example/localplugin/FCFSPreferedRandomClusterLocalPlugin.java
===================================================================
--- /xssim/branches/tpiontek/src/example/localplugin/FCFSPreferedRandomClusterLocalPlugin.java	(revision 252)
+++ /xssim/branches/tpiontek/src/example/localplugin/FCFSPreferedRandomClusterLocalPlugin.java	(revision 256)
@@ -8,4 +8,5 @@
 import java.util.Random;
 
+import schedframe.resources.PowerState;
 import schedframe.scheduling.TaskInterface;
 import schedframe.scheduling.events.SchedulingEvent;
@@ -14,4 +15,5 @@
 import test.rewolucja.energy.profile.PStateType;
 import test.rewolucja.resources.ResourceStatus;
+import test.rewolucja.resources.ResourceType;
 import test.rewolucja.resources.manager.implementation.ClusterResourceManager;
 import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface;
@@ -35,4 +37,6 @@
 	public SchedulingPlanInterfaceNew schedule(SchedulingEvent event, QueueList queues, JobRegistryInterface jobRegistry,
 			 ResourceManagerInterface resManager, ModuleList modules) {
+		
+		int scenario = 1;
 		
 		ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
@@ -66,28 +70,53 @@
 				// if status of the tasks in READY
 				if (task.getStatus() == Gridlet.READY) {
-					String nodeName = chooseRandomProvider(resourceManager, task);
-					if (nodeName != null) {
-						addToSchedulingPlan(plan, task, nodeName);
-					}
+					
+					ComputingNode node = chooseRandomProvider(resourceManager, task);
+					
+					if (node != null) {
+						List<Processor> cpus = chooseProcessorsForExecution(node, ResourceStatus.FREE, task);
+						addToSchedulingPlan(plan, task, cpus);
+					}
+					else
+					{
+						switch( scenario)
+						{
+						case 0: break;
+						case 1: break;
+						case 2:
+							findSuitableNodes( "", getCpuRequest(task), ResourceStatus.UNAVAILABLE, resourceManager.getComputingNodes());
+							break;
+						}
+					}
+					
+					
 				}
 			}
 			
-			int scenario = 0;
 			switch( scenario)
 			{
 				case 0: break;
-				case 1: ;
-				
-				List<Processor> cpus = resourceManager.getProcessors();
-				for( Processor cpu : cpus)
-				{
-					switch( cpu.getStatus())
+				case 1: 
+				
+					for( Processor cpu : resourceManager.getProcessors())
 					{
-						case FREE: cpu.getPowerInterface().setPState( PStateType.P3); break;
-						case PENDING: cpu.getPowerInterface().setPState( PStateType.P0); break;
-					}
-					
-				}
-				break;
+						switch( cpu.getStatus())
+						{
+							case FREE: cpu.getPowerInterface().setPState( PStateType.P3); break;
+							case PENDING: cpu.getPowerInterface().setPState( PStateType.P0); break;
+						}
+						
+					}
+					break;
+				
+				case 2:
+					for( Processor cpu : resourceManager.getProcessors())
+					{
+						switch( cpu.getStatus())
+						{
+							case FREE: cpu.getPowerInterface().setPowerState( PowerState.OFF); break;
+						}	
+					}
+					break;
+				
 				default: break;
 			}
@@ -98,9 +127,15 @@
 	}
 
-	private List<ComputingNode> findSuitableNodes(String model, int cpuRequest, List<ComputingNode> nodes){
+	private List<ComputingNode> findSuitableNodes(String model, int cpuRequest, ResourceStatus status, List<ComputingNode> nodes){
 		List<ComputingNode> avNodes = new ArrayList<ComputingNode>();
-		for(ComputingNode node: nodes){
-			if( (model == null || node.getCategory().getName().equals(model)) && node.getFreeProcessorsNumber() >= cpuRequest){
-				avNodes.add(node);
+		for(ComputingNode node: nodes)
+		{
+			if( (model == null || node.getCategory().getName().equals(model)))
+			{	
+				@SuppressWarnings("unchecked")
+				List<Processor> cpus = (List<Processor>)node.getDescendantsByTypeAndStatus( ResourceType.CPU, status);
+				
+				if( cpus.size() >= cpuRequest)
+					avNodes.add(node);
 			}
 		}
@@ -108,7 +143,8 @@
 	}
 	
-	private String chooseRandomProvider(ClusterResourceManager resourceManager, TaskInterface<?> task) {
-		
+	private int getCpuRequest( TaskInterface<?> task)
+	{
 		int cpuRequest;
+		
 		try {
 			cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
@@ -117,19 +153,26 @@
 		}
 		
+		return cpuRequest;
+	}
+	
+	private ComputingNode chooseRandomProvider(ClusterResourceManager resourceManager, TaskInterface<?> task) {
+		
+		int cpuRequest = getCpuRequest(task);
+		
 		List<ComputingNode> nodes = null;
 		
 		String prefered = null;
 		
-		nodes = findSuitableNodes(prefered, cpuRequest, resourceManager.getComputingNodes());
+		nodes = findSuitableNodes(prefered, cpuRequest, ResourceStatus.FREE, resourceManager.getComputingNodes());
 		if( nodes.size() > 0)
 		{	
 			int nodeIdx = rand.nextInt(nodes.size());
 			ComputingNode node = nodes.get(nodeIdx);
-			
-			//for( Processor cpu : node.getFreeProcessors())
-			//	if( cpu.getPowerInterface().getPState().getName() != PStateType.P0)
-			//		cpu.getPowerInterface().setPState( PStateType.P0);
-			
-			return node.getName();
+						
+			return node;
+		}
+		else
+		{
+			System.out.println("NO resources: " + prefered);
 		}
 		
@@ -141,15 +184,11 @@
 				prefered = "A";
 			
-			nodes = findSuitableNodes(prefered, cpuRequest, resourceManager.getComputingNodes());
+			nodes = findSuitableNodes(prefered, cpuRequest, ResourceStatus.FREE, resourceManager.getComputingNodes());
 			if( nodes.size() > 0)
 			{	
 				int nodeIdx = rand.nextInt(nodes.size());
 				ComputingNode node = nodes.get(nodeIdx);
-				
-				//for( Processor cpu : node.getFreeProcessors())
-				//	if( cpu.getPowerInterface().getPState().getName() != PStateType.P0)
-				//		cpu.getPowerInterface().setPState( PStateType.P0);
-				
-				return node.getName();
+							
+				return node;
 			}
 		}
@@ -165,4 +204,14 @@
 		// no extra initialization is expected.
 	}
+	
+	private List<Processor> chooseProcessorsForExecution( 
+			ComputingNode node, ResourceStatus status, TaskInterface<?> task) {
+		
+		int cpuRequest = getCpuRequest(task);
+
+		List<Processor> cpus = (List<Processor>)node.getDescendantsByTypeAndStatus( ResourceType.CPU, status);
+		
+		return cpus.subList(0, cpuRequest);
+	}
 
 }
Index: /xssim/branches/tpiontek/src/example/localplugin/BaseLocalPlugin.java
===================================================================
--- /xssim/branches/tpiontek/src/example/localplugin/BaseLocalPlugin.java	(revision 163)
+++ /xssim/branches/tpiontek/src/example/localplugin/BaseLocalPlugin.java	(revision 256)
@@ -1,4 +1,6 @@
 package example.localplugin;
 
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
@@ -13,5 +15,7 @@
 import schedframe.scheduling.utils.ResourceParameterName;
 import test.rewolucja.GSSIMJobInterface;
+import test.rewolucja.resources.ProcessingElements;
 import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface;
+import test.rewolucja.resources.physical.implementation.Processor;
 import test.rewolucja.scheduling.JobRegistry;
 import test.rewolucja.scheduling.plan.AllocationNew;
@@ -61,4 +65,15 @@
 	}
 	
+	public void addToSchedulingPlan(SchedulingPlanNew plan, TaskInterface<?> task,  List<Processor> cpus){
+		
+		Map<ResourceParameterName, ResourceUnit> map = new HashMap<ResourceParameterName, ResourceUnit>();
+		
+		ProcessingElements result = new ProcessingElements();
+		result.addAll( cpus);
+		map.put(ResourceParameterName.PROCESSINGELEMENTS, result);
+		
+		addToSchedulingPlan(plan, task, map);
+	}
+	
 	public void addToSchedulingPlan(SchedulingPlanNew plan, TaskInterface<?> task, Map<ResourceParameterName, ResourceUnit> choosenResources ){
 		
