public boolean hasFailure() { for (JobActionResult result : results) { if (result.hasFailure()) { return true; } } return false; } }
public static JobActionResult timeoutFailure(String command, ZonedDateTime createdAt) { return new JobActionResult(command, null, null, createdAt, ZonedDateTime.now(), "Timed out"); }
public void addResult(JobActionResult result) { this.results.add(result); this.updatedAt = ZonedDateTime.now(); long duration = getUpdatedAt().toInstant().getEpochSecond() - getCreatedAt().toInstant().getEpochSecond(); if (result.isFailure()) { this.summary = String.format("Action %s of %s failed (%s seconds)", this.results.size(), actionCount, duration); } else { this.summary = String.format("Processed %s of %s actions (%s seconds)", this.results.size(), actionCount, duration); } }
result = JobActionResult.finished(command, startedAt, exitValue, out, err); result = JobActionResult.timeoutFailure(command, startedAt); result = JobActionResult.fail(command, startedAt, ex, out, err);
if (action.getRegex() == null) { return JobActionResult.finished(command, startedAt, body); } else { return JobActionResult.finished(command, startedAt, text); } else { err += "Regular expression match failed\n"; return JobActionResult.timeoutFailure(command, startedAt, body, err);
private JobActionResult processAction(Application app, JobExecutionRequestEntity request, JobAction action) throws Exception { log.info(String.format("Executing action %s for request %s", action.getLabel(), request.getJobExecutionRequestId())); ActionType actionType = action.getActionType(); JobActionExecutor executor = executors.get(actionType); if (executor == null) { String msg = String.format("The action type \"%s\" is not supported.", actionType); throw new UnsupportedOperationException(msg); } JobActionResult result; ZonedDateTime startedAt = ZonedDateTime.now(); try { result = executor.execute(request, action, startedAt); } catch (Exception ex) { log.error("Unhandled exception while processing action", ex); result = JobActionResult.fail(action.getLabel(), startedAt, ex, null, null); } request.addResult(result); jobExecutionRequestStore.update(request); return result; } }
result = JobActionResult.finished(command, startedAt, exitValue, out, err); result = JobActionResult.timeoutFailure(command, startedAt); result = JobActionResult.fail(command, startedAt, ex, out, err);
if (action.getRegex() == null) { return JobActionResult.finished(command, startedAt, body); } else { return JobActionResult.finished(command, startedAt, text); } else { err += "Regular expression match failed\n"; return JobActionResult.timeoutFailure(command, startedAt, body, err);
private JobActionResult processAction(Application app, JobExecutionRequestEntity request, JobAction action) throws Exception { log.info(String.format("Executing action %s for request %s", action.getLabel(), request.getJobExecutionRequestId())); ActionType actionType = action.getActionType(); JobActionExecutor executor = executors.get(actionType); if (executor == null) { String msg = String.format("The action type \"%s\" is not supported.", actionType); throw new UnsupportedOperationException(msg); } JobActionResult result; ZonedDateTime startedAt = ZonedDateTime.now(); try { result = executor.execute(request, action, startedAt); } catch (Exception ex) { log.error("Unhandled exception while processing action", ex); result = JobActionResult.fail(action.getLabel(), startedAt, ex, null, null); } request.addResult(result); jobExecutionRequestStore.update(request); return result; } }
public boolean hasFailure() { for (JobActionResult result : results) { if (result.hasFailure()) { return true; } } return false; } }
public static JobActionResult finished(String command, ZonedDateTime createdAt, String out) { return new JobActionResult(command, out, null, createdAt, ZonedDateTime.now(), null); }
private JobExecutionRequest executeJob(Application app, JobExecutionRequestEntity request, JobDefinitionEntity jobDefinitionEntity, int commandIndex) throws Exception { List<JobAction> actions = jobDefinitionEntity.getJobActions(); if (commandIndex >= 0) { actions = singletonList(actions.get(commandIndex)); } for (JobAction jobAction : actions) { if (processAction(app, request, jobAction).isFailure()) { break; } } // One last update to make sure everything is current. JobsApplication.get(app, JobExecutionRequestStore.class).update(request); return request.toJobExecutionRequest(); }
public void addResult(JobActionResult result) { this.results.add(result); this.updatedAt = ZonedDateTime.now(); long duration = getUpdatedAt().toInstant().getEpochSecond() - getCreatedAt().toInstant().getEpochSecond(); if (result.hasFailure()) { this.summary = String.format("Action %s of %s failed (%s seconds)", this.results.size(), actionCount, duration); } else { this.summary = String.format("Processed %s of %s actions (%s seconds)", this.results.size(), actionCount, duration); } }
public static JobActionResult timeoutFailure(String command, ZonedDateTime createdAt, String out, String err) { return new JobActionResult(command, out, err, createdAt, ZonedDateTime.now(), "Timed out"); }
private JobExecutionRequest executeJob(Application app, JobExecutionRequestEntity request, JobDefinitionEntity jobDefinitionEntity) throws Exception { for (JobAction action : jobDefinitionEntity.getJobActions()) { JobActionResult result; if (action.getLock() == null) { result = processAction(app, request, action); } else { log.info(String.format("Locking action %s for request %s", action.getLabel(), request.getJobExecutionRequestId())); synchronized (action.getLock().intern()) { result = processAction(app, request, action); } } if (result.hasFailure()) { break; } } // One last update to make sure everything is current. jobExecutionRequestStore.update(request); return request.toJobExecutionRequest(); }
public static JobActionResult fail(String command, ZonedDateTime createdAt, String failure, String out, String err) { return new JobActionResult(command, out, err, createdAt, ZonedDateTime.now(), failure); }
private JobExecutionRequest executeJob(Application app, JobExecutionRequestEntity request, JobDefinitionEntity jobDefinitionEntity) throws Exception { for (JobAction action : jobDefinitionEntity.getJobActions()) { JobActionResult result; if (action.getLock() == null) { result = processAction(app, request, action); } else { log.info(String.format("Locking action %s for request %s", action.getLabel(), request.getJobExecutionRequestId())); synchronized (action.getLock().intern()) { result = processAction(app, request, action); } } if (result.hasFailure()) { break; } } // One last update to make sure everything is current. jobExecutionRequestStore.update(request); return request.toJobExecutionRequest(); }
public static JobActionResult finished(String command, ZonedDateTime createdAt, int exitValue, String out, String err) { String failure = (exitValue == 0) ? null : String.valueOf(exitValue); return new JobActionResult(command, out, err, createdAt, ZonedDateTime.now(), failure); }
public static JobActionResult fail(String command, ZonedDateTime createdAt, Exception ex, String out, String err) { StringWriter writer = new StringWriter(); ex.printStackTrace(new PrintWriter(writer)); String stackTrace = writer.toString(); return new JobActionResult(command, out, err, createdAt, ZonedDateTime.now(), stackTrace); } }