Search in sources :

Example 1 with Severity

use of org.opencastproject.job.api.Incident.Severity in project opencast by opencast.

the class IncidentCreatorWorkflowOperationHandler method start.

@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 = option(woi.getConfiguration(OPT_DETAILS)).mlist().bind(splitBy(";")).map(splitBy("=")).filter(Tuples.<String>listHasSize(2)).map(Tuples.<String>fromList()).value();
    final Map<String, String> params = Immutables.map(option(woi.getConfiguration(OPT_PARAMS)).mlist().bind(splitBy(";")).map(splitBy("=")).filter(Tuples.<String>listHasSize(2)).map(Tuples.<String>fromList()).value());
    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);
    }
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Severity(org.opencastproject.job.api.Incident.Severity) Job(org.opencastproject.job.api.Job) Tuple(org.opencastproject.util.data.Tuple)

Example 2 with Severity

use of org.opencastproject.job.api.Incident.Severity in project opencast by opencast.

the class IncidentServiceEndpoint method postIncident.

@POST
@Produces(MediaType.APPLICATION_XML)
@Path("/")
@RestQuery(name = "postincident", description = "Creates a new job incident and returns it as XML", returnDescription = "Returns the created job incident as XML", restParameters = { @RestParameter(name = "job", isRequired = true, description = "The job on where to create the incident", type = Type.TEXT), @RestParameter(name = "date", isRequired = true, description = "The incident creation date", type = Type.STRING), @RestParameter(name = "code", isRequired = true, description = "The incident error code", type = Type.STRING), @RestParameter(name = "severity", isRequired = true, description = "The incident error code", type = Type.STRING), @RestParameter(name = "details", isRequired = false, description = "The incident details", type = Type.TEXT), @RestParameter(name = "params", isRequired = false, description = "The incident parameters", type = Type.TEXT) }, reponses = { @RestResponse(responseCode = SC_CREATED, description = "New job incident has been created"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Unable to parse the one of the form params"), @RestResponse(responseCode = SC_CONFLICT, description = "No job incident related job exists") })
public Response postIncident(@FormParam("job") String jobXml, @FormParam("date") String date, @FormParam("code") String code, @FormParam("severity") String severityString, @FormParam("details") String details, @FormParam("params") LocalHashMap params) {
    Job job;
    Date timestamp;
    Severity severity;
    Map<String, String> map = new HashMap<String, String>();
    List<Tuple<String, String>> list = new ArrayList<Tuple<String, String>>();
    try {
        job = JobParser.parseJob(jobXml);
        timestamp = new Date(DateTimeSupport.fromUTC(date));
        severity = Severity.valueOf(severityString);
        if (params != null)
            map = params.getMap();
        if (StringUtils.isNotBlank(details)) {
            final JSONArray array = (JSONArray) JSONValue.parse(details);
            for (int i = 0; i < array.size(); i++) {
                JSONObject tuple = (JSONObject) array.get(i);
                list.add(Tuple.tuple((String) tuple.get("title"), (String) tuple.get("content")));
            }
        }
    } catch (Exception e) {
        return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
    }
    try {
        Incident incident = svc.storeIncident(job, timestamp, code, severity, map, list);
        String uri = UrlSupport.concat(serverUrl, serviceUrl, Long.toString(incident.getId()), ".xml");
        return Response.created(new URI(uri)).entity(new JaxbIncident(incident)).build();
    } catch (IllegalStateException e) {
        return Response.status(Status.CONFLICT).build();
    } catch (Exception e) {
        logger.warn("Unable to post incident for job {}: {}", job.getId(), e);
        throw new WebApplicationException(INTERNAL_SERVER_ERROR);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) LocalHashMap(org.opencastproject.util.LocalHashMap) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) Severity(org.opencastproject.job.api.Incident.Severity) URI(java.net.URI) Date(java.util.Date) WebApplicationException(javax.ws.rs.WebApplicationException) IncidentServiceException(org.opencastproject.serviceregistry.api.IncidentServiceException) NotFoundException(org.opencastproject.util.NotFoundException) JSONObject(org.json.simple.JSONObject) JaxbIncident(org.opencastproject.job.api.JaxbIncident) JaxbIncident(org.opencastproject.job.api.JaxbIncident) Incident(org.opencastproject.job.api.Incident) Job(org.opencastproject.job.api.Job) Tuple(org.opencastproject.util.data.Tuple) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 3 with Severity

use of org.opencastproject.job.api.Incident.Severity in project opencast by opencast.

the class JaxbIncidentTest method testEquivalence.

/**
 * This test ensures full mapping of all Incident properties to its accompanying JAXB DTO.
 */
@Test
public void testEquivalence() throws Exception {
    final Date now = new Date();
    final JaxbIncident dto = new JaxbIncident(new IncidentImpl(1, 2, "service", "localhost", now, Severity.FAILURE, "code", Immutables.list(tuple("detail-1", "value-1"), tuple("detail-2", "detail-2")), Immutables.map(tuple("param", "value"), tuple("param-2", "value-2"))));
    final Incident incident = dto.toIncident();
    run(Incident.class, new Incident() {

        @Override
        public long getId() {
            assertEquals("id transferred", 1L, incident.getId());
            return 0;
        }

        @Override
        public long getJobId() {
            assertEquals("jobId transferred", 2L, incident.getJobId());
            return 0;
        }

        @Override
        public String getServiceType() {
            assertEquals("serviceType transferred", "service", incident.getServiceType());
            return null;
        }

        @Override
        public String getProcessingHost() {
            assertEquals("processingHost transferred", "localhost", incident.getProcessingHost());
            return null;
        }

        @Override
        public Date getTimestamp() {
            assertEquals("timestamp transferred", now, incident.getTimestamp());
            return null;
        }

        @Override
        public Severity getSeverity() {
            assertEquals("severity transferred", Severity.FAILURE, incident.getSeverity());
            return null;
        }

        @Override
        public String getCode() {
            assertEquals("code transferred", "code", incident.getCode());
            return null;
        }

        @Override
        public List<Tuple<String, String>> getDetails() {
            assertEquals("details transferred", Immutables.list(tuple("detail-1", "value-1"), tuple("detail-2", "detail-2")), incident.getDetails());
            return null;
        }

        @Override
        public Map<String, String> getDescriptionParameters() {
            assertEquals("decriptionParameters transferred", Immutables.map(tuple("param", "value"), tuple("param-2", "value-2")), incident.getDescriptionParameters());
            return null;
        }
    });
}
Also used : Severity(org.opencastproject.job.api.Incident.Severity) List(java.util.List) Map(java.util.Map) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Severity (org.opencastproject.job.api.Incident.Severity)3 Date (java.util.Date)2 Job (org.opencastproject.job.api.Job)2 Tuple (org.opencastproject.util.data.Tuple)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 Test (org.junit.Test)1 Incident (org.opencastproject.job.api.Incident)1 JaxbIncident (org.opencastproject.job.api.JaxbIncident)1 IncidentServiceException (org.opencastproject.serviceregistry.api.IncidentServiceException)1 LocalHashMap (org.opencastproject.util.LocalHashMap)1