use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method createTransaction.
@Override
public SchedulerTransaction createTransaction(final String schedulingSource) throws UnauthorizedException, SchedulerConflictException, SchedulerException {
HttpPost post = new HttpPost("/transaction");
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("source", schedulingSource));
post.setEntity(new UrlEncodedFormEntity(params, UTF_8));
HttpResponse response = getResponse(post, SC_OK, SC_UNAUTHORIZED, SC_CONFLICT);
try {
if (response != null && SC_OK == response.getStatusLine().getStatusCode()) {
String transactionJson = EntityUtils.toString(response.getEntity(), UTF_8);
JSONObject json = (JSONObject) parser.parse(transactionJson);
String transactionId = (String) json.get("id");
String source = (String) json.get("source");
logger.info("Successfully created scheduler transaction '{}' with id '{}' to the scheduler service", source, transactionId);
return new SchedulerTransactionRemoteImpl(transactionId, source);
} else if (response != null && SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to create scheduler transaction");
throw new UnauthorizedException("Unauthorized to create scheduler transaction");
} else if (response != null && SC_CONFLICT == response.getStatusLine().getStatusCode()) {
logger.info("Transaction with source {} already exists!", schedulingSource);
throw new SchedulerConflictException("Transaction already exists with source " + schedulingSource);
}
} catch (UnauthorizedException e) {
throw e;
} catch (SchedulerConflictException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to create scheduler transaction '" + schedulingSource + "' to the scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to create scheduler transaction '" + schedulingSource + "' to the scheduler service");
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method getAccessControlList.
@Override
public AccessControlList getAccessControlList(String eventId) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpGet get = new HttpGet(eventId.concat("/acl"));
HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND, SC_NO_CONTENT, SC_UNAUTHORIZED);
try {
if (response != null) {
switch(response.getStatusLine().getStatusCode()) {
case SC_NOT_FOUND:
throw new NotFoundException("Event '" + eventId + "' not found on remote scheduler service!");
case SC_NO_CONTENT:
return null;
case SC_UNAUTHORIZED:
logger.info("Unauthorized to get acl of the event {}.", eventId);
throw new UnauthorizedException("Unauthorized to get acl of the event " + eventId);
default:
String aclString = EntityUtils.toString(response.getEntity(), "UTF-8");
AccessControlList accessControlList = AccessControlParser.parseAcl(aclString);
logger.info("Successfully get event {} access control list from the remote scheduler service", eventId);
return accessControlList;
}
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to get event access control list from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get event access control list from remote scheduler service");
}
use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.
the class SchedulerServiceRemoteImpl method getTransaction.
@Override
public SchedulerTransaction getTransaction(String id) throws NotFoundException, SchedulerException {
HttpGet get = new HttpGet("transaction/".concat(id));
HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND);
try {
if (response != null) {
if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
throw new NotFoundException("Scheduler transaction '" + id + "' not found on remote scheduler service!");
} else {
String transactionJson = EntityUtils.toString(response.getEntity(), UTF_8);
JSONObject json = (JSONObject) parser.parse(transactionJson);
String transactionId = (String) json.get("id");
String schedulingSource = (String) json.get("source");
logger.info("Successfully get scheduler transaction {} from the remote scheduler service", id);
return new SchedulerTransactionRemoteImpl(transactionId, schedulingSource);
}
}
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to get scheduler transaction from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get scheduler transaction from remote scheduler service");
}
Aggregations