/** Shorthand for {@link #getServiceRegistry()}.incident() */ public Incidents incident() { return getServiceRegistry().incident(); }
private void handleFailedProcessing(final Throwable t) throws Exception { if (t instanceof JobCanceledException) { logger.info(t.getMessage()); } else { Job jobAfterProcessing = getServiceRegistry().getJob(jobId); jobAfterProcessing.setStatus(Status.FAILED); jobAfterProcessing = getServiceRegistry().updateJob(jobAfterProcessing); getServiceRegistry().incident().unhandledException(jobAfterProcessing, Severity.FAILURE, t); logger.error("Error handling operation '{}': {}", jobAfterProcessing.getOperation(), getStackTrace(t)); if (t instanceof ServiceRegistryException) throw (ServiceRegistryException) t; } }
@Override public WorkflowOperationResult start(WorkflowInstance wi, JobContext ctx) throws WorkflowOperationException { final WorkflowOperationInstance woi = wi.getCurrentOperation(); final int code = option(woi.getConfiguration(OPT_CODE)).bind(Strings.toInt).getOrElse(1); final Severity severity = option(woi.getConfiguration(OPT_SEVERITY)).bind(parseEnum(Severity.FAILURE)).getOrElse(Severity.INFO); final List<Tuple<String, String>> details = Arrays.stream(ArrayUtils.nullToEmpty( StringUtils.split(woi.getConfiguration(OPT_DETAILS), ";"))) .map((opt) -> opt.split("=")) .filter((t) -> t.length == 2) .map((x) -> Tuple.tuple(x[0], x[1])) .collect(Collectors.toList()); final Map<String, String> params = Arrays.stream(ArrayUtils.nullToEmpty( StringUtils.split(woi.getConfiguration(OPT_PARAMS), ";"))) .map((opt) -> opt.split("=")) .filter((t) -> t.length == 2) .collect(Collectors.toMap(x -> x[0], x -> x[1])); log.info("Create nop job"); final Job job = nopService.nop(); log.info("Log a dummy incident with code %d", code); serviceRegistry.incident().record(job, severity, code, params, details); if (!waitForStatus(job).isSuccess()) { throw new WorkflowOperationException("Job did not complete successfully"); } else { return createResult(WorkflowOperationResult.Action.CONTINUE); } }