Search in sources :

Example 1 with Recording

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

use of org.opencastproject.scheduler.api.Recording 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 3 with Recording

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

the class SchedulerServiceImpl method updateRecordingState.

@Override
public boolean updateRecordingState(String id, String state) throws NotFoundException, SchedulerException {
    notEmpty(id, "id");
    notEmpty(state, "state");
    if (!RecordingState.KNOWN_STATES.contains(state)) {
        logger.warn("Invalid recording state: {}.", state);
        return false;
    }
    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.mediaPackageId(id).and(query.version().isLatest()).and(query.hasPropertiesOf(p.namespace())))).run();
        Opt<ARecord> record = result.getRecords().head();
        if (record.isNone())
            throw new NotFoundException();
        Opt<String> recordingState = record.get().getProperties().apply(Properties.getStringOpt(RECORDING_STATE_CONFIG));
        Opt<Long> lastHeard = record.get().getProperties().apply(Properties.getLongOpt(RECORDING_LAST_HEARD_CONFIG));
        if (recordingState.isSome() && lastHeard.isSome()) {
            Recording r = new RecordingImpl(id, recordingState.get(), lastHeard.get());
            if (state.equals(r.getState())) {
                logger.debug("Recording state not changed");
                // Reset the state anyway so that the last-heard-from time is correct...
                r.setState(state);
            } else {
                logger.debug("Setting Recording {} to state {}.", id, state);
                r.setState(state);
                sendRecordingUpdate(r);
            }
            assetManager.setProperty(p.recordingStatus().mk(id, r.getState()));
            assetManager.setProperty(p.recordingLastHeard().mk(id, r.getLastCheckinTime()));
            return true;
        } else {
            Recording r = new RecordingImpl(id, state);
            assetManager.setProperty(p.recordingStatus().mk(id, r.getState()));
            assetManager.setProperty(p.recordingLastHeard().mk(id, r.getLastCheckinTime()));
            sendRecordingUpdate(r);
            return true;
        }
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Failed to update recording status of event with mediapackage '{}': {}", id, getStackTrace(e));
        throw new SchedulerException(e);
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) NotFoundException(org.opencastproject.util.NotFoundException) RecordingImpl(org.opencastproject.scheduler.api.RecordingImpl) Log.getHumanReadableTimeString(org.opencastproject.util.Log.getHumanReadableTimeString) 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) ARecord(org.opencastproject.assetmanager.api.query.ARecord) AResult(org.opencastproject.assetmanager.api.query.AResult) Recording(org.opencastproject.scheduler.api.Recording)

Example 4 with Recording

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

the class SchedulerServiceImpl method getTechnicalMetadata.

private TechnicalMetadata getTechnicalMetadata(ARecord record, Props p) {
    final String agentId = record.getProperties().apply(Properties.getString(p.agent().name()));
    final boolean optOut = record.getProperties().apply(Properties.getBoolean(p.optOut().name()));
    final Date start = record.getProperties().apply(Properties.getDate(p.start().name()));
    final Date end = record.getProperties().apply(Properties.getDate(p.end().name()));
    final Set<String> presenters = getPresenters(record.getProperties().apply(getStringOpt(PRESENTERS_CONFIG)).getOr(""));
    final Opt<String> recordingStatus = record.getProperties().apply(Properties.getStringOpt(p.recordingStatus().name()));
    String caNamespace = CA_NAMESPACE;
    String wfNamespace = WORKFLOW_NAMESPACE;
    if (TRX_NAMESPACE.equals(p.namespace())) {
        caNamespace = TRX_CA_NAMESPACE;
        wfNamespace = TRX_WORKFLOW_NAMESPACE;
    } else {
        caNamespace = CA_NAMESPACE;
        wfNamespace = WORKFLOW_NAMESPACE;
    }
    final Opt<Long> lastHeard = record.getProperties().apply(Properties.getLongOpt(p.recordingLastHeard().name()));
    final Map<String, String> caMetadata = record.getProperties().filter(filterByNamespace._2(caNamespace)).group(toKey, toValue);
    final Map<String, String> wfProperties = record.getProperties().filter(filterByNamespace._2(wfNamespace)).group(toKey, toValue);
    Recording recording = null;
    if (recordingStatus.isSome() && lastHeard.isSome())
        recording = new RecordingImpl(record.getMediaPackageId(), recordingStatus.get(), lastHeard.get());
    return new TechnicalMetadataImpl(record.getMediaPackageId(), agentId, start, end, optOut, presenters, wfProperties, caMetadata, Opt.nul(recording));
}
Also used : TechnicalMetadataImpl(org.opencastproject.scheduler.api.TechnicalMetadataImpl) RecordingImpl(org.opencastproject.scheduler.api.RecordingImpl) Log.getHumanReadableTimeString(org.opencastproject.util.Log.getHumanReadableTimeString) Recording(org.opencastproject.scheduler.api.Recording) Date(java.util.Date)

Example 5 with Recording

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

the class SchedulerServiceRemoteImpl method getTechnicalMetadata.

@Override
public TechnicalMetadata getTechnicalMetadata(String eventId) throws NotFoundException, UnauthorizedException, SchedulerException {
    HttpGet get = new HttpGet(eventId.concat("/technical.json"));
    HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED);
    try {
        if (response != null) {
            if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
                throw new NotFoundException("Event with id '" + eventId + "' not found on remote scheduler service!");
            } else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
                logger.info("Unauthorized to get the technical metadata of the event {}.", eventId);
                throw new UnauthorizedException("Unauthorized to get the technical metadata of the event " + eventId);
            } else {
                String technicalMetadataJson = EntityUtils.toString(response.getEntity(), UTF_8);
                JSONObject json = (JSONObject) parser.parse(technicalMetadataJson);
                final String recordingId = (String) json.get("id");
                final Date start = new Date(DateTimeSupport.fromUTC((String) json.get("start")));
                final Date end = new Date(DateTimeSupport.fromUTC((String) json.get("end")));
                final boolean optOut = (Boolean) json.get("optOut");
                final String location = (String) json.get("location");
                final Set<String> presenters = new HashSet<>();
                JSONArray presentersArr = (JSONArray) json.get("presenters");
                for (int i = 0; i < presentersArr.size(); i++) {
                    presenters.add((String) presentersArr.get(i));
                }
                final Map<String, String> wfProperties = new HashMap<>();
                JSONObject wfPropertiesObj = (JSONObject) json.get("wfProperties");
                Set<Entry<String, String>> entrySet = wfPropertiesObj.entrySet();
                for (Entry<String, String> entry : entrySet) {
                    wfProperties.put(entry.getKey(), entry.getValue());
                }
                final Map<String, String> agentConfig = new HashMap<>();
                JSONObject agentConfigObj = (JSONObject) json.get("agentConfig");
                entrySet = agentConfigObj.entrySet();
                for (Entry<String, String> entry : entrySet) {
                    agentConfig.put(entry.getKey(), entry.getValue());
                }
                String status = (String) json.get("state");
                String lastHeard = (String) json.get("lastHeardFrom");
                Recording recording = null;
                if (StringUtils.isNotBlank(status) && StringUtils.isNotBlank(lastHeard)) {
                    recording = new RecordingImpl(recordingId, status, DateTimeSupport.fromUTC(lastHeard));
                }
                final Opt<Recording> recordingOpt = Opt.nul(recording);
                logger.info("Successfully get the technical metadata of event '{}' from the remote scheduler service", eventId);
                return new TechnicalMetadataImpl(recordingId, location, start, end, optOut, presenters, wfProperties, agentConfig, recordingOpt);
            }
        }
    } catch (NotFoundException e) {
        throw e;
    } catch (UnauthorizedException e) {
        throw e;
    } catch (Exception e) {
        throw new SchedulerException("Unable to parse the technical metadata from remote scheduler service: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SchedulerException("Unable to get the technical metadata from remote scheduler service");
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) TechnicalMetadataImpl(org.opencastproject.scheduler.api.TechnicalMetadataImpl) HttpGet(org.apache.http.client.methods.HttpGet) JSONArray(org.json.simple.JSONArray) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) RecordingImpl(org.opencastproject.scheduler.api.RecordingImpl) Date(java.util.Date) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) Entry(java.util.Map.Entry) Opt(com.entwinemedia.fn.data.Opt) JSONObject(org.json.simple.JSONObject) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) Recording(org.opencastproject.scheduler.api.Recording) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Recording (org.opencastproject.scheduler.api.Recording)11 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)6 RecordingImpl (org.opencastproject.scheduler.api.RecordingImpl)5 NotFoundException (org.opencastproject.util.NotFoundException)5 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)4 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)4 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)4 HashMap (java.util.HashMap)3 Log.getHumanReadableTimeString (org.opencastproject.util.Log.getHumanReadableTimeString)3 IOException (java.io.IOException)2 Date (java.util.Date)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ValidationException (net.fortuna.ical4j.model.ValidationException)2 HttpResponse (org.apache.http.HttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)2