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