use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method updateRecordingState.
@Override
public boolean updateRecordingState(String mediapackageId, String state) throws NotFoundException, SchedulerException {
HttpPut put = new HttpPut(UrlSupport.concat(mediapackageId, "recordingStatus"));
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("state", state));
put.setEntity(new UrlEncodedFormEntity(params, UTF_8));
HttpResponse response = getResponse(put, SC_OK, SC_NOT_FOUND, SC_BAD_REQUEST);
try {
if (response != null) {
if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
logger.warn("Event with mediapackage id {} was not found by the scheduler service", mediapackageId);
throw new NotFoundException("Event with mediapackage id '" + mediapackageId + "' not found on remote scheduler service!");
} else if (SC_BAD_REQUEST == response.getStatusLine().getStatusCode()) {
logger.info("Unable to update event with mediapackage id {}, invalid recording state: {}.", mediapackageId, state);
return false;
} else if (SC_OK == response.getStatusLine().getStatusCode()) {
logger.info("Event with mediapackage id {} successfully updated with recording status.", mediapackageId);
return true;
} else {
throw new SchedulerException("Unexpected status code " + response.getStatusLine());
}
}
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to update recording state of event with mediapackage id " + mediapackageId + " to the scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to update recording state of event with mediapackage id " + mediapackageId);
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method isOptOut.
@Override
public boolean isOptOut(String mediapackageId) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpGet get = new HttpGet(UrlSupport.concat(mediapackageId, "optOut"));
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 mediapackage id '" + mediapackageId + "' not found on remote scheduler service!");
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to get opt out status of the event {}.", mediapackageId);
throw new UnauthorizedException("Unauthorized to get opt out status of the event " + mediapackageId);
} else {
String optOutString = EntityUtils.toString(response.getEntity(), UTF_8);
Boolean booleanObject = BooleanUtils.toBooleanObject(optOutString);
if (booleanObject == null)
throw new SchedulerException("Could not parse opt out status from the remote scheduler service: " + optOutString);
logger.info("Successfully get opt out status of event with mediapackage id {} from the remote scheduler service", mediapackageId);
return booleanObject.booleanValue();
}
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to get event opt out status from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get event opt out status from remote scheduler service");
}
use of org.opencastproject.scheduler.api.SchedulerException 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.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method getWorkflowConfig.
@Override
public Map<String, String> getWorkflowConfig(String eventId) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpGet get = new HttpGet(eventId.concat("/workflow.properties"));
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 workflow configuration '" + eventId + "' not found on remote scheduler service!");
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to get workflow config of the event {}.", eventId);
throw new UnauthorizedException("Unauthorized to get workflow config of the event " + eventId);
} else {
Properties properties = new Properties();
properties.load(response.getEntity().getContent());
logger.info("Successfully get event workflow configuration {} from the remote scheduler service", eventId);
return new HashMap<String, String>((Map) properties);
}
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to parse event workflow configuration from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get event workflow configuration from remote scheduler service");
}
use of org.opencastproject.scheduler.api.SchedulerException 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