From 4eee3f8301bd2534fb3fa4ca955262e08427303a Mon Sep 17 00:00:00 2001 From: Andreas Egger Date: Wed, 22 May 2013 13:59:02 +0200 Subject: [PATCH] Fixed: Output File OK --- .../lsdc/management/MachineManager.java | 23 +++++++++++++++++-- .../tuwien/lsdc/sched/AbstractScheduler.java | 17 +++++++++----- .../ac/tuwien/lsdc/types/PhysicalMachine.java | 7 +++++- src/at/ac/tuwien/lsdc/util/NumberUtils.java | 12 ++++++++++ 4 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 src/at/ac/tuwien/lsdc/util/NumberUtils.java diff --git a/src/at/ac/tuwien/lsdc/management/MachineManager.java b/src/at/ac/tuwien/lsdc/management/MachineManager.java index d93734b..1a819b3 100644 --- a/src/at/ac/tuwien/lsdc/management/MachineManager.java +++ b/src/at/ac/tuwien/lsdc/management/MachineManager.java @@ -1,11 +1,17 @@ package at.ac.tuwien.lsdc.management; +import java.math.RoundingMode; +import java.text.DecimalFormat; import java.util.Collection; import java.util.HashMap; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import at.ac.tuwien.lsdc.exception.VMsRunningException; import at.ac.tuwien.lsdc.types.PhysicalMachine; +import at.ac.tuwien.lsdc.util.NumberUtils; /** * This class is responsible to start and stop PMs & VMs also it will be used to @@ -14,6 +20,8 @@ import at.ac.tuwien.lsdc.types.PhysicalMachine; */ public class MachineManager { + private static final Logger log = LoggerFactory.getLogger(MachineManager.class); + private HashMap PMs = new HashMap(); private int numPMs; @@ -120,9 +128,20 @@ public class MachineManager { public double getCurrentConsumption() { double consumption = 0; for (PhysicalMachine pm : PMs.values()) { - if (pm.isRunning()) - consumption += + pm.getConsumption(); + if (pm.isRunning()) { + consumption += pm.getConsumption(); + + } } + + consumption = NumberUtils.roundDouble(consumption); + + if(consumption < 0 || consumption > 9999) + log.info("consumptino is BIG " +consumption); + else + log.info("consumption normal "+consumption); + + return consumption; } diff --git a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java index 4d727f5..83de1ad 100644 --- a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java +++ b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java @@ -181,12 +181,17 @@ public abstract class AbstractScheduler { * directly to the specific scheduler/scenario csv file */ protected void doStateLogging() { - SchedulerData data = new SchedulerData(currTime, manager.getTotalRam(), - manager.getTotalCpu(), manager.getTotalSize(), - manager.countCurrentlyRunningPMs(), - manager.countCurrentlyRunningVMs(), - manager.getCurrentConsumption(), numCurrInSourced, - numCurrOutSourced); + SchedulerData data = new SchedulerData( + currTime, + manager.getTotalRam(), + manager.getTotalCpu(), + manager.getTotalSize(), + manager.countCurrentlyRunningPMs(), + manager.countCurrentlyRunningVMs(), + manager.getCurrentConsumption(), + numCurrInSourced, + numCurrOutSourced + ); totalConsumption += manager.getCurrentConsumption(); try { logger.logSchedulerData(data); diff --git a/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java b/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java index 8ebedf2..8190d72 100644 --- a/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java +++ b/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java @@ -52,7 +52,12 @@ public class PhysicalMachine { } public double getConsumption() { - return 200 + 0.3 * (CPU - initialCPU); + if(CPU > initialCPU) + return 200.0 + 0.3 * (CPU - initialCPU); + else if(running) + return 200.0; + else + return 0.0; } public VirtualMachine startVirtualMachine(int sz, int ram, int cpu, VMType type) { diff --git a/src/at/ac/tuwien/lsdc/util/NumberUtils.java b/src/at/ac/tuwien/lsdc/util/NumberUtils.java new file mode 100644 index 0000000..b8c6070 --- /dev/null +++ b/src/at/ac/tuwien/lsdc/util/NumberUtils.java @@ -0,0 +1,12 @@ +package at.ac.tuwien.lsdc.util; + +import java.math.RoundingMode; +import java.text.DecimalFormat; + +public class NumberUtils { + + public static double roundDouble(double val) { + return Math.floor(val * 100) / 100; + } + +} -- 2.43.0