in src/main/java/com/epam/grid/engine/provider/log/JobLogProviderImpl.java [73:109]
public JobLogInfo getJobLogInfo(final long jobId, final JobLogInfo.Type logType,
final int lines, final boolean fromHead) {
if (lines < 0) {
throw new GridEngineException(HttpStatus.BAD_REQUEST,
String.format("The 'lines' parameter can't be < 0, received value = %d", lines));
}
final Context context = new Context();
context.setVariable("path", getLogFilePath(jobId, logType));
context.setVariable("lines", lines);
context.setVariable("fromHead", fromHead);
final CommandResult resultLogFileInfoCommand = simpleCmdExecutor.execute(
commandCompiler.compileCommand(getProviderType(), GET_LOGFILE_INFO_COMMAND, context));
final CommandResult resultLogLinesCommand = simpleCmdExecutor.execute(
commandCompiler.compileCommand(getProviderType(), GET_LOG_LINES_COMMAND, context));
if (resultLogFileInfoCommand.getExitCode() != 0 || resultLogLinesCommand.getExitCode() != 0) {
throw new GridEngineException(HttpStatus.NOT_FOUND, String.format(CANT_FIND_LOG_FILE, jobId));
}
final String wcCommandResult = resultLogFileInfoCommand.getStdOut().stream()
.findFirst()
.orElseThrow(() -> new GridEngineException(HttpStatus.INTERNAL_SERVER_ERROR,
CANT_PARSE_WC_CMD_RESPONSE))
.trim();
if (!wcCommandResult.matches(WC_COMMAND_REGEX_PATTERN)) {
throw new GridEngineException(HttpStatus.INTERNAL_SERVER_ERROR, CANT_PARSE_WC_CMD_RESPONSE);
}
final String[] splitWcCommandResult = wcCommandResult.split(SPACE);
return JobLogInfo.builder()
.jobId(jobId)
.type(logType)
.lines(resultLogLinesCommand.getStdOut())
.totalCount(Integer.parseInt(splitWcCommandResult[0]))
.bytes(Integer.parseInt(splitWcCommandResult[1]))
.build();
}