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);
}
}
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);
}
}
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);
}
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);
}
}
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);
}
}
Aggregations