Skip to content

Commit 5e8caa8

Browse files
committed
ContainerCloudSim: fixed several bugs that were preventing some ContainerCloudSim's examples to run properly
1 parent cb406da commit 5e8caa8

File tree

7 files changed

+30
-38
lines changed

7 files changed

+30
-38
lines changed

modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/container/HelperEx.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.cloudbus.cloudsim.container.core.*;
77
import org.cloudbus.cloudsim.container.resourceAllocatorMigrationEnabled.PowerContainerVmAllocationPolicyMigrationAbstract;
88
import org.cloudbus.cloudsim.container.utils.IDs;
9+
import org.cloudbus.cloudsim.core.HostEntity;
910
import org.cloudbus.cloudsim.power.PowerHost;
1011
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
1112
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
@@ -115,22 +116,22 @@ public static List<ContainerVm> createVmList(int brokerId, int containerVmsNumbe
115116
}
116117

117118

118-
public static List<Host> createHostList(int hostsNumber) {
119-
ArrayList hostList = new ArrayList();
119+
public static List<HostEntity> createHostList(int hostsNumber) {
120+
List<HostEntity> hostList = new ArrayList<>();
120121
for (int i = 0; i < hostsNumber; ++i) {
121122
// int hostType = new RandomGen().getNum(ConstantsExamples.HOST_TYPES);
122123
int hostType = i / (int) Math.ceil((double) hostsNumber / 3.0D);
123124
// int hostType = i % 2;
124125
// int hostType = 2;
125-
ArrayList peList = new ArrayList();
126+
List<Pe> peList = new ArrayList<>();
126127

127128
for (int j = 0; j < ConstantsExamples.HOST_PES[hostType]; ++j) {
128-
peList.add(new Pe(j, new PeProvisionerSimple((double) ConstantsExamples.HOST_MIPS[hostType])));
129+
peList.add(new Pe(j, new PeProvisionerSimple(ConstantsExamples.HOST_MIPS[hostType])));
129130
}
130131

131132
// hostList.add(new PowerHost(i, new RamProvisionerSimple(ConstantsExamples.HOST_RAM[hostType]),
132133
// new BwProvisionerSimple(1000000L), 1000000L, peList, new VmSchedulerTimeSharedOverSubscription(peList), ConstantsExamples.HOST_POWER[hostType]));
133-
hostList.add(new PowerHost(IDs.pollId(Host.class), new RamProvisionerSimple(ConstantsExamples.HOST_RAM[hostType]),
134+
hostList.add(new PowerHost(IDs.pollId(HostEntity.class), new RamProvisionerSimple(ConstantsExamples.HOST_RAM[hostType]),
134135
new BwProvisionerSimple(1000000L), 1000000L, peList, new VmSchedulerTimeSharedOverSubscription(peList), ConstantsExamples.HOST_POWER[hostType]));
135136
}
136137

@@ -223,7 +224,7 @@ public static ContainerDatacenterBroker createBroker(double overBookingFactor) {
223224
*/
224225

225226
public static ContainerDatacenter createDatacenter(String name, Class<? extends ContainerDatacenter> datacenterClass,
226-
List<Host> hostList,
227+
List<HostEntity> hostList,
227228
VmAllocationPolicy vmAllocationPolicy,
228229
VmAllocationPolicy containerAllocationPolicy,
229230
String experimentName, double schedulingInterval, String logAddress, double VMStartupDelay,
@@ -263,7 +264,7 @@ public static void printResults(
263264
boolean outputInCsv,
264265
String outputFolder) {
265266
Log.enable();
266-
List<Host> hosts = datacenter.getHostList();
267+
List<HostEntity> hosts = datacenter.getHostList();
267268

268269
int numberOfHosts = hosts.size();
269270
int numberOfVms = vms.size();
@@ -545,9 +546,9 @@ public static List<Double> getTimesBeforeContainerMigration(List<Container> cont
545546
* @param hosts the hosts
546547
* @return the times before host shutdown
547548
*/
548-
public static List<Double> getTimesBeforeHostShutdown(List<Host> hosts) {
549+
public static List<Double> getTimesBeforeHostShutdown(List<HostEntity> hosts) {
549550
List<Double> timeBeforeShutdown = new LinkedList<>();
550-
for (Host host : hosts) {
551+
for (HostEntity host : hosts) {
551552
boolean previousIsActive = true;
552553
double lastTimeSwitchedOn = 0;
553554
for (HostStateHistoryEntry entry : ((HostDynamicWorkload) host).getStateHistory()) {
@@ -591,7 +592,7 @@ public static String parseExperimentName(String name) {
591592
* @param hosts the hosts
592593
* @return the sla time per active host
593594
*/
594-
protected static double getSlaTimePerActiveHost(List<Host> hosts) {
595+
protected static double getSlaTimePerActiveHost(List<HostEntity> hosts) {
595596
double slaViolationTimePerHost = 0;
596597
double totalTime = 0;
597598

@@ -627,7 +628,7 @@ protected static double getSlaTimePerActiveHost(List<Host> hosts) {
627628
* @param hosts the hosts
628629
* @return the sla time per host
629630
*/
630-
protected static double getSlaTimePerHost(List<Host> hosts) {
631+
protected static double getSlaTimePerHost(List<HostEntity> hosts) {
631632
double slaViolationTimePerHost = 0;
632633
double totalTime = 0;
633634

@@ -780,12 +781,12 @@ public static void writeDataRow(String data, String outputPath) {
780781
* @param outputPath the output path
781782
*/
782783
public static void writeMetricHistory(
783-
List<? extends Host> hosts,
784+
List<? extends HostEntity> hosts,
784785
PowerContainerVmAllocationPolicyMigrationAbstract vmAllocationPolicy,
785786
String outputPath) {
786787
// for (Host host : hosts) {
787788
for (int j = 0; j < 10; j++) {
788-
Host host = hosts.get(j);
789+
HostEntity host = hosts.get(j);
789790

790791
if (!vmAllocationPolicy.getTimeHistory().containsKey(host.getId())) {
791792
continue;
@@ -825,10 +826,10 @@ public static void writeMetricHistory(
825826
* @param vmAllocationPolicy the vm allocation policy
826827
*/
827828
public static void printMetricHistory(
828-
List<? extends Host> hosts,
829+
List<? extends HostEntity> hosts,
829830
PowerContainerVmAllocationPolicyMigrationAbstract vmAllocationPolicy) {
830831
for (int i = 0; i < 10; i++) {
831-
Host host = hosts.get(i);
832+
HostEntity host = hosts.get(i);
832833

833834
Log.println("Host #" + host.getId());
834835
Log.println("Time:");
@@ -861,7 +862,7 @@ public static void printResultsNew(PowerContainerDatacenter datacenter,
861862
List<ContainerVm> vms = broker.getGuestsCreatedList();
862863
List<Container> containers = broker.getContainersCreatedList();
863864
Log.enable();
864-
List<Host> hosts = datacenter.getHostList();
865+
List<HostEntity> hosts = datacenter.getHostList();
865866
Map<String, Double> slaMetrics = getSlaMetrics(vms);
866867
String[] msg = { "ExperimentName","hostSelectionPolicy","vmAllocationPolicy", "OLThreshold","ULThreshold", "VMSPolicy","ContainerSpolicy","ContainerPlacement","Percentile",
867868
"numberOfHosts",
@@ -1096,10 +1097,10 @@ public static void printResultsNew(PowerContainerDatacenter datacenter,
10961097
}
10971098

10981099

1099-
public static int getNumberofOverUtilization(List<? extends Host> hosts,
1100+
public static int getNumberofOverUtilization(List<? extends HostEntity> hosts,
11001101
PowerContainerVmAllocationPolicyMigrationAbstract vmAllocationPolicy) {
11011102
int numberOfOverUtilization = 0;
1102-
for (Host host : hosts) {
1103+
for (HostEntity host : hosts) {
11031104
if (!vmAllocationPolicy.getTimeHistory().containsKey(host.getId())) {
11041105
continue;
11051106
}

modules/cloudsim-examples/src/main/java/org/cloudbus/cloudsim/examples/container/RunnerAbs.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public abstract class RunnerAbs {
4040
/**
4141
* The host list.
4242
*/
43-
protected static List<Host> hostList;
43+
protected static List<HostEntity> hostList;
4444

4545
/**
4646
* The Cloudlet List
@@ -171,7 +171,8 @@ protected void start(String experimentName, String outputFolder, VmAllocationPol
171171
getExperimentName(), ConstantsExamples.SCHEDULING_INTERVAL, getLogAddress(),
172172
ConstantsExamples.VM_STARTTUP_DELAY, ConstantsExamples.CONTAINER_STARTTUP_DELAY);
173173
// PowerContainerDatacenter e = (PowerContainerDatacenter) HelperEx.createDatacenter("Datacenter", PowerContainerDatacenter.class, hostList, vmAllocationPolicy, containerAllocationPolicy);
174-
// not needed: vmAllocationPolicy.setDatacenter(e);
174+
vmAllocationPolicy.setDatacenter(e);
175+
175176
e.setDisableVmMigrations(false);
176177
broker.submitGuestList(vmList);
177178
broker.submitContainerList(containerList);

modules/cloudsim/src/main/java/org/cloudbus/cloudsim/VmAllocationPolicy.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package org.cloudbus.cloudsim;
1010

1111
import org.cloudbus.cloudsim.container.core.Container;
12-
import org.cloudbus.cloudsim.container.core.ContainerVm;
1312
import org.cloudbus.cloudsim.core.CloudSim;
1413
import org.cloudbus.cloudsim.core.GuestEntity;
1514
import org.cloudbus.cloudsim.core.HostEntity;
@@ -212,4 +211,7 @@ protected void setHostList(List<? extends HostEntity> hostList) {
212211
public <T extends HostEntity> List<T> getHostList() {
213212
return (List<T>) hostList;
214213
}
214+
215+
// Needed by ContainerCloudSim
216+
public <T extends Datacenter> void setDatacenter(T datacenter) { }
215217
}

modules/cloudsim/src/main/java/org/cloudbus/cloudsim/container/resourceAllocatorMigrationEnabled/PowerContainerVmAllocationPolicyMigrationAbstract.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public PowerContainerVmAllocationPolicyMigrationAbstract(
8181
SelectionPolicy<GuestEntity> vmSelectionPolicy) {
8282
super(hostList);
8383
setVmSelectionPolicy(vmSelectionPolicy);
84-
8584
}
8685

8786
/**
@@ -255,6 +254,7 @@ protected boolean isHostOverUtilizedAfterAllocation(PowerHost host, GuestEntity
255254
isHostOverUtilizedAfterAllocation = isHostOverUtilized(host);
256255
host.guestDestroy(vm);
257256
}
257+
258258
return isHostOverUtilizedAfterAllocation;
259259
}
260260

@@ -704,6 +704,5 @@ public List<Double> getExecutionTimeHistoryTotal() {
704704
return executionTimeHistoryTotal;
705705
}
706706

707-
708707
// public abstract List<? extends Container> getContainersToMigrateFromHosts(List<PowerHost> overUtilizedHosts);
709708
}

modules/cloudsim/src/main/java/org/cloudbus/cloudsim/container/resourceAllocatorMigrationEnabled/PowerContainerVmAllocationPolicyMigrationAbstractContainerAdded.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,9 @@ public ContainerDatacenter getDatacenter() {
721721
return datacenter;
722722
}
723723

724-
public void setDatacenter(ContainerDatacenter datacenter) {
725-
this.datacenter = datacenter;
724+
@Override
725+
public <T extends Datacenter> void setDatacenter(T datacenter) {
726+
this.datacenter = (ContainerDatacenter) datacenter;
726727
}
727728

728729
public SelectionPolicy<PowerGuestEntity> getContainerSelectionPolicy() {

modules/cloudsim/src/main/java/org/cloudbus/cloudsim/container/resourceAllocatorMigrationEnabled/PowerContainerVmAllocationPolicyMigrationStaticThresholdMC.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ protected void setUtilizationThreshold(double utilizationThreshold) {
8686
protected double getUtilizationThreshold() {
8787
return utilizationThreshold;
8888
}
89-
@Override
90-
public void setDatacenter(ContainerDatacenter datacenter) {
91-
super.setDatacenter(datacenter);
92-
}
93-
9489
}
9590

9691

modules/cloudsim/src/main/java/org/cloudbus/cloudsim/container/resourceAllocatorMigrationEnabled/PowerContainerVmAllocationPolicyMigrationStaticThresholdMCUnderUtilized.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class PowerContainerVmAllocationPolicyMigrationStaticThresholdMCUnderUtil
3838
* @param utilizationThreshold the utilization threshold
3939
*/
4040
public PowerContainerVmAllocationPolicyMigrationStaticThresholdMCUnderUtilized(
41-
List<? extends Host> hostList,
41+
List<? extends HostEntity> hostList,
4242
SelectionPolicy<GuestEntity> vmSelectionPolicy, SelectionPolicy<PowerGuestEntity> containerSelectionPolicy,
4343
SelectionPolicy<HostEntity> hostSelectionPolicy, double utilizationThreshold, double underUtilizationThresh,
4444
int numberOfVmTypes, int[] vmPes, int[] vmRam, long vmBw, long vmSize, double[] vmMips) {
@@ -86,11 +86,4 @@ protected void setUtilizationThreshold(double utilizationThreshold) {
8686
protected double getUtilizationThreshold() {
8787
return utilizationThreshold;
8888
}
89-
@Override
90-
public void setDatacenter(ContainerDatacenter datacenter) {
91-
super.setDatacenter(datacenter);
92-
}
93-
94-
95-
9689
}

0 commit comments

Comments
 (0)