Commit ea31eb0e authored by Manoel Campos's avatar Manoel Campos

Improved documentation of classes from package org.cloudbus.cloudsim.util.

parent a2543cff
...@@ -86,7 +86,7 @@ public class Cloudlet { ...@@ -86,7 +86,7 @@ public class Cloudlet {
private int reservationId = -1; private int reservationId = -1;
/** Indicates if transaction history records for this Cloudlet /** Indicates if transaction history records for this Cloudlet
* it to be outputted. */ * is to be outputted. */
private final boolean record; private final boolean record;
/** Stores the operating system line separator. */ /** Stores the operating system line separator. */
...@@ -1015,7 +1015,7 @@ public class Cloudlet { ...@@ -1015,7 +1015,7 @@ public class Cloudlet {
/** /**
* Gets the total length (across all PEs) of this Cloudlet. * Gets the total length (across all PEs) of this Cloudlet.
* It considers the {@link #cloudletLength} of the cloudlet to be execute * It considers the {@link #cloudletLength} of the cloudlet to be executed
* in each Pe and the {@link #numberOfPes}.<br/> * in each Pe and the {@link #numberOfPes}.<br/>
* *
* For example, setting the cloudletLenght as 10000 MI and {@link #numberOfPes} * For example, setting the cloudletLenght as 10000 MI and {@link #numberOfPes}
......
...@@ -12,30 +12,44 @@ import java.util.HashMap; ...@@ -12,30 +12,44 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* The class for measuring the execution time. * Measurement of execution times of CloudSim's methods.
* *
* @author Anton Beloglazov * @author Anton Beloglazov
* @since CloudSim Toolkit 3.0 * @since CloudSim Toolkit 3.0
*/ */
public class ExecutionTimeMeasurer { public class ExecutionTimeMeasurer {
/** The execution times. */ /** A map of execution times where each key
* represents the name of the method/process being its
* execution time computed and each key is the
* time the method/process started (in milliseconds).
* Usually, this name is the method/process name, making
* easy to identify the execution times into the map.
*
* @todo The name of the attribute doesn't match with what it stores.
* It in fact stores the method/process start time,
* no the time it spent executing.
*/
private final static Map<String, Long> executionTimes = new HashMap<String, Long>(); private final static Map<String, Long> executionTimes = new HashMap<String, Long>();
/** /**
* Start. * Start measuring the execution time of a method/process.
* Usually this method has to be called at the first line of the method
* that has to be its execution time measured.
* *
* @param name the name * @param name the name of the method/process being measured.
* @see #executionTimes
*/ */
public static void start(String name) { public static void start(String name) {
getExecutionTimes().put(name, System.currentTimeMillis()); getExecutionTimes().put(name, System.currentTimeMillis());
} }
/** /**
* End. * Finalizes measuring the execution time of a method/process.
* *
* @param name the name * @param name the name of the method/process being measured.
* @return the double * @see #executionTimes
* @return the time the method/process spent in execution (in seconds)
*/ */
public static double end(String name) { public static double end(String name) {
double time = (System.currentTimeMillis() - getExecutionTimes().get(name)) / 1000.0; double time = (System.currentTimeMillis() - getExecutionTimes().get(name)) / 1000.0;
...@@ -44,9 +58,10 @@ public class ExecutionTimeMeasurer { ...@@ -44,9 +58,10 @@ public class ExecutionTimeMeasurer {
} }
/** /**
* Gets the execution times. * Gets map the execution times.
* *
* @return the execution times * @return the execution times map
* @see #executionTimes
*/ */
public static Map<String, Long> getExecutionTimes() { public static Map<String, Long> getExecutionTimes() {
return executionTimes; return executionTimes;
......
...@@ -20,13 +20,14 @@ import org.apache.commons.math3.stat.regression.SimpleRegression; ...@@ -20,13 +20,14 @@ import org.apache.commons.math3.stat.regression.SimpleRegression;
* *
* @author Anton Beloglazov * @author Anton Beloglazov
* @since CloudSim Toolkit 3.0 * @since CloudSim Toolkit 3.0
* @todo Using Java 8 Stream, some methods here can be improved or removed.
*/ */
public class MathUtil { public class MathUtil {
/** /**
* Sums a list of numbers. * Sums a list of numbers.
* *
* @param list the list * @param list the list of numbers
* @return the double * @return the double
*/ */
public static double sum(final List<? extends Number> list) { public static double sum(final List<? extends Number> list) {
...@@ -38,10 +39,12 @@ public class MathUtil { ...@@ -38,10 +39,12 @@ public class MathUtil {
} }
/** /**
* List to array. * Converts a List to array.
* *
* @param list the list * @param list the list of numbers
* @return the double[] * @return the double[]
* @todo The method {@link List#toArray()} could be used directly
* instead of creating this method.
*/ */
public static double[] listToArray(final List<? extends Number> list) { public static double[] listToArray(final List<? extends Number> list) {
double[] array = new double[list.size()]; double[] array = new double[list.size()];
...@@ -52,9 +55,9 @@ public class MathUtil { ...@@ -52,9 +55,9 @@ public class MathUtil {
} }
/** /**
* Gets the median. * Gets the median from a list of numbers.
* *
* @param list the list * @param list the list of numbers
* @return the median * @return the median
*/ */
public static double median(final List<Double> list) { public static double median(final List<Double> list) {
...@@ -62,9 +65,9 @@ public class MathUtil { ...@@ -62,9 +65,9 @@ public class MathUtil {
} }
/** /**
* Gets the median. * Gets the median from an array of numbers.
* *
* @param list the list * @param list the array of numbers
* *
* @return the median * @return the median
*/ */
...@@ -73,11 +76,10 @@ public class MathUtil { ...@@ -73,11 +76,10 @@ public class MathUtil {
} }
/** /**
* Returns descriptive statistics for the list of numbers. * Returns an object to compute descriptive statistics for an list of numbers.
* *
* @param list * @param list the list of numbers. Must not be null.
* - the list of numbers. Must not be null. * @return descriptive statistics for the list of numbers.
* @return - descriptive statistics for the list of numbers.
*/ */
public static DescriptiveStatistics getStatistics(final List<Double> list) { public static DescriptiveStatistics getStatistics(final List<Double> list) {
// Get a DescriptiveStatistics instance // Get a DescriptiveStatistics instance
...@@ -91,10 +93,10 @@ public class MathUtil { ...@@ -91,10 +93,10 @@ public class MathUtil {
} }
/** /**
* Returns descriptive statistics for the array of numbers. * Returns an object to compute descriptive statistics for an array of numbers.
* *
* @param list - the array of numbers. Must not be null. * @param list the array of numbers. Must not be null.
* @return - descriptive statistics for the array of numbers. * @return descriptive statistics for the array of numbers.
*/ */
public static DescriptiveStatistics getStatistics(final double[] list) { public static DescriptiveStatistics getStatistics(final double[] list) {
// Get a DescriptiveStatistics instance // Get a DescriptiveStatistics instance
...@@ -108,9 +110,9 @@ public class MathUtil { ...@@ -108,9 +110,9 @@ public class MathUtil {
} }
/** /**
* Gets the average. * Gets the average from a list of numbers.
* *
* @param list the list * @param list the list of numbers
* *
* @return the average * @return the average
*/ */
...@@ -123,10 +125,10 @@ public class MathUtil { ...@@ -123,10 +125,10 @@ public class MathUtil {
} }
/** /**
* Variance. * Gets the Variance from a list of numbers.
* *
* @param list the list * @param list the list of numbers
* @return the double * @return the variance
*/ */
public static double variance(final List<Double> list) { public static double variance(final List<Double> list) {
long n = 0; long n = 0;
...@@ -145,19 +147,19 @@ public class MathUtil { ...@@ -145,19 +147,19 @@ public class MathUtil {
} }
/** /**
* Gets the standard deviation. * Gets the standard deviation from a list of numbers.
* *
* @param list the list * @param list the list of numbers
* @return the double * @return the standard deviation
*/ */
public static double stDev(final List<Double> list) { public static double stDev(final List<Double> list) {
return Math.sqrt(variance(list)); return Math.sqrt(variance(list));
} }
/** /**
* Gets the mad. * Gets the mad from a array of numbers.
* *
* @param data the data * @param data the array of numbers
* @return the mad * @return the mad
*/ */
public static double mad(final double[] data) { public static double mad(final double[] data) {
...@@ -174,9 +176,9 @@ public class MathUtil { ...@@ -174,9 +176,9 @@ public class MathUtil {
} }
/** /**
* Gets the IQR. * Gets the Interquartile Range (IQR) from an array of numbers.
* *
* @param data the data * @param data the array of numbers
* @return the IQR * @return the IQR
*/ */
public static double iqr(final double[] data) { public static double iqr(final double[] data) {
...@@ -187,10 +189,11 @@ public class MathUtil { ...@@ -187,10 +189,11 @@ public class MathUtil {
} }
/** /**
* Count non zero beginning of the data. * Counts the number of values different of zero at the beginning of
* an array.
* *
* @param data the data * @param data the array of numbers
* @return the int * @return the number of values different of zero at the beginning of the array
*/ */
public static int countNonZeroBeginning(final double[] data) { public static int countNonZeroBeginning(final double[] data) {
int i = data.length - 1; int i = data.length - 1;
...@@ -203,10 +206,10 @@ public class MathUtil { ...@@ -203,10 +206,10 @@ public class MathUtil {
} }
/** /**
* Count shortest row. * Gets the length of the shortest row in a given matrix
* *
* @param data the data * @param data the data matrix
* @return the int * @return the length of the shortest row int he matrix
*/ */
public static int countShortestRow(final double[][] data) { public static int countShortestRow(final double[][] data) {
int minLength = 0; int minLength = 0;
...@@ -219,10 +222,10 @@ public class MathUtil { ...@@ -219,10 +222,10 @@ public class MathUtil {
} }
/** /**
* Trim zero tail. * Trims zeros at the end of an array.
* *
* @param data the data * @param data the data array
* @return the double[] * @return the trimmed array
*/ */
public static double[] trimZeroTail(final double[] data) { public static double[] trimZeroTail(final double[] data) {
return Arrays.copyOfRange(data, 0, countNonZeroBeginning(data)); return Arrays.copyOfRange(data, 0, countNonZeroBeginning(data));
...@@ -231,7 +234,7 @@ public class MathUtil { ...@@ -231,7 +234,7 @@ public class MathUtil {
/** /**
* Gets the loess parameter estimates. * Gets the loess parameter estimates.
* *
* @param y the y * @param y the y array
* @return the loess parameter estimates * @return the loess parameter estimates
*/ */
public static double[] getLoessParameterEstimates(final double[] y) { public static double[] getLoessParameterEstimates(final double[] y) {
...@@ -291,7 +294,7 @@ public class MathUtil { ...@@ -291,7 +294,7 @@ public class MathUtil {
/** /**
* Gets the robust loess parameter estimates. * Gets the robust loess parameter estimates.
* *
* @param y the y * @param y the y array
* @return the robust loess parameter estimates * @return the robust loess parameter estimates
*/ */
public static double[] getRobustLoessParameterEstimates(final double[] y) { public static double[] getRobustLoessParameterEstimates(final double[] y) {
...@@ -318,10 +321,11 @@ public class MathUtil { ...@@ -318,10 +321,11 @@ public class MathUtil {
} }
/** /**
* Gets the tricube weigts. * Gets the tricube weigths.
* *
* @param n the n * @param n the number of weights
* @return the tricube weigts * @return an array of tricube weigths with n elements
* @todo The word "weight" is misspelled in the method name.
*/ */
public static double[] getTricubeWeigts(final int n) { public static double[] getTricubeWeigts(final int n) {
double[] weights = new double[n]; double[] weights = new double[n];
...@@ -340,10 +344,11 @@ public class MathUtil { ...@@ -340,10 +344,11 @@ public class MathUtil {
} }
/** /**
* Gets the tricube bisquare weigts. * Gets the tricube bisquare weigths.
* *
* @param residuals the residuals * @param residuals the residuals array
* @return the tricube bisquare weigts * @return the tricube bisquare weigths
* @todo The word "weight" is misspelled in the method name.
*/ */
public static double[] getTricubeBisquareWeigts(final double[] residuals) { public static double[] getTricubeBisquareWeigts(final double[] residuals) {
int n = residuals.length; int n = residuals.length;
...@@ -363,10 +368,10 @@ public class MathUtil { ...@@ -363,10 +368,10 @@ public class MathUtil {
} }
/** /**
* Abs. * Gets the absolute values of an array of values
* *
* @param data the data * @param data the array of values
* @return the double[] * @return a new array with the absolute value of each element in the given array.
*/ */
public static double[] abs(final double[] data) { public static double[] abs(final double[] data) {
double[] result = new double[data.length]; double[] result = new double[data.length];
......
...@@ -25,474 +25,539 @@ import org.cloudbus.cloudsim.UtilizationModel; ...@@ -25,474 +25,539 @@ import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull; import org.cloudbus.cloudsim.UtilizationModelFull;
/** /**
* This class is responsible for reading resource traces from a file and creating a list of jobs. * This class is responsible for reading resource traces from a file and creating a list of jobs
* <p> * ({@link Cloudlet Cloudlets}).
* <p/>
* <b>NOTE:</b> * <b>NOTE:</b>
* <ul> * <ul>
* <li>This class can only take <tt>one</tt> trace file of the following format: <i>ASCII text, zip, * <li>This class can only take <tt>one</tt> trace file of the following format: <i>ASCII text, zip,
* gz.</i> * gz.</i>
* <li>If you need to load multiple trace files, then you need to create multiple instances of this * <li>If you need to load multiple trace files, then you need to create multiple instances of this
* class <tt>each with a unique * class <tt>each with a unique entity name</tt>.
* entity name</tt>. * <li>If size of the trace file is huge or contains lots of traces, please increase the JVM heap
* <li>If size of the trace file is huge or contains lots of traces please increase the JVM heap
* size accordingly by using <tt>java -Xmx</tt> option when running the simulation. * size accordingly by using <tt>java -Xmx</tt> option when running the simulation.
* <li>The default job file size for sending to and receiving from a resource is * <li>The default job file size for sending to and receiving from a resource is
* {@link gridsim.net.Link#DEFAULT_MTU}. However, you can specify the file size by using * {@link gridsim.net.Link#DEFAULT_MTU}. However, you can specify the file size by using
* {@link #setGridletFileSize(int)}. * {@link #setCloudletFileSize(int)}.
* <li>A job run time is only for 1 PE <tt>not</tt> the total number of allocated PEs. Therefore, a * <li>A job run time is only for 1 PE <tt>not</tt> the total number of allocated PEs. Therefore, a
* Gridlet length is also calculated for 1 PE.<br> * Cloudlet length is also calculated for 1 PE.<br>
* For example, job #1 in the trace has a run time of 100 seconds for 2 processors. This means each * For example, job #1 in the trace has a run time of 100 seconds for 2 processors. This means each
* processor runs job #1 for 100 seconds, if the processors have the same specification. * processor runs job #1 for 100 seconds, if the processors have the same specification.
* </ul> * </ul>
* <p> *
* By default, this class follows the standard workload format as specified in <a * @todo The last item in the list above is not true. The cloudlet length is not
* href="http://www.cs.huji.ac.il/labs/parallel/workload/"> * divided by the number of PEs. If there is more than 1 PE, all PEs run the same
* http://www.cs.huji.ac.il/labs/parallel/workload/</a> <br> * number of MI as specified in the {@link Cloudlet#cloudletLength} attribute.
* However, you can use other format by calling the below methods before running the simulation: * See {@link Cloudlet#setNumberOfPes(int)} method documentation.
*
* <p/>
* By default, this class follows the standard workload format as specified in
* <a href="http://www.cs.huji.ac.il/labs/parallel/workload/">
* http://www.cs.huji.ac.il/labs/parallel/workload/</a> <br/>
* However, you can use other format by calling the methods below before running the simulation:
* <ul> * <ul>
* <li> {@link #setComment(String)} * <li> {@link #setComment(String)}
* <li> {@link #setField(int, int, int, int, int)} * <li> {@link #setField(int, int, int, int, int)}
* </ul> * </ul>
* *
* @author Anthony Sulistio and Marcos Dias de Assuncao * @author Anthony Sulistio
* @author Marcos Dias de Assuncao
* @since 5.0 * @since 5.0
* *
* @see Workload * @see Workload
*/ */
public class WorkloadFileReader implements WorkloadModel { public class WorkloadFileReader implements WorkloadModel {
/**
private final File file; // file name * Trace file name.
*/
private final int rating; // a PE rating private final File file;
private ArrayList<Cloudlet> jobs = null; // a list for getting all the /**
* The Cloudlet's PE rating (in MIPS), considering that all PEs of a Cloudlet
// Gridlets * have the same rate.
*/
// using Standard Workload Format private final int rating;
private int JOB_NUM = 1 - 1; // job number
/**
private int SUBMIT_TIME = 2 - 1; // submit time of a Gridlet * List of Cloudlets created from the trace {@link #file}.
*/
private final int RUN_TIME = 4 - 1; // running time of a Gridlet private ArrayList<Cloudlet> jobs = null;
private final int NUM_PROC = 5 - 1; // number of processors needed for a
/* Index of fields from the Standard Workload Format. */
// Gridlet
private int REQ_NUM_PROC = 8 - 1; // required number of processors /**
* Field index of job number.
private int REQ_RUN_TIME = 9 - 1; // required running time */
private int JOB_NUM = 1 - 1;
private final int USER_ID = 12 - 1; // if of user who submitted the job
/**
private final int GROUP_ID = 13 - 1; // if of group of the user who * Field index of submit time of a job.
*/
// submitted the private int SUBMIT_TIME = 2 - 1;
// job
private int MAX_FIELD = 18; // max number of field in the trace file /**
* Field index of running time of a job.
private String COMMENT = ";"; // a string that denotes the start of a */
private final int RUN_TIME = 4 - 1;
// comment
private static final int IRRELEVANT = -1; // irrelevant number /**
* Field index of number of processors needed for a job.
private String[] fieldArray = null; // a temp array storing all the fields */
private final int NUM_PROC = 5 - 1;
/**
* Create a new {@link WorkloadFileReader} object. /**
* * Field index of required number of processors.
* @param fileName the workload trace filename in one of the following format: <i>ASCII text, */
* zip, gz.</i> private int REQ_NUM_PROC = 8 - 1;
* @param rating the resource's PE rating
* @throws FileNotFoundException /**
* @throws IllegalArgumentException This happens for the following conditions: * Field index of required running time.
* <ul> */
* <li>the workload trace file name is null or empty private int REQ_RUN_TIME = 9 - 1;
* <li>the resource PE rating <= 0
* </ul> /**
* @pre fileName != null * Field index of user who submitted the job.
* @pre rating > 0 */
* @post $none private final int USER_ID = 12 - 1;
*/
public WorkloadFileReader(final String fileName, final int rating) throws FileNotFoundException { /**
if (fileName == null || fileName.length() == 0) { * Field index of group of the user who submitted the job.
throw new IllegalArgumentException("Invalid trace file name."); */
} else if (rating <= 0) { private final int GROUP_ID = 13 - 1;
throw new IllegalArgumentException("Resource PE rating must be > 0.");
} /**
* Max number of fields in the trace file.
file = new File(fileName); */
if (!file.exists()) { private int MAX_FIELD = 18;
throw new FileNotFoundException("Workload trace " + fileName + " does not exist");
} /**
* A string that denotes the start of a comment.
this.rating = rating; */
} private String COMMENT = ";";
/** /**
* Reads job information from a given file. * If the field index of the job number ({@link #JOB_NUM}) is equals
* * to this constant, it means the number of the job doesn't have to be
* @return the list of gridlets read from the file; <code>null</code> in case of failure. * gotten from the trace file, but has to be generated by this workload generator
*/ * class.
@Override */
public ArrayList<Cloudlet> generateWorkload() { private static final int IRRELEVANT = -1;
if (jobs == null) {
jobs = new ArrayList<Cloudlet>(); /**
* A temp array storing all the fields read from a line of the trace file.
// create a temp array */
fieldArray = new String[MAX_FIELD]; private String[] fieldArray = null;
try { /**
if (file.getName().endsWith(".gz")) { * Create a new WorkloadFileReader object.
readGZIPFile(file); *
} else if (file.getName().endsWith(".zip")) { * @param fileName the workload trace filename in one of the following formats:
readZipFile(file); * <i>ASCII text, zip, gz.</i>
} else { * @param rating the cloudlet's PE rating (in MIPS), considering that all PEs
readFile(file); * of a cloudlet have the same rate
} * @throws FileNotFoundException
} catch (final FileNotFoundException e) { * @throws IllegalArgumentException This happens for the following conditions:
} catch (final IOException e) { * <ul>
} * <li>the workload trace file name is null or empty
} * <li>the resource PE rating <= 0
* </ul>
return jobs; * @pre fileName != null
} * @pre rating > 0
* @post $none
/** */
* Identifies the start of a comment line. public WorkloadFileReader(final String fileName, final int rating) throws FileNotFoundException {
* if (fileName == null || fileName.length() == 0) {
* @param cmt a character that denotes the start of a comment, e.g. ";" or "#" throw new IllegalArgumentException("Invalid trace file name.");
* @return <code>true</code> if it is successful, <code>false</code> otherwise } else if (rating <= 0) {
* @pre comment != null throw new IllegalArgumentException("Resource PE rating must be > 0.");
* @post $none }
*/
public boolean setComment(final String cmt) { file = new File(fileName);
boolean success = false; if (!file.exists()) {
if (cmt != null && cmt.length() > 0) { throw new FileNotFoundException("Workload trace " + fileName + " does not exist");
COMMENT = cmt; }
success = true;
} this.rating = rating;
return success; }
}
/**
/** * Reads job information from a trace file and generates the respective cloudlets.
* Tells this class what to look in the trace file. This method should be called before the *
* start of the simulation. * @return the list of cloudlets read from the file; <code>null</code> in case of failure.
* <p> * @see #file
* By default, this class follows the standard workload format as specified in <a */
* href="http://www.cs.huji.ac.il/labs/parallel/workload/"> @Override
* http://www.cs.huji.ac.il/labs/parallel/workload/</a> <br> public ArrayList<Cloudlet> generateWorkload() {
* However, you can use other format by calling this method. if (jobs == null) {
* <p> jobs = new ArrayList<Cloudlet>();
* The parameters must be a positive integer number starting from 1. A special case is where
* <tt>jobNum == -1</tt>, meaning the job or gridlet ID starts at 1. // create a temp array
* fieldArray = new String[MAX_FIELD];
* @param maxField max. number of field/column in one row
* @param jobNum field/column number for locating the job ID try {
* @param submitTime field/column number for locating the job submit time /*@todo It would be implemented
* @param runTime field/column number for locating the job run time using specific classes to avoid using ifs.
* @param numProc field/column number for locating the number of PEs required to run a job If a new format is included, the code has to be
* @return <code>true</code> if successful, <code>false</code> otherwise changed to include another if*/
* @throws IllegalArgumentException if any of the arguments are not within the acceptable ranges if (file.getName().endsWith(".gz")) {
* @pre maxField > 0 readGZIPFile(file);
* @pre submitTime > 0 } else if (file.getName().endsWith(".zip")) {
* @pre runTime > 0 readZipFile(file);
* @pre numProc > 0 } else {
* @post $none readFile(file);
*/ }
public boolean setField( } catch (final FileNotFoundException e) {
final int maxField, } catch (final IOException e) {
final int jobNum, }
final int submitTime, }
final int runTime,
final int numProc) { return jobs;
// need to subtract by 1 since array starts at 0. }
if (jobNum > 0) {
JOB_NUM = jobNum - 1; /**
} else if (jobNum == 0) { * Sets the string that identifies the start of a comment line.
throw new IllegalArgumentException("Invalid job number field."); *
} else { * @param cmt a character that denotes the start of a comment, e.g. ";" or "#"
JOB_NUM = -1; * @return <code>true</code> if it is successful, <code>false</code> otherwise
} * @pre comment != null
* @post $none
// get the max. number of field */
if (maxField > 0) { public boolean setComment(final String cmt) {
MAX_FIELD = maxField; boolean success = false;
} else { if (cmt != null && cmt.length() > 0) {
throw new IllegalArgumentException("Invalid max. number of field."); COMMENT = cmt;
} success = true;
}
// get the submit time field return success;
if (submitTime > 0) { }
SUBMIT_TIME = submitTime - 1;
} else { /**
throw new IllegalArgumentException("Invalid submit time field."); * Tells this class what to look in the trace file. This method should be called before the
} * start of the simulation.
* <p/>
// get the run time field * By default, this class follows the standard workload format as specified in <a
if (runTime > 0) { * href="http://www.cs.huji.ac.il/labs/parallel/workload/">
REQ_RUN_TIME = runTime - 1; * http://www.cs.huji.ac.il/labs/parallel/workload/</a> <br>
} else { * However, you can use other format by calling this method.
throw new IllegalArgumentException("Invalid run time field."); * <p/>
} * The parameters must be a positive integer number starting from 1. A special case is where
* <tt>jobNum == {@link #IRRELEVANT}</tt>, meaning the job or cloudlet ID will be generate
// get the number of processors field * by the Workload class, instead of reading from the trace file.
if (numProc > 0) { *
REQ_NUM_PROC = numProc - 1; * @param maxField max. number of field/column in one row
} else { * @param jobNum field/column number for locating the job ID
throw new IllegalArgumentException("Invalid number of processors field."); * @param submitTime field/column number for locating the job submit time
} * @param runTime field/column number for locating the job run time
* @param numProc field/column number for locating the number of PEs required to run a job
return true; * @return <code>true</code> if successful, <code>false</code> otherwise
} * @throws IllegalArgumentException if any of the arguments are not within the acceptable ranges
* @pre maxField > 0
// ------------------- PRIVATE METHODS ------------------- * @pre submitTime > 0
* @pre runTime > 0
/** * @pre numProc > 0
* Creates a Gridlet with the given information and adds to the list * @post $none
* */
* @param id a Gridlet ID public boolean setField(
* @param submitTime Gridlet's submit time final int maxField,
* @param runTime Gridlet's run time final int jobNum,
* @param numProc number of processors final int submitTime,
* @param reqRunTime user estimated run time final int runTime,
* @param userID user id final int numProc) {
* @param groupID user's group id // need to subtract by 1 since array starts at 0.
* @pre id >= 0 if (jobNum > 0) {
* @pre submitTime >= 0 JOB_NUM = jobNum - 1;
* @pre runTime >= 0 } else if (jobNum == 0) {
* @pre numProc > 0 throw new IllegalArgumentException("Invalid job number field.");
* @post $none } else {
*/ JOB_NUM = -1;
private void createJob( }
final int id,
final long submitTime, // get the max. number of field
final int runTime, if (maxField > 0) {
final int numProc, MAX_FIELD = maxField;
final int reqRunTime, } else {
final int userID, throw new IllegalArgumentException("Invalid max. number of field.");
final int groupID) { }
// create the cloudlet
final int len = runTime * rating; // get the submit time field
UtilizationModel utilizationModel = new UtilizationModelFull(); if (submitTime > 0) {
final Cloudlet wgl = new Cloudlet( SUBMIT_TIME = submitTime - 1;
id, } else {
len, throw new IllegalArgumentException("Invalid submit time field.");
numProc, }
0,
0, // get the run time field
utilizationModel, if (runTime > 0) {
utilizationModel, REQ_RUN_TIME = runTime - 1;
utilizationModel); } else {
jobs.add(wgl); throw new IllegalArgumentException("Invalid run time field.");
} }
/** // get the number of processors field
* Extracts relevant information from a given array if (numProc > 0) {
* REQ_NUM_PROC = numProc - 1;
* @param array an array of String } else {
* @param line a line number throw new IllegalArgumentException("Invalid number of processors field.");
* @pre array != null }
* @pre line > 0
*/ return true;
private void extractField(final String[] array, final int line) { }
try {
Integer obj = null; // ------------------- PRIVATE METHODS -------------------
// get the job number /**
int id = 0; * Creates a Cloudlet with the given information and adds to the list of {@link #jobs}.
if (JOB_NUM == IRRELEVANT) { *
id = jobs.size() + 1; * @param id a Cloudlet ID
} else { * @param submitTime Cloudlet's submit time
obj = new Integer(array[JOB_NUM].trim()); * @param runTime The number of seconds the Cloudlet has to run. Considering that
id = obj.intValue(); * and the {@link #rating}, the {@link Cloudlet#cloudletLength} is computed.
} * @param numProc number of Cloudlet's PEs
* @param reqRunTime user estimated run time
// get the submit time * (@todo the parameter is not being used and it is not clear what it is)
final Long l = new Long(array[SUBMIT_TIME].trim()); * @param userID user id
final long submitTime = l.intValue(); * @param groupID user's group id
* @pre id >= 0
// get the user estimated run time * @pre submitTime >= 0
obj = new Integer(array[REQ_RUN_TIME].trim()); * @pre runTime >= 0
final int reqRunTime = obj.intValue(); * @pre numProc > 0
* @post $none
// if the required run time field is ignored, then use * @see #rating
// the actual run time */
obj = new Integer(array[RUN_TIME].trim()); private void createJob(
int runTime = obj.intValue(); final int id,
final long submitTime,
final int userID = new Integer(array[USER_ID].trim()).intValue(); final int runTime,
final int groupID = new Integer(array[GROUP_ID].trim()).intValue(); final int numProc,
final int reqRunTime,
// according to the SWF manual, runtime of 0 is possible due final int userID,
// to rounding down. E.g. runtime is 0.4 seconds -> runtime = 0 final int groupID) {
if (runTime <= 0) { // create the cloudlet
runTime = 1; // change to 1 second final int len = runTime * rating;
} UtilizationModel utilizationModel = new UtilizationModelFull();
final Cloudlet wgl = new Cloudlet(
// get the number of allocated processors id,
obj = new Integer(array[REQ_NUM_PROC].trim()); len,
int numProc = obj.intValue(); numProc,
0,
// if the required num of allocated processors field is ignored 0,
// or zero, then use the actual field utilizationModel,
if (numProc == IRRELEVANT || numProc == 0) { utilizationModel,
obj = new Integer(array[NUM_PROC].trim()); utilizationModel);
numProc = obj.intValue(); jobs.add(wgl);
} }
// finally, check if the num of PEs required is valid or not /**
if (numProc <= 0) { * Extracts relevant information from a given array of fields,
numProc = 1; * representing a line from the trace file, and create a cloudlet
} * using this information.
createJob(id, submitTime, runTime, numProc, reqRunTime, userID, groupID); *
} catch (final Exception e) { * @param array the array of fields generated from a line of the trace file.
* @param line the line number
} * @pre array != null
} * @pre line > 0
* @todo The name of the method doesn't describe what it in fact does.
/** */
* Breaks a line of string into many fields. private void extractField(final String[] array, final int line) {
* try {
* @param line a line of string Integer obj = null;
* @param lineNum a line number
* @pre line != null // get the job number
* @pre lineNum > 0 int id = 0;
* @post $none if (JOB_NUM == IRRELEVANT) {
*/ id = jobs.size() + 1;
private void parseValue(final String line, final int lineNum) { } else {
// skip a comment line obj = new Integer(array[JOB_NUM].trim());
if (line.startsWith(COMMENT)) { id = obj.intValue();
return; }
}
// get the submit time
final String[] sp = line.split("\\s+"); // split the fields based on a final Long l = new Long(array[SUBMIT_TIME].trim());
// space final long submitTime = l.intValue();
int len = 0; // length of a string
int index = 0; // the index of an array // get the user estimated run time
obj = new Integer(array[REQ_RUN_TIME].trim());
// check for each field in the array final int reqRunTime = obj.intValue();
for (final String elem : sp) {
len = elem.length(); // get the length of a string // if the required run time field is ignored, then use
// the actual run time
// if it is empty then ignore obj = new Integer(array[RUN_TIME].trim());
if (len == 0) { int runTime = obj.intValue();
continue;
} final int userID = new Integer(array[USER_ID].trim()).intValue();
fieldArray[index] = elem; final int groupID = new Integer(array[GROUP_ID].trim()).intValue();
index++;
} // according to the SWF manual, runtime of 0 is possible due
// to rounding down. E.g. runtime is 0.4 seconds -> runtime = 0
if (index == MAX_FIELD) { if (runTime <= 0) {
extractField(fieldArray, lineNum); runTime = 1; // change to 1 second
} }
}
// get the number of allocated processors
/** obj = new Integer(array[REQ_NUM_PROC].trim());
* Reads a text file one line at the time int numProc = obj.intValue();
*
* @param fl a file name // if the required num of allocated processors field is ignored
* @return <code>true</code> if successful, <code>false</code> otherwise. // or zero, then use the actual field
* @throws IOException if the there was any error reading the file if (numProc == IRRELEVANT || numProc == 0) {
* @throws FileNotFoundException if the file was not found obj = new Integer(array[NUM_PROC].trim());
*/ numProc = obj.intValue();
private boolean readFile(final File fl) throws IOException, FileNotFoundException { }
boolean success = false;
BufferedReader reader = null; // finally, check if the num of PEs required is valid or not
try { if (numProc <= 0) {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(fl))); numProc = 1;
}
// read one line at the time createJob(id, submitTime, runTime, numProc, reqRunTime, userID, groupID);
int line = 1; } catch (final Exception e) {
String readLine = null;
while (reader.ready() && (readLine = reader.readLine()) != null) { }
parseValue(readLine, line); }
line++;
} /**
* Breaks a line from the trace file into many fields into the
reader.close(); * {@link #fieldArray}.
success = true; *
} finally { * @param line a line from the trace file
if (reader != null) { * @param lineNum the line number
reader.close(); * @pre line != null
} * @pre lineNum > 0
} * @post $none
*/
return success; private void parseValue(final String line, final int lineNum) {
} // skip a comment line
if (line.startsWith(COMMENT)) {
/** return;
* Reads a gzip file one line at the time }
*
* @param fl a gzip file name final String[] sp = line.split("\\s+"); // split the fields based on a
* @return <code>true</code> if successful; <code>false</code> otherwise. // space
* @throws IOException if the there was any error reading the file int len = 0; // length of a string
* @throws FileNotFoundException if the file was not found int index = 0; // the index of an array
*/
private boolean readGZIPFile(final File fl) throws IOException, FileNotFoundException { // check for each field in the array
boolean success = false; for (final String elem : sp) {
BufferedReader reader = null; len = elem.length(); // get the length of a string
try {
reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(fl)))); // if it is empty then ignore
if (len == 0) {
// read one line at the time continue;
int line = 1; }
String readLine = null; fieldArray[index] = elem;
while (reader.ready() && (readLine = reader.readLine()) != null) { index++;
parseValue(readLine, line); }
line++;
} if (index == MAX_FIELD) {
extractField(fieldArray, lineNum);
reader.close(); }
success = true; }
} finally {
if (reader != null) { /**
reader.close(); * Reads traces from a text file, one line at a time.
} *
} * @param fl a file name
* @return <code>true</code> if successful, <code>false</code> otherwise.
return success; * @throws IOException if the there was any error reading the file
} * @throws FileNotFoundException if the file was not found
*/
/** private boolean readFile(final File fl) throws IOException, FileNotFoundException {
* Reads a Zip file. boolean success = false;
* BufferedReader reader = null;
* @param fl a zip file name try {
* @return <code>true</code> if reading a file is successful; <code>false</code> otherwise. reader = new BufferedReader(new InputStreamReader(new FileInputStream(fl)));
* @throws IOException if the there was any error reading the file
*/ // read one line at the time
private boolean readZipFile(final File fl) throws IOException { int line = 1;
boolean success = false; String readLine = null;
ZipFile zipFile = null; while (reader.ready() && (readLine = reader.readLine()) != null) {
try { parseValue(readLine, line);
BufferedReader reader = null; line++;
}
// ZipFile offers an Enumeration of all the files in the file
zipFile = new ZipFile(fl); reader.close();
final Enumeration<? extends ZipEntry> e = zipFile.entries(); success = true;
while (e.hasMoreElements()) { } finally {
success = false; // reset the value again if (reader != null) {
final ZipEntry zipEntry = e.nextElement(); reader.close();
}
reader = new BufferedReader(new InputStreamReader(zipFile.getInputStream(zipEntry))); }
// read one line at the time return success;
int line = 1; }
String readLine = null;
while (reader.ready() && (readLine = reader.readLine()) != null) { /**
parseValue(readLine, line); * Reads traces from a gzip file, one line at a time.
line++; *
} * @param fl a gzip file name
* @return <code>true</code> if successful; <code>false</code> otherwise.
reader.close(); * @throws IOException if the there was any error reading the file
success = true; * @throws FileNotFoundException if the file was not found
} */
} finally { private boolean readGZIPFile(final File fl) throws IOException, FileNotFoundException {
if (zipFile != null) { boolean success = false;
zipFile.close(); BufferedReader reader = null;
} try {
} reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(fl))));
return success; // read one line at the time
} int line = 1;
String readLine = null;
while (reader.ready() && (readLine = reader.readLine()) != null) {
parseValue(readLine, line);
line++;
}
reader.close();
success = true;
} finally {
if (reader != null) {
reader.close();
}
}
return success;
}
/**
* Reads traces from a Zip file, one line at a time.
*
* @param fl a zip file name
* @return <code>true</code> if reading a file is successful; <code>false</code> otherwise.
* @throws IOException if the there was any error reading the file
*/
private boolean readZipFile(final File fl) throws IOException {
boolean success = false;
ZipFile zipFile = null;
try {
BufferedReader reader = null;
// ZipFile offers an Enumeration of all the files in the file
zipFile = new ZipFile(fl);
final Enumeration<? extends ZipEntry> e = zipFile.entries();
while (e.hasMoreElements()) {
success = false; // reset the value again
final ZipEntry zipEntry = e.nextElement();
reader = new BufferedReader(new InputStreamReader(zipFile.getInputStream(zipEntry)));
// read one line at the time
int line = 1;
String readLine = null;
while (reader.ready() && (readLine = reader.readLine()) != null) {
parseValue(readLine, line);
line++;
}
reader.close();
success = true;
}
} finally {
if (zipFile != null) {
zipFile.close();
}
}
return success;
}
} }
...@@ -13,8 +13,8 @@ import java.util.List; ...@@ -13,8 +13,8 @@ import java.util.List;
import org.cloudbus.cloudsim.Cloudlet; import org.cloudbus.cloudsim.Cloudlet;
/** /**
* This interface defines what a workload model should provide. A workload model generates a list of * Defines what a workload model should provide. A workload model generates a list of
* jobs that can be dispatched to a resource by {@link Workload}. * jobs ({@link Cloudlet Cloudlets}) that can be dispatched to a resource by {@link Workload}.
* *
* @author Marcos Dias de Assuncao * @author Marcos Dias de Assuncao
* @since 5.0 * @since 5.0
...@@ -25,9 +25,9 @@ import org.cloudbus.cloudsim.Cloudlet; ...@@ -25,9 +25,9 @@ import org.cloudbus.cloudsim.Cloudlet;
public interface WorkloadModel { public interface WorkloadModel {
/** /**
* Returns a list with the jobs generated by the workload. * Generates a list of jobs to be executed ({@link Cloudlet Cloudlets}).
* *
* @return a list with the jobs generated by the workload. * @return a list with the jobs generated by the workload or null in case of failure.
*/ */
List<Cloudlet> generateWorkload(); List<Cloudlet> generateWorkload();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment