Last active
January 5, 2018 06:25
-
-
Save alessandroleite/4072321 to your computer and use it in GitHub Desktop.
An example of DatacenterBroker that allocates the VMs following the Round-Robin algorithm.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.cloudbus.cloudsim.examples; | |
import java.util.List; | |
import org.cloudbus.cloudsim.DatacenterBroker; | |
import org.cloudbus.cloudsim.DatacenterCharacteristics; | |
import org.cloudbus.cloudsim.Log; | |
import org.cloudbus.cloudsim.Vm; | |
import org.cloudbus.cloudsim.core.CloudSim; | |
import org.cloudbus.cloudsim.core.CloudSimTags; | |
import org.cloudbus.cloudsim.core.SimEvent; | |
import java.util.List; | |
import org.cloudbus.cloudsim.DatacenterBroker; | |
import org.cloudbus.cloudsim.DatacenterCharacteristics; | |
import org.cloudbus.cloudsim.Log; | |
import org.cloudbus.cloudsim.Vm; | |
import org.cloudbus.cloudsim.core.CloudSim; | |
import org.cloudbus.cloudsim.core.CloudSimTags; | |
import org.cloudbus.cloudsim.core.SimEvent; | |
/** | |
* This broker allocates VMs to data centers following the | |
* <a href="http://en.wikipedia.org/wiki/Round-robin_scheduling">Round-robin</a> algorithm. | |
* @author alessandro | |
*/ | |
public class RoundRobinDatacenterBroker extends DatacenterBroker | |
{ | |
/** | |
* Creates an instance of this class associating to it a given name. | |
* @param name The name to be associated to this broker. It might not be <code>null</code> or empty. | |
* @throws Exception If the name contains spaces. | |
*/ | |
public RoundRobinDatacenterBroker(String name) throws Exception | |
{ | |
super(name); | |
} | |
@Override | |
protected void processResourceCharacteristics(SimEvent ev) | |
{ | |
DatacenterCharacteristics characteristics = (DatacenterCharacteristics) ev.getData(); | |
getDatacenterCharacteristicsList().put(characteristics.getId(), characteristics); | |
if (getDatacenterCharacteristicsList().size() == getDatacenterIdsList().size()) | |
{ | |
distributeRequestsForNewVmsAcrossDatacentersUsingTheRoundRobinApproach(); | |
} | |
} | |
/** | |
* Distributes the VMs across the data centers using the round-robin approach. A VM is allocated to a data center only if there isn't | |
* a VM in the data center with the same id. | |
*/ | |
protected void distributeRequestsForNewVmsAcrossDatacentersUsingTheRoundRobinApproach() | |
{ | |
int numberOfVmsAllocated = 0; | |
int i = 0; | |
final List<Integer> availableDatacenters = getDatacenterIdsList(); | |
for (Vm vm : getVmList()) | |
{ | |
int datacenterId = availableDatacenters.get(i++ % availableDatacenters.size()); | |
String datacenterName = CloudSim.getEntityName(datacenterId); | |
if (!getVmsToDatacentersMap().containsKey(vm.getId())) | |
{ | |
Log.printLine(CloudSim.clock() + ": " + getName() + ": Trying to Create VM #" + vm.getId() + " in " + datacenterName); | |
sendNow(datacenterId, CloudSimTags.VM_CREATE_ACK, vm); | |
numberOfVmsAllocated++; | |
} | |
} | |
setVmsRequested(numberOfVmsAllocated); | |
setVmsAcks(0); | |
} | |
} |
where is the main function of this code?
is this the example of Intercloud?
hello,
i am not embedding my encryption algorithm in cloudsim example than where i embed this implementation code. please help and suggest me.
Dear alessandro,
I want to change this code to distributes the VMs across the data centers according to the available CPU capacity and energy on data centers
what I should do to achieve this?
Thanks in advance!
Dear alessandro,
The code ended up having an error at Line no: 64(getVmList()) "Type mismatch: cannot convert from element type Object to Vm". How can i be able to resolve it.
Thanking you, waiting for your valuable reply.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
i am pretty new to cloudsim and want to implement a RoundRobinDatacenterBroker in it ,but when i use the class introduced above an error occur in line 45 for characteristics.getId().how can it be solve?