Search in sources :

Example 61 with SchedulerException

use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.

the class SchedulerServiceImpl method findConflictingEvents.

private List<MediaPackage> findConflictingEvents(List<Period> periods, String captureAgentId, TimeZone tz) throws SchedulerException {
    notEmpty(captureAgentId, "captureAgentId");
    notNull(periods, "periods");
    requireTrue(periods.size() > 0, "periods");
    try {
        final ARecord[] alreadyScheduledEvents = getScheduledEvents(Opt.some(captureAgentId));
        final TimeZone utc = TimeZone.getTimeZone("utc");
        Set<MediaPackage> events = new HashSet<>();
        for (Period event : periods) {
            TimeZone.setDefault(utc);
            final Date startDate = event.getStart();
            final Date endDate = event.getEnd();
            events.addAll(findConflictingEvents(startDate, endDate, alreadyScheduledEvents));
        }
        TimeZone.setDefault(null);
        return new ArrayList<>(events);
    } catch (Exception e) {
        logger.error("Failed to search for conflicting events: {}", getStackTrace(e));
        throw new SchedulerException(e);
    }
}
Also used : ARecord(org.opencastproject.assetmanager.api.query.ARecord) DateTimeZone(org.joda.time.DateTimeZone) TimeZone(java.util.TimeZone) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) ArrayList(java.util.ArrayList) Period(net.fortuna.ical4j.model.Period) DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod) 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) HashSet(java.util.HashSet)

Example 62 with SchedulerException

use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.

the class SchedulerServiceImpl method getKnownRecordings.

@Override
public Map<String, Recording> getKnownRecordings() throws SchedulerException {
    try {
        AQueryBuilder query = assetManager.createQuery();
        Props p = new Props(query);
        AResult result = query.select(p.recordingStatus().target(), p.recordingLastHeard().target()).where(withOrganization(query).and(query.version().isLatest()).and(query.hasPropertiesOf(p.namespace())).and(p.recordingStatus().exists()).and(p.recordingLastHeard().exists())).run();
        Map<String, Recording> recordings = new HashMap<>();
        for (ARecord record : result.getRecords()) {
            String recordingState = record.getProperties().apply(Properties.getString(RECORDING_STATE_CONFIG));
            Long lastHeard = record.getProperties().apply(Properties.getLong(RECORDING_LAST_HEARD_CONFIG));
            recordings.put(record.getMediaPackageId(), new RecordingImpl(record.getMediaPackageId(), recordingState, lastHeard));
        }
        return recordings;
    } catch (Exception e) {
        logger.error("Failed to get known recording states: {}", getStackTrace(e));
        throw new SchedulerException(e);
    }
}
Also used : ARecord(org.opencastproject.assetmanager.api.query.ARecord) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) AResult(org.opencastproject.assetmanager.api.query.AResult) RecordingImpl(org.opencastproject.scheduler.api.RecordingImpl) Log.getHumanReadableTimeString(org.opencastproject.util.Log.getHumanReadableTimeString) Recording(org.opencastproject.scheduler.api.Recording) 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)

Example 63 with SchedulerException

use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.

the class SchedulerRestService method getCaptureAgentMetadata.

/**
 * Gets java Properties file with technical metadata for the specified event.
 *
 * @param eventId
 *          The unique ID of the event.
 * @return Java Properties File with the metadata for the event
 */
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("{id:.+}/agent.properties")
@RestQuery(name = "recordingsagentproperties", description = "Retrieves Capture Agent properties for specified event", returnDescription = "Capture Agent properties in the form of key, value pairs", pathParameters = { @RestParameter(name = "id", isRequired = true, description = "ID of event for which agent properties will be retrieved", type = Type.STRING) }, reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "Capture Agent properties of event is in the body of response"), @RestResponse(responseCode = HttpServletResponse.SC_NOT_FOUND, description = "Event with specified ID does not exist"), @RestResponse(responseCode = HttpServletResponse.SC_UNAUTHORIZED, description = "You do not have permission to remove the event. Maybe you need to authenticate.") })
public Response getCaptureAgentMetadata(@PathParam("id") String eventId) throws UnauthorizedException {
    try {
        Map<String, String> result = service.getCaptureAgentConfiguration(eventId);
        String serializedProperties = serializeProperties(result);
        return Response.ok(serializedProperties).build();
    } catch (NotFoundException e) {
        logger.info("Event with id '{}' does not exist.", eventId);
        return Response.status(Status.NOT_FOUND).build();
    } catch (SchedulerException e) {
        logger.error("Unable to retrieve event with id '{}': {}", eventId, getMessage(e));
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WebApplicationException(javax.ws.rs.WebApplicationException) NotFoundException(org.opencastproject.util.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 64 with SchedulerException

use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.

the class SchedulerRestService method getWorkflowConfiguration.

/**
 * Gets the workflow configuration for the specified event.
 *
 * @param eventId
 *          The unique ID of the event.
 * @return the workflow configuration
 */
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("{id:.+}/workflow.properties")
@RestQuery(name = "recordingsagentproperties", description = "Retrieves workflow configuration for specified event", returnDescription = "workflow configuration in the form of key, value pairs", pathParameters = { @RestParameter(name = "id", isRequired = true, description = "ID of event for which workflow configuration will be retrieved", type = Type.STRING) }, reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "workflow configuration of event is in the body of response"), @RestResponse(responseCode = HttpServletResponse.SC_NOT_FOUND, description = "Event with specified ID does not exist"), @RestResponse(responseCode = HttpServletResponse.SC_UNAUTHORIZED, description = "You do not have permission to remove the event. Maybe you need to authenticate.") })
public Response getWorkflowConfiguration(@PathParam("id") String eventId) throws UnauthorizedException {
    try {
        Map<String, String> result = service.getWorkflowConfig(eventId);
        String serializedProperties = serializeProperties(result);
        return Response.ok(serializedProperties).build();
    } catch (NotFoundException e) {
        logger.info("Event with id '{}' does not exist.", eventId);
        return Response.status(Status.NOT_FOUND).build();
    } catch (SchedulerException e) {
        logger.error("Unable to retrieve workflow configuration for event with id '{}': {}", eventId, getMessage(e));
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WebApplicationException(javax.ws.rs.WebApplicationException) NotFoundException(org.opencastproject.util.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 65 with SchedulerException

use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.

the class SchedulerRestService method getTechnicalMetadataJSON.

/**
 * Gets a XML with the media package for the specified event.
 *
 * @param eventId
 *          The unique ID of the event.
 * @return media package XML for the event
 */
@GET
@Produces(MediaType.TEXT_XML)
@Path("{id:.+}/technical.json")
@RestQuery(name = "gettechnicalmetadatajson", description = "Retrieves the technical metadata for specified event", returnDescription = "technical metadata as JSON", pathParameters = { @RestParameter(name = "id", isRequired = true, description = "ID of event for which the technical metadata will be retrieved", type = Type.STRING) }, reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "technical metadata of event is in the body of response"), @RestResponse(responseCode = HttpServletResponse.SC_NOT_FOUND, description = "Event with specified ID does not exist"), @RestResponse(responseCode = HttpServletResponse.SC_UNAUTHORIZED, description = "You do not have permission to remove the event. Maybe you need to authenticate.") })
public Response getTechnicalMetadataJSON(@PathParam("id") String eventId) throws UnauthorizedException {
    try {
        TechnicalMetadata metadata = service.getTechnicalMetadata(eventId);
        Val state = v("");
        Val lastHeard = v("");
        if (metadata.getRecording().isSome()) {
            state = v(metadata.getRecording().get().getState());
            lastHeard = v(DateTimeSupport.toUTC(metadata.getRecording().get().getLastCheckinTime()));
        }
        Arr presenters = arr(mlist(metadata.getPresenters()).map(Jsons.stringVal));
        List<Prop> wfProperties = new ArrayList<>();
        for (Entry<String, String> entry : metadata.getWorkflowProperties().entrySet()) {
            wfProperties.add(p(entry.getKey(), entry.getValue()));
        }
        List<Prop> agentConfig = new ArrayList<>();
        for (Entry<String, String> entry : metadata.getCaptureAgentConfiguration().entrySet()) {
            agentConfig.add(p(entry.getKey(), entry.getValue()));
        }
        return RestUtil.R.ok(obj(p("id", metadata.getEventId()), p("location", metadata.getAgentId()), p("start", DateTimeSupport.toUTC(metadata.getStartDate().getTime())), p("end", DateTimeSupport.toUTC(metadata.getEndDate().getTime())), p("optOut", metadata.isOptOut()), p("presenters", presenters), p("wfProperties", obj(wfProperties.toArray(new Prop[wfProperties.size()]))), p("agentConfig", obj(agentConfig.toArray(new Prop[agentConfig.size()]))), p("state", state), p("lastHeardFrom", lastHeard)));
    } catch (NotFoundException e) {
        logger.info("Event with id '{}' does not exist.", eventId);
        return Response.status(Status.NOT_FOUND).build();
    } catch (SchedulerException e) {
        logger.error("Unable to retrieve event with id '{}': {}", eventId, getMessage(e));
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : Val(org.opencastproject.util.Jsons.Val) Arr(org.opencastproject.util.Jsons.Arr) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WebApplicationException(javax.ws.rs.WebApplicationException) Prop(org.opencastproject.util.Jsons.Prop) ArrayList(java.util.ArrayList) NotFoundException(org.opencastproject.util.NotFoundException) TechnicalMetadata(org.opencastproject.scheduler.api.TechnicalMetadata) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

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