Search in sources :

Example 41 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class TimelinePreviewsServiceImpl method process.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
 */
@Override
protected String process(Job job) throws Exception {
    Operation op = null;
    String operation = job.getOperation();
    List<String> arguments = job.getArguments();
    try {
        op = Operation.valueOf(operation);
        switch(op) {
            case TimelinePreview:
                Track track = (Track) MediaPackageElementParser.getFromXml(arguments.get(0));
                int imageCount = Integer.parseInt(arguments.get(1));
                Attachment timelinePreviewsMpe = generatePreviewImages(job, track, imageCount);
                return MediaPackageElementParser.getAsXml(timelinePreviewsMpe);
            default:
                throw new IllegalStateException("Don't know how to handle operation '" + operation + "'");
        }
    } catch (IllegalArgumentException e) {
        throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'", e);
    } catch (IndexOutOfBoundsException e) {
        throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
    } catch (Exception e) {
        throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
    }
}
Also used : Attachment(org.opencastproject.mediapackage.Attachment) Track(org.opencastproject.mediapackage.Track) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) TimelinePreviewsException(org.opencastproject.timelinepreviews.api.TimelinePreviewsException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) FileNotFoundException(java.io.FileNotFoundException) UnknownFileTypeException(org.opencastproject.util.UnknownFileTypeException)

Example 42 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class AbstractJobProducer method isReadyToAccept.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.job.api.JobProducer#isReadyToAccept(org.opencastproject.job.api.Job)
 */
@Override
public boolean isReadyToAccept(Job job) throws ServiceRegistryException, UndispatchableJobException {
    if (!jobType.equals(job.getJobType())) {
        logger.debug("Invalid job type submitted: {}", job.getJobType());
        return false;
    }
    NodeLoad maxload;
    try {
        maxload = getServiceRegistry().getMaxLoadOnNode(getServiceRegistry().getRegistryHostname());
    } catch (NotFoundException e) {
        throw new ServiceRegistryException(e);
    }
    // Note: We are not adding the job load in the next line because it is already accounted for in the load values we
    // get back from the service registry.
    float currentLoad = getServiceRegistry().getOwnLoad();
    /* Note that this first clause looks at the *job's*, the other two look at the *node's* load
     * We're assuming that if this case is true, then we're also the most powerful node in the system for this service,
     * per the current job dispatching code in ServiceRegistryJpaImpl */
    if (job.getJobLoad() > maxload.getLoadFactor() && acceptJobLoadsExeedingMaxLoad) {
        logger.warn("Accepting job {} of type {} with load {} even though load of {} is above this node's limit of {}.", new Object[] { job.getId(), job.getJobType(), df.format(job.getJobLoad()), df.format(currentLoad), df.format(maxload.getLoadFactor()) });
        logger.warn("This is a configuration issue that you should resolve in a production system!");
        return true;
    } else if (currentLoad > maxload.getLoadFactor()) {
        logger.debug("Declining job {} of type {} with load {} because load of {} would exceed this node's limit of {}.", new Object[] { job.getId(), job.getJobType(), df.format(job.getJobLoad()), df.format(currentLoad), df.format(maxload.getLoadFactor()) });
        return false;
    } else {
        logger.debug("Accepting job {} of type {} with load {} because load of {} is within this node's limit of {}.", new Object[] { job.getId(), job.getJobType(), df.format(job.getJobLoad()), df.format(currentLoad), df.format(maxload.getLoadFactor()) });
        return true;
    }
}
Also used : NotFoundException(org.opencastproject.util.NotFoundException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) NodeLoad(org.opencastproject.serviceregistry.api.SystemLoad.NodeLoad)

Example 43 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class ExecuteServiceImpl method execute.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.execute.api.ExecuteService#execute(java.lang.String, java.lang.String,
 *      org.opencastproject.mediapackage.MediaPackageElement, java.lang.String,
 *      org.opencastproject.mediapackage.MediaPackageElement.Type, float)
 * @throws IllegalArgumentException
 *           if the input arguments are incorrect
 * @throws ExecuteException
 *           if an internal error occurs
 */
@Override
public Job execute(String exec, String params, MediaPackageElement inElement, String outFileName, Type expectedType, float load) throws ExecuteException, IllegalArgumentException {
    logger.debug("Creating Execute Job for command: {}", exec);
    if (StringUtils.isBlank(exec))
        throw new IllegalArgumentException("The command to execute cannot be null");
    if (StringUtils.isBlank(params))
        throw new IllegalArgumentException("The command arguments cannot be null");
    if (inElement == null)
        throw new IllegalArgumentException("The input MediaPackage element cannot be null");
    outFileName = StringUtils.trimToNull(outFileName);
    if ((outFileName == null) && (expectedType != null) || (outFileName != null) && (expectedType == null))
        throw new IllegalArgumentException("Expected element type and output filename cannot be null");
    try {
        List<String> paramList = new ArrayList<String>(5);
        paramList.add(exec);
        paramList.add(params);
        paramList.add(MediaPackageElementParser.getAsXml(inElement));
        paramList.add(outFileName);
        paramList.add((expectedType == null) ? null : expectedType.toString());
        return serviceRegistry.createJob(JOB_TYPE, Operation.Execute_Element.toString(), paramList, load);
    } catch (ServiceRegistryException e) {
        throw new ExecuteException(String.format("Unable to create a job of type '%s'", JOB_TYPE), e);
    } catch (MediaPackageException e) {
        throw new ExecuteException("Error serializing an element", e);
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) ArrayList(java.util.ArrayList) ExecuteException(org.opencastproject.execute.api.ExecuteException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 44 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class ExecuteServiceImpl method execute.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.execute.api.ExecuteService#execute(java.lang.String, java.lang.String,
 *      org.opencastproject.mediapackage.MediaPackage, java.lang.String,
 *      org.opencastproject.mediapackage.MediaPackageElement.Type, float)
 */
@Override
public Job execute(String exec, String params, MediaPackage mp, String outFileName, Type expectedType, float load) throws ExecuteException {
    if (StringUtils.isBlank(exec))
        throw new IllegalArgumentException("The command to execute cannot be null");
    if (StringUtils.isBlank(params))
        throw new IllegalArgumentException("The command arguments cannot be null");
    if (mp == null)
        throw new IllegalArgumentException("The input MediaPackage cannot be null");
    outFileName = StringUtils.trimToNull(outFileName);
    if ((outFileName == null) && (expectedType != null) || (outFileName != null) && (expectedType == null))
        throw new IllegalArgumentException("Expected element type and output filename cannot be null");
    try {
        List<String> paramList = new ArrayList<String>(5);
        paramList.add(exec);
        paramList.add(params);
        paramList.add(MediaPackageParser.getAsXml(mp));
        paramList.add(outFileName);
        paramList.add((expectedType == null) ? null : expectedType.toString());
        return serviceRegistry.createJob(JOB_TYPE, Operation.Execute_Mediapackage.toString(), paramList, load);
    } catch (ServiceRegistryException e) {
        throw new ExecuteException(String.format("Unable to create a job of type '%s'", JOB_TYPE), e);
    }
}
Also used : ArrayList(java.util.ArrayList) ExecuteException(org.opencastproject.execute.api.ExecuteException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 45 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class YouTubeV3PublicationServiceImpl method process.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
 */
@Override
protected String process(final Job job) throws Exception {
    Operation op = null;
    try {
        op = Operation.valueOf(job.getOperation());
        List<String> arguments = job.getArguments();
        MediaPackage mediapackage = MediaPackageParser.getFromXml(arguments.get(0));
        switch(op) {
            case Publish:
                Publication publicationElement = publish(job, mediapackage, arguments.get(1));
                return (publicationElement == null) ? null : MediaPackageElementParser.getAsXml(publicationElement);
            case Retract:
                Publication retractedElement = retract(job, mediapackage);
                return (retractedElement == null) ? null : MediaPackageElementParser.getAsXml(retractedElement);
            default:
                throw new IllegalStateException("Don't know how to handle operation '" + job.getOperation() + "'");
        }
    } catch (final IllegalArgumentException e) {
        throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'", e);
    } catch (final IndexOutOfBoundsException e) {
        throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
    } catch (final Exception e) {
        throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) Publication(org.opencastproject.mediapackage.Publication) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) PublicationException(org.opencastproject.publication.api.PublicationException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Aggregations

ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)99 NotFoundException (org.opencastproject.util.NotFoundException)61 ConfigurationException (org.osgi.service.cm.ConfigurationException)41 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)30 URISyntaxException (java.net.URISyntaxException)29 Job (org.opencastproject.job.api.Job)29 PersistenceException (javax.persistence.PersistenceException)26 RollbackException (javax.persistence.RollbackException)26 TrustedHttpClientException (org.opencastproject.security.api.TrustedHttpClientException)26 NoResultException (javax.persistence.NoResultException)25 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)25 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)24 EntityManager (javax.persistence.EntityManager)22 MediaPackage (org.opencastproject.mediapackage.MediaPackage)20 URI (java.net.URI)16 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)14 DistributionException (org.opencastproject.distribution.api.DistributionException)13 Attachment (org.opencastproject.mediapackage.Attachment)12 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)12