use of org.opendaylight.controller.config.api.DependencyResolver in project controller by opendaylight.
the class AbsFactoryGeneratedObjectFactory method getCreateModule.
private static String getCreateModule(FullyQualifiedName moduleFQN, List<Field> moduleFields) {
StringBuilder result = new StringBuilder("\n" + "@Override\n");
result.append(format("public %s createModule(String instanceName, %s dependencyResolver, %s old, %s bundleContext) " + "throws Exception {\n", Module.class.getCanonicalName(), DependencyResolver.class.getCanonicalName(), DynamicMBeanWithInstance.class.getCanonicalName(), BUNDLE_CONTEXT)).append(format("%s oldModule;\n", moduleFQN)).append("try {\n").append(format("oldModule = (%s) old.getModule();\n", moduleFQN)).append("} catch(Exception e) {\n" + "return handleChangedClass(dependencyResolver, old, bundleContext);\n" + "}\n").append(format("%s module = instantiateModule(instanceName, dependencyResolver, oldModule, old" + ".getInstance(), bundleContext);\n", moduleFQN));
for (Field field : moduleFields) {
result.append(format("module.set%s(oldModule.get%1$s());\n", field.getName()));
}
result.append("\n" + "return module;\n" + "}\n");
return result.toString();
}
use of org.opendaylight.controller.config.api.DependencyResolver in project controller by opendaylight.
the class ShutdownModuleFactory method getDefaultModules.
@Override
public Set<ShutdownModule> getDefaultModules(final DependencyResolverFactory dependencyResolverFactory, final BundleContext bundleContext) {
ModuleIdentifier id = new ModuleIdentifier(NAME, NAME);
DependencyResolver dependencyResolver = dependencyResolverFactory.createDependencyResolver(id);
ShutdownModule shutdownModule = instantiateModule(NAME, dependencyResolver, bundleContext);
return new java.util.HashSet<>(Arrays.asList(shutdownModule));
}
use of org.opendaylight.controller.config.api.DependencyResolver in project controller by opendaylight.
the class ConfigTransactionControllerImpl method copyExistingModule.
@SuppressWarnings("IllegalCatch")
private synchronized void copyExistingModule(final ModuleInternalInfo oldConfigBeanInfo) throws InstanceAlreadyExistsException {
transactionStatus.checkNotCommitStarted();
transactionStatus.checkNotAborted();
ModuleIdentifier moduleIdentifier = oldConfigBeanInfo.getIdentifier();
dependencyResolverManager.assertNotExists(moduleIdentifier);
ModuleFactory moduleFactory;
BundleContext bc;
try {
moduleFactory = factoriesHolder.findByModuleName(moduleIdentifier.getFactoryName());
bc = getModuleFactoryBundleContext(moduleFactory.getImplementationName());
} catch (final ModuleFactoryNotFoundException e) {
throw new IllegalStateException(e);
}
Module module;
DependencyResolver dependencyResolver = dependencyResolverManager.getOrCreate(moduleIdentifier);
try {
module = moduleFactory.createModule(moduleIdentifier.getInstanceName(), dependencyResolver, oldConfigBeanInfo.getReadableModule(), bc);
} catch (final Exception e) {
throw new IllegalStateException(String.format("Error while copying old configuration from %s to %s", oldConfigBeanInfo, moduleFactory), e);
}
putConfigBeanToJMXAndInternalMaps(moduleIdentifier, module, moduleFactory, oldConfigBeanInfo, dependencyResolver, oldConfigBeanInfo.isDefaultBean(), bc);
}
use of org.opendaylight.controller.config.api.DependencyResolver in project controller by opendaylight.
the class ConfigTransactionControllerImpl method createModule.
@Override
public synchronized ObjectName createModule(final String factoryName, final String instanceName) throws InstanceAlreadyExistsException {
transactionStatus.checkNotCommitStarted();
transactionStatus.checkNotAborted();
ModuleIdentifier moduleIdentifier = new ModuleIdentifier(factoryName, instanceName);
dependencyResolverManager.assertNotExists(moduleIdentifier);
// find factory
ModuleFactory moduleFactory = factoriesHolder.findByModuleName(factoryName);
DependencyResolver dependencyResolver = dependencyResolverManager.getOrCreate(moduleIdentifier);
BundleContext bundleContext = getModuleFactoryBundleContext(moduleFactory.getImplementationName());
Module module = moduleFactory.createModule(instanceName, dependencyResolver, bundleContext);
boolean defaultBean = false;
return putConfigBeanToJMXAndInternalMaps(moduleIdentifier, module, moduleFactory, null, dependencyResolver, defaultBean, bundleContext);
}
use of org.opendaylight.controller.config.api.DependencyResolver 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);
}
}
}
Aggregations