Search in sources :

Example 36 with SchedulerException

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

the class SchedulerServiceRemoteImpl method updateRecordingState.

@Override
public boolean updateRecordingState(String mediapackageId, String state) throws NotFoundException, SchedulerException {
    HttpPut put = new HttpPut(UrlSupport.concat(mediapackageId, "recordingStatus"));
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("state", state));
    put.setEntity(new UrlEncodedFormEntity(params, UTF_8));
    HttpResponse response = getResponse(put, SC_OK, SC_NOT_FOUND, SC_BAD_REQUEST);
    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_BAD_REQUEST == response.getStatusLine().getStatusCode()) {
                logger.info("Unable to update event with mediapackage id {}, invalid recording state: {}.", mediapackageId, state);
                return false;
            } else if (SC_OK == response.getStatusLine().getStatusCode()) {
                logger.info("Event with mediapackage id {} successfully updated with recording status.", mediapackageId);
                return true;
            } else {
                throw new SchedulerException("Unexpected status code " + response.getStatusLine());
            }
        }
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        throw new SchedulerException("Unable to update recording state of event with mediapackage id " + mediapackageId + " to the scheduler service: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SchedulerException("Unable to update recording state of event with mediapackage id " + mediapackageId);
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) 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 37 with SchedulerException

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

the class SchedulerServiceRemoteImpl method isOptOut.

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

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

the class SchedulerServiceRemoteImpl method getTechnicalMetadata.

@Override
public TechnicalMetadata getTechnicalMetadata(String eventId) throws NotFoundException, UnauthorizedException, SchedulerException {
    HttpGet get = new HttpGet(eventId.concat("/technical.json"));
    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 id '" + eventId + "' not found on remote scheduler service!");
            } else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
                logger.info("Unauthorized to get the technical metadata of the event {}.", eventId);
                throw new UnauthorizedException("Unauthorized to get the technical metadata of the event " + eventId);
            } else {
                String technicalMetadataJson = EntityUtils.toString(response.getEntity(), UTF_8);
                JSONObject json = (JSONObject) parser.parse(technicalMetadataJson);
                final String recordingId = (String) json.get("id");
                final Date start = new Date(DateTimeSupport.fromUTC((String) json.get("start")));
                final Date end = new Date(DateTimeSupport.fromUTC((String) json.get("end")));
                final boolean optOut = (Boolean) json.get("optOut");
                final String location = (String) json.get("location");
                final Set<String> presenters = new HashSet<>();
                JSONArray presentersArr = (JSONArray) json.get("presenters");
                for (int i = 0; i < presentersArr.size(); i++) {
                    presenters.add((String) presentersArr.get(i));
                }
                final Map<String, String> wfProperties = new HashMap<>();
                JSONObject wfPropertiesObj = (JSONObject) json.get("wfProperties");
                Set<Entry<String, String>> entrySet = wfPropertiesObj.entrySet();
                for (Entry<String, String> entry : entrySet) {
                    wfProperties.put(entry.getKey(), entry.getValue());
                }
                final Map<String, String> agentConfig = new HashMap<>();
                JSONObject agentConfigObj = (JSONObject) json.get("agentConfig");
                entrySet = agentConfigObj.entrySet();
                for (Entry<String, String> entry : entrySet) {
                    agentConfig.put(entry.getKey(), entry.getValue());
                }
                String status = (String) json.get("state");
                String lastHeard = (String) json.get("lastHeardFrom");
                Recording recording = null;
                if (StringUtils.isNotBlank(status) && StringUtils.isNotBlank(lastHeard)) {
                    recording = new RecordingImpl(recordingId, status, DateTimeSupport.fromUTC(lastHeard));
                }
                final Opt<Recording> recordingOpt = Opt.nul(recording);
                logger.info("Successfully get the technical metadata of event '{}' from the remote scheduler service", eventId);
                return new TechnicalMetadataImpl(recordingId, location, start, end, optOut, presenters, wfProperties, agentConfig, recordingOpt);
            }
        }
    } catch (NotFoundException e) {
        throw e;
    } catch (UnauthorizedException e) {
        throw e;
    } catch (Exception e) {
        throw new SchedulerException("Unable to parse the technical metadata from remote scheduler service: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SchedulerException("Unable to get the technical metadata from remote scheduler service");
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) TechnicalMetadataImpl(org.opencastproject.scheduler.api.TechnicalMetadataImpl) HttpGet(org.apache.http.client.methods.HttpGet) JSONArray(org.json.simple.JSONArray) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) RecordingImpl(org.opencastproject.scheduler.api.RecordingImpl) 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) Entry(java.util.Map.Entry) Opt(com.entwinemedia.fn.data.Opt) JSONObject(org.json.simple.JSONObject) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) Recording(org.opencastproject.scheduler.api.Recording) Map(java.util.Map) HashMap(java.util.HashMap)

Example 39 with SchedulerException

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

the class SchedulerServiceRemoteImpl method getWorkflowConfig.

@Override
public Map<String, String> getWorkflowConfig(String eventId) throws NotFoundException, UnauthorizedException, SchedulerException {
    HttpGet get = new HttpGet(eventId.concat("/workflow.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 workflow configuration '" + eventId + "' not found on remote scheduler service!");
            } else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
                logger.info("Unauthorized to get workflow config of the event {}.", eventId);
                throw new UnauthorizedException("Unauthorized to get workflow config of the event " + eventId);
            } else {
                Properties properties = new Properties();
                properties.load(response.getEntity().getContent());
                logger.info("Successfully get event workflow 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 workflow configuration from remote scheduler service: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SchedulerException("Unable to get event workflow 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)

Example 40 with SchedulerException

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

the class SchedulerServiceRemoteImpl method getKnownRecordings.

@Override
public Map<String, Recording> getKnownRecordings() throws SchedulerException {
    HttpGet get = new HttpGet("recordingStatus");
    HttpResponse response = getResponse(get, SC_OK);
    try {
        if (response != null) {
            if (SC_OK == response.getStatusLine().getStatusCode()) {
                String recordingStates = EntityUtils.toString(response.getEntity(), UTF_8);
                JSONArray recordings = (JSONArray) parser.parse(recordingStates);
                Map<String, Recording> recordingsMap = new HashMap<String, Recording>();
                for (int i = 0; i < recordings.size(); i++) {
                    JSONObject recording = (JSONObject) recordings.get(i);
                    String recordingId = (String) recording.get("id");
                    String status = (String) recording.get("state");
                    Long lastHeard = (Long) recording.get("lastHeardFrom");
                    recordingsMap.put(recordingId, new RecordingImpl(recordingId, status, lastHeard));
                }
                logger.info("Successfully get recording states from the remote scheduler service");
                return recordingsMap;
            }
        }
    } catch (Exception e) {
        throw new SchedulerException("Unable to get recording states from remote scheduler service: " + e);
    } finally {
        closeConnection(response);
    }
    throw new SchedulerException("Unable to get recording states from remote scheduler service");
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) HashMap(java.util.HashMap) HttpGet(org.apache.http.client.methods.HttpGet) JSONArray(org.json.simple.JSONArray) HttpResponse(org.apache.http.HttpResponse) RecordingImpl(org.opencastproject.scheduler.api.RecordingImpl) 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) Recording(org.opencastproject.scheduler.api.Recording)

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