use of org.opendaylight.controller.config.spi.Module in project controller by opendaylight.
the class ConfigTransactionControllerImpl method secondPhaseCommit.
/**
* {@inheritDoc}
*/
@Override
public synchronized List<ModuleIdentifier> secondPhaseCommit() {
transactionStatus.checkNotAborted();
transactionStatus.checkCommitStarted();
if (!configBeanModificationDisabled.get()) {
throw new IllegalStateException("Internal error - validateBeforeCommitAndLockTransaction should be called " + "to obtain a lock");
}
LOG.trace("Committing transaction {}", getTransactionIdentifier());
Map<ModuleIdentifier, Module> allModules = dependencyResolverManager.getAllModules();
// call getInstance() on all Modules from top to bottom (from source to target
// of the dependency relation)
// The source of a dependency closes itself and calls getInstance recursively on
// the dependencies (in case of reconfiguration)
// This makes close() calls from top to bottom while createInstance() calls are
// performed bottom to top
List<ModuleIdentifier> sortedModuleIdentifiers = Lists.reverse(dependencyResolverManager.getSortedModuleIdentifiers());
for (ModuleIdentifier moduleIdentifier : sortedModuleIdentifiers) {
Module module = allModules.get(moduleIdentifier);
LOG.debug("About to commit {} in transaction {}", moduleIdentifier, getTransactionIdentifier());
AutoCloseable instance = module.getInstance();
Preconditions.checkNotNull(instance, "Instance is null:%s in transaction %s", moduleIdentifier, getTransactionIdentifier());
}
LOG.trace("Committed configuration {}", getTransactionIdentifier());
transactionStatus.setCommitted();
return sortedModuleIdentifiers;
}
use of org.opendaylight.controller.config.spi.Module in project controller by opendaylight.
the class ConfigTransactionControllerImpl method processDefaultBeans.
private synchronized void processDefaultBeans(final List<ModuleFactory> lastListOfFactories) {
transactionStatus.checkNotCommitStarted();
transactionStatus.checkNotAborted();
Set<ModuleFactory> oldSet = new HashSet<>(lastListOfFactories);
Set<ModuleFactory> newSet = new HashSet<>(factoriesHolder.getModuleFactories());
List<ModuleFactory> toBeAdded = new ArrayList<>();
List<ModuleFactory> toBeRemoved = new ArrayList<>();
for (ModuleFactory moduleFactory : factoriesHolder.getModuleFactories()) {
if (!oldSet.contains(moduleFactory)) {
toBeAdded.add(moduleFactory);
}
}
for (ModuleFactory moduleFactory : lastListOfFactories) {
if (!newSet.contains(moduleFactory)) {
toBeRemoved.add(moduleFactory);
}
}
// add default modules
for (ModuleFactory moduleFactory : toBeAdded) {
BundleContext bundleContext = getModuleFactoryBundleContext(moduleFactory.getImplementationName());
Set<? extends Module> defaultModules = moduleFactory.getDefaultModules(dependencyResolverManager, bundleContext);
for (Module module : defaultModules) {
// ensure default module to be registered to jmx even if its module factory does
// not use dependencyResolverFactory
DependencyResolver dependencyResolver = dependencyResolverManager.getOrCreate(module.getIdentifier());
final ObjectName objectName;
try {
boolean defaultBean = true;
objectName = putConfigBeanToJMXAndInternalMaps(module.getIdentifier(), module, moduleFactory, null, dependencyResolver, defaultBean, bundleContext);
} catch (final InstanceAlreadyExistsException e) {
throw new IllegalStateException(e);
}
// register default module as every possible service
final Set<ServiceInterfaceAnnotation> serviceInterfaceAnnotations = InterfacesHelper.getServiceInterfaceAnnotations(moduleFactory);
for (String qname : InterfacesHelper.getQNames(serviceInterfaceAnnotations)) {
try {
saveServiceReference(qname, module.getIdentifier().getInstanceName(), objectName);
} catch (final InstanceNotFoundException e) {
throw new IllegalStateException("Unable to register default module instance " + module + " as a service of " + qname, e);
}
}
}
}
// remove modules belonging to removed factories
for (ModuleFactory removedFactory : toBeRemoved) {
List<ModuleIdentifier> modulesOfRemovedFactory = dependencyResolverManager.findAllByFactory(removedFactory);
for (ModuleIdentifier name : modulesOfRemovedFactory) {
// remove service refs
final ModuleFactory moduleFactory = dependencyResolverManager.findModuleInternalTransactionalInfo(name).getModuleFactory();
final Set<ServiceInterfaceAnnotation> serviceInterfaceAnnotations = InterfacesHelper.getServiceInterfaceAnnotations(moduleFactory);
for (String qname : InterfacesHelper.getQNames(serviceInterfaceAnnotations)) {
try {
removeServiceReference(qname, name.getInstanceName());
} catch (final InstanceNotFoundException e) {
throw new IllegalStateException("Unable to UNregister default module instance " + name + " as a service of " + qname, e);
}
}
// close module
destroyModule(name);
}
}
}
use of org.opendaylight.controller.config.spi.Module in project controller by opendaylight.
the class ConfigTransactionControllerImpl method reCreateModule.
@Override
public synchronized void reCreateModule(final ObjectName objectName) throws InstanceNotFoundException {
transactionStatus.checkNotCommitStarted();
transactionStatus.checkNotAborted();
checkTransactionName(objectName);
ObjectNameUtil.checkDomain(objectName);
ModuleIdentifier moduleIdentifier = ObjectNameUtil.fromON(objectName, ObjectNameUtil.TYPE_MODULE);
ModuleInternalTransactionalInfo txInfo = dependencyResolverManager.findModuleInternalTransactionalInfo(moduleIdentifier);
Module realModule = txInfo.getRealModule();
if (realModule instanceof AbstractModule) {
((AbstractModule<?>) realModule).setCanReuseInstance(false);
}
}
use of org.opendaylight.controller.config.spi.Module in project controller by opendaylight.
the class ModulesHolder method getAllModules.
public Map<ModuleIdentifier, Module> getAllModules() {
Map<ModuleIdentifier, Module> result = new HashMap<>();
for (ModuleInternalTransactionalInfo entry : commitMap.values()) {
ModuleIdentifier name = entry.getIdentifier();
result.put(name, entry.getProxiedModule());
}
return result;
}
use of org.opendaylight.controller.config.spi.Module in project controller by opendaylight.
the class JMXGeneratorTest method generateMBEsTest.
@Test
public void generateMBEsTest() throws Exception {
// default value for module factory file is true
map.put(JMXGenerator.MODULE_FACTORY_FILE_BOOLEAN, "randomValue");
jmxGenerator.setAdditionalConfig(map);
Collection<File> files = jmxGenerator.generateSources(context, outputBaseDir, Collections.singleton(threadsJavaModule), m -> Optional.empty());
assertEquals(expectedModuleFileNames, toFileNames(files));
for (File file : files) {
final String name = file.getName();
if (!name.endsWith("java")) {
continue;
}
MbeASTVisitor visitor = new MbeASTVisitor(EXPECTED_PACKAGE_PREFIX + ".threads.java", name);
verifyFile(file, visitor);
switch(name) {
case "AbstractDynamicThreadPoolModule.java":
assertAbstractDynamicThreadPoolModule(visitor);
break;
case "AsyncEventBusModuleMXBean.java":
assertEquals("Incorrenct number of generated methods", 4, visitor.methods.size());
break;
case "AbstractNamingThreadFactoryModuleFactory.java":
assertAbstractNamingThreadFactoryModuleFactory(visitor);
break;
case "AsyncEventBusModule.java":
assertContains(visitor.extnds, EXPECTED_PACKAGE_PREFIX + ".threads.java.AbstractAsyncEventBusModule");
visitor.assertFields(0);
assertEquals("Incorrenct number of generated methods", 2, visitor.methods.size());
visitor.assertConstructors(2);
visitor.assertMethodDescriptions(0);
visitor.assertMethodJavadocs(0);
break;
case "EventBusModuleFactory.java":
assertContains(visitor.extnds, EXPECTED_PACKAGE_PREFIX + ".threads.java.AbstractEventBusModuleFactory");
visitor.assertFields(0);
assertEquals("Incorrenct number of generated methods", 0, visitor.methods.size());
visitor.assertConstructors(0);
visitor.assertMethodDescriptions(0);
visitor.assertMethodJavadocs(0);
break;
}
}
verifyXmlFiles(Collections2.filter(files, input -> input.getName().endsWith("xml")));
// verify ModuleFactory file
File moduleFactoryFile = JMXGenerator.concatFolders(generatedResourcesDir, "META-INF", "services", ModuleFactory.class.getName());
assertTrue(moduleFactoryFile.exists());
Set<String> lines = ImmutableSet.copyOf(Files.readLines(moduleFactoryFile, StandardCharsets.UTF_8));
Set<String> expectedLines = ImmutableSet.of(EXPECTED_PACKAGE_PREFIX + ".threads.java.EventBusModuleFactory", EXPECTED_PACKAGE_PREFIX + ".threads.java.AsyncEventBusModuleFactory", EXPECTED_PACKAGE_PREFIX + ".threads.java.DynamicThreadPoolModuleFactory", EXPECTED_PACKAGE_PREFIX + ".threads.java.NamingThreadFactoryModuleFactory", EXPECTED_PACKAGE_PREFIX + ".threads.java.ThreadPoolRegistryImplModuleFactory");
assertEquals(expectedLines, lines);
}
Aggregations