Search in sources :

Example 1 with RecordingImpl

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

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

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

the class SchedulerServiceImpl method repopulate.

@Override
public void repopulate(final String indexName) {
    notEmpty(indexName, "indexName");
    final String destinationId = SchedulerItem.SCHEDULER_QUEUE_PREFIX + WordUtils.capitalize(indexName);
    Organization organization = new DefaultOrganization();
    SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(systemUserName, organization), new Effect0() {

        @Override
        protected void run() {
            int current = 1;
            AQueryBuilder query = assetManager.createQuery();
            Props p = new Props(query);
            AResult result = query.select(query.snapshot(), p.agent().target(), p.start().target(), p.end().target(), p.optOut().target(), p.presenters().target(), p.reviewDate().target(), p.reviewStatus().target(), p.recordingStatus().target(), p.recordingLastHeard().target(), query.propertiesOf(CA_NAMESPACE)).where(withOrganization(query).and(query.hasPropertiesOf(p.namespace())).and(withVersion(query))).run();
            final int total = (int) Math.min(result.getSize(), Integer.MAX_VALUE);
            logger.info("Re-populating '{}' index with scheduled events. There are {} scheduled events to add to the index.", indexName, total);
            final int responseInterval = (total < 100) ? 1 : (total / 100);
            try {
                for (ARecord record : result.getRecords()) {
                    String agentId = record.getProperties().apply(Properties.getString(AGENT_CONFIG));
                    boolean optOut = record.getProperties().apply(Properties.getBoolean(OPTOUT_CONFIG));
                    Date start = record.getProperties().apply(Properties.getDate(START_DATE_CONFIG));
                    Date end = record.getProperties().apply(Properties.getDate(END_DATE_CONFIG));
                    Set<String> presenters = getPresenters(record.getProperties().apply(getStringOpt(PRESENTERS_CONFIG)).getOr(""));
                    boolean blacklisted = isBlacklisted(record.getMediaPackageId(), start, end, agentId, presenters);
                    Map<String, String> caMetadata = record.getProperties().filter(filterByNamespace._2(CA_NAMESPACE)).group(toKey, toValue);
                    ReviewStatus reviewStatus = record.getProperties().apply(getStringOpt(REVIEW_STATUS_CONFIG)).map(toReviewStatus).getOr(UNSENT);
                    Date reviewDate = record.getProperties().apply(Properties.getDateOpt(REVIEW_DATE_CONFIG)).orNull();
                    Opt<String> recordingStatus = record.getProperties().apply(Properties.getStringOpt(RECORDING_STATE_CONFIG));
                    Opt<Long> lastHeard = record.getProperties().apply(Properties.getLongOpt(RECORDING_LAST_HEARD_CONFIG));
                    Opt<AccessControlList> acl = loadEpisodeAclFromAsset(record.getSnapshot().get());
                    Opt<DublinCoreCatalog> dublinCore = loadEpisodeDublinCoreFromAsset(record.getSnapshot().get());
                    sendUpdateAddEvent(record.getMediaPackageId(), acl, dublinCore, Opt.some(start), Opt.some(end), Opt.some(presenters), Opt.some(agentId), Opt.some(caMetadata), Opt.some(optOut));
                    messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SchedulerItem.updateBlacklist(record.getMediaPackageId(), blacklisted));
                    messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SchedulerItem.updateReviewStatus(record.getMediaPackageId(), reviewStatus, reviewDate));
                    if (((current % responseInterval) == 0) || (current == total)) {
                        messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.update(indexName, IndexRecreateObject.Service.Scheduler, total, current));
                    }
                    if (recordingStatus.isSome() && lastHeard.isSome())
                        sendRecordingUpdate(new RecordingImpl(record.getMediaPackageId(), recordingStatus.get(), lastHeard.get()));
                    current++;
                }
            } catch (Exception e) {
                logger.warn("Unable to index scheduled instances:", e);
                throw new ServiceException(e.getMessage());
            }
        }
    });
    SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(systemUserName, organization), new Effect0() {

        @Override
        protected void run() {
            messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Scheduler));
        }
    });
}
Also used : Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Set(java.util.Set) HashSet(java.util.HashSet) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) RecordingImpl(org.opencastproject.scheduler.api.RecordingImpl) 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) ARecord(org.opencastproject.assetmanager.api.query.ARecord) Opt(com.entwinemedia.fn.data.Opt) Properties.getStringOpt(org.opencastproject.assetmanager.api.fn.Properties.getStringOpt) ServiceException(org.osgi.framework.ServiceException) Effect0(org.opencastproject.util.data.Effect0) SchedulerUtil.toReviewStatus(org.opencastproject.scheduler.impl.SchedulerUtil.toReviewStatus) AResult(org.opencastproject.assetmanager.api.query.AResult) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization)

Example 4 with RecordingImpl

use of org.opencastproject.scheduler.api.RecordingImpl 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)

Example 5 with RecordingImpl

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

the class SchedulerServiceRemoteImpl method getKnownRecordings.

@Override
public Map<String, Recording> getKnownRecordings() throws SchedulerException {
    HttpGet get = new HttpGet("recordingStatus");
    HttpResponse response = getResponse(get, SC_OK);
    try {
        if (response != null) {
            if (SC_OK == response.getStatusLine().getStatusCode()) {
                String recordingStates = EntityUtils.toString(response.getEntity(), UTF_8);
                JSONArray recordings = (JSONArray) parser.parse(recordingStates);
                Map<String, Recording> recordingsMap = new HashMap<String, Recording>();
                for (int i = 0; i < recordings.size(); i++) {
                    JSONObject recording = (JSONObject) recordings.get(i);
                    String recordingId = (String) recording.get("id");
                    String status = (String) recording.get("state");
                    Long lastHeard = (Long) recording.get("lastHeardFrom");
                    recordingsMap.put(recordingId, new RecordingImpl(recordingId, status, lastHeard));
                }
                logger.info("Successfully get recording states from the remote scheduler service");
                return recordingsMap;
            }
        }
    } catch (Exception e) {
        throw new SchedulerException("Unable to get recording states from remote scheduler service: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SchedulerException("Unable to get recording states from remote scheduler service");
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) HashMap(java.util.HashMap) HttpGet(org.apache.http.client.methods.HttpGet) JSONArray(org.json.simple.JSONArray) HttpResponse(org.apache.http.HttpResponse) RecordingImpl(org.opencastproject.scheduler.api.RecordingImpl) 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) JSONObject(org.json.simple.JSONObject) Recording(org.opencastproject.scheduler.api.Recording)

Aggregations

RecordingImpl (org.opencastproject.scheduler.api.RecordingImpl)9 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)7 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)7 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)7 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)7 NotFoundException (org.opencastproject.util.NotFoundException)7 Recording (org.opencastproject.scheduler.api.Recording)5 Log.getHumanReadableTimeString (org.opencastproject.util.Log.getHumanReadableTimeString)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 ValidationException (net.fortuna.ical4j.model.ValidationException)4 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)4 ARecord (org.opencastproject.assetmanager.api.query.ARecord)4 AResult (org.opencastproject.assetmanager.api.query.AResult)4 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)4 SeriesException (org.opencastproject.series.api.SeriesException)4 ServiceException (org.osgi.framework.ServiceException)4 ConfigurationException (org.osgi.service.cm.ConfigurationException)4 Date (java.util.Date)3 HttpResponse (org.apache.http.HttpResponse)3