Search in sources :

Example 1 with IncidentTree

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));
}
Also used : IncidentTreeImpl(org.opencastproject.job.api.IncidentTreeImpl) IncidentTree(org.opencastproject.job.api.IncidentTree) Test(org.junit.Test)

Example 2 with IncidentTree

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);
    }
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) IncidentTreeImpl(org.opencastproject.job.api.IncidentTreeImpl) IncidentServiceException(org.opencastproject.serviceregistry.api.IncidentServiceException) ArrayList(java.util.ArrayList) NotFoundException(org.opencastproject.util.NotFoundException) Incident(org.opencastproject.job.api.Incident) Job(org.opencastproject.job.api.Job) IncidentServiceException(org.opencastproject.serviceregistry.api.IncidentServiceException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) NotFoundException(org.opencastproject.util.NotFoundException) IncidentTree(org.opencastproject.job.api.IncidentTree)

Example 3 with IncidentTree

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);
}
Also used : JobEndpointException(org.opencastproject.adminui.exception.JobEndpointException) IncidentServiceException(org.opencastproject.serviceregistry.api.IncidentServiceException) JValue(com.entwinemedia.fn.data.json.JValue) Incident(org.opencastproject.job.api.Incident) IncidentTree(org.opencastproject.job.api.IncidentTree)

Example 4 with IncidentTree

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);
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) HashMap(java.util.HashMap) Incident(org.opencastproject.job.api.Incident) IncidentTree(org.opencastproject.job.api.IncidentTree)

Example 5 with IncidentTree

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));
}
Also used : IncidentTreeImpl(org.opencastproject.job.api.IncidentTreeImpl) IncidentTree(org.opencastproject.job.api.IncidentTree) Test(org.junit.Test)

Aggregations

IncidentTree (org.opencastproject.job.api.IncidentTree)11 Incident (org.opencastproject.job.api.Incident)7 IncidentTreeImpl (org.opencastproject.job.api.IncidentTreeImpl)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)3 IncidentServiceException (org.opencastproject.serviceregistry.api.IncidentServiceException)3 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)3 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Job (org.opencastproject.job.api.Job)2 JValue (com.entwinemedia.fn.data.json.JValue)1 File (java.io.File)1 URI (java.net.URI)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 MediaType (javax.ws.rs.core.MediaType)1 Before (org.junit.Before)1 JobEndpointException (org.opencastproject.adminui.exception.JobEndpointException)1