Search in sources :

Example 6 with SchedulerException

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));
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) NotFoundException(org.opencastproject.util.NotFoundException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WebApplicationException(javax.ws.rs.WebApplicationException) EventCommentException(org.opencastproject.event.comment.EventCommentException) JSONException(org.codehaus.jettison.json.JSONException) JobEndpointException(org.opencastproject.adminui.exception.JobEndpointException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) ParseException(java.text.ParseException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) UrlSigningException(org.opencastproject.security.urlsigning.exception.UrlSigningException) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowStateException(org.opencastproject.workflow.api.WorkflowStateException) JSONObject(org.json.simple.JSONObject) Event(org.opencastproject.index.service.impl.index.event.Event) JSONParser(org.json.simple.parser.JSONParser) Map(java.util.Map) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) RestQuery(org.opencastproject.util.doc.rest.RestQuery) PUT(javax.ws.rs.PUT)

Example 7 with SchedulerException

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);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) Date(java.util.Date)

Example 8 with SchedulerException

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);
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WebApplicationException(javax.ws.rs.WebApplicationException) Recording(org.opencastproject.scheduler.api.Recording) RecordingStateUpdate(org.opencastproject.capture.admin.impl.RecordingStateUpdate) LinkedList(java.util.LinkedList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 9 with SchedulerException

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();
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) Recording(org.opencastproject.scheduler.api.Recording) RecordingStateUpdate(org.opencastproject.capture.admin.impl.RecordingStateUpdate) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 10 with SchedulerException

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");
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) NotFoundException(org.opencastproject.util.NotFoundException) Log.getHumanReadableTimeString(org.opencastproject.util.Log.getHumanReadableTimeString) Date(java.util.Date) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) IOException(java.io.IOException) ServiceException(org.osgi.framework.ServiceException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) ConfigurationException(org.osgi.service.cm.ConfigurationException) SeriesException(org.opencastproject.series.api.SeriesException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) ValidationException(net.fortuna.ical4j.model.ValidationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Aggregations

SchedulerException (org.opencastproject.scheduler.api.SchedulerException)83 NotFoundException (org.opencastproject.util.NotFoundException)76 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)68 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)62 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)60 HttpResponse (org.apache.http.HttpResponse)32 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)30 IOException (java.io.IOException)29 SeriesException (org.opencastproject.series.api.SeriesException)27 ValidationException (net.fortuna.ical4j.model.ValidationException)26 ServiceException (org.osgi.framework.ServiceException)26 ConfigurationException (org.osgi.service.cm.ConfigurationException)26 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)22 MediaPackage (org.opencastproject.mediapackage.MediaPackage)22 Date (java.util.Date)21 HttpGet (org.apache.http.client.methods.HttpGet)19 ARecord (org.opencastproject.assetmanager.api.query.ARecord)19 AResult (org.opencastproject.assetmanager.api.query.AResult)19 ArrayList (java.util.ArrayList)16 Log.getHumanReadableTimeString (org.opencastproject.util.Log.getHumanReadableTimeString)16