Commit 0a361921 authored by Lucas Cavalcante's avatar Lucas Cavalcante
Browse files

allocation -> utilization

parent dcab0f07
......@@ -24,36 +24,41 @@ public class SlaMonitor {
private Map<Integer,Boolean> violations;
private Map<Integer,Double> credits;
private int lastElement;
private int lastUtilization;
public SlaMonitor(Vm vm) {
this.vm = vm;
this.credits = new HashMap<Integer,Double>();
this.lastElement = 0;
this.lastUtilization = 0;
}
public double getCumulativeCredit(double time) {
double availability = vm.getContract().getAvailabilityMetric().getMinDimension().getValue();
List<VmStateHistoryEntry> stateList = vm.getStateHistory();
List<VmStateHistoryEntry> stateList = vm.getStateHistory();
List<Double> utilizationList = vm.getUtilizationHistory().getHistory();
double cumulativeCredit = 0;
ListIterator<VmStateHistoryEntry> it = vm.getStateHistory().listIterator(lastElement);
ListIterator<VmStateHistoryEntry> it = stateList.listIterator(lastElement);
ListIterator<Double> ut = utilizationList.listIterator(lastUtilization);
if((int) time <= 0) {
return 0;
}
while(it.hasNext()) {
while(it.hasNext() && ut.hasNext()) {
VmStateHistoryEntry state = it.next();
double provisioned = vm.getContract().getIopsProvisioned().getMinDimension().getValue();
double utilization = ut.next();
if((int) state.getTime() < (int) time) {
if(credits.containsKey((int) time)) {
cumulativeCredit = credits.get((int) time);
} else {
double dif = calculateMissingCredit((int) state.getTime(), availability, provisioned);
cumulativeCredit = putCredits(state, provisioned, dif, availability);
lastElement = it.nextIndex();
double dif = calculateMissingCredit((int) state.getTime(), availability, utilization);
cumulativeCredit = putCredits(state, utilization, dif, availability);
lastElement = it.nextIndex();
lastUtilization = ut.nextIndex();
}
}
......@@ -61,9 +66,10 @@ public double getCumulativeCredit(double time) {
if(credits.containsKey((int) time)) {
cumulativeCredit = credits.get((int) time);
} else {
double dif = calculateMissingCredit((int) state.getTime(), availability, provisioned);
cumulativeCredit = putCredits(state, provisioned, dif, availability);
lastElement = it.nextIndex();
double dif = calculateMissingCredit((int) state.getTime(), availability, utilization);
cumulativeCredit = putCredits(state, utilization, dif, availability);
lastElement = it.nextIndex();
lastUtilization = ut.nextIndex();
}
}
}
......@@ -82,9 +88,9 @@ public double getCumulativeCredit(double time) {
return cumulativeCredit;
}
private Double putCredits(VmStateHistoryEntry state, double provisioned, double dif, double availability) {
private Double putCredits(VmStateHistoryEntry state, double utilization, double dif, double availability) {
Double cumulativeCredit;
if(state.getAllocatedIops() < provisioned) {
if(state.getAllocatedIops() < utilization) {
credits.put((int) state.getTime(), dif - (1 / availability));
}
else {
......@@ -94,7 +100,7 @@ public double getCumulativeCredit(double time) {
return cumulativeCredit;
}
private double calculateMissingCredit(int time, double availability, double provisioned) {
private double calculateMissingCredit(int time, double availability, double utilization) {
double prevTime;
VmStateHistoryEntry state;
if(lastElement - 1 > 0) {
......@@ -116,7 +122,7 @@ public double getCumulativeCredit(double time) {
return previous;
}
if(state.getAllocatedIops() > provisioned)
if(state.getAllocatedIops() >= utilization)
dif = previous + (1 / availability) * (int )(time - prevTime - 1);
else
dif = previous - (1 / availability) * (int )(time - prevTime - 1);
......
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