use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method isBlacklisted.
@Override
public boolean isBlacklisted(String mediapackageId) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpGet get = new HttpGet(UrlSupport.concat(mediapackageId, "blacklisted"));
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 blacklist status of the event {}.", mediapackageId);
throw new UnauthorizedException("Unauthorized to get blacklist status of the event " + mediapackageId);
} else {
String blacklistString = EntityUtils.toString(response.getEntity(), UTF_8);
Boolean booleanObject = BooleanUtils.toBooleanObject(blacklistString);
if (booleanObject == null)
throw new SchedulerException("Could not parse blacklist status from the remote scheduler service: " + blacklistString);
logger.info("Successfully get blacklist 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 blacklist status from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get event blacklist status from remote scheduler service");
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method findConflictingEvents.
@Override
public List<MediaPackage> findConflictingEvents(String captureAgentId, RRule rrule, Date startDate, Date endDate, long duration, TimeZone timezone) throws UnauthorizedException, SchedulerException {
List<NameValuePair> queryStringParams = new ArrayList<NameValuePair>();
queryStringParams.add(new BasicNameValuePair("agent", captureAgentId));
queryStringParams.add(new BasicNameValuePair("rrule", rrule.getRecur().toString()));
queryStringParams.add(new BasicNameValuePair("start", Long.toString(startDate.getTime())));
queryStringParams.add(new BasicNameValuePair("end", Long.toString(endDate.getTime())));
queryStringParams.add(new BasicNameValuePair("duration", Long.toString(duration)));
queryStringParams.add(new BasicNameValuePair("timezone", timezone.getID()));
HttpGet get = new HttpGet("conflicts.xml?".concat(URLEncodedUtils.format(queryStringParams, UTF_8)));
HttpResponse response = getResponse(get, SC_OK, SC_NO_CONTENT);
try {
if (response != null) {
if (SC_OK == response.getStatusLine().getStatusCode()) {
String mediaPackageXml = EntityUtils.toString(response.getEntity(), UTF_8);
List<MediaPackage> events = MediaPackageParser.getArrayFromXml(mediaPackageXml);
logger.info("Successfully get conflicts from the remote scheduler service");
return events;
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to search for conflicting events");
throw new UnauthorizedException("Unauthorized to search for conflicting events");
} else if (SC_NO_CONTENT == response.getStatusLine().getStatusCode()) {
return Collections.<MediaPackage>emptyList();
}
}
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to get conflicts from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get conflicts from remote scheduler service");
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method getReviewStatus.
@Override
public ReviewStatus getReviewStatus(String mediapackageId) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpGet get = new HttpGet(UrlSupport.concat(mediapackageId, "reviewStatus"));
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 review status of the event {}.", mediapackageId);
throw new UnauthorizedException("Unauthorized to get review status of the event " + mediapackageId);
} else {
String reviewStatusString = EntityUtils.toString(response.getEntity(), UTF_8);
ReviewStatus reviewStatus;
try {
reviewStatus = ReviewStatus.valueOf(reviewStatusString);
} catch (Exception e) {
throw new SchedulerException("Could not parse review status from the remote scheduler service: " + reviewStatusString);
}
logger.info("Successfully get review status of event with mediapackage id {} from the remote scheduler service", mediapackageId);
return reviewStatus;
}
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to get event review status from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get event review status from remote scheduler service");
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method removeEvent.
@Override
public void removeEvent(String eventId) throws NotFoundException, UnauthorizedException, SchedulerTransactionLockException, SchedulerException {
logger.debug("Start removing event {} from scheduling service.", eventId);
HttpDelete delete = new HttpDelete("/" + eventId);
HttpResponse response = getResponse(delete, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED, SC_CONFLICT);
try {
if (response != null && SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
logger.info("Event {} was not found by the scheduler service", eventId);
throw new NotFoundException("Event '" + eventId + "' not found on remote scheduler service!");
} else if (response != null && SC_OK == response.getStatusLine().getStatusCode()) {
logger.info("Event {} removed from scheduling service.", eventId);
return;
} else if (response != null && SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to remove the event {}.", eventId);
throw new UnauthorizedException("Unauthorized to remove the event " + eventId);
} else if (response != null && SC_CONFLICT == response.getStatusLine().getStatusCode()) {
logger.info("Event is locked by a transaction, unable to delete event {}", eventId);
throw new SchedulerTransactionLockException("Event is locked by a transaction, unable to delete event " + eventId);
}
} catch (UnauthorizedException e) {
throw e;
} catch (NotFoundException e) {
throw e;
} catch (SchedulerTransactionLockException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to remove event " + eventId + " from the scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to remove event " + eventId);
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method getRecordingState.
@Override
public Recording getRecordingState(String id) throws NotFoundException, SchedulerException {
HttpGet get = new HttpGet(UrlSupport.concat(id, "recordingStatus"));
HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND);
try {
if (response != null) {
if (SC_OK == response.getStatusLine().getStatusCode()) {
String recordingStateJson = EntityUtils.toString(response.getEntity(), UTF_8);
JSONObject json = (JSONObject) parser.parse(recordingStateJson);
String recordingId = (String) json.get("id");
String status = (String) json.get("state");
Long lastHeard = (Long) json.get("lastHeardFrom");
logger.info("Successfully get calendar of agent with id {} from the remote scheduler service", id);
return new RecordingImpl(recordingId, status, lastHeard);
} else if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
logger.warn("Event with mediapackage id {} was not found by the scheduler service", id);
throw new NotFoundException("Event with mediapackage id '" + id + "' not found on remote scheduler service!");
}
}
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to get calendar from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get calendar from remote scheduler service");
}
Aggregations