Example usage for org.apache.commons.io FileUtils ONE_GB

List of usage examples for org.apache.commons.io FileUtils ONE_GB

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils ONE_GB.

Prototype

long ONE_GB

To view the source code for org.apache.commons.io FileUtils ONE_GB.

Click Source Link

Document

The number of bytes in a gigabyte.

Usage

From source file:net.pickapack.util.StorageUnitHelper.java

/**
 * Convert the specified display size to the byte count.
 *
 * @param displaySize the display size//from   w ww. j a  va2s .  c  o m
 * @return the byte count corresponding to the specified display size
 */
public static long displaySizeToByteCount(String displaySize) {
    String[] parts = displaySize.split(" ");
    if (parts.length == 2) {
        double scale = Double.parseDouble(parts[0]);
        String unit = parts[1];

        if (unit.equals("KB")) {
            return (long) (scale * FileUtils.ONE_KB);
        } else if (unit.equals("MB")) {
            return (long) (scale * FileUtils.ONE_MB);
        } else if (unit.equals("GB")) {
            return (long) (scale * FileUtils.ONE_GB);
        } else if (unit.equals("TB")) {
            return (long) (scale * FileUtils.ONE_TB);
        } else if (unit.equals("PB")) {
            return (long) (scale * FileUtils.ONE_PB);
        } else if (unit.equals("EB")) {
            return (long) (scale * FileUtils.ONE_EB);
        }
    }

    throw new IllegalArgumentException();
}

From source file:com.discursive.jccook.io.FileDeleteExample.java

public void start() {
    File file = new File("project.xml");
    String display = FileUtils.byteCountToDisplaySize(file.length());
    System.out.println("project.xml is " + display);
    System.out.println("Byte in KB: " + FileUtils.ONE_GB);

    display = FileUtils.byteCountToDisplaySize(12073741824l);
    System.out.println("size: " + display);
}

From source file:edu.ucsb.eucalyptus.cloud.ws.WalrusAvailabilityEventListener.java

@Override
public void fireEvent(final ClockTick event) {
    if (Bootstrap.isFinished() && Hosts.isCoordinator()) {
        try {//from  w  ww  .  j a va  2 s . c o m

            WalrusInfo wInfo = WalrusInfo.getWalrusInfo();
            long capacity = 0;
            if (wInfo != null)
                capacity = wInfo.getStorageMaxTotalCapacity();

            ListenerRegistry.getInstance()
                    .fireEvent(new ResourceAvailabilityEvent(StorageWalrus,
                            new Availability(capacity, Math.max(0, capacity - (long) Math
                                    .ceil((double) WalrusUtil.countTotalObjectSize() / FileUtils.ONE_GB)))));
        } catch (Exception ex) {
            logger.error(ex, ex);
        }
    }
}

From source file:com.eucalyptus.objectstorage.WalrusAvailabilityEventListener.java

@Override
public void fireEvent(final ClockTick event) {
    if (BootstrapArgs.isCloudController() && Bootstrap.isOperational()) {
        try {//from ww w .j a  v  a 2s .com

            WalrusInfo wInfo = WalrusInfo.getWalrusInfo();
            long capacity = 0;
            if (wInfo != null)
                capacity = wInfo.getStorageMaxTotalCapacity();

            ListenerRegistry.getInstance().fireEvent(new ResourceAvailabilityEvent(StorageWalrus,
                    new Availability(capacity, Math.max(0, capacity - (long) Math
                            .ceil((double) WalrusQuotaUtil.countTotalObjectSize() / FileUtils.ONE_GB)))));
        } catch (Exception ex) {
            logger.error(ex, ex);
        }
    }
}

From source file:fr.paris.lutece.plugins.plu.utils.PluUtils.java

/**
 * Transform a byte size to a readable size including units
 * @param size size in bytes//w  w  w  .  j  a  va 2 s  .  c  o  m
 * @return size in string
 */
public static String formatSize(Long size) {
    String displaySize;

    if (size / FileUtils.ONE_GB > 0) {
        displaySize = String.valueOf(new BigDecimal(size).divide(BD_ONE_GO, BigDecimal.ROUND_CEILING)) + " GO";
    } else if (size / FileUtils.ONE_MB > 0) {
        displaySize = String.valueOf(new BigDecimal(size).divide(BD_ONE_MO, BigDecimal.ROUND_CEILING)) + " MO";
    } else if (size / FileUtils.ONE_KB > 0) {
        displaySize = String.valueOf(new BigDecimal(size).divide(BD_ONE_KO, BigDecimal.ROUND_CEILING)) + " KO";
    } else {
        displaySize = String.valueOf(size) + " octets";
    }
    return displaySize;
}

From source file:com.eucalyptus.objectstorage.ObjectStorageAvailabilityEventListener.java

@Override
public void fireEvent(final ClockTick event) {
    if (BootstrapArgs.isCloudController() && Bootstrap.isOperational()) {
        try {/*from   w  ww .j av  a2  s  . c o m*/
            long capacity = 0;
            capacity = ConfigurationCache.getConfiguration(ObjectStorageGlobalConfiguration.class)
                    .getMax_total_reporting_capacity_gb();

            ListenerRegistry.getInstance().fireEvent(new ResourceAvailabilityEvent(StorageWalrus,
                    new Availability(capacity, Math.max(0, capacity - (long) Math
                            .ceil((double) ObjectStorageQuotaUtil.getTotalObjectSize() / FileUtils.ONE_GB)))));
        } catch (Exception ex) {
            logger.error(ex, ex);
        }
    }
}

From source file:com.linkedin.drelephant.tuning.APIFitnessComputeUtil.java

/**
 * Updates the execution metrics//ww w  . j  a v a2s .  c o m
 * @param completedExecutions List of completed executions
 */
protected void updateExecutionMetrics(List<TuningJobExecution> completedExecutions) {
    logger.debug("Updating execution metrics");
    updateAuthToken();
    for (TuningJobExecution tuningJobExecution : completedExecutions) {
        logger.debug("Completed executions before updating metric: " + Json.toJson(tuningJobExecution));
        try {

            JobExecution jobExecution = tuningJobExecution.jobExecution;
            JobDefinition job = jobExecution.job;

            URL jobExecURL = new URL(new URL(_drElephantURL),
                    String.format("/rest/jobexec?id=%s", URLEncoder.encode(jobExecution.jobExecId)));
            HttpURLConnection conn = (HttpURLConnection) jobExecURL.openConnection();
            JsonNode allApps = _objectMapper.readTree(conn.getInputStream());

            // job id match and tuning enabled
            TuningJobDefinition tuningJobDefinition = TuningJobDefinition.find.select("*")
                    .fetch(TuningJobDefinition.TABLE.job, "*").where()
                    .eq(TuningJobDefinition.TABLE.job + "." + JobDefinition.TABLE.id, job.id)
                    .eq(TuningJobDefinition.TABLE.tuningEnabled, 1).findUnique();

            if (allApps != null && allApps.size() > 0) {
                Long totalExecutionTime = 0L;
                Double totalResourceUsed = 0D;
                Double totalInputBytesInBytes = 0D;

                for (JsonNode app : allApps) {
                    logger.info("Job Execution Update: ApplicationID " + app.get("id").getTextValue());
                    Long executionTime = app.get("finishTime").getLongValue()
                            - app.get("startTime").getLongValue() - app.get("totalDelay").getLongValue();
                    totalExecutionTime += executionTime;
                    totalResourceUsed += app.get("resourceUsed").getDoubleValue();
                    totalInputBytesInBytes += getTotalInputBytes(app.get("id").getTextValue());
                }

                if (totalExecutionTime != 0) {
                    jobExecution.executionTime = totalExecutionTime * 1.0 / (1000 * 60);
                    jobExecution.resourceUsage = totalResourceUsed * 1.0 / (1024 * 3600);
                    jobExecution.inputSizeInBytes = totalInputBytesInBytes;
                    logger.info("Job Execution Update: UpdatedValue " + totalExecutionTime + ":"
                            + totalResourceUsed + ":" + totalInputBytesInBytes);
                }

                logger.debug("Job execution " + jobExecution.resourceUsage);
                logger.debug("Job details: AvgResourceUsage " + tuningJobDefinition.averageResourceUsage
                        + ", allowedMaxResourceUsagePercent: "
                        + tuningJobDefinition.allowedMaxResourceUsagePercent);
                if (jobExecution.executionState.equals(JobExecution.ExecutionState.FAILED)
                        || jobExecution.executionState.equals(JobExecution.ExecutionState.CANCELLED)) {
                    // Todo: Check if the reason of failure is auto tuning and  handle cancelled cases
                    tuningJobExecution.fitness = 3 * tuningJobDefinition.averageResourceUsage
                            * tuningJobDefinition.allowedMaxResourceUsagePercent * FileUtils.ONE_GB
                            / (100.0 * tuningJobDefinition.averageInputSizeInBytes);
                } else if (jobExecution.resourceUsage > (tuningJobDefinition.averageResourceUsage
                        * tuningJobDefinition.allowedMaxResourceUsagePercent / 100.0)) {
                    tuningJobExecution.fitness = 3 * tuningJobDefinition.averageResourceUsage
                            * tuningJobDefinition.allowedMaxResourceUsagePercent * FileUtils.ONE_GB
                            / (100.0 * totalInputBytesInBytes);
                } else {
                    tuningJobExecution.fitness = jobExecution.resourceUsage * FileUtils.ONE_GB
                            / totalInputBytesInBytes;
                }
                tuningJobExecution.paramSetState = ParamSetStatus.FITNESS_COMPUTED;
                jobExecution.update();
                tuningJobExecution.update();

                logger.debug("Completed executions after updating metrics: " + Json.toJson(tuningJobExecution));
            } else {
                if (jobExecution.executionState.equals(JobExecution.ExecutionState.FAILED)
                        || jobExecution.executionState.equals(JobExecution.ExecutionState.CANCELLED)) {
                    // Todo: Check if the reason of failure is auto tuning and  handle cancelled cases
                    tuningJobExecution.fitness = 3 * tuningJobDefinition.averageResourceUsage
                            * tuningJobDefinition.allowedMaxResourceUsagePercent * FileUtils.ONE_GB
                            / (100.0 * tuningJobDefinition.averageInputSizeInBytes);
                    jobExecution.executionTime = 0D;
                    jobExecution.resourceUsage = 0D;
                    jobExecution.inputSizeInBytes = 0D;
                    tuningJobExecution.paramSetState = ParamSetStatus.FITNESS_COMPUTED;
                    jobExecution.update();
                    tuningJobExecution.update();
                }
            }
        } catch (Exception e) {
            logger.error("Error updating fitness of job_exec_id: " + tuningJobExecution.jobExecution.id
                    + "\n Stacktrace: ", e);
        }
    }
    logger.debug("Execution metrics updated");
}

From source file:com.linkedin.drelephant.tuning.AutoTuningAPIHelper.java

/**
 * Applies penalty to the param set corresponding to the given execution
 * @param jobExecId String job execution id/url of the execution whose parameter set has to be penalized
 * Assumption: Best param set will never be penalized
 *//*  w w  w  .  java  2 s .co m*/
private void applyPenalty(String jobExecId) {
    Integer penaltyConstant = 3;
    logger.info("Execution " + jobExecId + " failed/cancelled. Applying penalty");

    TuningJobExecutionParamSet tuningJobExecutionParamSet = TuningJobExecutionParamSet.find.where()
            .eq(TuningJobExecutionParamSet.TABLE.jobExecution + '.' + JobExecution.TABLE.jobExecId, jobExecId)
            .setMaxRows(1).findUnique();

    JobSuggestedParamSet jobSuggestedParamSet = tuningJobExecutionParamSet.jobSuggestedParamSet;
    JobExecution jobExecution = tuningJobExecutionParamSet.jobExecution;
    JobDefinition jobDefinition = jobExecution.job;

    TuningJobDefinition tuningJobDefinition = TuningJobDefinition.find.where()
            .eq(TuningJobDefinition.TABLE.job + '.' + JobDefinition.TABLE.id, jobDefinition.id).findUnique();
    Double averageResourceUsagePerGBInput = tuningJobDefinition.averageResourceUsage * FileUtils.ONE_GB
            / tuningJobDefinition.averageInputSizeInBytes;
    Double maxDesiredResourceUsagePerGBInput = averageResourceUsagePerGBInput
            * tuningJobDefinition.allowedMaxResourceUsagePercent / 100.0;

    jobSuggestedParamSet.fitness = penaltyConstant * maxDesiredResourceUsagePerGBInput;
    jobSuggestedParamSet.paramSetState = ParamSetStatus.FITNESS_COMPUTED;
    jobSuggestedParamSet.fitnessJobExecution = jobExecution;
    jobSuggestedParamSet.update();

    jobExecution.resourceUsage = 0D;
    jobExecution.executionTime = 0D;
    jobExecution.inputSizeInBytes = 1D;
    jobExecution.save();
}

From source file:com.turn.griffin.GriffinModule.java

private long getMaxBlobSizePermitted() {
    return new GriffinRangedIntConfig(PROPERTY_PREFIX + "MaxBlobSizeInGB",
            "Maximum size of the blob (in GB) allowed in Griffin", 2, 1, 10).getValue() * FileUtils.ONE_GB;
}

From source file:com.linkedin.drelephant.tuning.FitnessComputeUtil.java

/**
 * Updates the execution metrics//from   w  w  w . j  a va 2 s  . c  om
 * @param completedExecutions List of completed executions
 */
protected void updateExecutionMetrics(List<TuningJobExecution> completedExecutions) {
    for (TuningJobExecution tuningJobExecution : completedExecutions) {

        logger.info("Updating execution metrics and fitness for execution: "
                + tuningJobExecution.jobExecution.jobExecId);

        try {
            JobExecution jobExecution = tuningJobExecution.jobExecution;
            JobDefinition job = jobExecution.job;

            // job id match and tuning enabled
            TuningJobDefinition tuningJobDefinition = TuningJobDefinition.find.select("*")
                    .fetch(TuningJobDefinition.TABLE.job, "*").where()
                    .eq(TuningJobDefinition.TABLE.job + "." + JobDefinition.TABLE.id, job.id)
                    .eq(TuningJobDefinition.TABLE.tuningEnabled, 1).findUnique();

            List<AppResult> results = AppResult.find.select("*")
                    .fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS, "*")
                    .fetch(AppResult.TABLE.APP_HEURISTIC_RESULTS + "."
                            + AppHeuristicResult.TABLE.APP_HEURISTIC_RESULT_DETAILS, "*")
                    .where().eq(AppResult.TABLE.FLOW_EXEC_ID, jobExecution.flowExecution.flowExecId)
                    .eq(AppResult.TABLE.JOB_EXEC_ID, jobExecution.jobExecId).findList();

            if (results != null && results.size() > 0) {
                Long totalExecutionTime = 0L;
                Double totalResourceUsed = 0D;
                Double totalInputBytesInBytes = 0D;

                for (AppResult appResult : results) {
                    totalResourceUsed += appResult.resourceUsed;
                    totalInputBytesInBytes += getTotalInputBytes(appResult);
                }

                Long totalRunTime = Utils.getTotalRuntime(results);
                Long totalDelay = Utils.getTotalWaittime(results);
                totalExecutionTime = totalRunTime - totalDelay;

                if (totalExecutionTime != 0) {
                    jobExecution.executionTime = totalExecutionTime * 1.0 / (1000 * 60);
                    jobExecution.resourceUsage = totalResourceUsed * 1.0 / (1024 * 3600);
                    jobExecution.inputSizeInBytes = totalInputBytesInBytes;

                    logger.info("Metric Values for execution " + jobExecution.jobExecId + ": Execution time = "
                            + totalExecutionTime + ", Resource usage = " + totalResourceUsed
                            + " and total input size = " + totalInputBytesInBytes);
                }

                if (tuningJobDefinition.averageResourceUsage == null && totalExecutionTime != 0) {
                    tuningJobDefinition.averageResourceUsage = jobExecution.resourceUsage;
                    tuningJobDefinition.averageExecutionTime = jobExecution.executionTime;
                    tuningJobDefinition.averageInputSizeInBytes = jobExecution.inputSizeInBytes.longValue();
                    tuningJobDefinition.update();
                }

                //Compute fitness
                if (jobExecution.executionState.equals(JobExecution.ExecutionState.FAILED)
                        || jobExecution.executionState.equals(JobExecution.ExecutionState.CANCELLED)) {
                    logger.info("Execution " + jobExecution.jobExecId + " failed/cancelled. Applying penalty");
                    // Todo: Check if the reason of failure is auto tuning and  handle cancelled cases
                    tuningJobExecution.fitness = 3 * tuningJobDefinition.averageResourceUsage
                            * tuningJobDefinition.allowedMaxResourceUsagePercent * FileUtils.ONE_GB
                            / (100.0 * tuningJobDefinition.averageInputSizeInBytes);
                } else if (jobExecution.resourceUsage > (
                // Todo: Check execution time constraint as well
                tuningJobDefinition.averageResourceUsage * tuningJobDefinition.allowedMaxResourceUsagePercent
                        / 100.0)) {
                    logger.info(
                            "Execution " + jobExecution.jobExecId + " violates constraint on resource usage");
                    tuningJobExecution.fitness = 3 * tuningJobDefinition.averageResourceUsage
                            * tuningJobDefinition.allowedMaxResourceUsagePercent * FileUtils.ONE_GB
                            / (100.0 * totalInputBytesInBytes);
                } else {
                    tuningJobExecution.fitness = jobExecution.resourceUsage * FileUtils.ONE_GB
                            / totalInputBytesInBytes;
                }
                tuningJobExecution.paramSetState = ParamSetStatus.FITNESS_COMPUTED;
                jobExecution.update();
                tuningJobExecution.update();
            } else {
                if (jobExecution.executionState.equals(JobExecution.ExecutionState.FAILED)
                        || jobExecution.executionState.equals(JobExecution.ExecutionState.CANCELLED)) {
                    // Todo: Check if the reason of failure is auto tuning and  handle cancelled cases
                    tuningJobExecution.fitness = 3 * tuningJobDefinition.averageResourceUsage
                            * tuningJobDefinition.allowedMaxResourceUsagePercent * FileUtils.ONE_GB
                            / (100.0 * tuningJobDefinition.averageInputSizeInBytes);
                    jobExecution.executionTime = 0D;
                    jobExecution.resourceUsage = 0D;
                    jobExecution.inputSizeInBytes = 0D;
                    tuningJobExecution.paramSetState = ParamSetStatus.FITNESS_COMPUTED;
                    jobExecution.update();
                    tuningJobExecution.update();
                }
            }
        } catch (Exception e) {
            logger.error("Error updating fitness of execution: " + tuningJobExecution.jobExecution.id
                    + "\n Stacktrace: ", e);
        }
    }
    logger.info("Execution metrics updated");
}