Skip to content

Commit 74a621f

Browse files
committed
Update InterDatacenterMigration1.java
Signed-off-by: Manoel Campos <[email protected]>
1 parent 29ac4d5 commit 74a621f

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/main/java/org/cloudsimplus/examples/migration/InterDatacenterMigration1.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.cloudsimplus.cloudlets.CloudletSimple;
3535
import org.cloudsimplus.core.CloudSimPlus;
3636
import org.cloudsimplus.datacenters.Datacenter;
37+
import org.cloudsimplus.datacenters.DatacenterCharacteristics;
38+
import org.cloudsimplus.datacenters.DatacenterCharacteristics.Distribution;
3739
import org.cloudsimplus.datacenters.DatacenterSimple;
3840
import org.cloudsimplus.hosts.Host;
3941
import org.cloudsimplus.hosts.HostSimple;
@@ -293,8 +295,8 @@ private void printResults() {
293295
new CloudletsTableBuilder(cloudletFinishedList).setTitle(broker.toString()).build();
294296
}
295297

296-
System.out.printf("%nNumber of VM migrations: %d%n", migrationsNumber);
297298
printHostStateHistory();
299+
System.out.printf("%nNumber of VM migrations: %d%n", migrationsNumber);
298300
}
299301

300302
private void printHostStateHistory() {
@@ -327,12 +329,18 @@ private void createVmsAndCloudlets() {
327329
* setting the allocation policy to the default value
328330
* so that some Hosts will be overloaded with the placed VMs and migration will be fired.
329331
*
330-
* The listener is removed after finishing, so that it's called just once,
331-
* even if new VMs are submitted and created latter on.
332+
* <p>The listener is removed after finishing, so that it's called just once,
333+
* even if new VMs are submitted and created later on.</p>
332334
*/
333335
private void onVmsCreatedListener(final DatacenterBrokerEventInfo info) {
334336
final var broker = info.getDatacenterBroker();
335-
System.out.printf("# All %d VMs submitted to %s have been created.%n", broker.getVmCreatedList().size(), broker);
337+
final String vmIds = broker.getVmCreatedList()
338+
.stream()
339+
.mapToLong(Vm::getId)
340+
.mapToObj(Long::toString)
341+
.collect(joining(", "));
342+
343+
System.out.printf("# %d VMs submitted to %s have been created. VMs: %s.%n", broker.getVmCreatedList().size(), broker, vmIds);
336344
datacenterList.stream()
337345
.map(dc -> (VmAllocationPolicyMigrationFirstFitStaticThreshold)dc.getVmAllocationPolicy())
338346
.forEach(policy -> policy.setOverUtilizationThreshold(HOST_OVER_UTILIZATION_THRESHOLD_FOR_VM_MIGRATION));
@@ -442,18 +450,27 @@ private List<Datacenter> createDatacenters() {
442450
return IntStream.range(0, datacentersNumber).mapToObj(this::createDatacenter).toList();
443451
}
444452

453+
/**
454+
* Create a private-cloud Datacenter for even indexes and public-cloud one for odd indexes.
455+
* @param index the Datacenter index
456+
* @return the created Datacenter
457+
* @see DatacenterCharacteristics.Distribution
458+
*/
445459
private Datacenter createDatacenter(final int index) {
460+
final var distribution = index % 2 == 0 ? Distribution.PRIVATE : Distribution.PUBLIC;
446461
final var hostList = createHosts(DC_HOST_PES[index]);
447462
final var allocationPolicy = createVmAllocationPolicy();
448463
final var dc = new DatacenterSimple(simulation, hostList, allocationPolicy);
449464
dc.setSchedulingInterval(SCHEDULING_INTERVAL)
450-
.setHostSearchRetryDelay(HOST_SEARCH_RETRY_DELAY);
465+
.setHostSearchRetryDelay(HOST_SEARCH_RETRY_DELAY)
466+
.getCharacteristics()
467+
.setDistribution(distribution);
451468

452469
final String hostsStr =
453470
hostList.stream()
454471
.map(host -> String.format("Host %d w/ %d PEs", host.getId(), host.getPesNumber()))
455472
.collect(joining(", "));
456-
System.out.printf("%s: %s%n", dc, hostsStr);
473+
System.out.printf("%7s-cloud %s: %s%n", distribution, dc, hostsStr);
457474
return dc;
458475
}
459476

0 commit comments

Comments
 (0)