Search in sources :

Example 6 with Effect0

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

the class SimpleServicePublisher method updated.

@Override
public synchronized void updated(Dictionary properties) throws ConfigurationException {
    shutdown.apply();
    if (properties != null) {
        final SimpleServicePublisher self = this;
        logger.info("[{}] Registering service", self.getClass().getName());
        final ServiceReg registrations = registerService(properties, cc);
        shutdown = new Effect0() {

            @Override
            protected void run() {
                logger.info("[{}] Unregister service", self.getClass().getName());
                for (ServiceRegistration reg : registrations.getServiceRegistrations()) reg.unregister();
                mlist(registrations.getOnShutdown()).each(run);
            }
        };
    } else {
        logger.info("[{}] No config", this.getClass().getName());
    }
}
Also used : Effect0(org.opencastproject.util.data.Effect0) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 7 with Effect0

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

the class SchedulerMigrationService method activate.

public void activate(final ComponentContext cc) throws ConfigurationException, SQLException {
    logger.info("Start migrating scheduled events");
    // read config
    final String orgId = StringUtils.trimToNull((String) cc.getBundleContext().getProperty(CFG_ORGANIZATION));
    if (StringUtils.isBlank(orgId)) {
        logger.debug("No organization set for migration. Aborting.");
        return;
    }
    // create security context
    final Organization org;
    try {
        org = organizationDirectoryService.getOrganization(orgId);
    } catch (NotFoundException e) {
        throw new ConfigurationException(CFG_ORGANIZATION, String.format("Could not find organization '%s'", orgId), e);
    }
    SecurityUtil.runAs(securityService, org, SecurityUtil.createSystemUser(cc, org), new Effect0() {

        @Override
        protected void run() {
            // check if migration is needed
            try {
                int size = schedulerService.search(none(), none(), none(), none(), none()).size();
                if (size > 0) {
                    logger.info("There are already '{}' existing scheduled events, skip scheduler migration!", size);
                    return;
                }
            } catch (UnauthorizedException | SchedulerException e) {
                logger.error("Unable to read existing scheduled events, skip scheduler migration!", e);
            }
            try {
                migrateScheduledEvents();
            } catch (SQLException e) {
                chuck(e);
            }
        }
    });
    logger.info("Finished migrating scheduled events");
}
Also used : Organization(org.opencastproject.security.api.Organization) ConfigurationException(org.osgi.service.cm.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SQLException(java.sql.SQLException) Effect0(org.opencastproject.util.data.Effect0) NotFoundException(org.opencastproject.util.NotFoundException)

Example 8 with Effect0

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

the class OsgiAclServiceFactory method repopulate.

@Override
public void repopulate(final String indexName) {
    final String destinationId = AclItem.ACL_QUEUE_PREFIX + WordUtils.capitalize(indexName);
    for (final Organization organization : organizationDirectoryService.getOrganizations()) {
        SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(cc, organization), new Effect0() {

            @Override
            protected void run() {
                AclService aclService = serviceFor(organization);
                List<ManagedAcl> acls = aclService.getAcls();
                int total = aclService.getAcls().size();
                logger.info("Re-populating index with acls. There are {} acls(s) to add to the index.", total);
                int current = 1;
                for (ManagedAcl acl : acls) {
                    logger.trace("Adding acl '{}' for org '{}'", acl.getName(), organization.getId());
                    messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, AclItem.create(acl.getName()));
                    messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.update(indexName, IndexRecreateObject.Service.Acl, total, current));
                    current++;
                }
            }
        });
    }
    Organization organization = new DefaultOrganization();
    SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(cc, organization), new Effect0() {

        @Override
        protected void run() {
            messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Acl));
        }
    });
}
Also used : Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Effect0(org.opencastproject.util.data.Effect0) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) List(java.util.List) AclService(org.opencastproject.authorization.xacml.manager.api.AclService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization)

Example 9 with Effect0

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

the class IndexEndpoint method recreateIndex.

@POST
@Path("recreateIndex")
@RestQuery(name = "recreateIndex", description = "Clear and repopulates the Admin UI Index directly from the Services", returnDescription = "OK if repopulation has started", reponses = { @RestResponse(description = "OK if repopulation has started", responseCode = HttpServletResponse.SC_OK) })
public Response recreateIndex() {
    final SecurityContext securityContext = new SecurityContext(securityService, securityService.getOrganization(), securityService.getUser());
    executor.execute(new Runnable() {

        @Override
        public void run() {
            securityContext.runInContext(new Effect0() {

                @Override
                protected void run() {
                    try {
                        logger.info("Starting to repopulate the index");
                        adminUISearchIndex.recreateIndex();
                    } catch (InterruptedException e) {
                        logger.error("Repopulating the index was interrupted", e);
                    } catch (CancellationException e) {
                        logger.trace("Listening for index messages has been cancelled.");
                    } catch (ExecutionException e) {
                        logger.error("Repopulating the index failed to execute", e);
                    } catch (Throwable t) {
                        logger.error("Repopulating the index failed", t);
                    }
                }
            });
        }
    });
    return R.ok();
}
Also used : CancellationException(java.util.concurrent.CancellationException) Effect0(org.opencastproject.util.data.Effect0) SecurityContext(org.opencastproject.security.util.SecurityContext) ExecutionException(java.util.concurrent.ExecutionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 10 with Effect0

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

the class BaseEndpoint method recreateIndexFromService.

@POST
@Path("recreateIndex/{service}")
@RestQuery(name = "recreateIndexFromService", description = "Repopulates the external Index from an specific service", returnDescription = "OK if repopulation has started", pathParameters = { @RestParameter(name = "service", isRequired = true, description = "The service to recreate index from. " + "The available services are: Groups, Acl, Themes, Series, Scheduler, Workflow, AssetManager and Comments. " + "The service order (see above) is very important! Make sure, you do not run index rebuild for more than one " + "service at a time!", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "OK if repopulation has started", responseCode = HttpServletResponse.SC_OK) })
public Response recreateIndexFromService(@PathParam("service") final String service) {
    final SecurityContext securityContext = new SecurityContext(securityService, securityService.getOrganization(), securityService.getUser());
    executor.execute(new Runnable() {

        @Override
        public void run() {
            securityContext.runInContext(new Effect0() {

                @Override
                protected void run() {
                    try {
                        logger.info("Starting to repopulate the index from service {}", service);
                        externalIndex.recreateIndex(service);
                    } catch (InterruptedException e) {
                        logger.error("Repopulating the index was interrupted", e);
                    } catch (CancellationException e) {
                        logger.trace("Listening for index messages has been cancelled.");
                    } catch (ExecutionException e) {
                        logger.error("Repopulating the index failed to execute", e);
                    } catch (Throwable t) {
                        logger.error("Repopulating the index failed", t);
                    }
                }
            });
        }
    });
    return R.ok();
}
Also used : CancellationException(java.util.concurrent.CancellationException) Effect0(org.opencastproject.util.data.Effect0) SecurityContext(org.opencastproject.security.util.SecurityContext) ExecutionException(java.util.concurrent.ExecutionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

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