Search in sources :

Example 1 with DependencyResolver

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();
}
Also used : Field(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field) Module(org.opendaylight.controller.config.spi.Module) DynamicMBeanWithInstance(org.opendaylight.controller.config.api.DynamicMBeanWithInstance) DependencyResolver(org.opendaylight.controller.config.api.DependencyResolver)

Example 2 with DependencyResolver

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));
}
Also used : ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) DependencyResolver(org.opendaylight.controller.config.api.DependencyResolver)

Example 3 with DependencyResolver

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);
}
Also used : ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) AbstractModule(org.opendaylight.controller.config.spi.AbstractModule) Module(org.opendaylight.controller.config.spi.Module) ModuleFactoryNotFoundException(org.opendaylight.controller.config.api.ModuleFactoryNotFoundException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ValidationException(org.opendaylight.controller.config.api.ValidationException) ModuleFactoryNotFoundException(org.opendaylight.controller.config.api.ModuleFactoryNotFoundException) BundleContext(org.osgi.framework.BundleContext) DependencyResolver(org.opendaylight.controller.config.api.DependencyResolver)

Example 4 with DependencyResolver

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);
}
Also used : ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) AbstractModule(org.opendaylight.controller.config.spi.AbstractModule) Module(org.opendaylight.controller.config.spi.Module) DependencyResolver(org.opendaylight.controller.config.api.DependencyResolver) BundleContext(org.osgi.framework.BundleContext)

Example 5 with DependencyResolver

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);
        }
    }
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ArrayList(java.util.ArrayList) ServiceInterfaceAnnotation(org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation) DependencyResolver(org.opendaylight.controller.config.api.DependencyResolver) ObjectName(javax.management.ObjectName) ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) AbstractModule(org.opendaylight.controller.config.spi.AbstractModule) Module(org.opendaylight.controller.config.spi.Module) HashSet(java.util.HashSet) BundleContext(org.osgi.framework.BundleContext)

Aggregations

DependencyResolver (org.opendaylight.controller.config.api.DependencyResolver)5 ModuleIdentifier (org.opendaylight.controller.config.api.ModuleIdentifier)4 Module (org.opendaylight.controller.config.spi.Module)4 AbstractModule (org.opendaylight.controller.config.spi.AbstractModule)3 ModuleFactory (org.opendaylight.controller.config.spi.ModuleFactory)3 BundleContext (org.osgi.framework.BundleContext)3 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ObjectName (javax.management.ObjectName)1 DynamicMBeanWithInstance (org.opendaylight.controller.config.api.DynamicMBeanWithInstance)1 ModuleFactoryNotFoundException (org.opendaylight.controller.config.api.ModuleFactoryNotFoundException)1 ValidationException (org.opendaylight.controller.config.api.ValidationException)1 ServiceInterfaceAnnotation (org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation)1 Field (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field)1