/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* Cloudlet is an extension to the cloudlet. It stores, despite all the information encapsulated in
* the Cloudlet, the ID of the VM running it.
*
* @author Rodrigo N. Calheiros
* @author Anton Beloglazov
* @since CloudSim Toolkit 1.0
*/
public class Cloudlet {
/**
* The User or Broker ID. It is advisable that broker set this ID with its own ID, so that
* CloudResource returns to it after the execution.
**/
private int userId;
/**
* The size of this Cloudlet to be executed in a CloudResource (unit: in MI).
*/
private long cloudletLength;
/**
* The input file size of this Cloudlet before execution (unit: in byte). in byte = program +
* input data size
*/
private final long cloudletFileSize;
/** The output file size of this Cloudlet after execution (unit: in byte). */
private final long cloudletOutputSize;
/** The num of Pe required to execute this job. */
private int numberOfPes;
/** The cloudlet ID. */
private final int cloudletId;
/** The status of this Cloudlet. */
private int status;
/** The format of decimal numbers. */
private DecimalFormat num;
/** The time where this Cloudlet completes. */
private double finishTime;
/**
* Start time of executing this Cloudlet. With new functionalities, such as CANCEL, PAUSED and
* RESUMED, this attribute only stores the latest execution time. Previous execution time are
* ignored.
*/
private double execStartTime;
/** The ID of a reservation made for this cloudlet. */
private int reservationId = -1;
/** The records the transaction history for this Cloudlet. */
private final boolean record;
/** The newline. */
private String newline;
/** The history. */
private StringBuffer history;
/** The res list. */
private final List<Resource> resList;
/** The index. */
private int index;
/** The class type of Cloudlet for resource scheduling. */
private int classType;
/** The ToS for sending Cloudlet over the network. */
private int netToS;
// //////////////////////////////////////////
// Below are CONSTANTS attributes
/** The Cloudlet has been created and added to the CloudletList object. */
public static final int CREATED = 0;
/** The Cloudlet has been assigned to a CloudResource object as planned. */
public static final int READY = 1;
/** The Cloudlet has moved to a Cloud node. */
public static final int QUEUED = 2;
/** The Cloudlet is in execution in a Cloud node. */
public static final int INEXEC = 3;
/** The Cloudlet has been executed successfully. */
public static final int SUCCESS = 4;
/** The Cloudlet is failed. */
public static final int FAILED = 5;
/** The Cloudlet has been canceled. */
public static final int CANCELED = 6;
/**
* The Cloudlet has been paused. It can be resumed by changing the status into <tt>RESUMED</tt>.
*/
public static final int PAUSED = 7;
/** The Cloudlet has been resumed from <tt>PAUSED</tt> state. */
public static final int RESUMED = 8;
/** The cloudlet has failed due to a resource failure. */
public static final int FAILED_RESOURCE_UNAVAILABLE = 9;
/** The vm id. */
protected int vmId;
/** The cost per bw. */
protected double costPerBw;
/** The accumulated bw cost. */
protected double accumulatedBwCost;
// Utilization
/** The utilization of cpu model. */
private UtilizationModel utilizationModelCpu;
/** The utilization of memory model. */
private UtilizationModel utilizationModelRam;
/** The utilization of bw model. */
private UtilizationModel utilizationModelBw;
// Data cloudlet
/** The required files. */
private List<String> requiredFiles = null; // list of required filenames
/**
* Allocates a new Cloudlet object. The Cloudlet length, input and output file sizes should be
* greater than or equal to 1. By default this constructor sets the history of this object.
*
* @param cloudletId the unique ID of this Cloudlet
* @param cloudletLength the length or size (in MI) of this cloudlet to be executed in a
* PowerDatacenter
* @param cloudletFileSize the file size (in byte) of this cloudlet <tt>BEFORE</tt> submitting
* to a PowerDatacenter
* @param cloudletOutputSize the file size (in byte) of this cloudlet <tt>AFTER</tt> finish
* executing by a PowerDatacenter
* @param pesNumber the pes number
* @param utilizationModelCpu the utilization model cpu
* @param utilizationModelRam the utilization model ram
* @param utilizationModelBw the utilization model bw
* @pre cloudletID >= 0
* @pre cloudletLength >= 0.0
* @pre cloudletFileSize >= 1
* @pre cloudletOutputSize >= 1
* @post $none
*/
public Cloudlet(
final int cloudletId,
final long cloudletLength,
final int pesNumber,
final long cloudletFileSize,
final long cloudletOutputSize,
final UtilizationModel utilizationModelCpu,
final UtilizationModel utilizationModelRam,
final UtilizationModel utilizationModelBw) {
this(
cloudletId,
cloudletLength,
pesNumber,
cloudletFileSize,
cloudletOutputSize,
utilizationModelCpu,
utilizationModelRam,
utilizationModelBw,
false);
vmId = -1;
accumulatedBwCost = 0.0;
costPerBw = 0.0;
requiredFiles = new LinkedList<String>();
}
/**
* Allocates a new Cloudlet object. The Cloudlet length, input and output file sizes should be
* greater than or equal to 1.
*
* @param cloudletId the unique ID of this cloudlet
* @param cloudletLength the length or size (in MI) of this cloudlet to be executed in a
* PowerDatacenter
* @param cloudletFileSize the file size (in byte) of this cloudlet <tt>BEFORE</tt> submitting
* to a PowerDatacenter
* @param cloudletOutputSize the file size (in byte) of this cloudlet <tt>AFTER</tt> finish
* executing by a PowerDatacenter
* @param record record the history of this object or not
* @param fileList list of files required by this cloudlet
* @param pesNumber the pes number
* @param utilizationModelCpu the utilization model cpu
* @param utilizationModelRam the utilization model ram
* @param utilizationModelBw the utilization model bw
* @pre cloudletID >= 0
* @pre cloudletLength >= 0.0
* @pre cloudletFileSize >= 1
* @pre cloudletOutputSize >= 1
* @post $none
*/
public Cloudlet(
final int cloudletId,
final long cloudletLength,
final int pesNumber,
final long cloudletFileSize,
final long cloudletOutputSize,
final UtilizationModel utilizationModelCpu,
final UtilizationModel utilizationModelRam,
final UtilizationModel utilizationModelBw,
final boolean record,
final List<String> fileList) {
this(
cloudletId,
cloudletLength,
pesNumber,
cloudletFileSize,
cloudletOutputSize,
utilizationModelCpu,
utilizationModelRam,
utilizationModelBw,
record);
vmId = -1;
accumulatedBwCost = 0.0;
costPerBw = 0.0;
requiredFiles = fileList;
}
/**
* Allocates a new Cloudlet object. The Cloudlet length, input and output file sizes should be
* greater than or equal to 1. By default this constructor sets the history of this object.
*
* @param cloudletId the unique ID of this Cloudlet
* @param cloudletLength the length or size (in MI) of this cloudlet to be executed in a
* PowerDatacenter
* @param cloudletFileSize the file size (in byte) of this cloudlet <tt>BEFORE</tt> submitting
* to a PowerDatacenter
* @param cloudletOutputSize the file size (in byte) of this cloudlet <tt>AFTER</tt> finish
*