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

Office Address

Social List

How to Create a Cloud Environment ?

How to Create a Cloud Environment

Condition for Cloud Environment using CloudSim in Cloud Computing

  • Description:
    To create a cloud environment using CloudSim in cloud computing, you need to follow a few steps to model cloud resources such as Data Centers, Hosts (VMs), and Cloudlets (tasks). CloudSim is a simulation framework that allows modeling, simulating, and evaluating cloud computing systems.
Process
  • Download and Set Up CloudSim:
    • TDownload CloudSim from the official CloudSim website or GitHub.
    • Ensure that you have the necessary Java Development Kit (JDK) installed and set up correctly on your system.
  • Cloud Environment Components:
    • Datacenter: Represents a cloud data center.
    • Host: Represents physical servers inside a data center.
    • VirtualMachine (VM): Virtualized resources running on hosts.
    • Cloudlet: Represents the tasks to be executed by VMs.
  • Create a Java Project:
    • Set up a new Java project in your IDE (e.g., Eclipse, IntelliJ).
    • Add the CloudSim library .jar files to the classpath.
Explanations
  • Datacenter Creation:
    • The createDatacenter method initializes the data center, creating multiple hosts and adding processing elements (PEs) to each host.
  • Broker Creation:
    • The DatacenterBroker represents the cloud broker that manages VM allocation and cloudlet scheduling.
  • Virtual Machine and Cloudlet Creation:
    • The createVMs creates virtual machines with specified configurations.
    • createCloudlets creates cloudlets (tasks) for execution.
  • Simulation Execution:
    • The simulation is started with CloudSim.startSimulation(), and after the simulation, the results of each cloudlet are printed.
Sample Code
  • import org.cloudbus.cloudsim.*;
    import org.cloudbus.cloudsim.lists.*;
    import org.cloudbus.cloudsim.core.*;
    import java.util.*;
    import java.io.*;
    public class CloudSimExample {
    public static void main(String[] args) {
    try {
    // Initialize CloudSim library
    int numUser = 1; // Number of users
    Calendar calendar = Calendar.getInstance();
    boolean traceFlag = false; // Enabling trace info
    CloudSim.init(numUser, calendar, traceFlag);
    // Create a Datacenter
    Datacenter datacenter = createDatacenter("Datacenter_1");
    // Create a Broker
    DatacenterBroker broker = createBroker();
    int brokerId = broker.getId();
    // Create Virtual Machines
    List vms = createVMs(brokerId, 2); // Create 2 VMs
    // Create Cloudlets (tasks)
    List cloudlets = createCloudlets(brokerId, 5); // Create 5 tasks
    // Submit VM list to the broker
    broker.submitVmList(vms);
    // Submit Cloudlet list to the broker
    broker.submitCloudletList(cloudlets);
    // Start the simulation
    CloudSim.startSimulation();
    // Stop the simulation
    CloudSim.stopSimulation();
    // Print results after simulation
    List executedCloudlets = broker.getCloudletFinishedList();
    printCloudletResults(executedCloudlets);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    // Method to create a DataCenter
    private static Datacenter createDatacenter(String name) throws Exception {
    List hostList = new ArrayList();
    // Creating Hosts for the Datacenter
    for (int i = 0; i < 2; i++) { // Add 2 hosts to the datacenter
    int hostId = i;
    int ram = 1024; // 1 GB of RAM
    long storage = 10000; // 10 GB of storage
    int bw = 10000; // 10 Mbps network bandwidth
    List peList = new ArrayList();
    peList.add(new Pe(0, new PeProvisionerSimple(1000))); // 1 GHz CPU
    hostList.add(new Host(hostId, new RamProvisionerSimple(ram), new
    BwProvisionerSimple(bw), storage, peList, new VmSchedulerSpaceShared(peList)));
    }
    // Creating the Datacenter
    String arch = "x86"; // Architecture
    String os = "Linux"; // Operating system
    String vmm = "Xen"; // Virtual Machine Monitor
    DatacenterCharacteristics characteristics = new DatacenterCharacteristics(arch, os, vmm,
    hostList, 0.01, 0.01, 0.01);
    Datacenter datacenter = new Datacenter(name, characteristics, new
    VmAllocationPolicySimple(hostList), new LinkedList(), 0);
    return datacenter;
    }
    // Method to create Virtual Machines
    private static List createVMs(int brokerId, int num) {
    List vms = new ArrayList();
    for (int i = 0; i < num; i++) {
    int vmId = i;
    int mips = 1000;
    long size = 10000; // VM size (MB)
    int ram = 512; // RAM (MB)
    int bw = 1000; // Bandwidth (MB/s)
    int pesNumber = 1; // Number of CPU cores
    String vmm = "Xen";
    Vm vm = new Vm(vmId, brokerId, mips, pesNumber, ram, bw, size, vmm, new
    CloudletSchedulerTimeShared());
    vms.add(vm);
    }
    return vms;
    }
    // Method to create Cloudlets (tasks)
    private static List createCloudlets(int brokerId, int num) {
    List cloudlets = new ArrayList();
    for (int i = 0; i < num; i++) {
    int id = i;
    long length = 40000; // Cloudlet length
    long fileSize = 300; // File size (MB)
    long outputSize = 300; // Output size (MB)
    Cloudlet cloudlet = new Cloudlet(id, length, 1, fileSize, outputSize, new
    UtilizationModelStochastic(), new UtilizationModelStochastic(), new
    UtilizationModelStochastic());
    cloudlet.setUserId(brokerId);
    cloudlets.add(cloudlet);
    }
    return cloudlets;
    }
    // Method to print Cloudlet results
    private static void printCloudletResults(List cloudlets) {
    Cloudlet c;
    for (int i = 0; i < cloudlets.size(); i++) {
    c = cloudlets.get(i);
    System.out.println("Cloudlet ID: " + c.getCloudletId() +
    "\nStatus: " + (c.getStatus() == Cloudlet.SUCCESS ? "Success" : "Failed") +
    "\nResource Id: " + c.getResourceId() +
    "\nTime: " + c.getActualCpuTime() +
    "\nStart Time: " + c.getExecStartTime() +
    "\nFinish Time: " + c.getFinishTime());
    }
    }
    // Method to create a Broker
    private static DatacenterBroker createBroker() throws Exception {
    DatacenterBroker broker = new DatacenterBroker("Broker");
    return broker;
    }
    }
ScreenShots
  • To Create a Downward task for HEFT Algorithm like Datacenter Infrastructure.
  • create-cloud-environment