Search in sources :

Example 71 with SchedulerException

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");
}
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) 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 72 with SchedulerException

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");
}
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) MediaPackage(org.opencastproject.mediapackage.MediaPackage) 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 73 with SchedulerException

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");
}
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) 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 74 with SchedulerException

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

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");
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) JSONObject(org.json.simple.JSONObject) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) RecordingImpl(org.opencastproject.scheduler.api.RecordingImpl) 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)

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