Search in sources :

Example 96 with ServiceRegistryException

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

the class WorkflowServiceSolrIndex method activate.

/**
 * Activates the index by configuring solr with the server url that must have been set previously.
 */
public void activate(String systemUserName) {
    // Set up the solr server
    if (solrServerUrl != null) {
        solrServer = SolrServerFactory.newRemoteInstance(solrServerUrl);
    } else {
        try {
            setupSolr(new File(solrRoot));
        } catch (IOException e) {
            throw new IllegalStateException("Unable to connect to solr at " + solrRoot, e);
        } catch (SolrServerException e) {
            throw new IllegalStateException("Unable to connect to solr at " + solrRoot, e);
        }
    }
    // If the solr is empty, add all of the existing workflows
    long instancesInSolr = 0;
    try {
        instancesInSolr = count();
    } catch (WorkflowDatabaseException e) {
        throw new IllegalStateException(e);
    }
    if (instancesInSolr == 0) {
        logger.info("The workflow index is empty, looking for workflows to index");
        // this may be a new index, so get all of the existing workflows and index them
        List<String> workflowPayloads;
        try {
            workflowPayloads = serviceRegistry.getJobPayloads(WorkflowServiceImpl.Operation.START_WORKFLOW.toString());
        } catch (ServiceRegistryException e) {
            logger.error("Unable to load the workflows jobs: {}", e.getMessage());
            throw new ServiceException(e.getMessage());
        }
        final int total = workflowPayloads.size();
        if (total == 0) {
            logger.info("No workflows found. Repopulating index finished.");
            return;
        }
        logger.info("Populating the workflow index with {} workflows", total);
        int current = 0;
        for (String payload : workflowPayloads) {
            current++;
            WorkflowInstance instance = null;
            try {
                instance = WorkflowParser.parseWorkflowInstance(payload);
                Organization organization = instance.getOrganization();
                securityService.setOrganization(organization);
                securityService.setUser(SecurityUtil.createSystemUser(systemUserName, organization));
                index(instance);
            } catch (WorkflowParsingException | WorkflowDatabaseException e) {
                logger.warn("Skipping restoring of workflow {}", payload, e);
            }
            if (current % 100 == 0) {
                logger.info("Indexing workflow {}/{} ({} percent done)", current, total, current * 100 / total);
            }
        }
        logger.info("Finished populating the workflow search index");
    }
}
Also used : Organization(org.opencastproject.security.api.Organization) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) ServiceException(org.osgi.framework.ServiceException) File(java.io.File) WorkflowParsingException(org.opencastproject.workflow.api.WorkflowParsingException)

Example 97 with ServiceRegistryException

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

the class WaveformServiceImpl 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 Waveform:
                Track track = (Track) MediaPackageElementParser.getFromXml(arguments.get(0));
                Attachment waveformMpe = extractWaveform(track);
                return MediaPackageElementParser.getAsXml(waveformMpe);
            default:
                throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'");
        }
    } catch (IndexOutOfBoundsException e) {
        throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
    } catch (MediaPackageException | WaveformServiceException e) {
        throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) WaveformServiceException(org.opencastproject.waveform.api.WaveformServiceException) Attachment(org.opencastproject.mediapackage.Attachment) Track(org.opencastproject.mediapackage.Track) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 98 with ServiceRegistryException

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

the class WorkflowServiceImpl method acceptJob.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.job.api.AbstractJobProducer#acceptJob(org.opencastproject.job.api.Job)
 */
@Override
public synchronized void acceptJob(Job job) throws ServiceRegistryException {
    User originalUser = securityService.getUser();
    Organization originalOrg = securityService.getOrganization();
    try {
        Organization organization = organizationDirectoryService.getOrganization(job.getOrganization());
        securityService.setOrganization(organization);
        User user = userDirectoryService.loadUser(job.getCreator());
        securityService.setUser(user);
        job.setStatus(Job.Status.RUNNING);
        job = serviceRegistry.updateJob(job);
        // Check if this workflow was initially delayed
        if (delayedWorkflows.contains(job.getId())) {
            delayedWorkflows.remove(job.getId());
            logger.info("Starting initially delayed workflow %s, %d more waiting", job.getId(), delayedWorkflows.size());
        }
        executorService.submit(new JobRunner(job, serviceRegistry.getCurrentJob()));
    } catch (Exception e) {
        if (e instanceof ServiceRegistryException)
            throw (ServiceRegistryException) e;
        throw new ServiceRegistryException(e);
    } finally {
        securityService.setUser(originalUser);
        securityService.setOrganization(originalOrg);
    }
}
Also used : User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) UndispatchableJobException(org.opencastproject.serviceregistry.api.UndispatchableJobException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) IOException(java.io.IOException) ConfigurationException(org.osgi.service.cm.ConfigurationException) SeriesException(org.opencastproject.series.api.SeriesException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) WorkflowParsingException(org.opencastproject.workflow.api.WorkflowParsingException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowStateException(org.opencastproject.workflow.api.WorkflowStateException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 99 with ServiceRegistryException

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

the class CleanupWorkflowOperationHandler method cleanUpJobArgument.

/**
 * Deletes JobArguments for every finished Job of the WorkfloInstance
 *
 * @param workflowInstance
 */
public void cleanUpJobArgument(WorkflowInstance workflowInstance) {
    List<WorkflowOperationInstance> operationInstances = workflowInstance.getOperations();
    for (WorkflowOperationInstance operationInstance : operationInstances) {
        logger.debug("Delete JobArguments for Job id from Workflowinstance" + operationInstance.getId());
        // delete job Arguments
        Long operationInstanceId = null;
        try {
            operationInstanceId = operationInstance.getId();
            // instanceId can be null if the operation never run
            if (operationInstanceId != null) {
                Job operationInstanceJob = (serviceRegistry.getJob(operationInstanceId));
                List<String> list = new ArrayList<>();
                operationInstanceJob.setArguments(list);
                serviceRegistry.updateJob(operationInstanceJob);
                List<Job> jobs = serviceRegistry.getChildJobs(operationInstanceId);
                for (Job job : jobs) {
                    if (job.getStatus() == Job.Status.FINISHED) {
                        logger.debug("Deleting Arguments:  " + job.getArguments());
                        job.setArguments(list);
                        serviceRegistry.updateJob(job);
                    }
                }
            }
        } catch (ServiceRegistryException | NotFoundException ex) {
            logger.error("Deleting JobArguments failed for Job {}: {} ", operationInstanceId, ex);
        }
    }
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) ArrayList(java.util.ArrayList) NotFoundException(org.opencastproject.util.NotFoundException) Job(org.opencastproject.job.api.Job) 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