use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method getScheduleLastModified.
@Override
public String getScheduleLastModified(String agentId) throws SchedulerException {
HttpGet get = new HttpGet(UrlSupport.concat(agentId, "lastmodified"));
HttpResponse response = getResponse(get, SC_OK);
try {
if (response != null) {
if (SC_OK == response.getStatusLine().getStatusCode()) {
String agentHash = EntityUtils.toString(response.getEntity(), UTF_8);
logger.info("Successfully get agent last modified hash of agent with id {} from the remote scheduler service", agentId);
return agentHash;
}
}
} catch (Exception e) {
throw new SchedulerException("Unable to get agent last modified hash from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get agent last modified hash from remote scheduler service");
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method rollbackTransaction.
private void rollbackTransaction(String id) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpPost post = new HttpPost(UrlSupport.concat("transaction", id, "rollback"));
HttpResponse response = getResponse(post, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED);
try {
if (response != null && SC_OK == response.getStatusLine().getStatusCode()) {
logger.info("Successfully rolled back scheduler transaction '{}' to the scheduler service", id);
return;
} else if (response != null && SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to rollback scheduler transaction '{}'", id);
throw new UnauthorizedException("Unauthorized to rollback scheduler transaction");
} else if (response != null && SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
logger.info("Scheduler transaction '{}' not found", id);
throw new NotFoundException("Not found scheduler transaction " + id);
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to rollback scheduler transaction '" + id + "' to the scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to rollback scheduler transaction '" + id + "' to the scheduler service");
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method commitTransaction.
private void commitTransaction(String id) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpPost post = new HttpPost(UrlSupport.concat("transaction", id, "commit"));
HttpResponse response = getResponse(post, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED);
try {
if (response != null && SC_OK == response.getStatusLine().getStatusCode()) {
logger.info("Successfully committed scheduler transaction '{}' to the scheduler service", id);
return;
} else if (response != null && SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to commit scheduler transaction '{}'", id);
throw new UnauthorizedException("Unauthorized to commit scheduler transaction");
} else if (response != null && SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
logger.info("Scheduler transaction '{}' not found", id);
throw new NotFoundException("Not found scheduler transaction " + id);
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to commit scheduler transaction '" + id + "' to the scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to commit scheduler transaction '" + id + "' to the scheduler service");
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method updateEvent.
@Override
public void updateEvent(String eventId, Opt<Date> startDateTime, Opt<Date> endDateTime, Opt<String> captureAgentId, Opt<Set<String>> userIds, Opt<MediaPackage> mediaPackage, Opt<Map<String, String>> wfProperties, Opt<Map<String, String>> caMetadata, Opt<Opt<Boolean>> optOut, String origin) throws NotFoundException, UnauthorizedException, SchedulerTransactionLockException, SchedulerConflictException, SchedulerException {
logger.debug("Start updating event {}.", eventId);
HttpPut put = new HttpPut("/" + eventId);
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
if (startDateTime.isSome())
params.add(new BasicNameValuePair("start", Long.toString(startDateTime.get().getTime())));
if (endDateTime.isSome())
params.add(new BasicNameValuePair("end", Long.toString(endDateTime.get().getTime())));
if (captureAgentId.isSome())
params.add(new BasicNameValuePair("agent", captureAgentId.get()));
if (userIds.isSome())
params.add(new BasicNameValuePair("users", StringUtils.join(userIds.get(), ",")));
if (mediaPackage.isSome())
params.add(new BasicNameValuePair("mediaPackage", MediaPackageParser.getAsXml(mediaPackage.get())));
if (wfProperties.isSome())
params.add(new BasicNameValuePair("wfproperties", toPropertyString(wfProperties.get())));
if (caMetadata.isSome())
params.add(new BasicNameValuePair("agentparameters", toPropertyString(caMetadata.get())));
if (optOut.isSome()) {
params.add(new BasicNameValuePair("updateOptOut", Boolean.toString(true)));
if (optOut.get().isSome())
params.add(new BasicNameValuePair("optOut", Boolean.toString(optOut.get().get())));
} else {
params.add(new BasicNameValuePair("updateOptOut", Boolean.toString(false)));
}
params.add(new BasicNameValuePair("origin", origin));
put.setEntity(new UrlEncodedFormEntity(params, UTF_8));
HttpResponse response = getResponse(put, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED, SC_FORBIDDEN, SC_CONFLICT);
try {
if (response != null) {
if (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 (SC_OK == response.getStatusLine().getStatusCode()) {
logger.info("Event {} successfully updated with capture agent metadata.", 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 update event {}", eventId);
throw new SchedulerTransactionLockException("Event is locked by a transaction, unable to update event " + eventId);
} else if (SchedulerConflictException.ERROR_CODE.equals(errorCode)) {
logger.info("Conflicting events found when updating event {}", eventId);
throw new SchedulerConflictException("Conflicting events found when updating event " + eventId);
} else {
throw new SchedulerException("Unexpected error code " + errorCode);
}
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to update the event {}.", eventId);
throw new UnauthorizedException("Unauthorized to update the event " + eventId);
} else if (SC_FORBIDDEN == response.getStatusLine().getStatusCode()) {
logger.info("Forbidden to update the event {}.", eventId);
throw new SchedulerException("Event with specified ID cannot be updated");
} else {
throw new SchedulerException("Unexpected status code " + response.getStatusLine());
}
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (SchedulerTransactionLockException e) {
throw e;
} catch (SchedulerConflictException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to update event " + eventId + " to the scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to update event " + eventId);
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method search.
@Override
public List<MediaPackage> search(Opt<String> captureAgentId, Opt<Date> startsFrom, Opt<Date> startsTo, Opt<Date> endFrom, Opt<Date> endTo) throws UnauthorizedException, SchedulerException {
List<NameValuePair> queryStringParams = new ArrayList<NameValuePair>();
for (String s : captureAgentId) {
queryStringParams.add(new BasicNameValuePair("agent", s));
}
for (Date d : startsFrom) {
queryStringParams.add(new BasicNameValuePair("startsfrom", Long.toString(d.getTime())));
}
for (Date d : startsTo) {
queryStringParams.add(new BasicNameValuePair("startsto", Long.toString(d.getTime())));
}
for (Date d : endFrom) {
queryStringParams.add(new BasicNameValuePair("endsfrom", Long.toString(d.getTime())));
}
for (Date d : endTo) {
queryStringParams.add(new BasicNameValuePair("endsto", Long.toString(d.getTime())));
}
HttpGet get = new HttpGet("recordings.xml?".concat(URLEncodedUtils.format(queryStringParams, UTF_8)));
HttpResponse response = getResponse(get, SC_OK, SC_UNAUTHORIZED);
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 recordings from the remote scheduler service");
return events;
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to search for events");
throw new UnauthorizedException("Unauthorized to search for events");
}
}
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to get recordings from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get recordings from remote scheduler service");
}
Aggregations