use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method removeRecording.
@Override
public void removeRecording(String eventId) throws NotFoundException, SchedulerException {
HttpDelete delete = new HttpDelete(UrlSupport.concat(eventId, "recordingStatus"));
HttpResponse response = getResponse(delete, SC_OK, SC_NOT_FOUND);
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("Recording status of event {} removed from scheduling service.", eventId);
return;
}
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to remove recording status of event " + eventId + " from the scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to remove recording status of event " + eventId);
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method cleanupTransactions.
@Override
public void cleanupTransactions() throws UnauthorizedException, SchedulerException {
HttpPost post = new HttpPost("/transaction/cleanup");
HttpResponse response = getResponse(post, SC_OK, SC_UNAUTHORIZED);
try {
if (response != null && SC_OK == response.getStatusLine().getStatusCode()) {
logger.info("Successfully cleaned up scheduler transactions to the scheduler service");
return;
} else if (response != null && SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to cleanup scheduler transactions");
throw new UnauthorizedException("Unauthorized to cleanup scheduler transactions");
}
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to cleanup scheduler transactions to the scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to cleanup scheduler transactions to the scheduler service");
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method getCalendar.
@Override
public String getCalendar(Opt<String> captureAgentId, Opt<String> seriesId, Opt<Date> cutoff) throws SchedulerException {
List<NameValuePair> queryStringParams = new ArrayList<NameValuePair>();
for (String s : captureAgentId) {
queryStringParams.add(new BasicNameValuePair("agentid", s));
}
for (String s : seriesId) {
queryStringParams.add(new BasicNameValuePair("seriesid", s));
}
for (Date d : cutoff) {
queryStringParams.add(new BasicNameValuePair("cutoff", Long.toString(d.getTime())));
}
HttpGet get = new HttpGet("calendars?".concat(URLEncodedUtils.format(queryStringParams, UTF_8)));
HttpResponse response = getResponse(get, SC_OK);
try {
if (response != null) {
if (SC_OK == response.getStatusLine().getStatusCode()) {
String calendar = EntityUtils.toString(response.getEntity(), UTF_8);
logger.info("Successfully get calendar of agent with id {} from the remote scheduler service", captureAgentId);
return calendar;
}
}
} 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");
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method addEvent.
@Override
public void addEvent(Date startDateTime, Date endDateTime, String captureAgentId, Set<String> userIds, MediaPackage mediaPackage, Map<String, String> wfProperties, Map<String, String> caMetadata, Opt<Boolean> optOut, Opt<String> schedulingSource, String origin) throws UnauthorizedException, SchedulerTransactionLockException, SchedulerConflictException, SchedulerException {
HttpPost post = new HttpPost("/");
String eventId = mediaPackage.getIdentifier().compact();
logger.debug("Start adding a new event {} through remote Schedule Service", eventId);
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("start", Long.toString(startDateTime.getTime())));
params.add(new BasicNameValuePair("end", Long.toString(endDateTime.getTime())));
params.add(new BasicNameValuePair("agent", captureAgentId));
params.add(new BasicNameValuePair("users", StringUtils.join(userIds, ",")));
params.add(new BasicNameValuePair("mediaPackage", MediaPackageParser.getAsXml(mediaPackage)));
params.add(new BasicNameValuePair("wfproperties", toPropertyString(wfProperties)));
params.add(new BasicNameValuePair("agentparameters", toPropertyString(caMetadata)));
if (optOut.isSome())
params.add(new BasicNameValuePair("optOut", Boolean.toString(optOut.get())));
if (schedulingSource.isSome())
params.add(new BasicNameValuePair("source", schedulingSource.get()));
params.add(new BasicNameValuePair("origin", origin));
post.setEntity(new UrlEncodedFormEntity(params, UTF_8));
HttpResponse response = getResponse(post, SC_CREATED, SC_UNAUTHORIZED, SC_CONFLICT);
try {
if (response != null && SC_CREATED == response.getStatusLine().getStatusCode()) {
logger.info("Successfully added event {} to the scheduler service", eventId);
return;
} else if (response != null && SC_CONFLICT == response.getStatusLine().getStatusCode()) {
String errorJson = EntityUtils.toString(response.getEntity(), UTF_8);
JSONObject json = (JSONObject) parser.parse(errorJson);
JSONObject error = (JSONObject) json.get("error");
String errorCode = (String) error.get("code");
if (SchedulerTransactionLockException.ERROR_CODE.equals(errorCode)) {
logger.info("Event is locked by a transaction, unable to add event {}", eventId);
throw new SchedulerTransactionLockException("Event is locked by a transaction, unable to add event " + eventId);
} else if (SchedulerConflictException.ERROR_CODE.equals(errorCode)) {
logger.info("Conflicting events found when adding event {}", eventId);
throw new SchedulerConflictException("Conflicting events found when adding event " + eventId);
} else {
throw new SchedulerException("Unexpected error code " + errorCode);
}
} else if (response != null && SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to create the event");
throw new UnauthorizedException("Unauthorized to create the event");
} else {
throw new SchedulerException("Unable to add event " + eventId + " to the scheduler service");
}
} catch (UnauthorizedException e) {
throw e;
} catch (SchedulerTransactionLockException e) {
throw e;
} catch (SchedulerConflictException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to add event " + eventId + " to the scheduler service: " + e);
} finally {
closeConnection(response);
}
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method getCaptureAgentConfiguration.
@Override
public Map<String, String> getCaptureAgentConfiguration(String eventId) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpGet get = new HttpGet(eventId.concat("/agent.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 capture agent configuration '" + eventId + "' not found on remote scheduler service!");
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to get capture agent config of the event {}.", eventId);
throw new UnauthorizedException("Unauthorized to get capture agent config of the event " + eventId);
} else {
Properties properties = new Properties();
properties.load(response.getEntity().getContent());
logger.info("Successfully get event capture agent 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 capture agent configuration from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get event capture agent configuration from remote scheduler service");
}
Aggregations