Commit 9ee46fbd authored by Benardi's avatar Benardi
Browse files

Replace getVmCredit for getCumulativeCredit. Update tests. Fix SlaMonitor.

parent d9f30a5d
......@@ -70,7 +70,7 @@ public class VmAllocationPolicyMigrationSlaFixedTightHost extends VmAllocationPo
for (Host host : looseHosts) {
int creditVms = 0;
for (Vm vm : host.getVmList()) {
if (vm.getMonitor().getVmCredit(clock) - getMIGRATION_TIME() > 0) {
if (vm.getMonitor().getCumulativeCredit(clock) - getMIGRATION_TIME() > 0) {
creditVms++;
}
}
......
......@@ -163,7 +163,7 @@ public class CsvGenerator {
writer.append(',');
writer.append(String.valueOf(cl.getVm().getMonitor().getCumulativeVmViolationTime(i)));
writer.append(',');
writer.append(String.valueOf(cl.getVm().getMonitor().getVmCredit(i)));
writer.append(String.valueOf(cl.getVm().getMonitor().getCumulativeCredit(i)));
writer.append('\n');
}
}
......
......@@ -28,6 +28,7 @@ public class SlaMonitor {
public SlaMonitor(Vm vm) {
this.vm = vm;
this.credits = new HashMap<Integer,Double>();
this.violations = new HashMap<Integer,Boolean>();
this.lastElement = 0;
}
......@@ -38,6 +39,7 @@ public double getCumulativeCredit(double time) {
List<VmStateHistoryEntry> stateList = vm.getStateHistory();
double cumulativeCredit = 0;
ListIterator<VmStateHistoryEntry> it = vm.getStateHistory().listIterator(lastElement);
double provisioned = vm.getContract().getIopsProvisioned().getMinDimension().getValue();
if((int) time <= 0) {
return 0;
......@@ -45,7 +47,7 @@ public double getCumulativeCredit(double time) {
while(it.hasNext()) {
VmStateHistoryEntry state = it.next();
double provisioned = vm.getContract().getIopsProvisioned().getMinDimension().getValue();
if((int) state.getTime() < (int) time) {
if(credits.containsKey((int) time)) {
......@@ -69,11 +71,10 @@ public double getCumulativeCredit(double time) {
}
if(stateList.get(lastElement - 1).getTime() < time) {
VmStateHistoryEntry last = stateList.get(lastElement - 1);
Double previous = credits.get((int) last.getTime());
Double previous = credits.get((int) stateList.get(lastElement - 1).getTime());
Double preprevious = credits.get((int) stateList.get(lastElement - 2).getTime());;
if (previous > preprevious) {
if (last.getAllocatedIops() < provisioned) {
cumulativeCredit = previous - (((int) time - stateList.get(lastElement - 1).getTime())) * (1 / availability);
} else {
cumulativeCredit = previous + (((int) time - stateList.get(lastElement - 1).getTime())) * (1 / availability);
......@@ -160,10 +161,6 @@ public double getCumulativeCredit(double time) {
return false;
}
public double getVmCredit(double time){
return Math.max(0, getMaximumAllowedSlaViolationTime() - getCumulativeVmViolationTime(time));
}
public long getInstantaneousVmViolationTime(int time){
if(violations.containsKey(time)){
return violations.get(time)?1:0;
......
......@@ -19,7 +19,7 @@ public class SlaMonitorTest {
private static final long MINIMUM_IOPS = 500;
private static final double MINIMUM_AVAILABILITY = 99.9;
private static final double STEP_CREDIT = 1 / MINIMUM_AVAILABILITY;
private static final long INITIAL_CREDIT = (long) ((100-MINIMUM_AVAILABILITY)*SlaMonitor.SECONDS_OF_A_MONTH);
private static SlaContract contract;
private static double imprecision = 0.0001;
......@@ -76,7 +76,7 @@ public class SlaMonitorTest {
}
@Test
public void getVmCredit_test1() {
public void getVmCredit_test() {
Vm vm = new VmSimple(0, 0);
vm.addStateHistoryEntry(new VmStateHistoryEntry(1,0,0,400,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(2,0,0,500,0,false));
......@@ -99,28 +99,7 @@ public class SlaMonitorTest {
assertEquals(1184 * STEP_CREDIT, vm.getMonitor().getCumulativeCredit(1196), imprecision);
}
@Test
public void getVmCredit_test() {
Vm vm = new VmSimple(0, 0);
vm.addStateHistoryEntry(new VmStateHistoryEntry(1,0,0,400,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(2,0,0,500,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(3,0,0,500,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(4,0,0,600,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(5,0,0,600,0,false));
vm.addStateHistoryEntry(new VmStateHistoryEntry(11,0,0,400,0,false));
vm.setContract(contract);
assertEquals(INITIAL_CREDIT, vm.getMonitor().getVmCredit(0), imprecision);
assertEquals(INITIAL_CREDIT-1, vm.getMonitor().getVmCredit(1), imprecision);
assertEquals(INITIAL_CREDIT-1, vm.getMonitor().getVmCredit(2), imprecision);
assertEquals(INITIAL_CREDIT-1, vm.getMonitor().getVmCredit(3), imprecision);
assertEquals(INITIAL_CREDIT-1, vm.getMonitor().getVmCredit(4), imprecision);
assertEquals(INITIAL_CREDIT-1, vm.getMonitor().getVmCredit(5), imprecision);
assertEquals(INITIAL_CREDIT-2, vm.getMonitor().getVmCredit(11), imprecision);
assertEquals(INITIAL_CREDIT-6, vm.getMonitor().getVmCredit(15), imprecision);
assertEquals(0, vm.getMonitor().getVmCredit(INITIAL_CREDIT+10000), imprecision);
}
@Test
public void getVmCreditAfterOneMonth_test() {
Vm vm = new VmSimple(0, 0);
......@@ -129,11 +108,15 @@ public class SlaMonitorTest {
vm.addStateHistoryEntry(new VmStateHistoryEntry(SlaMonitor.SECONDS_OF_A_MONTH+5,0,0,400,0,false));
vm.setContract(contract);
assertEquals(INITIAL_CREDIT, vm.getMonitor().getVmCredit(0), imprecision);
assertEquals(0, vm.getMonitor().getVmCredit(INITIAL_CREDIT), imprecision);
assertEquals(INITIAL_CREDIT, vm.getMonitor().getVmCredit(SlaMonitor.SECONDS_OF_A_MONTH), imprecision);
assertEquals(INITIAL_CREDIT-1, vm.getMonitor().getVmCredit(SlaMonitor.SECONDS_OF_A_MONTH+5), imprecision);
assertEquals(INITIAL_CREDIT-101, vm.getMonitor().getVmCredit(SlaMonitor.SECONDS_OF_A_MONTH+105), imprecision);
assertEquals(0, vm.getMonitor().getCumulativeCredit(0), imprecision);
assertEquals(-1 * STEP_CREDIT, vm.getMonitor().getCumulativeCredit(1), 0); // starts indebted
assertEquals((-1 * STEP_CREDIT) * (SlaMonitor.SECONDS_OF_A_MONTH -1),vm.getMonitor().getCumulativeCredit((SlaMonitor.SECONDS_OF_A_MONTH -1)), imprecision);
assertEquals((-1 * STEP_CREDIT) * (SlaMonitor.SECONDS_OF_A_MONTH -2),vm.getMonitor().getCumulativeCredit((SlaMonitor.SECONDS_OF_A_MONTH)), imprecision);
assertEquals((-1 * STEP_CREDIT) * (SlaMonitor.SECONDS_OF_A_MONTH -6), vm.getMonitor().getCumulativeCredit(SlaMonitor.SECONDS_OF_A_MONTH + 4), imprecision);
assertEquals((STEP_CREDIT) * (-1 * SlaMonitor.SECONDS_OF_A_MONTH -5), vm.getMonitor().getCumulativeCredit(SlaMonitor.SECONDS_OF_A_MONTH + 5), 0.2);
assertEquals((STEP_CREDIT) * (-1 * SlaMonitor.SECONDS_OF_A_MONTH -15), vm.getMonitor().getCumulativeCredit(SlaMonitor.SECONDS_OF_A_MONTH + 15), 0.2);
assertEquals((STEP_CREDIT) * (-1 * SlaMonitor.SECONDS_OF_A_MONTH -55), vm.getMonitor().getCumulativeCredit(SlaMonitor.SECONDS_OF_A_MONTH + 55), 0.2);
assertEquals((STEP_CREDIT) * (-1 * SlaMonitor.SECONDS_OF_A_MONTH -101), vm.getMonitor().getCumulativeCredit(SlaMonitor.SECONDS_OF_A_MONTH + 101), 0.2);
}
@Test
......@@ -164,7 +147,7 @@ public class SlaMonitorTest {
vm.setContract(contract);
assertEquals(0, vm.getMonitor().getCumulativeVmViolationTime(0));
assertEquals(1, vm.getMonitor().getCumulativeVmViolationTime(1));
assertEquals(1, vm.getMonitor().getCumulativeVmViolationTime(1));
assertEquals(100, vm.getMonitor().getCumulativeVmViolationTime(100));
assertEquals(0, vm.getMonitor().getCumulativeVmViolationTime(SlaMonitor.SECONDS_OF_A_MONTH));
assertEquals(1, vm.getMonitor().getCumulativeVmViolationTime(SlaMonitor.SECONDS_OF_A_MONTH+5));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment