Search in sources :

Example 6 with Recording

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");
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) HashMap(java.util.HashMap) HttpGet(org.apache.http.client.methods.HttpGet) JSONArray(org.json.simple.JSONArray) HttpResponse(org.apache.http.HttpResponse) RecordingImpl(org.opencastproject.scheduler.api.RecordingImpl) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) JSONObject(org.json.simple.JSONObject) Recording(org.opencastproject.scheduler.api.Recording)

Example 7 with Recording

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));
}
Also used : Recording(org.opencastproject.scheduler.api.Recording) Test(org.junit.Test)

Example 8 with Recording

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;
}
Also used : Recording(org.opencastproject.scheduler.api.Recording)

Example 9 with 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);
}
Also used : Recording(org.opencastproject.scheduler.api.Recording) Before(org.junit.Before)

Example 10 with Recording

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);
    }
}
Also used : ARecord(org.opencastproject.assetmanager.api.query.ARecord) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) AResult(org.opencastproject.assetmanager.api.query.AResult) RecordingImpl(org.opencastproject.scheduler.api.RecordingImpl) Log.getHumanReadableTimeString(org.opencastproject.util.Log.getHumanReadableTimeString) Recording(org.opencastproject.scheduler.api.Recording) 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

Recording (org.opencastproject.scheduler.api.Recording)11 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)6 RecordingImpl (org.opencastproject.scheduler.api.RecordingImpl)5 NotFoundException (org.opencastproject.util.NotFoundException)5 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)4 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)4 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)4 HashMap (java.util.HashMap)3 Log.getHumanReadableTimeString (org.opencastproject.util.Log.getHumanReadableTimeString)3 IOException (java.io.IOException)2 Date (java.util.Date)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ValidationException (net.fortuna.ical4j.model.ValidationException)2 HttpResponse (org.apache.http.HttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)2