Search in sources :

Example 16 with Effect0

use of org.opencastproject.util.data.Effect0 in project opencast by opencast.

the class SchedulerServiceImpl method removeTransactionsAfterRestart.

/**
 * Remove incomplete transactions after a restart
 */
private void removeTransactionsAfterRestart() {
    logger.info("Checking for incomplete transactions from a shutdown or restart.");
    for (final Organization org : orgDirectoryService.getOrganizations()) {
        SecurityUtil.runAs(securityService, org, SecurityUtil.createSystemUser(systemUserName, org), new Effect0() {

            private void rollbackTransaction(String transactionID) throws NotFoundException, UnauthorizedException, SchedulerException {
                SchedulerTransaction transaction = getTransaction(transactionID);
                logger.info("Rolling back transaction with id: {}", transactionID);
                transaction.rollback();
                logger.info("Finished rolling back transaction with id: {}", transactionID);
            }

            @Override
            protected void run() {
                try {
                    for (String transactionID : persistence.getTransactions()) {
                        try {
                            rollbackTransaction(transactionID);
                        } catch (NotFoundException e) {
                            logger.info("Unable to find the transaction with id {}, so it wasn't rolled back.", transactionID);
                        } catch (UnauthorizedException e) {
                            logger.error("Unable to delete transaction with id: {} using organization {} because: {}", new Object[] { transactionID, org, getStackTrace(e) });
                        } catch (Exception e) {
                            logger.error("Unable to rollback transaction because: {}", getStackTrace(e));
                        }
                    }
                } catch (SchedulerServiceDatabaseException e) {
                    logger.error("Unable to get transactions to cleanup incomplete transactions because: {}", getStackTrace(e));
                }
            }
        });
    }
    logger.info("Finished checking for incomplete transactions from a shutdown or a restart.");
}
Also used : Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) Effect0(org.opencastproject.util.data.Effect0) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) Log.getHumanReadableTimeString(org.opencastproject.util.Log.getHumanReadableTimeString) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) IOException(java.io.IOException) ServiceException(org.osgi.framework.ServiceException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) ConfigurationException(org.osgi.service.cm.ConfigurationException) SeriesException(org.opencastproject.series.api.SeriesException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) ValidationException(net.fortuna.ical4j.model.ValidationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 17 with Effect0

use of org.opencastproject.util.data.Effect0 in project opencast by opencast.

the class WorkflowServiceImpl method repopulate.

@Override
public void repopulate(final String indexName) throws Exception {
    List<String> workflows = serviceRegistry.getJobPayloads(Operation.START_WORKFLOW.toString());
    final String destinationId = WorkflowItem.WORKFLOW_QUEUE_PREFIX + indexName.substring(0, 1).toUpperCase() + indexName.substring(1);
    if (workflows.size() > 0) {
        final int total = workflows.size();
        logger.info("Populating index '{}' with {} workflows", indexName, total);
        final int responseInterval = (total < 100) ? 1 : (total / 100);
        int current = 0;
        for (final String workflow : workflows) {
            current += 1;
            if (StringUtils.isEmpty(workflow)) {
                logger.warn("Skipping restoring of workflow no {}: Payload is empty", current);
                continue;
            }
            WorkflowInstance instance;
            try {
                instance = WorkflowParser.parseWorkflowInstance(workflow);
            } catch (WorkflowParsingException e) {
                logger.warn("Skipping restoring of workflow. Error parsing: {}", workflow, e);
                continue;
            }
            Organization organization = instance.getOrganization();
            SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(componentContext, organization), new Effect0() {

                @Override
                public void run() {
                    // Send message to update index item
                    messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, WorkflowItem.updateInstance(instance));
                }
            });
            if ((current % responseInterval == 0) || (current == total)) {
                logger.info("Updating {} workflow index {}/{}: {} percent complete.", indexName, current, total, current * 100 / total);
            }
        }
    }
    logger.info("Finished populating {} index with workflows", indexName);
    Organization organization = new DefaultOrganization();
    SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(componentContext, organization), new Effect0() {

        @Override
        protected void run() {
            messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Workflow));
        }
    });
}
Also used : Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Effect0(org.opencastproject.util.data.Effect0) Collections.mkString(org.opencastproject.util.data.Collections.mkString) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) WorkflowParsingException(org.opencastproject.workflow.api.WorkflowParsingException) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization)

Aggregations

Effect0 (org.opencastproject.util.data.Effect0)17 Organization (org.opencastproject.security.api.Organization)10 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)9 NotFoundException (org.opencastproject.util.NotFoundException)6 SecurityContext (org.opencastproject.security.util.SecurityContext)5 IOException (java.io.IOException)4 List (java.util.List)4 CancellationException (java.util.concurrent.CancellationException)4 ExecutionException (java.util.concurrent.ExecutionException)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)4 SeriesException (org.opencastproject.series.api.SeriesException)4 RestQuery (org.opencastproject.util.doc.rest.RestQuery)4 ServiceException (org.osgi.framework.ServiceException)4 ArrayList (java.util.ArrayList)3 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)3 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)3 ValidationException (net.fortuna.ical4j.model.ValidationException)2 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)2