Search in sources :

Example 26 with SchedulerException

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");
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) HttpGet(org.apache.http.client.methods.HttpGet) 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 27 with SchedulerException

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

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

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

Example 30 with SchedulerException

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");
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) 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) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) MediaPackage(org.opencastproject.mediapackage.MediaPackage) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException)

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