Search in sources :

Example 76 with SchedulerException

use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.

the class SchedulerServiceRemoteImpl method updateReviewStatus.

@Override
public void updateReviewStatus(String mediapackageId, ReviewStatus reviewStatus) throws NotFoundException, UnauthorizedException, SchedulerException {
    HttpPut put = new HttpPut(UrlSupport.concat(mediapackageId, "reviewStatus"));
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("reviewStatus", reviewStatus.toString()));
    put.setEntity(new UrlEncodedFormEntity(params, UTF_8));
    HttpResponse response = getResponse(put, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED);
    try {
        if (response != null) {
            if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
                logger.warn("Event with mediapackage id {} was not found by the scheduler service", mediapackageId);
                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 update review status of the event {}.", mediapackageId);
                throw new UnauthorizedException("Unauthorized to update review status of the event " + mediapackageId);
            } else if (SC_OK == response.getStatusLine().getStatusCode()) {
                logger.info("Event with mediapackage id {} successfully updated with review status.", mediapackageId);
                return;
            } else {
                throw new SchedulerException("Unexpected status code " + response.getStatusLine());
            }
        }
    } catch (NotFoundException e) {
        throw e;
    } catch (UnauthorizedException e) {
        throw e;
    } catch (Exception e) {
        throw new SchedulerException("Unable to update event with mediapackage id " + mediapackageId + " to the scheduler service: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SchedulerException("Unable to update  event with mediapackage id " + mediapackageId);
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) HttpPut(org.apache.http.client.methods.HttpPut) 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 77 with SchedulerException

use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.

the class SchedulerServiceRemoteImpl method getMediaPackage.

@Override
public MediaPackage getMediaPackage(String eventId) throws NotFoundException, UnauthorizedException, SchedulerException {
    HttpGet get = new HttpGet(eventId.concat("/mediapackage.xml"));
    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 mediapackage '" + eventId + "' not found on remote scheduler service!");
            } else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
                logger.info("Unauthorized to get mediapacakge of the event {}.", eventId);
                throw new UnauthorizedException("Unauthorized to get mediapackage of the event " + eventId);
            } else {
                MediaPackage mp = MediaPackageParser.getFromXml(EntityUtils.toString(response.getEntity(), UTF_8));
                logger.info("Successfully get event mediapackage {} from the remote scheduler service", eventId);
                return mp;
            }
        }
    } catch (NotFoundException e) {
        throw e;
    } catch (UnauthorizedException e) {
        throw e;
    } catch (Exception e) {
        throw new SchedulerException("Unable to parse event media package from remote scheduler service: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SchedulerException("Unable to get event media package 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) MediaPackage(org.opencastproject.mediapackage.MediaPackage) 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 78 with SchedulerException

use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.

the class SchedulerServiceRemoteImpl method getTransactionBySource.

@Override
public SchedulerTransaction getTransactionBySource(String source) throws NotFoundException, SchedulerException {
    HttpGet get = new HttpGet("transaction/source/".concat(source));
    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 with source '" + source + "' 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 with source {} from the remote scheduler service", source);
                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");
}
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) 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 79 with SchedulerException

use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.

the class SchedulerServiceRemoteImpl method removeScheduledRecordingsBeforeBuffer.

@Override
public void removeScheduledRecordingsBeforeBuffer(long buffer) throws UnauthorizedException, SchedulerException {
    HttpPost post = new HttpPost("/removeOldScheduledRecordings");
    logger.debug("Start removing old schedules before buffer {} through remote Schedule Service", buffer);
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("buffer", Long.toString(buffer)));
    post.setEntity(new UrlEncodedFormEntity(params, UTF_8));
    HttpResponse response = getResponse(post, SC_OK, SC_UNAUTHORIZED);
    try {
        if (response != null && SC_OK == response.getStatusLine().getStatusCode()) {
            logger.info("Successfully started removing old schedules before butter {} to the scheduler service", buffer);
            return;
        } else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
            logger.info("Unauthorized to remove old schedules before buffer {}.", buffer);
            throw new UnauthorizedException("Unauthorized to remove old schedules");
        }
    } catch (UnauthorizedException e) {
        throw e;
    } catch (Exception e) {
        throw new SchedulerException("Unable to remove old schedules from the scheduler service: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SchedulerException("Unable to remove old schedules from the scheduler service");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) 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)

Example 80 with SchedulerException

use of org.opencastproject.scheduler.api.SchedulerException in project opencast by opencast.

the class SchedulerServiceRemoteImpl method hasActiveTransaction.

@Override
public boolean hasActiveTransaction(String mediaPackageId) throws NotFoundException, UnauthorizedException, SchedulerException {
    HttpGet get = new HttpGet("transaction/event/".concat(mediaPackageId));
    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 active transaction status of event {}.", mediaPackageId);
                throw new UnauthorizedException("Unauthorized to get active transaction status of the event " + mediaPackageId);
            } else {
                String hasActiveTransactionString = EntityUtils.toString(response.getEntity(), UTF_8);
                Boolean booleanObject = BooleanUtils.toBooleanObject(hasActiveTransactionString);
                if (booleanObject == null)
                    throw new SchedulerException("Could not parse active transaction status from the remote scheduler service: " + hasActiveTransactionString);
                logger.info("Successfully get active transaction 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 active transaction status for event from remote scheduler service: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SchedulerException("Unable to get active transaction status for event from 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)

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