use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class AbstractEventEndpoint method updateEventWorkflow.
@PUT
@Path("{eventId}/workflows")
@RestQuery(name = "updateEventWorkflow", description = "Update the workflow configuration for the scheduled event with the given id", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING) }, restParameters = { @RestParameter(name = "configuration", isRequired = true, description = "The workflow configuration as JSON", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(description = "Request executed succesfully", responseCode = HttpServletResponse.SC_NO_CONTENT), @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) }, returnDescription = "The method does not retrun any content.")
public Response updateEventWorkflow(@PathParam("eventId") String id, @FormParam("configuration") String configuration) throws SearchIndexException, UnauthorizedException {
Opt<Event> optEvent = getIndexService().getEvent(id, getIndex());
if (optEvent.isNone())
return notFound("Cannot find an event with id '%s'.", id);
if (!optEvent.get().hasRecordingStarted()) {
try {
JSONObject configJSON;
try {
configJSON = (JSONObject) new JSONParser().parse(configuration);
} catch (Exception e) {
logger.warn("Unable to parse the workflow configuration {}", configuration);
return badRequest();
}
Opt<Map<String, String>> caMetadataOpt = Opt.none();
Opt<Map<String, String>> workflowConfigOpt = Opt.none();
String workflowId = (String) configJSON.get("id");
Map<String, String> caMetadata = new HashMap<>(getSchedulerService().getCaptureAgentConfiguration(id));
if (!workflowId.equals(caMetadata.get(CaptureParameters.INGEST_WORKFLOW_DEFINITION))) {
caMetadata.put(CaptureParameters.INGEST_WORKFLOW_DEFINITION, workflowId);
caMetadataOpt = Opt.some(caMetadata);
}
Map<String, String> workflowConfig = new HashMap<>((JSONObject) configJSON.get("configuration"));
Map<String, String> oldWorkflowConfig = new HashMap<>(getSchedulerService().getWorkflowConfig(id));
if (!oldWorkflowConfig.equals(workflowConfig))
workflowConfigOpt = Opt.some(workflowConfig);
if (caMetadataOpt.isNone() && workflowConfigOpt.isNone())
return Response.noContent().build();
getSchedulerService().updateEvent(id, Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), Opt.<MediaPackage>none(), workflowConfigOpt, caMetadataOpt, Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
return Response.noContent().build();
} catch (NotFoundException e) {
return notFound("Cannot find event %s in scheduler service", id);
} catch (SchedulerException e) {
logger.error("Unable to update scheduling workflow data for event with id {}", id);
throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
}
} else {
return badRequest(String.format("Event %s workflow can not be updated as the recording already started.", id));
}
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerMigrationService method schedule.
void schedule(SchedulerTransaction tx, Event event) {
final Map<String, String> wfProperties = Collections.emptyMap();
final Map<String, String> caMetadata = PropertiesUtil.toMap(event.captureAgentProperites);
final MediaPackage mp = mkMediaPackage();
mp.setIdentifier(new IdImpl(event.mediaPackageId));
// create the catalog
final DublinCoreCatalog dc = event.dublinCore;
mp.setSeries(dc.getFirst(DublinCore.PROPERTY_IS_PART_OF));
// and make them available for download in the workspace
dc.setURI(storeInWs(event.mediaPackageId, dc.getIdentifier(), "dc-episode.xml", inputStream(dc)));
// add them to the media package
mp.add(dc);
// add acl to the media package
for (AccessControlList acl : event.accessControlList) {
authorizationService.setAcl(mp, AclScope.Episode, acl);
}
//
// add to scheduler service
Tuple<Date, Date> schedulingDate = getSchedulingDate(dc);
String caId = dc.getFirst(DublinCore.PROPERTY_SPATIAL);
try {
tx.addEvent(schedulingDate.getA(), schedulingDate.getB(), caId, Collections.<String>emptySet(), mp, wfProperties, caMetadata, Opt.some(event.optOut));
} catch (UnauthorizedException e) {
logger.error("Not authorized to schedule an event", e);
chuck(e);
} catch (SchedulerException e) {
logger.warn("Not able to schedule event.", e);
chuck(e);
} catch (NotFoundException e) {
logger.error("Transaction disappeared");
chuck(e);
}
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class CaptureAgentStateRestService method getAllRecordings.
@GET
@Produces(MediaType.TEXT_XML)
@Path("recordings")
@RestQuery(name = "getAllRecordings", description = "Return all registered recordings and their state", pathParameters = {}, restParameters = {}, reponses = { @RestResponse(description = "Returns all known recordings.", responseCode = SC_OK) }, returnDescription = "")
public List<RecordingStateUpdate> getAllRecordings() {
try {
LinkedList<RecordingStateUpdate> update = new LinkedList<RecordingStateUpdate>();
Map<String, Recording> data = schedulerService.getKnownRecordings();
// Run through and build a map of updates (rather than states)
for (Entry<String, Recording> e : data.entrySet()) {
update.add(new RecordingStateUpdate(e.getValue()));
}
return update;
} catch (SchedulerException e) {
logger.debug("Unable to get all recordings: {}", ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class CaptureAgentStateRestService method getRecordingState.
@GET
@Produces({ MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
@Path("recordings/{id}.{type:xml|json|}")
@RestQuery(name = "getRecordingState", description = "Return the state of a given recording", pathParameters = { @RestParameter(description = "The ID of a given recording", isRequired = true, name = "id", type = Type.STRING), @RestParameter(description = "The Documenttype", isRequired = true, name = "type", type = Type.STRING) }, restParameters = {}, reponses = { @RestResponse(description = "Returns the state of the recording with the correct id", responseCode = SC_OK), @RestResponse(description = "The recording with the specified ID does not exist", responseCode = SC_NOT_FOUND) }, returnDescription = "")
public Response getRecordingState(@PathParam("id") String id, @PathParam("type") String type) throws NotFoundException {
try {
Recording rec = schedulerService.getRecordingState(id);
logger.debug("Submitting state for recording {}", id);
if ("json".equals(type)) {
return Response.ok(new RecordingStateUpdate(rec)).type(MediaType.APPLICATION_JSON).build();
} else {
return Response.ok(new RecordingStateUpdate(rec)).type(MediaType.TEXT_XML).build();
}
} catch (SchedulerException e) {
logger.debug("Unable to get recording state of {}: {}", id, ExceptionUtils.getStackTrace(e));
return Response.serverError().build();
}
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceImpl method cleanupTransactions.
@Override
public synchronized void cleanupTransactions() throws UnauthorizedException, SchedulerException {
logger.info("Cleanup transactions | start");
List<String> transactions;
try {
transactions = persistence.getTransactions();
} catch (SchedulerServiceDatabaseException e) {
logger.error("Unable to get transactions: {}", getStackTrace(e));
throw new SchedulerException(e);
}
logger.info("Cleanup transaction | checking {} transactions...", transactions.size());
for (String trxId : transactions) {
try {
Date lastModified = persistence.getTransactionLastModified(trxId);
if (lastModified.getTime() + transactionOffsetMillis < new Date().getTime()) {
logger.info("Cleanup transactions | rollback outdated transaction {}", trxId);
SchedulerTransaction t = getTransaction(trxId);
t.rollback();
} else {
logger.info("Cleanup transactions | nothing to do");
}
} catch (NotFoundException e) {
logger.info("Cleanup transaction | transaction '{}' has been removed in the meantime.", trxId);
} catch (Exception e) {
logger.warn("Cleanup transaction | unable to cleanup transaction with id '{}': {}", trxId, getStackTrace(e));
}
}
logger.info("Cleanup transactions | end");
}
Aggregations