From b3a3ad95e19a6a18b1dbab4e9aec6e8510cbe301 Mon Sep 17 00:00:00 2001 From: Andreas Egger Date: Thu, 13 Jun 2013 18:06:44 +0200 Subject: [PATCH] Adding resize code , still not working ?! --- .../ac/tuwien/lsdc/types/PhysicalMachine.java | 4 -- .../ac/tuwien/lsdc/types/VirtualMachine.java | 50 ++++++++----------- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java b/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java index f4fdbca..c80505e 100644 --- a/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java +++ b/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java @@ -127,10 +127,6 @@ public class PhysicalMachine implements Comparable { reservedCPU = reservedCPU - app.getCpu(); return true; } - - public void resizeVM(VirtualMachine vm, Application app) { - - } public boolean checkExtendVM(int sizeDiff, int ramDiff, int CPUDiff) { return ((sizeDiff <= availableSize()) && (ramDiff <= availableRAM()) && (CPUDiff <= availableCPU())); diff --git a/src/at/ac/tuwien/lsdc/types/VirtualMachine.java b/src/at/ac/tuwien/lsdc/types/VirtualMachine.java index 1e04c6e..747f407 100644 --- a/src/at/ac/tuwien/lsdc/types/VirtualMachine.java +++ b/src/at/ac/tuwien/lsdc/types/VirtualMachine.java @@ -61,43 +61,41 @@ public class VirtualMachine { * the new CPU of the VM, excluding the initial consumption. * @return */ - public boolean resizeVM(int newSize, int newRAM, int newCPU) { - if (type == VMType.Resizable - && runningOn.checkExtendVM(newSize - reservedSize, newRAM - reservedRAM, newCPU - - reservedCPU)) { - // Resize VM - reservedSize = initialSize + newSize; - reservedRAM = initialRAM + newRAM; - reservedCPU = initialCPU + newCPU; - return true; - } else - return false; -// throw new VMResizeException("Could not resize VM!", this); - } +// public boolean resizeVM(int newSize, int newRAM, int newCPU) { +// if (type == VMType.Resizable +// && runningOn.checkExtendVM(newSize - reservedSize, newRAM - reservedRAM, newCPU +// - reservedCPU)) { +// // Resize VM +// reservedSize = initialSize + newSize; +// reservedRAM = initialRAM + newRAM; +// reservedCPU = initialCPU + newCPU; +// return true; +// } else +// return false; +//// throw new VMResizeException("Could not resize VM!", this); +// } public boolean resizeUp(Application app) throws VMResizeException { - int newSize = reservedSize + (app.getSize() - availableSize()) - initialSize; - int newRAM = reservedRAM + (app.getRam() - availableRAM()) - initialRAM; - int newCPU = reservedCPU + (app.getCpu() - availableCPU()) - initialCPU; - - int diffSize = newSize + initialSize - reservedSize; - int diffRAM = newRAM + initialRAM - reservedRAM; - int diffCPU = newCPU + initialCPU - reservedCPU; + int diffSize = (app.getSize() - availableSize()); + int diffRAM = (app.getRam() - availableRAM()); + int diffCPU = (app.getCpu() - availableCPU()); - if(!(type == VMType.Resizable) || !runningOn.checkVM(newSize, newRAM, newCPU)) { + if(!(type == VMType.Resizable) || !runningOn.checkExtendVM(diffSize, diffRAM, diffCPU)) { throw new VMResizeException("Could not resize VM!", this); } runningOn.resizeUp(diffSize, diffRAM, diffCPU); - reservedSize = newSize + initialSize; - reservedRAM = newRAM + initialRAM; - reservedCPU = newCPU + initialCPU; + reservedSize = reservedSize + diffSize; + reservedRAM = reservedRAM + diffRAM; + reservedCPU = reservedCPU + diffCPU; return true; } public boolean resizeDown(Application app) { + runningOn.resizeDown(app); + reservedSize = reservedSize - app.getSize(); reservedRAM = reservedRAM - app.getRam(); reservedCPU = reservedCPU - app.getCpu(); @@ -176,10 +174,6 @@ public class VirtualMachine { public int getReservedCPU() { return reservedCPU; } - - public int getDiffSize() { - - } @Override public String toString() { -- 2.43.0