private Job findJob(long jobId) throws NotFoundException, IncidentServiceException { try { return getServiceRegistry().getJob(jobId); } catch (NotFoundException e) { logger.info("Job with Id {} does not exist", jobId); throw e; } catch (ServiceRegistryException e) { logger.error("Could not retrieve job {}: {}", jobId, e.getMessage()); throw new IncidentServiceException(e); } }
private List<Incident> getIncidentsOfJob(long jobId) throws NotFoundException, IncidentServiceException { final Job job = findJob(jobId); try { return mlist(getPenv().tx(IncidentDto.findByJobId(jobId))).map(toIncident(job)).value(); } catch (Exception e) { logger.error("Could not retrieve incidents of job '{}': {}", job.getId(), e.getMessage()); throw new IncidentServiceException(e); } }
@Override public Incident storeIncident(Job job, Date timestamp, String code, Incident.Severity severity, Map<String, String> descriptionParameters, List<Tuple<String, String>> details) throws IncidentServiceException, IllegalStateException { try { job = getServiceRegistry().getJob(job.getId()); final IncidentDto dto = getPenv().tx( Queries.persist(IncidentDto.mk(job.getId(), timestamp, code, severity, descriptionParameters, details))); return toIncident(job, dto); } catch (NotFoundException e) { throw new IllegalStateException("Can't create incident for not-existing job"); } catch (Exception e) { logger.error("Could not store job incident: {}", e.getMessage()); throw new IncidentServiceException(e); } }
@Override public IncidentTree getIncidentsOfJob(long jobId, boolean cascade) throws NotFoundException, IncidentServiceException { List<Incident> incidents = getIncidentsOfJob(jobId); List<IncidentTree> childIncidents = new ArrayList<IncidentTree>(); try { Job job = getServiceRegistry().getJob(jobId); if (cascade && !"START_WORKFLOW".equals(job.getOperation())) { childIncidents = getChildIncidents(jobId); } else if (cascade && "START_WORKFLOW".equals(job.getOperation())) { for (WorkflowOperationInstance operation : getWorkflowService().getWorkflowById(jobId).getOperations()) { if (operation.getState().equals(OperationState.INSTANTIATED)) continue; IncidentTree operationResult = getIncidentsOfJob(operation.getId(), true); if (hasIncidents(Collections.list(operationResult))) childIncidents.add(operationResult); } } return new IncidentTreeImpl(incidents, childIncidents); } catch (NotFoundException ignore) { // Workflow deleted return new IncidentTreeImpl(incidents, childIncidents); } catch (Exception e) { logger.error("Error loading child jobs of {}: {}", jobId); throw new IncidentServiceException(e); } }