Research Breakthrough Possible @S-Logix pro@slogix.in

Office Address

Social List

How to Create Multi-Datacenter with Multiple Broker?

Multi-Datacenter with Multiple Broker

Condition for Multi-Datacenter with Multiple Broker

  • Description:
    To create a multi-datacenter setup with multiple brokers in cloud computing using CloudSim or WorkflowSim, begin by initializing the CloudSim environment. Create multiple Datacenter objects, each configured with unique properties using DatacenterCharacteristics. Add Host objects with defined resources like PEs, RAM, bandwidth, and storage, and allocate VM objects to these hosts. Create multiple DatacenterBroker objects to manage task scheduling and distribution, with each broker handling its own VMs and cloudlets. Distribute tasks among the brokers and run the simulation to observe task distribution and load management across data centers, providing insights into performance and resource efficiency.
Sample Code
  • package multidatacenter;
    import java.text.DecimalFormat;
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.HashMap;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.Map;
    import org.cloudbus.cloudsim.Cloudlet;
    import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
    import org.cloudbus.cloudsim.Datacenter;
    import org.cloudbus.cloudsim.DatacenterBroker;
    import org.cloudbus.cloudsim.DatacenterCharacteristics;
    import org.cloudbus.cloudsim.Host;
    import org.cloudbus.cloudsim.Log;
    import org.cloudbus.cloudsim.Pe;
    import org.cloudbus.cloudsim.Storage;
    import org.cloudbus.cloudsim.UtilizationModel;
    import org.cloudbus.cloudsim.UtilizationModelFull;
    import org.cloudbus.cloudsim.Vm;
    import org.cloudbus.cloudsim.VmAllocationPolicySimple;
    import org.cloudbus.cloudsim.VmSchedulerTimeShared;
    import org.cloudbus.cloudsim.core.CloudSim;
    import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
    import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
    import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
    public class MultiDatacenterSample extends javax.swing.JFrame {
    private static List vmlist1;
    DatacenterBroker broker;
    int brokerId[] = new int[100];
    Map< DatacenterBroker, List> Cloudletmap = new HashMap();
    List brokerlist = new ArrayList(); //we are not adding SAN
    devices by now
    Map> VMmap = new HashMap();
    static Map> datacentermap = new HashMap();
    List brokername = new ArrayList();
    List list1 = new ArrayList();
    List listcloudlet = new ArrayList();
    static List datacenterlist = new ArrayList();
    /**
    * Creates new form MultiDatacenterSample
    */
    public MultiDatacenterSample() {
    initComponents();
    }
    private static Datacenter createDatacenter(String name,int num) {
    // Here are the steps needed to create a PowerDatacenter:
    // 1. We need to create a list to store one or more
    // Machines
    // 2. A Machine contains one or more PEs or CPUs/Cores. Therefore, should
    // create a list to store these PEs before creating
    // a Machine.
    List peList1 = new ArrayList();
    List hostList = new ArrayList();
    int hostId;
    int mips = Configuration.Hostmips1;
    int ram = Configuration.Hostram1;
    long storage = Configuration.Hoststorage1; //host storage
    int bw = Configuration.Hostbandwidth1;
    // 3. Create PEs and add these into the list.
    //for a quad-core machine, a list of 4 PEs is required:
    for (int i = 1; i < 9; i++) {
    peList1.add(new Pe(i, new PeProvisionerSimple(mips)));
    }
    //4. Create Hosts with its id and list of PEs and add them to the
    list of machines
    //in this example, the VMAllocatonPolicy in use is SpaceShared. It means
    that only one VM
    //is allowed to run on each Pe. As each Host has only one Pe, only one VM
    can run on each Host.
    for (int i = 0; i hostList.add(
    new Host(
    i,
    new RamProvisionerSimple(ram),
    new BwProvisionerSimple(bw),
    storage,
    peList1,
    new VmSchedulerTimeShared(peList1)
    )
    );
    // This is our first machine
    }
    // 5. Create a DatacenterCharacteristics object that stores the
    // properties of a data center: architecture, OS, list of
    // Machines, allocation policy: time- or space-shared, time zone
    // and its price (G$/Pe time unit).
    String arch = "x86"; // system architecture
    String os = "Linux"; // operating system
    String vmm = "Xen";
    double time_zone = 10.0; // time zone this resource located
    double cost = 3.0; // the cost of using processing in this
    resource
    double costPerMem = 0.05; // the cost of using memory in this
    resource
    double costPerStorage = 0.1; // the cost of using storage in this
    resource
    double costPerBw = 0.1; // the cost of using bw in this
    resource
    LinkedList storageList = new LinkedList(); //we are not
    adding SAN devices by now
    DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
    arch, os, vmm, hostList, time_zone, cost, costPerMem,
    costPerStorage, costPerBw);
    // 6. Finally, we need to create a PowerDatacenter object.
    Datacenter datacenter = null;
    try {
    datacenter = new Datacenter(name, characteristics, new
    VmAllocationPolicySimple(hostList), storageList, 0);
    } catch (Exception e) {
    }
    return datacenter;
    }
    private static LinkedList createVM(int userId, int vms, int idShift) {
    //Creates a container to store VMs. This list is passed to the broker later
    LinkedList list = new LinkedList();
    //VM Parameters
    long size = Configuration.storagesize1; //image size (MB)
    int ram = Configuration.VMram1; //vm memory (MB)
    double mips = Configuration.Vmmips1;
    long bw = Configuration.VMBandwidth1;
    int pesNumber = Configuration.VMpes1; //number of cpus
    String vmm = "Xen"; //VMM name
    //create VMs
    Vm[] vm = new Vm[vms];
    for (int i = 0; i < vms; i++) {
    vm[i] = new Vm(idShift + i, userId, mips, pesNumber, ram, bw, size,
    vmm, new CloudletSchedulerTimeShared());
    list.add(vm[i]);
    }
    // list.remove(n);
    return list;
    }
    private static LinkedList createCloudlet(int userId, int cloudlets,
    int idShift) {
    // Creates a container to store Cloudlets
    LinkedList list = new LinkedList();
    //cloudlet parameters
    long length = Configuration.Cloudletlength1;
    long fileSize = Configuration.Cloudletfilesize1;
    long outputSize = Configuration.Cloudletoutputsize1;
    int pesNumber = Configuration.NoOfpes1;
    UtilizationModel utilizationModel = new UtilizationModelFull();
    Cloudlet[] cloudlet = new Cloudlet[cloudlets];
    for (int i = 0; i < cloudlets; i++) {
    cloudlet[i] = new Cloudlet(idShift + i, length, pesNumber, fileSize,
    outputSize, utilizationModel, utilizationModel, utilizationModel);
    // setting the owner of these Cloudlets
    cloudlet[i].setUserId(userId);
    list.add(cloudlet[i]);
    }
    return list;
    // return Cloudletmap.values();
    }
    //We strongly encourage users to develop their own broker policies, to submit
    vms and cloudlets according
    //to the specific rules of the simulated scenario
    private static DatacenterBroker createBroker(String name) {
    DatacenterBroker broker = null;
    try {
    broker = new DatacenterBroker(name);
    } catch (Exception e) {
    return null;
    }
    return broker;
    }
    /** * Prints the Cloudlet objects
    *
    * @param list list of Cloudlets
    */
    private static void printCloudletList(List list) {
    int size = list.size();
    Cloudlet cloudlet;
    String indent = " ";
    Log.printLine();
    Log.printLine(" ========== OUTPUT ========== ");
    Log.printLine("Cloudlet ID" + indent + "STATUS" + indent
    + "Data center ID" + indent + "VM ID" + indent + "Time" + indent +
    "Start Time" + indent + "Finish Time");
    DecimalFormat dft = new DecimalFormat("###.##");
    for (int i = 0; i < size; i++) {
    cloudlet = list.get(i);
    Log.print(indent + cloudlet.getCloudletId() + indent + indent);
    if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
    Log.print("SUCCESS");
    Log.printLine(indent + indent + cloudlet.getResourceId() + indent +
    indent + indent + cloudlet.getVmId()
    + indent + indent + dft.format(cloudlet.getActualCPUTime())
    + indent + indent +
    dft.format(cloudlet.getExecStartTime())
    + indent + indent + dft.format(cloudlet.getFinishTime()));
    }
    }
    }
    /**
    * This method is called from within the constructor to initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is always
    * regenerated by the Form Editor.
    */
    @SuppressWarnings("unchecked")
    // //GEN-
    BEGIN:initComponents
    private void initComponents() {
    jPanel1 = new javax.swing.JPanel();
    btnConfiguration = new javax.swing.JButton();
    btnDatacenterCreation = new javax.swing.JButton();
    btnSimulation = new javax.swing.JButton();
    btnHostCreation = new javax.swing.JButton();
    btnBrokerCreation = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new
    java.awt.Color(0, 0, 0)));
    btnConfiguration.setText("Configuration");
    btnConfiguration.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnConfigurationActionPerformed(evt);
    }
    });
    btnDatacenterCreation.setText("Datacenter Creation");
    btnDatacenterCreation.addActionListener(new java.awt.event.ActionListener()
    {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnDatacenterCreationActionPerformed(evt);
    }
    });
    btnSimulation.setText("Simulation");
    btnSimulation.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnSimulationActionPerformed(evt);
    }
    });
    btnHostCreation.setText("HostCreation");
    btnHostCreation.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnHostCreationActionPerformed(evt);
    }
    });
    btnBrokerCreation.setText("BrokerCreation");
    btnBrokerCreation.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnBrokerCreationActionPerformed(evt);
    }
    });
    javax.swing.GroupLayout jPanel1Layout = new
    javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAIL
    ING)
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(btnBrokerCreation,
    javax.swing.GroupLayout.PREFERRED_SIZE, 174,
    javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
    jPanel1Layout.createSequentialGroup()
    .addGap(80, 80, 80)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAIL
    ING)
    .addComponent(btnDatacenterCreation,
    javax.swing.GroupLayout.PREFERRED_SIZE, 174,
    javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(btnSimulation,
    javax.swing.GroupLayout.PREFERRED_SIZE, 175,
    javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(btnConfiguration,
    javax.swing.GroupLayout.PREFERRED_SIZE, 174,
    javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(btnHostCreation,
    javax.swing.GroupLayout.PREFERRED_SIZE, 174,
    javax.swing.GroupLayout.PREFERRED_SIZE))))
    .addContainerGap(61, Short.MAX_VALUE))
    );
    jPanel1Layout.setVerticalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(btnConfiguration)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(btnBrokerCreation)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14,
    Short.MAX_VALUE)
    .addComponent(btnHostCreation)
    .addGap(18, 18, 18)
    .addComponent(btnDatacenterCreation)
    .addGap(18, 18, 18)
    .addComponent(btnSimulation)
    .addGap(20, 20, 20))
    );
    javax.swing.GroupLayout layout = new
    javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(37, 37, 37)
    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(43, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
    layout.createSequentialGroup()
    .addContainerGap(47, Short.MAX_VALUE)
    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addGap(35, 35, 35))
    );
    pack(); }//
    //GEN-END:initComponents
    private void btnConfigurationActionPerformed(java.awt.event.ActionEvent evt)
    {//GEN-FIRST:event_btnConfigurationActionPerformed
    Configuration configuration = new Configuration();
    configuration.setVisible(true);
    }//GEN-LAST:event_btnConfigurationActionPerformed
    private void btnHostCreationActionPerformed(java.awt.event.ActionEvent evt)
    {//GEN-FIRST:event_btnHostCreationActionPerformed
    // TODO add your handling code here:
    HostCreation hostcreation = new HostCreation();
    hostcreation.setVisible(true);
    }//GEN-LAST:event_btnHostCreationActionPerformed
    private void btnDatacenterCreationActionPerformed(java.awt.event.ActionEvent
    evt) {//GEN-FIRST:event_btnDatacenterCreationActionPerformed
    try { // First step: Initialize the CloudSim package. It should be called
    // before creating any entities.
    int num_user = Configuration.NoOfDatacenter; // number of grid users
    Calendar calendar = Calendar.getInstance();
    boolean trace_flag = false; // mean trace events
    int brokerId[] = new int[20];
    // Initialize the CloudSim library CloudSim.init(num_user, calendar, trace_flag);
    // Second step: Create Datacenters
    int k=0;
    for(MultiDatacenter multiDatacenter:HostCreation.multiDatacenter)
    {
    Datacenter datacenter =
    createDatacenter("datacenter-"+k,multiDatacenter.NoOfHost);
    datacenterlist.add(datacenter);
    System.out.println(" ");
    System.out.println("******datacenter ID******:" +
    datacenter.getId());
    System.out.println("******datacenter name******:" +
    datacenter.getName());
    k++;
    }
    for (BrokerVmCloudletMap brokerVmCloudletMap :
    Brokercreation.brokerVmmap) {
    System.out.println("**********************");
    System.out.println("broker id" + brokerVmCloudletMap.brid);
    System.out.println("no of vm" + brokerVmCloudletMap.numOfVm);
    System.out.println("broker cloudlet" +
    brokerVmCloudletMap.numofCloudlet);
    }
    System.out.println("the vmmap list size:" +
    Brokercreation.brokerVmmap.size());
    System.out.println(" ");
    //Third step: Create Broker
    // int i=0;
    // for (BrokerVmCloudletMap brokerVmCloudletMap :
    BrokerCreation.brokerVmmap)
    for (int i = 1; i <= Brokercreation.brokerVmmap.size(); i++) {
    broker = createBroker("Broker-" + i);
    brokerlist.add(broker);
    System.out.println("broker name is:" + broker.getName());
    brokerId[i] = broker.getId();
    System.out.println(" ");
    System.out.println("id:" + brokerId[i]);
    }
    for (BrokerVmCloudletMap brokerVmCloudletMap :
    Brokercreation.brokerVmmap) {
    System.out.println("**********************");
    System.out.println("****broker id*****:" +
    brokerVmCloudletMap.brid);
    System.out.println("no of vm:" + brokerVmCloudletMap.numOfVm);
    System.out.println("broker cloudlet:" +
    brokerVmCloudletMap.numofCloudlet);
    System.out.println(" ");
    System.out.println("**********************");
    }
    int v = 0;
    int i = 0;
    //Fourth step: Create VMs and Cloudlets and send them to broker
    for (BrokerVmCloudletMap brokerVmCloudletMap :
    (Brokercreation.brokerVmmap)) {
    List vmlist = new ArrayList();
    vmlist = createVM(brokerlist.get(i).getId(),
    brokerVmCloudletMap.numOfVm, v); //creating 40 vms
    VMmap.put(brokerlist.get(i), vmlist);
    brokerlist.get(i).submitVmList(vmlist);
    v = (v + (brokerVmCloudletMap.numOfVm));
    i++;
    }
    int c = 0;
    int j = 0;
    System.out.println("size is####:" + Brokercreation.brokerVmmap.size());
    System.out.println("Size of the Broker:" + Configuration.NoOfBroker1);
    System.out.println("size of broker list:" + brokerlist.size());
    for (BrokerVmCloudletMap brokerVmCloudletMap :
    Brokercreation.brokerVmmap) {
    List cloudletList = new ArrayList();
    cloudletList = createCloudlet(brokerlist.get(j).getId(),
    brokerVmCloudletMap.numofCloudlet, c); // creating 40 cloudlets
    Cloudletmap.put(brokerlist.get(j), cloudletList);
    brokerlist.get(j).submitCloudletList(cloudletList);
    c = (c + brokerVmCloudletMap.numofCloudlet);
    j++;
    }
    } catch (Exception e) {
    Log.printLine("The simulation has been terminated due to an unexpected
    error");
    }
    }//GEN-LAST:event_btnDatacenterCreationActionPerformed
    private void btnBrokerCreationActionPerformed(java.awt.event.ActionEvent evt)
    {//GEN-FIRST:event_btnBrokerCreationActionPerformed
    // TODO add your handling code here:
    Brokercreation brokercreation = new Brokercreation();
    brokercreation.setVisible(true);
    }//GEN-LAST:event_btnBrokerCreationActionPerformed
    private void btnSimulationActionPerformed(java.awt.event.ActionEvent evt)
    {//GEN-FIRST:event_btnSimulationActionPerformed
    CloudSim.startSimulation();
    int i = 0;
    for (BrokerVmCloudletMap brokerVmCloudletMap : Brokercreation.brokerVmmap)
    {
    List newList = brokerlist.get(i).getCloudletReceivedList();
    printCloudletList(newList);
    i++;
    }
    CloudSim.stopSimulation();
    }//GEN-LAST:event_btnSimulationActionPerformed
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(() -> {
    new MultiDatacenterSample().setVisible(true);
    });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBrokerCreation;
    private javax.swing.JButton btnConfiguration;
    private javax.swing.JButton btnDatacenterCreation;
    private javax.swing.JButton btnHostCreation;
    private javax.swing.JButton btnSimulation;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
    }
Step 1
  • To set the environment for multiple datacenter creation.
  • multi-datacenter1
Step 2
  • To put the Host, Virtual machine, cloudlet datacenter and broker configurations.
  • multi-datacenter2
Step 3
  • To create the broker for multiple datacenters.
  • multi-datacenter3
Step 4
  • To set the broker number, number of virtual machines and number of cloudlets.
  • multi-datacenter4
Step 5
  • To create the host for multiple datacenters.
  • multi-datacenter5
Step 6
  • To set the values for Datacenter number, number of hosts.
  • multi-datacenter6
Step 7
  • To create a datacenter with multiple broker.
  • multi-datacenter7
Step 8
  • To simulate the result of multiple datacenters with multiple broker.
  • multi-datacenter8
Step 9
  • To get the results for Host, virtual machines and broker.
  • multi-datacenter9
Step 10
  • To get the cloudlet results of creating multiple datacenters with multiple brokers.
  • multi-datacenter10