Skip to content

Commit 8ef1014

Browse files
committed
Docs update
Signed-off-by: Manoel Campos <[email protected]>
1 parent c499e11 commit 8ef1014

26 files changed

+249
-27
lines changed

src/main/java/org/cloudsimplus/examples/BasicFirstExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private BasicFirstExample() {
8686
simulation = new CloudSimPlus();
8787
datacenter0 = createDatacenter();
8888

89-
//Creates a broker that is a software acting on behalf a cloud customer to manage his/her VMs and Cloudlets
89+
//Creates a broker that is a software acting on behalf of a cloud customer to manage his/her VMs and Cloudlets
9090
broker0 = new DatacenterBrokerSimple(simulation);
9191

9292
vmList = createVms();
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
/*
2+
* CloudSim Plus: A modern, highly-extensible and easier-to-use Framework for
3+
* Modeling and Simulation of Cloud Computing Infrastructures and Services.
4+
* http://cloudsimplus.org
5+
*
6+
* Copyright (C) 2015-2021 Universidade da Beira Interior (UBI, Portugal) and
7+
* the Instituto Federal de Educação Ciência e Tecnologia do Tocantins (IFTO, Brazil).
8+
*
9+
* This file is part of CloudSim Plus.
10+
*
11+
* CloudSim Plus is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation, either version 3 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* CloudSim Plus is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with CloudSim Plus. If not, see <http://www.gnu.org/licenses/>.
23+
*/
24+
package org.cloudsimplus.examples;
25+
26+
import org.cloudsimplus.brokers.DatacenterBroker;
27+
import org.cloudsimplus.brokers.DatacenterBrokerSimple;
28+
import org.cloudsimplus.builders.tables.CloudletsTableBuilder;
29+
import org.cloudsimplus.builders.tables.MarkdownTableColumn;
30+
import org.cloudsimplus.cloudlets.Cloudlet;
31+
import org.cloudsimplus.cloudlets.CloudletSimple;
32+
import org.cloudsimplus.core.CloudSimPlus;
33+
import org.cloudsimplus.core.Lifetimed;
34+
import org.cloudsimplus.datacenters.Datacenter;
35+
import org.cloudsimplus.datacenters.DatacenterSimple;
36+
import org.cloudsimplus.hosts.Host;
37+
import org.cloudsimplus.hosts.HostSimple;
38+
import org.cloudsimplus.resources.Pe;
39+
import org.cloudsimplus.resources.PeSimple;
40+
import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared;
41+
import org.cloudsimplus.util.TimeUtil;
42+
import org.cloudsimplus.utilizationmodels.UtilizationModelFull;
43+
import org.cloudsimplus.utilizationmodels.UtilizationModelStochastic;
44+
import org.cloudsimplus.vms.Vm;
45+
import org.cloudsimplus.vms.VmSimple;
46+
47+
import java.time.LocalTime;
48+
import java.util.ArrayList;
49+
import java.util.Comparator;
50+
import java.util.List;
51+
import java.util.stream.IntStream;
52+
53+
/**
54+
* An example showing how to use the new {@link Lifetimed#setLifeTime(double)} to
55+
* define the maximum time {@link Cloudlet} or {@link Vm} entity is allowed to execute.
56+
* After this time is reached, the entity is finished as soon as possible.
57+
*
58+
* <p>
59+
* If the VM has a lifeTime set, it's Cloudlets follow the same lifetime.
60+
* If both Cloudlet and Vm have a lifetime, the shorter defines the maximum
61+
* amount of time the Cloudlet will execute.
62+
* </p>
63+
*
64+
* <p>The example creates all Cloudlets and some VMs with a given lifetime.
65+
* Since VM lifetime is shorter than their Cloudlets' lifetime,
66+
* such Cloudlets finish sooner than their own lifetime.</p>
67+
*
68+
* @author Manoel Campos da Silva Filho
69+
* @since CloudSim Plus 8.2.0
70+
* @see CloudletLifeTimeExample
71+
*/
72+
public class CloudletAndVmLifeTimeExample {
73+
private static final int HOSTS = 3;
74+
private static final int HOST_PES = 10;
75+
76+
private static final int VMS = 4;
77+
private static final int VM_PES = 4;
78+
private static final int VM_MIPS = 1000;
79+
80+
private static final int CLOUDLETS = 4;
81+
private static final int CLOUDLET_PES = 2;
82+
private static final int CLOUDLET_LENGTH = 10_000;
83+
84+
/**
85+
* If the scheduling interval is not multiple of the VM/Cloudlet lifetime,
86+
* Cloudlets may execute more than you desire.
87+
* @see Datacenter#getSchedulingInterval()
88+
*/
89+
private static final int SCHEDULING_INTERVAL = 3;
90+
91+
/**
92+
* Maximum time (in seconds) Cloudlets are allowed to execute.
93+
* Set -1 to disable lifeTime and execute the Cloudlet entirely.
94+
*/
95+
private static final double CLOUDLET_LIFE_TIME = 5;
96+
97+
/**
98+
* Maximum time (in seconds) some VMs are allowed to execute.
99+
* @see Lifetimed#setLifeTime(double)
100+
*/
101+
private static final double VM_LIFE_TIME = 3;
102+
103+
private final CloudSimPlus simulation;
104+
private final DatacenterBroker broker0;
105+
private List<Vm> vmList;
106+
private List<Cloudlet> cloudletList;
107+
private Datacenter datacenter0;
108+
109+
public static void main(String[] args) {
110+
new CloudletAndVmLifeTimeExample();
111+
}
112+
113+
private CloudletAndVmLifeTimeExample() {
114+
/*Enables just some level of log messages.
115+
Make sure to import org.cloudsimplus.util.Log;*/
116+
//Log.setLevel(ch.qos.logback.classic.Level.WARN);
117+
118+
final double startSecs = TimeUtil.currentTimeSecs();
119+
System.out.printf("Simulation started at %s%n%n", LocalTime.now());
120+
simulation = new CloudSimPlus();
121+
datacenter0 = createDatacenter();
122+
123+
//Creates a broker that is a software acting on behalf of a cloud customer to manage his/her VMs and Cloudlets
124+
broker0 = new DatacenterBrokerSimple(simulation);
125+
126+
vmList = createVms();
127+
setVmsLifeTime();
128+
129+
cloudletList = createCloudlets();
130+
broker0.submitVmList(vmList);
131+
broker0.submitCloudletList(cloudletList);
132+
133+
simulation.start();
134+
135+
final var cloudletFinishedList = broker0.getCloudletFinishedList();
136+
cloudletFinishedList.sort(Comparator.comparingLong(c -> c.getVm().getId()));
137+
new CloudletsTableBuilder(cloudletFinishedList)
138+
.addColumn(new MarkdownTableColumn("Cloudlet", "LifeTime"), this::getLifeTimeStr)
139+
.addColumn(new MarkdownTableColumn("Vm ", "LifeTime"), c -> getLifeTimeStr(c.getVm()))
140+
.build();
141+
System.out.printf("Simulation finished at %s. Execution time: %.2f seconds%n", LocalTime.now(), TimeUtil.elapsedSeconds(startSecs));
142+
}
143+
144+
/**
145+
* Gets the lifetime as a String.
146+
* If the lifetime is {@link Double#MAX_VALUE} (the default value),
147+
* returns an empty string to indicate the attribute was not set.
148+
*
149+
* @param entity a Cloudlet of VM entity
150+
* @return a String lifetime
151+
*/
152+
private String getLifeTimeStr(final Lifetimed entity) {
153+
return entity.getLifeTime() == Double.MAX_VALUE ? "" : "%.2f".formatted(entity.getLifeTime());
154+
}
155+
156+
/**
157+
* Sets a lifetime for half of the VMs.
158+
*/
159+
private void setVmsLifeTime() {
160+
vmList.stream()
161+
.filter(vm -> vm.getId() < VMS/2)
162+
.forEach(vm -> vm.setLifeTime(VM_LIFE_TIME));
163+
}
164+
165+
private Datacenter createDatacenter() {
166+
final var hostList = new ArrayList<Host>(HOSTS);
167+
for(int i = 0; i < HOSTS; i++) {
168+
final var host = createHost();
169+
hostList.add(host);
170+
}
171+
172+
final var datacenter = new DatacenterSimple(simulation, hostList);
173+
datacenter.setSchedulingInterval(SCHEDULING_INTERVAL);
174+
return datacenter;
175+
}
176+
177+
private Host createHost() {
178+
final var peList = new ArrayList<Pe>(HOST_PES);
179+
//List of Host's CPUs (Processing Elements, PEs)
180+
IntStream.range(0, HOST_PES).forEach(i -> peList.add(new PeSimple(1000)));
181+
182+
final long ram = 2048; //in Megabytes
183+
final long bw = 10000; //in Megabits/s
184+
final long storage = 1000000; //in Megabytes
185+
final var host = new HostSimple(ram, bw, storage, peList);
186+
host.setVmScheduler(new VmSchedulerTimeShared());
187+
return host;
188+
}
189+
190+
private List<Vm> createVms() {
191+
final var vmList = new ArrayList<Vm>(VMS);
192+
for (int i = 0; i < VMS; i++) {
193+
final var vm = new VmSimple(i, VM_MIPS, VM_PES);
194+
vmList.add(vm);
195+
}
196+
197+
return vmList;
198+
}
199+
200+
private List<Cloudlet> createCloudlets() {
201+
final var cloudletList = new ArrayList<Cloudlet>(CLOUDLETS);
202+
for (int i = 0; i < CLOUDLETS; i++) {
203+
final var cloudlet = new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_PES);
204+
cloudlet
205+
.setFileSize(1024)
206+
.setOutputSize(1024)
207+
.setUtilizationModelCpu(new UtilizationModelFull())
208+
.setUtilizationModelBw(new UtilizationModelStochastic())
209+
.setUtilizationModelRam(new UtilizationModelStochastic())
210+
.setLifeTime(CLOUDLET_LIFE_TIME);
211+
cloudletList.add(cloudlet);
212+
}
213+
214+
return cloudletList;
215+
}
216+
}

src/main/java/org/cloudsimplus/examples/CloudletCancellationExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private CloudletCancellationExample() {
9797
simulation = new CloudSimPlus();
9898
datacenter0 = createDatacenter();
9999

100-
//Creates a broker that is a software acting on behalf a cloud customer to manage his/her VMs and Cloudlets
100+
//Creates a broker that is a software acting on behalf of a cloud customer to manage his/her VMs and Cloudlets
101101
broker0 = new DatacenterBrokerSimple(simulation);
102102

103103
vmList = createVms();

src/main/java/org/cloudsimplus/examples/CloudletLifeTimeExample.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.cloudsimplus.cloudlets.Cloudlet;
3030
import org.cloudsimplus.cloudlets.CloudletSimple;
3131
import org.cloudsimplus.core.CloudSimPlus;
32+
import org.cloudsimplus.core.Lifetimed;
3233
import org.cloudsimplus.datacenters.Datacenter;
3334
import org.cloudsimplus.datacenters.DatacenterSimple;
3435
import org.cloudsimplus.hosts.Host;
@@ -55,6 +56,7 @@
5556
* @author Sun Lingyu
5657
* @author Manoel Campos da Silva Filho
5758
* @since CloudSim Plus 7.2.1
59+
* @see CloudletAndVmLifeTimeExample
5860
*/
5961
public class CloudletLifeTimeExample {
6062
private static final int HOSTS = 3;
@@ -68,12 +70,16 @@ public class CloudletLifeTimeExample {
6870
private static final int CLOUDLET_PES = 2;
6971
private static final int CLOUDLET_LENGTH = 10_000;
7072

71-
/** @see Datacenter#getSchedulingInterval() */
73+
/**
74+
* If the scheduling interval is not multiple of the VM/Cloudlet lifetime,
75+
* Cloudlets may execute more than you desire.
76+
* @see Datacenter#getSchedulingInterval()
77+
*/
7278
private static final int SCHEDULING_INTERVAL = 2;
7379

7480
/**
7581
* Maximum time (in seconds) Cloudlets are allowed to execute.
76-
* Set -1 to disable lifeTime and execute the Cloudlet entirely.
82+
* @see Lifetimed#setLifeTime(double)
7783
*/
7884
private static final double CLOUDLET_LIFE_TIME = 5;
7985

@@ -97,7 +103,7 @@ private CloudletLifeTimeExample() {
97103
simulation = new CloudSimPlus();
98104
datacenter0 = createDatacenter();
99105

100-
//Creates a broker that is a software acting on behalf a cloud customer to manage his/her VMs and Cloudlets
106+
//Creates a broker that is a software acting on behalf of a cloud customer to manage his/her VMs and Cloudlets
101107
broker0 = new DatacenterBrokerSimple(simulation);
102108

103109
vmList = createVms();

src/main/java/org/cloudsimplus/examples/CloudletsTableBuilderFormattingExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private CloudletsTableBuilderFormattingExample() {
9292
simulation = new CloudSimPlus();
9393
datacenter0 = createDatacenter();
9494

95-
//Creates a broker that is a software acting on behalf a cloud customer to manage his/her VMs and Cloudlets
95+
//Creates a broker that is a software acting on behalf of a cloud customer to manage his/her VMs and Cloudlets
9696
broker0 = new DatacenterBrokerSimple(simulation);
9797

9898
vmList = createVms();

src/main/java/org/cloudsimplus/examples/LargeScaleExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private LargeScaleExample() {
112112
simulation = new CloudSimPlus();
113113
datacenter0 = createDatacenter();
114114

115-
//Creates a broker that is a software acting on behalf a cloud customer to manage his/her VMs and Cloudlets
115+
//Creates a broker that is a software acting on behalf of a cloud customer to manage his/her VMs and Cloudlets
116116
broker0 = new DatacenterBrokerSimple(simulation);
117117

118118
vmList = createVms();

src/main/java/org/cloudsimplus/examples/LoggingExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private LoggingExample() {
9797
simulation = new CloudSimPlus();
9898
datacenter0 = createDatacenter();
9999

100-
//Creates a broker that is a software acting on behalf a cloud customer to manage his/her VMs and Cloudlets
100+
//Creates a broker that is a software acting on behalf of a cloud customer to manage his/her VMs and Cloudlets
101101
broker0 = new DatacenterBrokerSimple(simulation);
102102

103103
vmList = createVms();

src/main/java/org/cloudsimplus/examples/RandomVmAllocationPolicyExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private RandomVmAllocationPolicyExample() {
105105
random = new UniformDistr();
106106
datacenter0 = createDatacenter();
107107

108-
//Creates a broker that is a software acting on behalf a cloud customer to manage his/her VMs and Cloudlets
108+
//Creates a broker that is a software acting on behalf of a cloud customer to manage his/her VMs and Cloudlets
109109
broker0 = new DatacenterBrokerSimple(simulation);
110110

111111
vmList = createVms();

src/main/java/org/cloudsimplus/examples/StorageAreaNetworkExample1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private StorageAreaNetworkExample1() {
103103
simulation = new CloudSimPlus();
104104
datacenter0 = createDatacenter();
105105

106-
//Creates a broker that is a software acting on behalf a cloud customer to manage his/her VMs and Cloudlets
106+
//Creates a broker that is a software acting on behalf of a cloud customer to manage his/her VMs and Cloudlets
107107
broker0 = new DatacenterBrokerSimple(simulation);
108108

109109
vmList = createVms();

src/main/java/org/cloudsimplus/examples/VmAllocationPolicyRoundRobinExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private VmAllocationPolicyRoundRobinExample() {
8686
simulation = new CloudSimPlus();
8787
datacenter0 = createDatacenter();
8888

89-
//Creates a broker that is a software acting on behalf a cloud customer to manage his/her VMs and Cloudlets
89+
//Creates a broker that is a software acting on behalf of a cloud customer to manage his/her VMs and Cloudlets
9090
broker0 = new DatacenterBrokerSimple(simulation);
9191

9292
vmList = createVms();

0 commit comments

Comments
 (0)