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");
}
}
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);
}
}
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);
}
}
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);
}
}
}
Aggregations