From f972b2a84853018466353dca00bc0a2d80f0080b Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Tue, 11 Jun 2013 15:19:32 +0200 Subject: [PATCH] moved sorting of PMs into MachineManager --- .../lsdc/management/MachineManager.java | 36 +++++++++++++------ src/at/ac/tuwien/lsdc/sched/SchedulerA.java | 16 ++------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/at/ac/tuwien/lsdc/management/MachineManager.java b/src/at/ac/tuwien/lsdc/management/MachineManager.java index d41ecb5..70f8d60 100644 --- a/src/at/ac/tuwien/lsdc/management/MachineManager.java +++ b/src/at/ac/tuwien/lsdc/management/MachineManager.java @@ -1,7 +1,10 @@ package at.ac.tuwien.lsdc.management; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import at.ac.tuwien.lsdc.exception.OutOfPMsException; import at.ac.tuwien.lsdc.exception.VMsRunningException; @@ -11,7 +14,7 @@ import at.ac.tuwien.lsdc.util.NumberUtils; /** * This class is responsible to start and stop PMs & VMs also it will be used to * put an application on a VM move an application and get utilization data - * + * */ public class MachineManager { @@ -28,7 +31,7 @@ public class MachineManager { /** * Start a physical machine - * + * * @return the PM that was started, null if all machines already running */ public PhysicalMachine startPhysicalMachine() { @@ -44,7 +47,7 @@ public class MachineManager { /** * Stops a physical machine with the given id - * + * * @param id * the id of the PM to stop * @throws VMsRunningException @@ -61,7 +64,7 @@ public class MachineManager { /** * Returns all running physical machines - * + * * @return the currently active PMs */ public Collection getPMs() { @@ -70,7 +73,7 @@ public class MachineManager { /** * Returns the maximum number of available physical machines - * + * * @return the maximum number of PMs */ public int getMaxPMs() { @@ -79,7 +82,7 @@ public class MachineManager { /** * Get the total size on all PMs - * + * * @return the total size on all PMs */ public int getTotalSize() { @@ -93,7 +96,7 @@ public class MachineManager { /** * Get the total Ram usage of all PMs - * + * * @return the total usage of Ram */ public int getTotalRam() { @@ -107,7 +110,7 @@ public class MachineManager { /** * Get the total Cpu usage of all PMs - * + * * @return the total usage of Cpu power */ public int getTotalCpu() { @@ -121,7 +124,7 @@ public class MachineManager { /** * Gets the total power consumption summed up from each PM - * + * * @return the total power consumption */ public double getCurrentConsumption() { @@ -136,7 +139,7 @@ public class MachineManager { /** * Gets the number of currently running PMs - * + * * @return the number of currently running PMs */ public int countCurrentlyRunningPMs() { @@ -150,7 +153,7 @@ public class MachineManager { /** * Gets the number of currently running VMs - * + * * @return the number of currently running VMs */ public int countCurrentlyRunningVMs() { @@ -163,6 +166,17 @@ public class MachineManager { return running; } + /** + * sorting physical machines by resource utilization + * + * @return List of PMs sorted by resource utilization + */ + public List getSortedPMs() { + List sortedPMs = new ArrayList(PMs.values()); + Collections.sort(sortedPMs); + return sortedPMs; + } + public int getTotalPMs() { return totalPMs; } diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java index 354bfad..6230ec2 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java @@ -80,7 +80,8 @@ public class SchedulerA extends AbstractScheduler { } else { // sorting physical machines by resource utilization // (descending) - List sortedPMs = sortPMs(); + List sortedPMs = manager.getSortedPMs(); + Collections.reverse(sortedPMs); for (PhysicalMachine pm : sortedPMs) { @@ -145,19 +146,6 @@ public class SchedulerA extends AbstractScheduler { return sortedApps; } - // sorting physical machines by resource utilization (descending) - private List sortPMs() { - List sortedPMs = new LinkedList(); - for (PhysicalMachine pm : manager.getPMs()) { - sortedPMs.add(pm); - // log.info("pm util = "+pm.getAverageUtilization()); - } - - Collections.sort(sortedPMs); - Collections.reverse(sortedPMs); - return sortedPMs; - } - @Override protected String getSchedulerType() { return SchedulerType.A.toString(); -- 2.43.0