use of org.opencastproject.scheduler.api.Recording 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");
}
use of org.opencastproject.scheduler.api.Recording in project opencast by opencast.
the class AbstractEventEndpointTest method testRecordingToJson.
@Test
public void testRecordingToJson() throws WebApplicationException, IOException {
String id = "rec-id";
// 09/17/2015 @ 8:46pm UTC
long lastCheckinTime = 1442522772000L;
Recording recording = createRecording(id, lastCheckinTime, RecordingState.CAPTURING);
String result = RestUtils.getJsonString(AbstractEventEndpoint.recordingToJson.apply(Opt.some(recording)));
String expected = "{\"lastCheckInTimeUTC\":\"2015-09-17T20:46:12Z\",\"id\":\"rec-id\",\"state\":\"capturing\",\"lastCheckInTime\":1442522772000}";
assertThat(expected, SameJSONAs.sameJSONAs(result));
recording = createRecording(null, 0L, null);
result = RestUtils.getJsonString(AbstractEventEndpoint.recordingToJson.apply(Opt.some(recording)));
expected = "{\"lastCheckInTimeUTC\":\"1970-01-01T00:00:00Z\",\"id\":\"\",\"state\":\"\",\"lastCheckInTime\":0}";
assertThat(expected, SameJSONAs.sameJSONAs(result));
result = RestUtils.getJsonString(AbstractEventEndpoint.recordingToJson.apply(Opt.<Recording>none()));
expected = "{}";
assertThat(expected, SameJSONAs.sameJSONAs(result));
}
use of org.opencastproject.scheduler.api.Recording in project opencast by opencast.
the class AbstractEventEndpointTest method createRecording.
private Recording createRecording(String id, long checkin, String state) {
Recording recording = EasyMock.createMock(Recording.class);
EasyMock.expect(recording.getID()).andStubReturn(id);
EasyMock.expect(recording.getLastCheckinTime()).andStubReturn(checkin);
EasyMock.expect(recording.getState()).andStubReturn(state);
EasyMock.replay(recording);
return recording;
}
use of org.opencastproject.scheduler.api.Recording in project opencast by opencast.
the class RecordingStateUpdateTest method setUp.
@Before
public void setUp() throws InterruptedException {
final long lastHeardFrom = System.currentTimeMillis();
recording = new Recording() {
@Override
public void setState(String newState) {
}
@Override
public String getState() {
return RecordingState.CAPTURING;
}
@Override
public Long getLastCheckinTime() {
return lastHeardFrom;
}
@Override
public String getID() {
return "test";
}
};
Assert.assertNotNull(recording);
Thread.sleep(5);
rsu = new RecordingStateUpdate(recording);
Assert.assertNotNull(rsu);
}
use of org.opencastproject.scheduler.api.Recording in project opencast by opencast.
the class SchedulerServiceImpl method getKnownRecordings.
@Override
public Map<String, Recording> getKnownRecordings() throws SchedulerException {
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.version().isLatest()).and(query.hasPropertiesOf(p.namespace())).and(p.recordingStatus().exists()).and(p.recordingLastHeard().exists())).run();
Map<String, Recording> recordings = new HashMap<>();
for (ARecord record : result.getRecords()) {
String recordingState = record.getProperties().apply(Properties.getString(RECORDING_STATE_CONFIG));
Long lastHeard = record.getProperties().apply(Properties.getLong(RECORDING_LAST_HEARD_CONFIG));
recordings.put(record.getMediaPackageId(), new RecordingImpl(record.getMediaPackageId(), recordingState, lastHeard));
}
return recordings;
} catch (Exception e) {
logger.error("Failed to get known recording states: {}", getStackTrace(e));
throw new SchedulerException(e);
}
}
Aggregations