public UsageReport parseAccountingDataFromStdOut()

in src/main/java/com/epam/grid/engine/provider/utils/sge/usage/SgeJobAccountingDataParser.java [54:109]


    public UsageReport parseAccountingDataFromStdOut(final List<String> stdOut) {
        final int numberFooterLines = stdOut.size() % JOB_REPORT_LENGTH;
        if (stdOut.isEmpty() || !(numberFooterLines == 0 || numberFooterLines == FOOTER_LENGTH)) {
            throw new GridEngineException(HttpStatus.INTERNAL_SERVER_ERROR, PARSING_ERROR);
        }

        final JobFilteredUsageReport report = JobFilteredUsageReport.builder()
                .matchingJobIds(new HashSet<>())
                .owners(new HashSet<>())
                .queues(new HashSet<>())
                .hosts(new HashSet<>())
                .parallelEnvs(new HashSet<>())
                .build();

        int wallClock = 0;
        double userTime = 0;
        double systemTime = 0;
        double cpuTime = 0;
        double memory = 0;
        double ioData = 0;
        double ioWaiting = 0;

        for (int i = 1; i < stdOut.size() - numberFooterLines; i += JOB_REPORT_LENGTH) {

            final EnumMap<SgeAccountingHeaders, String> accountingMap =
                    parseJobFilteredEntitiesToMap(stdOut.subList(i, i + JOB_REPORT_LENGTH - 1));

            report.getMatchingJobIds().add(Long.parseLong(accountingMap.get(SgeAccountingHeaders.JOB_ID)));
            report.getOwners().add(accountingMap.get(SgeAccountingHeaders.OWNER));
            report.getQueues().add(accountingMap.get(SgeAccountingHeaders.QUEUE));
            report.getHosts().add(accountingMap.get(SgeAccountingHeaders.HOST));

            wallClock += Integer.parseInt(removeLastChar(accountingMap.get(SgeAccountingHeaders.WALL_CLOCK)));
            userTime += Double.parseDouble(removeLastChar(accountingMap.get(SgeAccountingHeaders.USER_TIME)));
            systemTime += Double.parseDouble(removeLastChar(accountingMap.get(SgeAccountingHeaders.SYSTEM_TIME)));
            cpuTime += Double.parseDouble(removeLastChar(accountingMap.get(SgeAccountingHeaders.CPU_TIME)));
            memory += convertHumanReadableMemoryToGbytes(
                    removeLastChar(accountingMap.get(SgeAccountingHeaders.MEMORY)));
            ioData += convertHumanReadableMemoryToGbytes(accountingMap.get(SgeAccountingHeaders.IO_DATA));
            ioWaiting += Double.parseDouble(removeLastChar(accountingMap.get(SgeAccountingHeaders.IO_WAITING)));

            Optional.ofNullable(accountingMap.get(SgeAccountingHeaders.PARALLEL_ENV))
                    .filter(parallelEnv -> !parallelEnv.equals(NONE))
                    .ifPresent(report.getParallelEnvs()::add);
        }

        report.setWallClock(wallClock);
        report.setUserTime(truncateDoubleValue(userTime, VALUES_PRECISION));
        report.setSystemTime(truncateDoubleValue(systemTime, VALUES_PRECISION));
        report.setCpuTime(truncateDoubleValue(cpuTime, VALUES_PRECISION));
        report.setMemory(truncateDoubleValue(memory, VALUES_PRECISION));
        report.setIoData(truncateDoubleValue(ioData, VALUES_PRECISION));
        report.setIoWaiting(truncateDoubleValue(ioWaiting, VALUES_PRECISION));

        return report;
    }