Search in sources :

Example 1 with IncidentServiceException

use of org.opencastproject.serviceregistry.api.IncidentServiceException 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 2 with IncidentServiceException

use of org.opencastproject.serviceregistry.api.IncidentServiceException in project opencast by opencast.

the class IncidentServiceEndpoint method getIncidentsOfJobAsList.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("job/incidents.{type:xml|json}")
@RestQuery(name = "incidentsofjobaslist", description = "Returns the job incidents with the given identifiers.", returnDescription = "Returns the job incidents.", pathParameters = { @RestParameter(name = "type", isRequired = true, description = "The media type of the response [xml|json]", defaultValue = "xml", type = Type.STRING) }, restParameters = { @RestParameter(name = "id", isRequired = true, description = "The job identifiers.", type = Type.INTEGER), @RestParameter(name = "format", isRequired = false, description = "The response format [full|digest|sys]. Defaults to sys", defaultValue = "sys", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The job incidents.") })
public Response getIncidentsOfJobAsList(@Context HttpServletRequest request, @QueryParam("id") final List<Long> jobIds, @QueryParam("format") @DefaultValue(FMT_DEFAULT) final String format, @PathParam("type") final String type) {
    try {
        final List<Incident> incidents = svc.getIncidentsOfJob(jobIds);
        final MediaType mt = getResponseType(type);
        if (eq(FMT_SYS, format)) {
            return ok(mt, new JaxbIncidentList(incidents));
        } else if (eq(FMT_DIGEST, format)) {
            return ok(mt, new JaxbIncidentDigestList(svc, request.getLocale(), incidents));
        } else if (eq(FMT_FULL, format)) {
            return ok(mt, new JaxbIncidentFullList(svc, request.getLocale(), incidents));
        } else {
            return unknownFormat();
        }
    } catch (NotFoundException e) {
        // should not happen
        logger.error("Unable to get job incident for id {}! Consistency issue!");
        throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
    } catch (IncidentServiceException e) {
        logger.warn("Unable to get job incident for id {}: {}", jobIds, e.getMessage());
        throw new WebApplicationException(INTERNAL_SERVER_ERROR);
    }
}
Also used : JaxbIncidentDigestList(org.opencastproject.job.api.JaxbIncidentDigestList) WebApplicationException(javax.ws.rs.WebApplicationException) IncidentServiceException(org.opencastproject.serviceregistry.api.IncidentServiceException) MediaType(javax.ws.rs.core.MediaType) JaxbIncidentList(org.opencastproject.job.api.JaxbIncidentList) NotFoundException(org.opencastproject.util.NotFoundException) JaxbIncident(org.opencastproject.job.api.JaxbIncident) Incident(org.opencastproject.job.api.Incident) JaxbIncidentFullList(org.opencastproject.job.api.JaxbIncidentFullList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 3 with IncidentServiceException

use of org.opencastproject.serviceregistry.api.IncidentServiceException 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 IncidentServiceException

use of org.opencastproject.serviceregistry.api.IncidentServiceException in project opencast by opencast.

the class AbstractIncidentService method storeIncident.

@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);
    }
}
Also used : IncidentServiceException(org.opencastproject.serviceregistry.api.IncidentServiceException) NotFoundException(org.opencastproject.util.NotFoundException) IncidentServiceException(org.opencastproject.serviceregistry.api.IncidentServiceException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 5 with IncidentServiceException

use of org.opencastproject.serviceregistry.api.IncidentServiceException in project opencast by opencast.

the class IncidentServiceEndpoint method getIncidentsOfJobAsTree.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("job/{id}.{type:xml|json}")
@RestQuery(name = "incidentsofjobastree", description = "Returns the job incident for the job with the given identifier.", returnDescription = "Returns the job incident.", pathParameters = { @RestParameter(name = "id", isRequired = true, description = "The job identifier.", type = Type.INTEGER), @RestParameter(name = "type", isRequired = true, description = "The media type of the response [xml|json]", defaultValue = "xml", type = Type.STRING) }, restParameters = { @RestParameter(name = "cascade", isRequired = false, description = "Whether to show the cascaded incidents.", type = Type.BOOLEAN, defaultValue = "false"), @RestParameter(name = "format", isRequired = false, description = "The response format [full|digest|sys]. Defaults to sys", defaultValue = "sys", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The job incident."), @RestResponse(responseCode = SC_NOT_FOUND, description = "No job incident with this identifier was found.") })
public Response getIncidentsOfJobAsTree(@Context HttpServletRequest request, @PathParam("id") final long jobId, @QueryParam("cascade") @DefaultValue("false") boolean cascade, @QueryParam("format") @DefaultValue(FMT_DEFAULT) final String format, @PathParam("type") final String type) throws NotFoundException {
    try {
        final IncidentTree tree = svc.getIncidentsOfJob(jobId, cascade);
        final MediaType mt = getResponseType(type);
        if (eq(FMT_SYS, format)) {
            return ok(mt, new JaxbIncidentTree(tree));
        } else if (eq(FMT_DIGEST, format)) {
            return ok(mt, new JaxbIncidentFullTree(svc, request.getLocale(), tree));
        } else if (eq(FMT_FULL, format)) {
            return ok(mt, new JaxbIncidentFullTree(svc, request.getLocale(), tree));
        } else {
            return unknownFormat();
        }
    } catch (IncidentServiceException e) {
        logger.warn("Unable to get job incident for id {}: {}", jobId, e.getMessage());
        throw new WebApplicationException(INTERNAL_SERVER_ERROR);
    }
}
Also used : JaxbIncidentFullTree(org.opencastproject.job.api.JaxbIncidentFullTree) WebApplicationException(javax.ws.rs.WebApplicationException) IncidentServiceException(org.opencastproject.serviceregistry.api.IncidentServiceException) MediaType(javax.ws.rs.core.MediaType) JaxbIncidentTree(org.opencastproject.job.api.JaxbIncidentTree) IncidentTree(org.opencastproject.job.api.IncidentTree) JaxbIncidentTree(org.opencastproject.job.api.JaxbIncidentTree) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

IncidentServiceException (org.opencastproject.serviceregistry.api.IncidentServiceException)6 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 Incident (org.opencastproject.job.api.Incident)3 IncidentTree (org.opencastproject.job.api.IncidentTree)3 NotFoundException (org.opencastproject.util.NotFoundException)3 RestQuery (org.opencastproject.util.doc.rest.RestQuery)3 MediaType (javax.ws.rs.core.MediaType)2 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)2 JValue (com.entwinemedia.fn.data.json.JValue)1 ArrayList (java.util.ArrayList)1 JSONObject (org.json.simple.JSONObject)1 JobEndpointException (org.opencastproject.adminui.exception.JobEndpointException)1 IncidentTreeImpl (org.opencastproject.job.api.IncidentTreeImpl)1 JaxbIncident (org.opencastproject.job.api.JaxbIncident)1 JaxbIncidentDigestList (org.opencastproject.job.api.JaxbIncidentDigestList)1 JaxbIncidentFullList (org.opencastproject.job.api.JaxbIncidentFullList)1 JaxbIncidentFullTree (org.opencastproject.job.api.JaxbIncidentFullTree)1