Search in sources :

Example 51 with SchedulerException

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

the class SchedulerServiceImpl method populateLastModifiedCache.

private void populateLastModifiedCache() throws SchedulerException {
    try {
        Map<String, Date> lastModifiedDates = persistence.getLastModifiedDates();
        for (Entry<String, Date> entry : lastModifiedDates.entrySet()) {
            Date lastModifiedDate = entry.getValue() != null ? entry.getValue() : new Date();
            lastModifiedCache.put(entry.getKey(), generateLastModifiedHash(lastModifiedDate));
        }
    } catch (Exception e) {
        logger.error("Failed to retrieve last modified for CA: {}", getStackTrace(e));
        throw new SchedulerException(e);
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) 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)

Example 52 with SchedulerException

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

the class SchedulerServiceImpl method preCollisionEventCheck.

private List<String> preCollisionEventCheck(String trxId, String schedulingSource) throws SchedulerException {
    try {
        AQueryBuilder query = assetManager.createQuery();
        Props p = new Props(query);
        TrxProps trxP = new TrxProps(query);
        Predicate isSourceWithTrx = trxP.source().eq(schedulingSource).and(trxP.transactionId().eq(trxId));
        Predicate hasProperties = p.agent().exists().and(p.start().exists()).and(p.end().exists());
        Predicate isNotSource = p.source().eq(schedulingSource).not().and(hasProperties);
        Predicate isNotOptedOut = p.optOut().eq(false).or(trxP.optOut().eq(false));
        ASelectQuery select = query.select(trxP.optOut().target(), p.optOut().target(), p.agent().target(), p.start().target(), p.end().target(), trxP.agent().target(), trxP.start().target(), trxP.end().target(), trxP.transactionId().target()).where(withOrganization(query).and(isSourceWithTrx.or(isNotSource)).and(query.version().isLatest()).and(isNotOptedOut));
        AResult result = select.run();
        // Check for conflicts
        List<String> conflictingRecords = new ArrayList<>();
        Map<String, List<Interval>> invervalMap = new HashMap<>();
        for (ARecord record : result.getRecords()) {
            String agentId;
            Date start;
            Date end;
            Opt<String> optTrxId = record.getProperties().apply(Properties.getStringOpt(TRANSACTION_ID_CONFIG));
            if (optTrxId.isSome() && trxId.equals(optTrxId.get())) {
                agentId = record.getProperties().filter(filterByNamespace._2(trxP.namespace())).apply(Properties.getString(AGENT_CONFIG));
                start = record.getProperties().filter(filterByNamespace._2(trxP.namespace())).apply(Properties.getDate(START_DATE_CONFIG));
                end = record.getProperties().filter(filterByNamespace._2(trxP.namespace())).apply(Properties.getDate(END_DATE_CONFIG));
            } else {
                agentId = record.getProperties().filter(filterByNamespace._2(p.namespace())).apply(Properties.getString(AGENT_CONFIG));
                start = record.getProperties().filter(filterByNamespace._2(p.namespace())).apply(Properties.getDate(START_DATE_CONFIG));
                end = record.getProperties().filter(filterByNamespace._2(p.namespace())).apply(Properties.getDate(END_DATE_CONFIG));
            }
            Interval currentInterval = new Interval(start.getTime(), end.getTime());
            List<Interval> intervals = invervalMap.get(agentId);
            if (intervals == null)
                intervals = new ArrayList<>();
            boolean overlaps = false;
            for (Interval i : intervals) {
                if (!i.overlaps(currentInterval))
                    continue;
                overlaps = true;
                break;
            }
            if (!overlaps) {
                intervals.add(currentInterval);
            } else {
                conflictingRecords.add(record.getMediaPackageId());
            }
            invervalMap.put(agentId, intervals);
        }
        return conflictingRecords;
    } catch (Exception e) {
        logger.error("Failed to search for conflicting events: {}", getStackTrace(e));
        throw new SchedulerException(e);
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) 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) Predicate(org.opencastproject.assetmanager.api.query.Predicate) ARecord(org.opencastproject.assetmanager.api.query.ARecord) AResult(org.opencastproject.assetmanager.api.query.AResult) ArrayList(java.util.ArrayList) AccessControlList(org.opencastproject.security.api.AccessControlList) List(java.util.List) LinkedList(java.util.LinkedList) ASelectQuery(org.opencastproject.assetmanager.api.query.ASelectQuery) Interval(org.joda.time.Interval)

Example 53 with SchedulerException

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

the class SchedulerServiceImpl method removeRecording.

@Override
public void removeRecording(String id) throws NotFoundException, SchedulerException {
    notEmpty(id, "id");
    try {
        AQueryBuilder query = assetManager.createQuery();
        Props p = new Props(query);
        AResult result = query.select(query.nothing()).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();
        query = assetManager.createQuery();
        p = new Props(query);
        final Predicate predicate = withOrganization(query).and(query.mediaPackageId(id));
        query.delete(SNAPSHOT_OWNER, p.recordingStatus().target()).where(predicate).run();
        query.delete(SNAPSHOT_OWNER, p.recordingLastHeard().target()).where(predicate).run();
        messageSender.sendObjectMessage(SchedulerItem.SCHEDULER_QUEUE, MessageSender.DestinationType.Queue, SchedulerItem.deleteRecordingState(id));
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Failed to delete recording status of event with mediapackage '{}': {}", id, getStackTrace(e));
        throw new SchedulerException(e);
    }
}
Also used : ARecord(org.opencastproject.assetmanager.api.query.ARecord) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) AResult(org.opencastproject.assetmanager.api.query.AResult) NotFoundException(org.opencastproject.util.NotFoundException) 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) Predicate(org.opencastproject.assetmanager.api.query.Predicate)

Example 54 with SchedulerException

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

the class SchedulerServiceImpl method isBlacklisted.

@Override
public boolean isBlacklisted(String mediaPackageId) throws NotFoundException, SchedulerException {
    notEmpty(mediaPackageId, "mediaPackageId");
    try {
        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.presenters().target()).where(withOrganization(query).and(query.mediaPackageId(mediaPackageId).and(withVersion(query)).and(query.hasPropertiesOf(p.namespace())))).run();
        Opt<ARecord> record = result.getRecords().head();
        if (record.isNone())
            throw new NotFoundException();
        Opt<MediaPackage> mp = record.bind(recordToMp);
        if (mp.isNone())
            throw new NotFoundException();
        String agentId = record.get().getProperties().apply(Properties.getString(AGENT_CONFIG));
        Date start = record.get().getProperties().apply(Properties.getDate(START_DATE_CONFIG));
        Date end = record.get().getProperties().apply(Properties.getDate(END_DATE_CONFIG));
        Set<String> presenters = getPresenters(record.get().getProperties().apply(getStringOpt(PRESENTERS_CONFIG)).getOr(""));
        return isBlacklisted(mediaPackageId, start, end, agentId, presenters);
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Failed to get blacklist status of event with mediapackage '{}': {}", mediaPackageId, 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) 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) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AResult(org.opencastproject.assetmanager.api.query.AResult)

Example 55 with SchedulerException

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

the class SchedulerServiceImpl method removeScheduledRecordingsBeforeBuffer.

@Override
public void removeScheduledRecordingsBeforeBuffer(long buffer) throws SchedulerException {
    DateTime end = new DateTime(DateTimeZone.UTC).minus(buffer * 1000);
    logger.info("Starting to look for scheduled recordings that have finished before {}.", DateTimeSupport.toUTC(end.getMillis()));
    List<MediaPackage> finishedEvents;
    try {
        finishedEvents = search(Opt.<String>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.some(end.toDate()));
        logger.debug("Found {} events from search.", finishedEvents.size());
    } catch (SchedulerException e) {
        logger.error("Unable to search for finished events: {}", getStackTrace(e));
        throw new SchedulerException(e);
    }
    int recordingsRemoved = 0;
    for (MediaPackage event : finishedEvents) {
        String eventId = event.getIdentifier().compact();
        try {
            removeEvent(eventId);
            logger.debug("Sucessfully removed scheduled event with id " + eventId);
            recordingsRemoved++;
        } catch (NotFoundException e) {
            logger.debug("Skipping event with id {} because it is not found", eventId);
        } catch (Exception e) {
            logger.warn("Unable to delete event with id '{}': {}", eventId, getStackTrace(e));
        }
    }
    logger.info("Found {} to remove that ended before {}.", recordingsRemoved, DateTimeSupport.toUTC(end.getMillis()));
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) Log.getHumanReadableTimeString(org.opencastproject.util.Log.getHumanReadableTimeString) DateTime(org.joda.time.DateTime) 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