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);
}
}
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);
}
}
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);
}
}
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);
}
}
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()));
}
Aggregations