/** * Reads traces from a text file, then creates a Cloudlet for each line read. * * @param inputStream a {@link InputStream} to read the file * @param processParsedLineFunction a {@link Function} that receives each parsed line as an array * and performs an operation over it, returning true if the operation was executed * @return <code>true</code> if successful, <code>false</code> otherwise. * @throws IOException if the there was any error reading the file */ protected void readTextFile(final InputStream inputStream, final Function<String[], Boolean> processParsedLineFunction) throws IOException { readFile(inputStream, processParsedLineFunction); }
/** * Gets the utilization estimates. * * @param utilizationHistoryReversed the utilization history reversed * @return the utilization estimates */ @Override protected double[] getParameterEstimates(double[] utilizationHistoryReversed) { return MathUtil.getRobustLoessParameterEstimates(utilizationHistoryReversed); }
/** * Gets the start time converted to seconds. * @param reader the reader for the trace file * @return */ @Override public Double getValue(final GoogleTaskUsageTraceReader reader) { return Conversion.microToSeconds(reader.getFieldDoubleValue(this)); } },
@Override protected List<Cloudlet> createCloudlets() { final SwfWorkloadFileReader reader = SwfWorkloadFileReader.getInstance("METACENTRUM-2009-2.swf", 1); reader.setMaxLinesToRead(70); return reader.generateWorkload(); }
/** * Converts a value in bytes to Megabites (Mb) * @param bytes the value in bytes * @return the value in Megabites (Mb) */ public static double bytesToMegaBits(final double bytes){ return bytesToBits(bytesToMegaBytes(bytes)); }
/** * Gets utilization estimates. * * @param utilizationHistoryReversed the utilization history in reverse order * @return the utilization estimates */ protected double[] getParameterEstimates(double[] utilizationHistoryReversed) { return MathUtil.getLoessParameterEstimates(utilizationHistoryReversed); }
/** * Gets the median from a list of numbers. * * @param list the list of numbers * @return the median */ public static double median(final List<Double> list) { return getStatistics(list).getPercentile(50); }
/** * Gets a {@link SwfWorkloadFileReader} instance from a workload file * inside the <b>application's resource directory</b>. * Use the available constructors if you want to load a file outside the resource directory. * * @param fileName the workload trace <b>relative file name</b> in one of the following formats: <i>ASCII text, zip, gz.</i> * @param mips the MIPS capacity of the PEs from the VM where each created Cloudlet is supposed to run. * Considering the workload reader provides the run time for each * application registered inside the reader, the MIPS value will be used * to compute the {@link Cloudlet#getLength() length of the Cloudlet (in MI)} * so that it's expected to execute, inside the VM with the given MIPS capacity, * for the same time as specified into the workload reader. * @throws IllegalArgumentException when the workload trace file name is null or empty; or the resource PE mips <= 0 * @throws UncheckedIOException when the file cannot be accessed (such as when it doesn't exist) */ public static SwfWorkloadFileReader getInstance(final String fileName, final int mips) { final InputStream reader = ResourceLoader.getInputStream(fileName, SwfWorkloadFileReader.class); return new SwfWorkloadFileReader(fileName, reader, mips); }
/** * Trims zeros at the end of an array. * * @param data the data array * @return the trimmed array */ public static double[] trimZeroTail(final double[] data) { return Arrays.copyOfRange(data, 0, countNonZeroBeginning(data)); }
/** * Converts any value in tera to mega, * doesn't matter if it's terabits or terabytes. * * @param tera the value in terabits or terabytes * @return the value in megabits or megabytes (according to the input value) */ public static double teraToMega(final double tera){ return teraToGiga(tera) * KILO; }
/** * Checks if two double numbers are equals, considering a precision error or 0.01. * That is, if the different between the two numbers are lower or equal to 0.01, they are considered equal. * @param first the first number to check * @param second the second number to check * @return true if the numbers are equal considering the precision error */ public static boolean same(final double first, final double second){ return same(first,second, 0.01); }
/** * Converts any value in microseconds (μ) to seconds. * <p>The existing {@link java.util.concurrent.TimeUnit} and {@link java.time.Duration} classes * don't provide the double precision required here.</p> * * @param micro the value in microseconds (μ) * @return the value in seconds */ public static double microToSeconds(final double micro) { return microToMilli(micro)/1000.0; } }
/** * Gets the time to transfer a file (in MBytes) * according to a given transfer speed (in Mbits/sec). * * @param fileSize the size of the file to compute the transfer time (in MBytes) * @param speed the speed (in MBits/sec) to compute the time to transfer the file * @return the transfer time in seconds */ protected final double getTransferTime(final int fileSize, final double speed){ return Conversion.bytesToBits(fileSize)/speed; }
/** * Instantiates a new PlanetLab resource utilization model with variable * utilization samples from a workload file. * * @param workloadFilePath the path of a PlanetLab Datacenter workload file. * @param schedulingInterval the time interval in which precise utilization can be got from the file * @param dataSamples number of samples to read from the workload file * @throws NumberFormatException the number format exception * @see #getSchedulingInterval() */ public UtilizationModelPlanetLab(final String workloadFilePath, final double schedulingInterval, final int dataSamples) throws NumberFormatException { this(ResourceLoader.getFileReader(workloadFilePath), schedulingInterval, dataSamples); }
/** * Gets the utilization estimates. * * @param reversedUsageHistory the utilization history in reverse order * @return the utilization estimates */ @Override protected double[] getParameterEstimates(final double[] reversedUsageHistory) { return MathUtil.getRobustLoessParameterEstimates(reversedUsageHistory); }
/** * Gets utilization estimates. * * @param utilizationHistoryReversed the utilization history in reverse order * @return the utilization estimates */ protected double[] getParameterEstimates(final double... utilizationHistoryReversed) { return MathUtil.getLoessParameterEstimates(utilizationHistoryReversed); }
/** * Gets the median from an array of numbers. * * @param list the array of numbers * * @return the median */ public static double median(final double[] list) { return getStatistics(list).getPercentile(50); }
/** * Gets the timestamp converted to milliseconds. * @param reader the reader for the trace file * @return */ @Override public Double getValue(final GoogleMachineEventsTraceReader reader) { return Conversion.microToSeconds(reader.getFieldDoubleValue(this)); } },
/** * Gets the timestamp converted to seconds. * @param reader the reader for the trace file * @return */ @Override public Double getValue(final GoogleTaskEventsTraceReader reader) { return Conversion.microToSeconds(reader.getFieldDoubleValue(this)); } },
/** * Gets the end time converted to seconds. * @param reader the reader for the trace file * @return */ @Override public Double getValue(final GoogleTaskUsageTraceReader reader) { return Conversion.microToSeconds(reader.getFieldDoubleValue(this)); } },