Search in sources :

Example 31 with SchedulerException

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);
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 32 with SchedulerException

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");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) HttpResponse(org.apache.http.HttpResponse) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 33 with SchedulerException

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");
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) Date(java.util.Date) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 34 with SchedulerException

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);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) ArrayList(java.util.ArrayList) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) JSONObject(org.json.simple.JSONObject) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException)

Example 35 with SchedulerException

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");
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) HttpGet(org.apache.http.client.methods.HttpGet) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) Properties(java.util.Properties) Map(java.util.Map) HashMap(java.util.HashMap) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Aggregations

SchedulerException (org.opencastproject.scheduler.api.SchedulerException)83 NotFoundException (org.opencastproject.util.NotFoundException)76 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)68 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)62 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)60 HttpResponse (org.apache.http.HttpResponse)32 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)30 IOException (java.io.IOException)29 SeriesException (org.opencastproject.series.api.SeriesException)27 ValidationException (net.fortuna.ical4j.model.ValidationException)26 ServiceException (org.osgi.framework.ServiceException)26 ConfigurationException (org.osgi.service.cm.ConfigurationException)26 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)22 MediaPackage (org.opencastproject.mediapackage.MediaPackage)22 Date (java.util.Date)21 HttpGet (org.apache.http.client.methods.HttpGet)19 ARecord (org.opencastproject.assetmanager.api.query.ARecord)19 AResult (org.opencastproject.assetmanager.api.query.AResult)19 ArrayList (java.util.ArrayList)16 Log.getHumanReadableTimeString (org.opencastproject.util.Log.getHumanReadableTimeString)16