Search in sources :

Example 36 with ServiceRegistryException

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

the class ServiceRegistryJpaImpl method countByOperation.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.serviceregistry.api.ServiceRegistry#countByOperation(java.lang.String, java.lang.String,
 *      Status)
 */
@Override
public long countByOperation(String serviceType, String operation, Status status) throws ServiceRegistryException {
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        Query query = em.createNamedQuery("Job.countByOperation");
        query.setParameter("status", status.ordinal());
        query.setParameter("serviceType", serviceType);
        query.setParameter("operation", operation);
        Number countResult = (Number) query.getSingleResult();
        return countResult.longValue();
    } catch (Exception e) {
        throw new ServiceRegistryException(e);
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) URISyntaxException(java.net.URISyntaxException) NoResultException(javax.persistence.NoResultException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) TrustedHttpClientException(org.opencastproject.security.api.TrustedHttpClientException) PersistenceException(javax.persistence.PersistenceException) RollbackException(javax.persistence.RollbackException) NotFoundException(org.opencastproject.util.NotFoundException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 37 with ServiceRegistryException

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

the class JobEndpoint method getTasksAsJSON.

/**
 * Returns the list of tasks matching the given query as JSON Object
 *
 * @param query
 *          The worklfow query
 * @return The list of matching tasks as JSON Object
 * @throws JobEndpointException
 * @throws NotFoundException
 */
public JObject getTasksAsJSON(WorkflowQuery query) throws JobEndpointException, NotFoundException {
    // Get results
    WorkflowSet workflowInstances = null;
    long totalWithoutFilters = 0;
    List<JValue> jsonList = new ArrayList<>();
    try {
        workflowInstances = workflowService.getWorkflowInstances(query);
        totalWithoutFilters = workflowService.countWorkflowInstances();
    } catch (WorkflowDatabaseException e) {
        throw new JobEndpointException(String.format("Not able to get the list of job from the database: %s", e), e.getCause());
    }
    WorkflowInstance[] items = workflowInstances.getItems();
    for (WorkflowInstance instance : items) {
        long instanceId = instance.getId();
        String series = instance.getMediaPackage().getSeriesTitle();
        // Retrieve submission date with the workflow instance main job
        Date created;
        try {
            created = serviceRegistry.getJob(instanceId).getDateCreated();
        } catch (ServiceRegistryException e) {
            throw new JobEndpointException(String.format("Error when retrieving job %s from the service registry: %s", instanceId, e), e.getCause());
        }
        jsonList.add(obj(f("id", v(instanceId)), f("title", v(nul(instance.getMediaPackage().getTitle()).getOr(""))), f("series", v(series, Jsons.BLANK)), f("workflow", v(instance.getTitle(), Jsons.BLANK)), f("status", v(instance.getState().toString())), f("submitted", v(created != null ? DateTimeSupport.toUTC(created.getTime()) : ""))));
    }
    JObject json = obj(f("results", arr(jsonList)), f("count", v(workflowInstances.getTotalCount())), f("offset", v(query.getStartPage())), f("limit", v(jsonList.size())), f("total", v(totalWithoutFilters)));
    return json;
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) ArrayList(java.util.ArrayList) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Date(java.util.Date) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) JobEndpointException(org.opencastproject.adminui.exception.JobEndpointException) JValue(com.entwinemedia.fn.data.json.JValue) JObject(com.entwinemedia.fn.data.json.JObject)

Example 38 with ServiceRegistryException

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

the class AnimateServiceImpl method process.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
 */
@Override
protected String process(Job job) throws Exception {
    logger.debug("Started processing job {}", job.getId());
    if (!OPERATION.equals(job.getOperation())) {
        throw new ServiceRegistryException(String.format("This service can't handle operations of type '%s'", job.getOperation()));
    }
    List<String> arguments = job.getArguments();
    URI animation = new URI(arguments.get(0));
    Gson gson = new Gson();
    Map<String, String> metadata = gson.fromJson(arguments.get(1), stringMapType);
    List<String> options = gson.fromJson(arguments.get(2), stringListType);
    // filter animation and get new, custom input file
    File input = customAnimation(job, animation, metadata);
    // prepare output file
    File output = new File(workspace.rootDirectory(), String.format("animate/%d/%s.%s", job.getId(), FilenameUtils.getBaseName(animation.getPath()), "mkv"));
    FileUtils.forceMkdirParent(output);
    // create animation process.
    final List<String> command = new ArrayList<>();
    command.add(synfigBinary);
    command.add("-i");
    command.add(input.getAbsolutePath());
    command.add("-o");
    command.add(output.getAbsolutePath());
    command.addAll(options);
    logger.info("Executing animation command: {}", command);
    Process process = null;
    try {
        ProcessBuilder processBuilder = new ProcessBuilder(command);
        processBuilder.redirectErrorStream(true);
        process = processBuilder.start();
        // print synfig (+ffmpeg) output
        try (BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
            String line;
            while ((line = in.readLine()) != null) {
                logger.debug("Synfig: {}", line);
            }
        }
        // wait until the task is finished
        int exitCode = process.waitFor();
        if (exitCode != 0) {
            throw new AnimateServiceException(String.format("Synfig exited abnormally with status %d (command: %s)", exitCode, command));
        }
        if (!output.isFile()) {
            throw new AnimateServiceException("Synfig produced no output");
        }
        logger.info("Animation generated successfully: {}", output);
    } catch (Exception e) {
        // Ensure temporary data are removed
        FileUtils.deleteQuietly(output.getParentFile());
        logger.debug("Removed output directory of failed animation process: {}", output.getParentFile());
        throw new AnimateServiceException(e);
    } finally {
        IoSupport.closeQuietly(process);
        FileUtils.deleteQuietly(input);
    }
    URI uri = workspace.putInCollection("animate-" + job.getId(), output.getName(), new FileInputStream(output));
    FileUtils.deleteQuietly(new File(workspace.rootDirectory(), String.format("animate/%d", job.getId())));
    return uri.toString();
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) AnimateServiceException(org.opencastproject.animate.api.AnimateServiceException) NotFoundException(org.opencastproject.util.NotFoundException) ConfigurationException(org.opencastproject.util.ConfigurationException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) AnimateServiceException(org.opencastproject.animate.api.AnimateServiceException) BufferedReader(java.io.BufferedReader) File(java.io.File)

Example 39 with ServiceRegistryException

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

the class AnimateServiceImpl method animate.

@Override
public Job animate(URI animation, Map<String, String> metadata, List<String> arguments) throws AnimateServiceException {
    Gson gson = new Gson();
    List<String> jobArguments = Arrays.asList(animation.toString(), gson.toJson(metadata), gson.toJson(arguments));
    try {
        logger.debug("Create animate service job");
        return serviceRegistry.createJob(JOB_TYPE, OPERATION, jobArguments, jobLoad);
    } catch (ServiceRegistryException e) {
        throw new AnimateServiceException(e);
    }
}
Also used : AnimateServiceException(org.opencastproject.animate.api.AnimateServiceException) Gson(com.google.gson.Gson) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 40 with ServiceRegistryException

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

the class TextAnalyzerServiceImpl 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 Extract:
                Attachment element = (Attachment) MediaPackageElementParser.getFromXml(arguments.get(0));
                Catalog catalog = extract(job, element);
                return MediaPackageElementParser.getAsXml(catalog);
            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) Catalog(org.opencastproject.mediapackage.Catalog) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) TextExtractorException(org.opencastproject.textextractor.api.TextExtractorException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) TextAnalyzerException(org.opencastproject.textanalyzer.api.TextAnalyzerException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException)

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