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