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