List of Topics:
Location Research Breakthrough Possible @S-Logix pro@slogix.in

Office Address

Social List

How to Categorize and Analyze Cloudlets Based on Computational Length in Containercloudsim to Improve Task Allocation and Performance Analysis?

Host-Level Power Consumption Using Planetlab

Condition for Categorize and Analyze Cloudlets Based on Computational Length in Containercloudsim

  • Description:
    This project presents a cloudlet categorization and performance analysis model for container-based cloud computing using ContainerCloudSim. The objective is to classify cloudlets (tasks) based on their computational length—Short, Medium, Long, and Very Long—and evaluate how these categories influence resource utilization, task execution time, and completion efficiency.The simulation creates a data center with multiple hosts, virtual machines (VMs), and containers, managed through energy-aware allocation and scheduling policies. Each cloudlet’s length (in Million Instructions - MI) determines its category, which enables systematic workload characterization. The system then computes and displays category-wise performance statistics, such as execution time, completion rate, and percentage contribution to the total workload.By integrating task categorization with container-based scheduling, the model demonstrates how differentiated workloads can be analyzed to achieve better task management, balanced resource allocation, and improved Quality of Service (QoS) in cloud environments. This approach provides valuable insights into optimizing scheduling algorithms for diverse cloud workloads.
Sample Code
  • package containercloudsim;

    import org.cloudbus.cloudsim.Log;
    import org.cloudbus.cloudsim.Storage;
    import org.cloudbus.cloudsim.UtilizationModelNull;
    import org.cloudbus.cloudsim.container.containerProvisioners.ContainerBwProvisionerSimple;
    import org.cloudbus.cloudsim.container.containerProvisioners.ContainerPe;
    import org.cloudbus.cloudsim.container.containerProvisioners.ContainerRamProvisionerSimple;
    import org.cloudbus.cloudsim.container.containerProvisioners.ContainerPeProvisionerSimple;
    import org.cloudbus.cloudsim.container.containerVmProvisioners.ContainerVmBwProvisionerSimple;
    import org.cloudbus.cloudsim.container.containerVmProvisioners.ContainerVmPe;
    import org.cloudbus.cloudsim.container.containerVmProvisioners.ContainerVmPeProvisionerSimple;
    import org.cloudbus.cloudsim.container.containerVmProvisioners.ContainerVmRamProvisionerSimple;
    import org.cloudbus.cloudsim.container.core.*;
    import org.cloudbus.cloudsim.container.hostSelectionPolicies.HostSelectionPolicy;
    import org.cloudbus.cloudsim.container.hostSelectionPolicies.HostSelectionPolicyFirstFit;
    import org.cloudbus.cloudsim.container.resourceAllocatorMigrationEnabled
    .PowerContainerVmAllocationPolicyMigrationAbstractHostSelection;
    import org.cloudbus.cloudsim.container.resourceAllocators.ContainerAllocationPolicy;
    import org.cloudbus.cloudsim.container.resourceAllocators.ContainerVmAllocationPolicy;
    import org.cloudbus.cloudsim.container.resourceAllocators.PowerContainerAllocationPolicySimple;
    import org.cloudbus.cloudsim.container.schedulers.ContainerCloudletSchedulerDynamicWorkload;
    import org.cloudbus.cloudsim.container.schedulers.ContainerSchedulerTimeSharedOverSubscription;
    import org.cloudbus.cloudsim.container.schedulers.ContainerVmSchedulerTimeSharedOverSubscription;
    import org.cloudbus.cloudsim.container.utils.IDs;
    import org.cloudbus.cloudsim.container.vmSelectionPolicies.PowerContainerVmSelectionPolicy;
    import org.cloudbus.cloudsim.container.vmSelectionPolicies
    .PowerContainerVmSelectionPolicyMaximumUsage;
    import org.cloudbus.cloudsim.core.CloudSim;
    import org.cloudbus.cloudsim.container.core.PowerContainer;
    import org.cloudbus.cloudsim.container.core.Container;

    import java.io.FileNotFoundException;
    import java.text.DecimalFormat;
    import java.util.*;
    import org.cloudbus.cloudsim.examples.container.ConstantsExamples;
    import org.cloudbus.cloudsim.examples.container.UtilizationModelPlanetLabInMemoryExtended;

    /**
    * A simple example showing how to create a data center with one host, one VM,
    * one container and run one cloudlet on it.
    * Enhanced with Cloudlet Categorization by Length feature.
    */
    public class CloudletCategorization {

    /**
    * The cloudlet list.
    */
    private static List cloudletList;

    /**
    * The vmlist.
    */
    private static List vmList;

    /**
    * The vmlist.
    */
    private static List containerList;

    /**
    * The hostList.
    */
    private static List hostList;

    /**
    * Cloudlet categories based on length
    */
    private static enum CloudletCategory {
    SHORT("Short", 0, 10000), // 0-10,000 MI
    MEDIUM("Medium", 10001, 30000), // 10,001-30,000 MI
    LONG("Long", 30001, 100000), // 30,001-100,000 MI
    VERY_LONG("Very Long", 100001, Long.MAX_VALUE); // 100,001+ MI

    private final String name;
    private final long minLength;
    private final long maxLength;

    CloudletCategory(String name, long minLength, long maxLength) {
    this.name = name;
    this.minLength = minLength;
    this.maxLength = maxLength;
    }

    public String getName() { return name; }
    public long getMinLength() { return minLength; }
    public long getMaxLength() { return maxLength; }

    public static CloudletCategory getCategory(long cloudletLength) {
    for (CloudletCategory category : values()) {
    if (cloudletLength >= category.minLength && cloudletLength <= category.maxLength) {
    return category;
    }
    }
    return VERY_LONG;
    }
    }

    /**
    * Creates main() to run this example.
    *
    * @param args the args
    */
    public static void main(String[] args) {
    Log.printLine("Starting ContainerCloudSim with Cloudlet Categorization...");

    try {
    /**
    * number of cloud Users
    */
    int num_user = 1;
    /**
    * The fields of calender have been initialized with the current
    * date and time.
    */
    Calendar calendar = Calendar.getInstance();
    /**
    * Deactivating the event tracing
    */
    boolean trace_flag = false;
    /**
    * 1- Like CloudSim the first step is initializing the CloudSim
    * Package before creating any entities.
    *
    */

    CloudSim.init(num_user, calendar, trace_flag);
    /**
    * 2- Defining the container allocation Policy. This policy
    * determines how Containers are allocated to VMs in the data
    * center.
    *
    */

    ContainerAllocationPolicy containerAllocationPolicy = new PowerContainerAllocationPolicySimple();

    /**
    * 3- Defining the VM selection Policy. This policy determines which
    * VMs should be selected for migration when a host is identified as
    * over-loaded.
    *
    */
    PowerContainerVmSelectionPolicy vmSelectionPolicy = new PowerContainerVmSelectionPolicyMaximumUsage();

    /**
    * 4- Defining the host selection Policy. This policy determines
    * which hosts should be selected as migration destination.
    *
    */
    HostSelectionPolicy hostSelectionPolicy = new HostSelectionPolicyFirstFit();
    /**
    * 5- Defining the thresholds for selecting the under-utilized and
    * over-utilized hosts.
    */

    double overUtilizationThreshold = 0.80;
    double underUtilizationThreshold = 0.70;
    /**
    * 6- The host list is created considering the number of hosts, and
    * host types which are specified in the {@link ConstantsExamples}.
    */
    hostList = new ArrayList();
    hostList = createHostList(ConstantsExamples.NUMBER_HOSTS);
    cloudletList = new ArrayList();
    vmList = new ArrayList();
    /**
    * 7- The container allocation policy which defines the allocation
    * of VMs to containers.
    */
    ContainerVmAllocationPolicy vmAllocationPolicy = new PowerContainerVmAllocationPolicyMigrationAbstractHostSelection(hostList, vmSelectionPolicy,
    hostSelectionPolicy, overUtilizationThreshold, underUtilizationThreshold);
    /**
    * 8- The overbooking factor for allocating containers to VMs. This
    * factor is used by the broker for the allocation process.
    */
    int overBookingFactor = 80;
    ContainerDatacenterBroker broker = createBroker(overBookingFactor);
    int brokerId = broker.getId();
    /**
    * 9- Creating the cloudlet, container and VM lists for submitting
    * to the broker.
    */
    cloudletList = createContainerCloudletList(brokerId, ConstantsExamples.NUMBER_CLOUDLETS);
    containerList = createContainerList(brokerId, ConstantsExamples.NUMBER_CLOUDLETS);
    vmList = createVmList(brokerId, ConstantsExamples.NUMBER_VMS);
    /**
    * 10- The address for logging the statistics of the VMs, containers
    * in the data center.
    */
    String logAddress = "~/Results";

    @SuppressWarnings("unused")
    PowerContainerDatacenter e = (PowerContainerDatacenter) createDatacenter("datacenter",
    PowerContainerDatacenterCM.class, hostList, vmAllocationPolicy, containerAllocationPolicy,
    getExperimentName("ContainerCloudSimExample-1", String.valueOf(overBookingFactor)),
    ConstantsExamples.SCHEDULING_INTERVAL, logAddress,
    ConstantsExamples.VM_STARTTUP_DELAY, ConstantsExamples.CONTAINER_STARTTUP_DELAY);

    /**
    * 11- Submitting the cloudlet's , container's , and VM's lists to
    * the broker.
    */
    broker.submitCloudletList(cloudletList.subList(0, containerList.size()));
    broker.submitContainerList(containerList);
    broker.submitVmList(vmList);
    /**
    * 12- Determining the simulation termination time according to the
    * cloudlet's workload.
    */
    CloudSim.terminateSimulation(86400.00);
    /**
    * 13- Starting the simualtion.
    */
    CloudSim.startSimulation();
    /**
    * 14- Stopping the simualtion.
    */
    CloudSim.stopSimulation();
    /**
    * 15- Printing the results when the simulation is finished.
    */
    List newList = broker.getCloudletReceivedList();
    printCloudletList(newList);

    /**
    * 16- Print cloudlet categorization report
    */
    printCloudletCategorizationReport(newList);

    Log.printLine("ContainerCloudSimExample1 finished!");
    } catch (Exception e) {
    e.printStackTrace();
    Log.printLine("Unwanted errors happen");
    }
    }

    /**
    * Prints cloudlet categorization report
    */
    private static void printCloudletCategorizationReport(List cloudlets) {
    Log.printLine("\n=== CLOUDLET CATEGORIZATION REPORT ===");

    // Initialize category counters
    Map> categorizedCloudlets = new HashMap<>();
    Map categoryCounts = new HashMap<>();
    Map categoryTotalTime = new HashMap<>();
    Map categoryAvgTime = new HashMap<>();

    // Initialize maps
    for (CloudletCategory category : CloudletCategory.values()) {
    categorizedCloudlets.put(category, new ArrayList<>());
    categoryCounts.put(category, 0);
    categoryTotalTime.put(category, 0.0);
    categoryAvgTime.put(category, 0.0);
    }

    // Categorize cloudlets
    for (ContainerCloudlet cloudlet : cloudlets) {
    CloudletCategory category = CloudletCategory.getCategory(cloudlet.getCloudletLength());
    categorizedCloudlets.get(category).add(cloudlet);
    categoryCounts.put(category, categoryCounts.get(category) + 1);

    if (cloudlet.getCloudletStatusString().equals("Success")) {
    double executionTime = cloudlet.getActualCPUTime();
    categoryTotalTime.put(category, categoryTotalTime.get(category) + executionTime);
    }
    }

    // Calculate averages
    for (CloudletCategory category : CloudletCategory.values()) {
    int count = categoryCounts.get(category);
    if (count > 0) {
    categoryAvgTime.put(category, categoryTotalTime.get(category) / count);
    }
    }

    // Print summary
    Log.printLine("\n--- Category Summary ---");
    Log.printLine(String.format("%-12s | %6s | %10s | %12s | %12s",
    "Category", "Count", "Percentage", "Avg Time(s)", "Total Time(s)"));
    Log.printLine("------------|--------|------------|--------------|--------------");

    int totalCloudlets = cloudlets.size();
    DecimalFormat df = new DecimalFormat("###.##");

    for (CloudletCategory category : CloudletCategory.values()) {
    int count = categoryCounts.get(category);
    double percentage = (double) count / totalCloudlets * 100;
    double avgTime = categoryAvgTime.get(category);
    double totalTime = categoryTotalTime.get(category);

    Log.printLine(String.format("%-12s | %6d | %9.2f%% | %12s | %12s",
    category.getName(), count, percentage,
    df.format(avgTime), df.format(totalTime)));
    }

    // Print detailed breakdown per category
    for (CloudletCategory category : CloudletCategory.values()) {
    List categoryCloudlets = categorizedCloudlets.get(category);
    if (!categoryCloudlets.isEmpty()) {
    printCategoryDetails(category, categoryCloudlets);
    }
    }
    }

    /**
    * Prints detailed information for a specific cloudlet category
    */
    private static void printCategoryDetails(CloudletCategory category, List cloudlets) {
    Log.printLine("\n--- " + category.getName() + " Cloudlets (" + cloudlets.size() + ") ---");
    Log.printLine("Length Range: " + category.getMinLength() + " - " +
    (category.getMaxLength() == Long.MAX_VALUE ? "∞" : category.getMaxLength()) + " MI");

    // Calculate statistics
    long minLength = Long.MAX_VALUE;
    long maxLength = 0;
    long totalLength = 0;
    int completed = 0;
    double totalExecutionTime = 0;

    for (ContainerCloudlet cloudlet : cloudlets) {
    long length = cloudlet.getCloudletLength();
    minLength = Math.min(minLength, length);
    maxLength = Math.max(maxLength, length);
    totalLength += length;

    if (cloudlet.getCloudletStatusString().equals("Success")) {
    completed++;
    totalExecutionTime += cloudlet.getActualCPUTime();
    }
    }

    double avgLength = cloudlets.isEmpty() ? 0 : (double) totalLength / cloudlets.size();
    double avgExecutionTime = completed == 0 ? 0 : totalExecutionTime / completed;
    double completionRate = (double) completed / cloudlets.size() * 100;

    DecimalFormat df = new DecimalFormat("###,###.##");
    Log.printLine("Length Stats - Min: " + df.format(minLength) +
    ", Max: " + df.format(maxLength) +
    ", Avg: " + df.format(avgLength) + " MI");
    Log.printLine("Completion: " + completed + "/" + cloudlets.size() +
    " (" + df.format(completionRate) + "%)");
    Log.printLine("Avg Execution Time: " + df.format(avgExecutionTime) + " seconds");

    // Print top 5 longest cloudlets in this category
    if (!cloudlets.isEmpty()) {
    Log.printLine("\nTop 5 Longest Cloudlets in " + category.getName() + " category:");
    List sorted = new ArrayList<>(cloudlets);
    sorted.sort((c1, c2) -> Long.compare(c2.getCloudletLength(), c1.getCloudletLength()));

    int limit = Math.min(5, sorted.size());
    for (int i = 0; i < limit; i++) {
    ContainerCloudlet cloudlet = sorted.get(i);
    Log.printLine(" Cloudlet " + cloudlet.getCloudletId() +
    ": " + df.format(cloudlet.getCloudletLength()) + " MI" +
    (cloudlet.getCloudletStatusString().equals("Success") ?
    " (Completed in " + df.format(cloudlet.getActualCPUTime()) + "s)" : " (Not completed)"));
    }
    }
    }

    /**
    * It creates a specific name for the experiment which is used for creating
    * the Log address folder.
    */
    private static String getExperimentName(String... args) {
    StringBuilder experimentName = new StringBuilder();

    for (int i = 0; i < args.length; ++i) {
    if (!args[i].isEmpty()) {
    if (i != 0) {
    experimentName.append("_");
    }

    experimentName.append(args[i]);
    }
    }

    return experimentName.toString();
    }

    /**
    * Creates the broker.
    *
    * @param overBookingFactor
    * @return the datacenter broker
    */
    private static ContainerDatacenterBroker createBroker(int overBookingFactor) {

    ContainerDatacenterBroker broker = null;

    try {
    broker = new ContainerDatacenterBroker("Broker", overBookingFactor);
    } catch (Exception var2) {
    var2.printStackTrace();
    System.exit(0);
    }

    return broker;
    }

    /**
    * Prints the Cloudlet objects.
    *
    * @param list list of Cloudlets
    */
    private static void printCloudletList(List list) {
    int size = list.size();
    ContainerCloudlet cloudlet;

    String indent = " ";
    Log.printLine();
    Log.printLine("========== OUTPUT ==========");
    Log.printLine("Cloudlet ID" + indent + "Container ID" + indent + "STATUS" + indent
    + "Data center ID" + indent + "VM ID" + indent + "Time" + indent
    + "Start Time" + indent + "Finish Time" + indent + "Length" + indent + "Category");

    DecimalFormat dft = new DecimalFormat("###,###.##");
    for (int i = 0; i < size; i++) {
    cloudlet = list.get(i);
    Log.print(indent + cloudlet.getCloudletId() + indent);

    // Print Container ID
    Log.print(cloudlet.getContainerId() + indent);

    if (cloudlet.getCloudletStatusString().equals("Success")) {
    Log.print("SUCCESS");

    CloudletCategory category = CloudletCategory.getCategory(cloudlet.getCloudletLength());

    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())
    + indent + dft.format(cloudlet.getCloudletLength())
    + indent + category.getName());
    } else {
    CloudletCategory category = CloudletCategory.getCategory(cloudlet.getCloudletLength());
    Log.printLine("FAILED" + indent + indent + cloudlet.getResourceId()
    + indent + indent + indent + cloudlet.getVmId()
    + indent + indent + "N/A" + indent + indent + "N/A"
    + indent + indent + "N/A"
    + indent + dft.format(cloudlet.getCloudletLength())
    + indent + category.getName());
    }
    try {
    Thread.sleep(50); // Reduced sleep for faster output
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }
    }

    /**
    * Create the Virtual machines and add them to the list
    *
    * @param brokerId
    * @param containerVmsNumber
    */
    private static ArrayList createVmList(int brokerId, int containerVmsNumber) {
    ArrayList containerVms = new ArrayList();

    for (int i = 0; i < containerVmsNumber; ++i) {
    ArrayList peList = new ArrayList();
    int vmType = i / (int) Math.ceil((double) containerVmsNumber / 4.0D);

    for (int j = 0; j < ConstantsExamples.VM_PES[vmType]; ++j) {
    peList.add(new ContainerPe(j,
    new ContainerPeProvisionerSimple((double) ConstantsExamples.VM_MIPS[vmType])));
    }
    containerVms.add(new PowerContainerVm(IDs.pollId(ContainerVm.class), brokerId,
    (double) ConstantsExamples.VM_MIPS[vmType], (float) ConstantsExamples.VM_RAM[vmType],
    ConstantsExamples.VM_BW, ConstantsExamples.VM_SIZE, "Xen",
    new ContainerSchedulerTimeSharedOverSubscription(peList),
    new ContainerRamProvisionerSimple(ConstantsExamples.VM_RAM[vmType]),
    new ContainerBwProvisionerSimple(ConstantsExamples.VM_BW),
    peList, ConstantsExamples.SCHEDULING_INTERVAL));

    }

    return containerVms;
    }

    /**
    * Create the host list considering the specs listed in the
    * {@link ConstantsExamples}.
    *
    * @param hostsNumber
    * @return
    */
    public static List createHostList(int hostsNumber) {
    ArrayList hostList = new ArrayList();
    for (int i = 0; i < hostsNumber; ++i) {
    int hostType = i / (int) Math.ceil((double) hostsNumber / 3.0D);
    ArrayList peList = new ArrayList();
    for (int j = 0; j < ConstantsExamples.HOST_PES[hostType]; ++j) {
    peList.add(new ContainerVmPe(j,
    new ContainerVmPeProvisionerSimple((double) ConstantsExamples.HOST_MIPS[hostType])));
    }

    hostList.add(new PowerContainerHostUtilizationHistory(IDs.pollId(ContainerHost.class),
    new ContainerVmRamProvisionerSimple(ConstantsExamples.HOST_RAM[hostType]),
    new ContainerVmBwProvisionerSimple(1000000L), 1000000L, peList,
    new ContainerVmSchedulerTimeSharedOverSubscription(peList),
    ConstantsExamples.HOST_POWER[hostType]));
    }

    return hostList;
    }

    /**
    * Create the data center
    *
    * @param name
    * @param datacenterClass
    * @param hostList
    * @param vmAllocationPolicy
    * @param containerAllocationPolicy
    * @param experimentName
    * @param logAddress
    * @return
    * @throws Exception
    */
    public static ContainerDatacenter createDatacenter(String name, Class< extends ContainerDatacenter> datacenterClass,
    List hostList,
    ContainerVmAllocationPolicy vmAllocationPolicy,
    ContainerAllocationPolicy containerAllocationPolicy,
    String experimentName, double schedulingInterval, String logAddress, double VMStartupDelay,
    double ContainerStartupDelay) throws Exception {
    String arch = "x86";
    String os = "Linux";
    String vmm = "Xen";
    double time_zone = 10.0D;
    double cost = 3.0D;
    double costPerMem = 0.05D;
    double costPerStorage = 0.001D;
    double costPerBw = 0.0D;
    ContainerDatacenterCharacteristics characteristics = new ContainerDatacenterCharacteristics(arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage,
    costPerBw);
    ContainerDatacenter datacenter = new PowerContainerDatacenterCM(name, characteristics, vmAllocationPolicy,
    containerAllocationPolicy, new LinkedList(), schedulingInterval, experimentName, logAddress,
    VMStartupDelay, ContainerStartupDelay);

    return datacenter;
    }

    /**
    * create the containers for hosting the cloudlets and binding them
    * together.
    *
    * @param brokerId
    * @param containersNumber
    * @return
    */
    public static List createContainerList(int brokerId, int containersNumber) {
    ArrayList containers = new ArrayList();

    for (int i = 0; i < containersNumber; ++i) {
    int containerType = i / (int) Math.ceil((double) containersNumber / 3.0D);

    containers.add(new PowerContainer(IDs.pollId(Container.class), brokerId, (
    double) ConstantsExamples.CONTAINER_MIPS[containerType],
    ConstantsExamples.CONTAINER_PES[containerType], ConstantsExamples.CONTAINER_RAM[
    containerType], ConstantsExamples.CONTAINER_BW, 0L, "Xen",
    new ContainerCloudletSchedulerDynamicWorkload(
    ConstantsExamples.CONTAINER_MIPS[containerType],
    ConstantsExamples.CONTAINER_PES[containerType]),
    ConstantsExamples.SCHEDULING_INTERVAL));
    }

    return containers;
    }

    /**
    * Creating the cloudlet list that are going to run on containers
    * Enhanced to create cloudlets with varying lengths for categorization
    *
    * @param brokerId
    * @param numberOfCloudlets
    * @return
    * @throws FileNotFoundException
    */
    public static List createContainerCloudletList(int brokerId, int numberOfCloudlets)
    throws FileNotFoundException {
    String inputFolderName = "/home/soft13/soft13/Project 2019/Cloudsim-4.0-examples/src/workload/planetlab";
    ArrayList cloudletList = new ArrayList();
    long fileSize = 300L;
    long outputSize = 300L;
    UtilizationModelNull utilizationModelNull = new UtilizationModelNull();

    // Create cloudlets with varying lengths for better categorization demonstration
    Random random = new Random();
    int createdCloudlets = 0;

    // Try to use PlanetLab workload files if available
    java.io.File inputFolder1 = new java.io.File(inputFolderName);
    if (inputFolder1.exists() && inputFolder1.listFiles() != null) {
    java.io.File[] files1 = inputFolder1.listFiles();
    for (java.io.File aFiles1 : files1) {
    java.io.File inputFolder = new java.io.File(aFiles1.toString());
    java.io.File[] files = inputFolder.listFiles();
    if (files != null) {
    for (int i = 0; i < files.length; ++i) {
    if (createdCloudlets < numberOfCloudlets) {
    ContainerCloudlet cloudlet = null;

    try {
    // Vary cloudlet lengths for categorization
    long variedLength = ConstantsExamples.CLOUDLET_LENGTH +
    (random.nextInt(5) * 10000); // Add 0-40k variation

    cloudlet = new ContainerCloudlet(IDs.pollId(ContainerCloudlet.class),
    variedLength, 1,
    fileSize, outputSize,
    new UtilizationModelPlanetLabInMemoryExtended(files[i].getAbsolutePath(), 300.0D),
    utilizationModelNull, utilizationModelNull);
    } catch (Exception var13) {
    var13.printStackTrace();
    // Fallback to simple cloudlet creation
    cloudlet = createSimpleCloudlet(IDs.pollId(ContainerCloudlet.class), brokerId);
    }

    cloudlet.setUserId(brokerId);
    cloudletList.add(cloudlet);
    createdCloudlets += 1;
    } else {
    return cloudletList;
    }
    }
    }
    }
    }

    // If not enough cloudlets created from files, create simple ones
    while (createdCloudlets < numberOfCloudlets) {
    ContainerCloudlet cloudlet = createSimpleCloudlet(IDs.pollId(ContainerCloudlet.class), brokerId);
    cloudletList.add(cloudlet);
    createdCloudlets += 1;
    }

    return cloudletList;
    }

    /**
    * Creates a simple cloudlet with random length for categorization demonstration
    */
    private static ContainerCloudlet createSimpleCloudlet(int cloudletId, int brokerId) {
    Random random = new Random();
    // Create cloudlets with lengths that will fall into different categories
    long[] possibleLengths = {5000, 15000, 25000, 50000, 150000}; // Cover all categories
    long length = possibleLengths[random.nextInt(possibleLengths.length)];

    ContainerCloudlet cloudlet = new ContainerCloudlet(cloudletId, length, 1,
    300L, 300L, new UtilizationModelNull(),
    new UtilizationModelNull(), new UtilizationModelNull());
    cloudlet.setUserId(brokerId);
    return cloudlet;
    }

    /**
    * Additional method: Categorize and assign cloudlets to appropriate VMs based on length
    */
    public static void assignCloudletsByCategory(List cloudlets,
    List vms,
    List containers) {
    Log.printLine("\n=== Category-Based Cloudlet Assignment ===");

    // Group cloudlets by category
    Map> cloudletsByCategory = new HashMap<>();
    for (CloudletCategory category : CloudletCategory.values()) {
    cloudletsByCategory.put(category, new ArrayList<>());
    }

    for (ContainerCloudlet cloudlet : cloudlets) {
    CloudletCategory category = CloudletCategory.getCategory(cloudlet.getCloudletLength());
    cloudletsByCategory.get(category).add(cloudlet);
    }

    // Print assignment strategy
    for (CloudletCategory category : CloudletCategory.values()) {
    List categoryCloudlets = cloudletsByCategory.get(category);
    Log.printLine(category.getName() + " cloudlets (" + categoryCloudlets.size() +
    "): " + getAssignmentStrategy(category));
    }
    }

    /**
    * Returns assignment strategy description for each category
    */
    private static String getAssignmentStrategy(CloudletCategory category) {
    switch (category) {
    case SHORT:
    return "Assign to any available VM (low priority)";
    case MEDIUM:
    return "Assign to balanced VMs (medium priority)";
    case LONG:
    return "Assign to high-performance VMs (high priority)";
    case VERY_LONG:
    return "Assign to dedicated high-performance VMs (highest priority)";
    default:
    return "Standard assignment";
    }
    }
    }
Screenshots
  • 99
  • 100
  • 101
  • 102