Skip to content

Commit

Permalink
feat: Select a VM in a fixed position for a given Cloudlet in Network…
Browse files Browse the repository at this point in the history
…VmsExampleWorkflowApp

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
  • Loading branch information
manoelcampos committed Nov 7, 2024
1 parent ac160e2 commit 50177de
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.cloudsimplus.cloudlets.network.NetworkCloudlet;
import org.cloudsimplus.core.CloudSimPlus;
import org.cloudsimplus.datacenters.network.NetworkDatacenter;
import org.cloudsimplus.distributions.UniformDistr;
import org.cloudsimplus.hosts.network.NetworkHost;
import org.cloudsimplus.network.switches.AggregateSwitch;
import org.cloudsimplus.network.switches.EdgeSwitch;
Expand Down Expand Up @@ -261,33 +260,17 @@ private List<NetworkHost> getDatacenterHostList() {
return datacenter.getHostList();
}

/**
* Randomly select a given number of VMs from the list of created VMs,
* to be used by the NetworkCloudlets of the given application.
*
* @param vmsToSelect number of VMs to selected from the existing list of VMs.
* @return The list of randomly selected VMs
*/
protected List<NetworkVm> randomlySelectVmsForApp(int vmsToSelect) {
final var netVmList = new ArrayList<NetworkVm>();
final int existingVms = this.vmList.size();
final var rand = new UniformDistr(0, existingVms, 5);
for (int i = 0; i < vmsToSelect; i++) {
final int vmIndex = (int)rand.sample() % vmList.size();
final NetworkVm vm = vmList.get(vmIndex);
netVmList.add(vm);
}

return netVmList;
}

/**
* @return List of VMs of all Brokers.
*/
public List<NetworkVm> getVmList() {
return vmList;
}

public NetworkVm getVm(final int i) {
return vmList.get(i);
}

public NetworkDatacenter getDatacenter() {
return datacenter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ private NetworkVmsExampleWorkflowApp(){
@Override
public List<NetworkCloudlet> createNetworkCloudlets(final DatacenterBroker broker) {
final var networkCloudlets = new NetworkCloudlet[3];
final List<NetworkVm> selectedVms = randomlySelectVmsForApp(networkCloudlets.length);

for(int i = 0; i < networkCloudlets.length; i++){
networkCloudlets[i] = createNetworkCloudlet(i, selectedVms.get(i), broker);
networkCloudlets[i] = createNetworkCloudlet(i, getVm(i));
System.out.printf(
"Created NetworkCloudlet %d for %s (broker %d)%n",
networkCloudlets[i].getId(), broker.getName(), broker.getId());
Expand Down

0 comments on commit 50177de

Please sign in to comment.