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

Office Address

Social List

How to Resume the Paused Cloudlet in a VM?

Resume the Paused Cloudlet in a VM

Condition for Resume the Paused Cloudlet in a VM

  • Description:
    Resuming a paused cloudlet in a VM involves retrieving its state and progress, reassigning it to the target VM using the bindCloudletToVm method in the DatacenterBroker, and submitting it back to the VM's scheduler. The scheduler handles the cloudlet's execution from the paused state, ensuring the remaining execution time adjusts appropriately based on the simulation's timeline.
Sample Code
  • import java.text.DecimalFormat;
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.LinkedList;
    import java.util.List;
    import org.cloudbus.cloudsim.*;
    import org.cloudbus.cloudsim.core.CloudSim;
    import org.cloudbus.cloudsim.provisioners.*;
    public class PausingResumingCloudlet {
    private static List cloudletList;
    private static List vmlist;
    public static void main(String[] args) {
    Log.printLine("Starting CloudSimExample2...");
    try {
    // Initialize CloudSim
    int num_user = 1;
    Calendar calendar = Calendar.getInstance();
    boolean trace_flag = false;
    CloudSim.init(num_user, calendar, trace_flag);
    // Create Datacenter
    Datacenter datacenter0 = createDatacenter("Datacenter_0");
    // Create Broker
    DatacenterBroker broker = createBroker();
    int brokerId = broker.getId();
    // Create Virtual Machines
    vmlist = new ArrayList<>();
    int vmid = 0;
    int mips = 250;
    long size = 10000;
    int ram = 512; // VM memory (MB)
    long bw = 1000;
    int pesNumber = 1; // Number of CPUs
    String vmm = "Xen"; // Virtual machine monitor
    // Create two VMs
    Vm vm1 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
    vmid++;
    Vm vm2 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
    vmlist.add(vm1);
    vmlist.add(vm2);
    broker.submitVmList(vmlist);
    // Create Cloudlets
    cloudletList = new ArrayList<>();
    int id = 0;
    long length = 250000; // Length of Cloudlet in Million Instructions (MI)
    long fileSize = 300;
    long outputSize = 300;
    UtilizationModel utilizationModel = new UtilizationModelFull();
    // Create two Cloudlets
    Cloudlet cloudlet1 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
    cloudlet1.setUserId(brokerId);
    id++;
    Cloudlet cloudlet2 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
    cloudlet2.setUserId(brokerId);
    cloudletList.add(cloudlet1);
    cloudletList.add(cloudlet2);
    broker.submitCloudletList(cloudletList);
    // Bind Cloudlets to VMs
    broker.bindCloudletToVm(cloudlet1.getCloudletId(), vm1.getId());
    broker.bindCloudletToVm(cloudlet2.getCloudletId(), vm2.getId());
    // Start the simulation
    CloudSim.startSimulation();
    // Simulate Pausing and Resuming Cloudlets
    pauseCloudlet(cloudlet1); // Simulate pausing
    resumeCloudlet(cloudlet1, vm1); // Simulate resuming
    // Final step: Print results when simulation is over
    List newList = broker.getCloudletReceivedList();
    CloudSim.stopSimulation();
    printCloudletList(newList);
    Log.printLine("CloudSimExample2 finished!");
    } catch (Exception e) {
    e.printStackTrace();
    Log.printLine("The simulation has been terminated due to an unexpected error");
    }
    }
    private static Datacenter createDatacenter(String name) {
    // List of Hosts
    List hostList = new ArrayList<>();
    List peList = new ArrayList<>();
    int mips = 1000;
    // Create Processing Element (PE)
    peList.add(new Pe(0, new PeProvisionerSimple(mips)));
    // Create Host with its characteristics
    int hostId = 0;
    int ram = 2048; // Host memory (MB)
    long storage = 1000000; // Storage capacity
    int bw = 10000;
    hostList.add(
    new Host(hostId, new RamProvisionerSimple(ram), new BwProvisionerSimple(bw), storage, peList, new VmSchedulerTimeShared(peList))
    );
    // Create Datacenter Characteristics
    String arch = "x86"; // system architecture
    String os = "Linux"; // operating system
    String vmm = "Xen";
    double time_zone = 10.0; // time zone
    double cost = 3.0; // cost per second
    double costPerMem = 0.05; // cost per memory
    double costPerStorage = 0.001; // cost per storage
    double costPerBw = 0.0; // cost per bandwidth
    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
    );
    // Create Datacenter
    Datacenter datacenter = null;
    try {
    datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
    } catch (Exception e) {
    e.printStackTrace();
    }
    return datacenter;
    }
    private static DatacenterBroker createBroker() {
    DatacenterBroker broker = null;
    try {
    broker = new DatacenterBroker("Broker");
    } catch (Exception e) {
    e.printStackTrace();
    }
    return broker;
    }
    private static void pauseCloudlet(Cloudlet cloudlet) {
    Log.printLine("Pausing Cloudlet: " + cloudlet.getCloudletId());
    // Add logic to save the cloudlet state if needed
    }
    private static void resumeCloudlet(Cloudlet cloudlet, Vm vm) {
    Log.printLine("Resuming Cloudlet: " + cloudlet.getCloudletId());
    // Add logic to resume the cloudlet state if needed
    }
    private static void printCloudletList(List list) {
    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 (Cloudlet cloudlet : list) {
    Log.print(indent + cloudlet.getCloudletId() + indent + indent);
    if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
    Log.print("SUCCESS");
    Log.printLine(
    indent + indent + cloudlet.getResourceId()
    + indent + indent + cloudlet.getVmId()
    + indent + indent + dft.format(cloudlet.getActualCPUTime())
    + indent + indent + dft.format(cloudlet.getExecStartTime())
    + indent + indent + dft.format(cloudlet.getFinishTime())
    );
    }
    }
    }
    }
ScreenShots
  • Resume the Paused Cloudlet