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