Solved Issue 44: UtilizationModelPlanetLabInMemory: use a global constant to…

Solved Issue 44: UtilizationModelPlanetLabInMemory: use a global constant to define the size of the data field: a new constructor for the classes, allowing definition of data size, was added.

Solved Issue 49: Wrong calculation of debt during migrationL: all references to debt from Datacenter and its subclasses were removed.

parent 71b1e039
......@@ -51,6 +51,7 @@ public class CloudSimExample1 {
*
* @param args the args
*/
@SuppressWarnings("unused")
public static void main(String[] args) {
Log.printLine("Starting CloudSimExample1...");
......@@ -124,9 +125,6 @@ public class CloudSimExample1 {
List<Cloudlet> newList = broker.getCloudletReceivedList();
printCloudletList(newList);
// Print the debt of each user to each datacenter
datacenter0.printDebts();
Log.printLine("CloudSimExample1 finished!");
} catch (Exception e) {
e.printStackTrace();
......
......@@ -71,7 +71,8 @@ public class CloudSimExample2 {
// Second step: Create Datacenters
//Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
Datacenter datacenter0 = createDatacenter("Datacenter_0");
@SuppressWarnings("unused")
Datacenter datacenter0 = createDatacenter("Datacenter_0");
//Third step: Create Broker
DatacenterBroker broker = createBroker();
......@@ -145,9 +146,6 @@ public class CloudSimExample2 {
printCloudletList(newList);
//Print the debt of each user to each datacenter
datacenter0.printDebts();
Log.printLine("CloudSimExample2 finished!");
}
catch (Exception e) {
......
......@@ -71,6 +71,7 @@ public class CloudSimExample3 {
// Second step: Create Datacenters
//Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
@SuppressWarnings("unused")
Datacenter datacenter0 = createDatacenter("Datacenter_0");
//Third step: Create Broker
......@@ -145,9 +146,6 @@ public class CloudSimExample3 {
printCloudletList(newList);
//Print the debt of each user to each datacenter
datacenter0.printDebts();
Log.printLine("CloudSimExample3 finished!");
}
catch (Exception e) {
......
......@@ -67,7 +67,9 @@ public class CloudSimExample4 {
// Second step: Create Datacenters
//Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
@SuppressWarnings("unused")
Datacenter datacenter0 = createDatacenter("Datacenter_0");
@SuppressWarnings("unused")
Datacenter datacenter1 = createDatacenter("Datacenter_1");
//Third step: Create Broker
......@@ -141,10 +143,6 @@ public class CloudSimExample4 {
printCloudletList(newList);
//Print the debt of each user to each datacenter
datacenter0.printDebts();
datacenter1.printDebts();
Log.printLine("CloudSimExample4 finished!");
}
catch (Exception e) {
......
......@@ -69,7 +69,9 @@ public class CloudSimExample5 {
// Second step: Create Datacenters
//Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
@SuppressWarnings("unused")
Datacenter datacenter0 = createDatacenter("Datacenter_0");
@SuppressWarnings("unused")
Datacenter datacenter1 = createDatacenter("Datacenter_1");
//Third step: Create Brokers
......@@ -146,10 +148,6 @@ public class CloudSimExample5 {
Log.print("=============> User "+brokerId2+" ");
printCloudletList(newList2);
//Print the debt of each user to each datacenter
datacenter0.printDebts();
datacenter1.printDebts();
Log.printLine("CloudSimExample5 finished!");
}
catch (Exception e) {
......
......@@ -119,7 +119,9 @@ public class CloudSimExample6 {
// Second step: Create Datacenters
//Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
@SuppressWarnings("unused")
Datacenter datacenter0 = createDatacenter("Datacenter_0");
@SuppressWarnings("unused")
Datacenter datacenter1 = createDatacenter("Datacenter_1");
//Third step: Create Broker
......@@ -143,10 +145,6 @@ public class CloudSimExample6 {
printCloudletList(newList);
//Print the debt of each user to each datacenter
datacenter0.printDebts();
datacenter1.printDebts();
Log.printLine("CloudSimExample6 finished!");
}
catch (Exception e)
......
......@@ -116,7 +116,9 @@ public class CloudSimExample7 {
// Second step: Create Datacenters
//Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
@SuppressWarnings("unused")
Datacenter datacenter0 = createDatacenter("Datacenter_0");
@SuppressWarnings("unused")
Datacenter datacenter1 = createDatacenter("Datacenter_1");
//Third step: Create Broker
......@@ -181,10 +183,6 @@ public class CloudSimExample7 {
printCloudletList(newList);
//Print the debt of each user to each datacenter
datacenter0.printDebts();
datacenter1.printDebts();
Log.printLine("CloudSimExample7 finished!");
}
catch (Exception e)
......
......@@ -120,7 +120,9 @@ public class CloudSimExample8 {
// Second step: Create Datacenters
//Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
@SuppressWarnings("unused")
Datacenter datacenter0 = createDatacenter("Datacenter_0");
@SuppressWarnings("unused")
Datacenter datacenter1 = createDatacenter("Datacenter_1");
//Third step: Create Broker
......@@ -145,10 +147,6 @@ public class CloudSimExample8 {
printCloudletList(newList);
//Print the debt of each user to each datacenter
datacenter0.printDebts();
datacenter1.printDebts();
Log.printLine("CloudSimExample8 finished!");
}
catch (Exception e)
......
......@@ -139,9 +139,6 @@ public class NetworkExample1 {
printCloudletList(newList);
//Print the debt of each user to each datacenter
datacenter0.printDebts();
Log.printLine("NetworkExample1 finished!");
}
catch (Exception e) {
......
......@@ -163,10 +163,6 @@ public class NetworkExample2 {
printCloudletList(newList);
//Print the debt of each user to each datacenter
datacenter0.printDebts();
datacenter1.printDebts();
Log.printLine("NetworkExample2 finished!");
}
catch (Exception e) {
......
......@@ -169,10 +169,6 @@ public class NetworkExample3 {
Log.print("=============> User "+brokerId2+" ");
printCloudletList(newList2);
//Print the debt of each user to each datacenter
datacenter0.printDebts();
datacenter1.printDebts();
Log.printLine("NetworkExample3 finished!");
}
catch (Exception e) {
......
......@@ -131,9 +131,6 @@ public class NetworkExample4 {
printCloudletList(newList);
//Print the debt of each user to each datacenter
datacenter0.printDebts();
Log.printLine("NetworkExample4 finished!");
}
catch (Exception e) {
......
......@@ -77,8 +77,6 @@ public class TestExample {
System.out.println("numberofcloudlet " + newList.size() + " Cached "
+ NetDatacenterBroker.cachedcloudlet + " Data transfered "
+ NetworkConstants.totaldatatransfer);
// Print the debt of each user to each datacenter
datacenter0.printDebts();
Log.printLine("CloudSimExample1 finished!");
} catch (Exception e) {
......
......@@ -7,13 +7,11 @@
package org.cloudbus.cloudsim;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
......@@ -45,9 +43,6 @@ public class Datacenter extends SimEntity {
/** The last process time. */
private double lastProcessTime;
/** The debts. */
private Map<Integer, Double> debts;
/** The storage list. */
private List<Storage> storageList;
......@@ -88,7 +83,6 @@ public class Datacenter extends SimEntity {
setCharacteristics(characteristics);
setVmAllocationPolicy(vmAllocationPolicy);
setLastProcessTime(0.0);
setDebts(new HashMap<Integer, Double>());
setStorageList(storageList);
setVmList(new ArrayList<Vm>());
setSchedulingInterval(schedulingInterval);
......@@ -331,17 +325,6 @@ public class Datacenter extends SimEntity {
int msg = addFile(file); // add the file
double debit;
if (getDebts().containsKey(sentFrom)) {
debit = getDebts().get(sentFrom);
} else {
debit = 0.0;
}
debit += getCharacteristics().getCostPerBw() * file.getSize();
getDebts().put(sentFrom, debit);
if (ack) {
data[1] = Integer.valueOf(-1); // no sender id
data[2] = Integer.valueOf(msg); // the result of adding a master file
......@@ -461,15 +444,6 @@ public class Datacenter extends SimEntity {
}
if (result) {
double amount = 0.0;
if (getDebts().containsKey(vm.getUserId())) {
amount = getDebts().get(vm.getUserId());
}
amount += getCharacteristics().getCostPerMem() * vm.getRam();
amount += getCharacteristics().getCostPerStorage() * vm.getSize();
getDebts().put(vm.getUserId(), amount);
getVmList().add(vm);
if (vm.isBeingInstantiated()) {
......@@ -549,16 +523,6 @@ public class Datacenter extends SimEntity {
sendNow(ev.getSource(), CloudSimTags.VM_CREATE_ACK, data);
}
double amount = 0.0;
if (debts.containsKey(vm.getUserId())) {
amount = debts.get(vm.getUserId());
}
amount += getCharacteristics().getCostPerMem() * vm.getRam();
amount += getCharacteristics().getCostPerStorage() * vm.getSize();
debts.put(vm.getUserId(), amount);
Log.formatLine(
"%.2f: Migration of VM #%d to Host #%d is completed",
CloudSim.clock(),
......@@ -1045,24 +1009,6 @@ public class Datacenter extends SimEntity {
return msg;
}
/**
* Prints the debts.
*/
public void printDebts() {
Log.printLine("*****Datacenter: " + getName() + "*****");
Log.printLine("User id\t\tDebt");
Set<Integer> keys = getDebts().keySet();
Iterator<Integer> iter = keys.iterator();
DecimalFormat df = new DecimalFormat("#.##");
while (iter.hasNext()) {
int key = iter.next();
double value = getDebts().get(key);
Log.printLine(key + "\t\t" + df.format(value));
}
Log.printLine("**********************************");
}
/*
* (non-Javadoc)
* @see cloudsim.core.SimEntity#shutdownEntity()
......@@ -1175,24 +1121,6 @@ public class Datacenter extends SimEntity {
this.lastProcessTime = lastProcessTime;
}
/**
* Gets the debts.
*
* @return the debts
*/
protected Map<Integer, Double> getDebts() {
return debts;
}
/**
* Sets the debts.
*
* @param debts the debts
*/
protected void setDebts(Map<Integer, Double> debts) {
this.debts = debts;
}
/**
* Gets the storage list.
*
......
......@@ -8,13 +8,13 @@ import java.io.IOException;
* The Class UtilizationModelPlanetLab.
*/
public class UtilizationModelPlanetLabInMemory implements UtilizationModel {
/** The scheduling interval. */
private double schedulingInterval;
/** The data (5 min * 288 = 24 hours). */
private final double[] data = new double[289];
private final double[] data;
/**
* Instantiates a new utilization model PlanetLab.
*
......@@ -25,7 +25,30 @@ public class UtilizationModelPlanetLabInMemory implements UtilizationModel {
public UtilizationModelPlanetLabInMemory(String inputPath, double schedulingInterval)
throws NumberFormatException,
IOException {
data = new double[289];
setSchedulingInterval(schedulingInterval);
BufferedReader input = new BufferedReader(new FileReader(inputPath));
int n = data.length;
for (int i = 0; i < n - 1; i++) {
data[i] = Integer.valueOf(input.readLine()) / 100.0;
}
data[n - 1] = data[n - 2];
input.close();
}
/**
* Instantiates a new utilization model PlanetLab with variable data samples.
*
* @param inputPath the input path
* @param dataSamples number of samples in the file
* @throws NumberFormatException the number format exception
* @throws IOException Signals that an I/O exception has occurred.
*/
public UtilizationModelPlanetLabInMemory(String inputPath, double schedulingInterval, int dataSamples)
throws NumberFormatException,
IOException {
setSchedulingInterval(schedulingInterval);
data = new double[dataSamples];
BufferedReader input = new BufferedReader(new FileReader(inputPath));
int n = data.length;
for (int i = 0; i < n - 1; i++) {
......
......@@ -463,6 +463,7 @@ public class CloudSim {
public static boolean runClockTick() {
SimEntity ent;
boolean queue_empty;
int entities_size = entities.size();
for (int i = 0; i < entities_size; i++) {
......@@ -471,26 +472,26 @@ public class CloudSim {
ent.run();
}
}
// If there are more future events then deal with them
if (future.size() > 0) {
List<SimEvent> toRemove = new ArrayList<SimEvent>();
Iterator<SimEvent> it = future.iterator();
Iterator<SimEvent> fit = future.iterator();
queue_empty = false;
SimEvent first = it.next();
SimEvent first = fit.next();
processEvent(first);
future.remove(first);
it = future.iterator();
fit = future.iterator();
// Check if next events are at same time...
boolean trymore = it.hasNext();
boolean trymore = fit.hasNext();
while (trymore) {
SimEvent next = it.next();
SimEvent next = fit.next();
if (next.eventTime() == first.eventTime()) {
processEvent(next);
toRemove.add(next);
trymore = it.hasNext();
trymore = fit.hasNext();
} else {
trymore = false;
}
......
......@@ -118,14 +118,6 @@ public class NetworkDatacenter extends Datacenter {
VmToSwitchid.put(vm.getId(), ((NetworkHost) vm.getHost()).sw.getId());
VmtoHostlist.put(vm.getId(), vm.getHost().getId());
System.out.println(vm.getId() + " VM is created on " + vm.getHost().getId());
double amount = 0.0;
if (getDebts().containsKey(vm.getUserId())) {
amount = getDebts().get(vm.getUserId());
}
amount += getCharacteristics().getCostPerMem() * vm.getRam();
amount += getCharacteristics().getCostPerStorage() * vm.getSize();
getDebts().put(vm.getUserId(), amount);
getVmList().add(vm);
......
......@@ -62,6 +62,7 @@ public class TimeSharedProblemDetector {
// Second step: Create Datacenters
// Datacenters are the resource providers in CloudSim. We need at
// list one of them to run a CloudSim simulation
@SuppressWarnings("unused")
Datacenter datacenter0 = createDatacenter("Datacenter_0");
// Third step: Create Broker
......@@ -135,9 +136,6 @@ public class TimeSharedProblemDetector {
List<Cloudlet> newList = broker.getCloudletReceivedList();
printCloudletList(newList);
// Print the debt of each user to each datacenter
datacenter0.printDebts();
Log.printLine("CloudSimExample1 finished!");
} catch (Exception e) {
e.printStackTrace();
......
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