use of org.opencastproject.job.api.IncidentTree in project opencast by opencast.
the class IncidentsTest method testFindFailure2.
@Test
public void testFindFailure2() {
final IncidentTree r = new IncidentTreeImpl(Immutables.list(mkIncident(Severity.INFO), mkIncident(Severity.INFO), mkIncident(Severity.INFO)), Immutables.<IncidentTree>list(new IncidentTreeImpl(Immutables.list(mkIncident(Severity.INFO), mkIncident(Severity.WARNING)), Immutables.<IncidentTree>list(new IncidentTreeImpl(Immutables.list(mkIncident(Severity.WARNING), mkIncident(Severity.INFO)), Immutables.<IncidentTree>nil())))));
assertFalse(Incidents.findFailure(r));
}
use of org.opencastproject.job.api.IncidentTree in project opencast by opencast.
the class AbstractIncidentService method getIncidentsOfJob.
@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);
}
}
use of org.opencastproject.job.api.IncidentTree in project opencast by opencast.
the class JobEndpoint method getIncidentsAsJSON.
/**
* Returns the list of incidents for a given workflow instance
*
* @param jobId
* the workflow instance id
* @param locale
* the language in which title and description shall be returned
* @param cascade
* if true, return the incidents of the given job and those of of its descendants
* @return the list incidents as JSON array
* @throws JobEndpointException
* @throws NotFoundException
*/
public JValue getIncidentsAsJSON(long jobId, final Locale locale, boolean cascade) throws JobEndpointException, NotFoundException {
final List<Incident> incidents;
try {
final IncidentTree it = incidentService.getIncidentsOfJob(jobId, cascade);
incidents = cascade ? flatten(it) : it.getIncidents();
} catch (IncidentServiceException e) {
throw new JobEndpointException(String.format("Not able to get the incidents for the job %d from the incident service : %s", jobId, e), e.getCause());
}
final Stream<JValue> json = $(incidents).map(new Fn<Incident, JValue>() {
@Override
public JValue apply(Incident i) {
return obj(f("id", v(i.getId())), f("severity", v(i.getSeverity(), Jsons.BLANK)), f("timestamp", v(toUTC(i.getTimestamp().getTime()), Jsons.BLANK))).merge(localizeIncident(i, locale));
}
});
return arr(json);
}
use of org.opencastproject.job.api.IncidentTree in project opencast by opencast.
the class EmailTemplateServiceImpl method applyTemplate.
/**
* Apply the template to the workflow instance.
*
* @param templateName
* template name
* @param templateContent
* template content
* @param workflowInstance
* workflow
* @return text with applied template
*/
@Override
public String applyTemplate(String templateName, String templateContent, WorkflowInstance workflowInstance) {
if (templateContent == null && templateScannerRef.get() != null) {
templateContent = templateScannerRef.get().getTemplate(templateName);
}
if (templateContent == null) {
logger.warn("E-mail template not found: {}", templateName);
// it's probably missing
return "TEMPLATE NOT FOUND: " + templateName;
}
// Build email data structure and apply the template
HashMap<String, HashMap<String, String>> catalogs = initCatalogs(workflowInstance.getMediaPackage());
WorkflowOperationInstance failed = findFailedOperation(workflowInstance);
List<Incident> incidentList = null;
if (failed != null) {
try {
IncidentTree incidents = incidentService.getIncidentsOfJob(failed.getId(), true);
incidentList = generateIncidentList(incidents);
} catch (Exception e) {
logger.error("Error when populating template with incidents", e);
// Incidents in email will be empty
}
}
return DocUtil.generate(new EmailData(templateName, workflowInstance, catalogs, failed, incidentList), templateContent);
}
use of org.opencastproject.job.api.IncidentTree in project opencast by opencast.
the class IncidentsTest method testFindFailure3.
@Test
public void testFindFailure3() {
final IncidentTree r = new IncidentTreeImpl(Immutables.list(mkIncident(Severity.FAILURE), mkIncident(Severity.INFO), mkIncident(Severity.INFO)), Immutables.<IncidentTree>list(new IncidentTreeImpl(Immutables.list(mkIncident(Severity.INFO), mkIncident(Severity.WARNING)), Immutables.<IncidentTree>list(new IncidentTreeImpl(Immutables.list(mkIncident(Severity.WARNING), mkIncident(Severity.INFO)), Immutables.<IncidentTree>nil())))));
assertTrue(Incidents.findFailure(r));
}
Aggregations