Search in sources :

Example 16 with ModuleIdentifier

use of org.opendaylight.controller.config.api.ModuleIdentifier 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)

Example 17 with ModuleIdentifier

use of org.opendaylight.controller.config.api.ModuleIdentifier 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);
    }
}
Also used : ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) ModuleInternalTransactionalInfo(org.opendaylight.controller.config.manager.impl.dependencyresolver.ModuleInternalTransactionalInfo) AbstractModule(org.opendaylight.controller.config.spi.AbstractModule) Module(org.opendaylight.controller.config.spi.Module) AbstractModule(org.opendaylight.controller.config.spi.AbstractModule)

Example 18 with ModuleIdentifier

use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.

the class ConfigTransactionControllerImpl method destroyModule.

@Override
public synchronized void destroyModule(final ObjectName objectName) throws InstanceNotFoundException {
    checkTransactionName(objectName);
    ObjectNameUtil.checkDomain(objectName);
    ModuleIdentifier moduleIdentifier = ObjectNameUtil.fromON(objectName, ObjectNameUtil.TYPE_MODULE);
    destroyModule(moduleIdentifier);
}
Also used : ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier)

Example 19 with ModuleIdentifier

use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.

the class ServiceReferenceRegistryImpl method findServiceReferencesLinkingTo.

private Set<ServiceReference> findServiceReferencesLinkingTo(final ObjectName moduleObjectName, final Set<String> serviceInterfaceQNames) {
    String factoryName = ObjectNameUtil.getFactoryName(moduleObjectName);
    if (serviceInterfaceQNames == null) {
        LOG.warn("Possible error in code: cannot find factoryName {} in {}, object name {}", factoryName, factoryNamesToQNames, moduleObjectName);
        throw new IllegalStateException("Possible error in code: cannot find annotations of existing factory " + factoryName);
    }
    String instanceName = ObjectNameUtil.getInstanceName(moduleObjectName);
    ModuleIdentifier moduleIdentifier = new ModuleIdentifier(factoryName, instanceName);
    Set<ServiceReference> result = new HashSet<>();
    for (Entry<ServiceReference, ModuleIdentifier> entry : refNames.entrySet()) {
        if (entry.getValue().equals(moduleIdentifier)) {
            result.add(entry.getKey());
        }
    }
    return result;
}
Also used : ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) ServiceReference(org.opendaylight.controller.config.manager.impl.jmx.ServiceReference) HashSet(java.util.HashSet)

Example 20 with ModuleIdentifier

use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.

the class ServiceReferenceRegistryImpl method saveServiceReference.

private synchronized ObjectName saveServiceReference(final ServiceReference serviceReference, final ObjectName moduleON, final boolean skipChecks) throws InstanceNotFoundException {
    // make sure it is found
    if (!skipChecks) {
        lookupRegistry.checkConfigBeanExists(moduleON);
    }
    String factoryName = ObjectNameUtil.getFactoryName(moduleON);
    String instanceName = ObjectNameUtil.getInstanceName(moduleON);
    ModuleIdentifier moduleIdentifier = new ModuleIdentifier(factoryName, instanceName);
    // check that service interface name exist
    Set<String> serviceInterfaceQNames = factoryNamesToQNames.get(moduleIdentifier.getFactoryName());
    if (serviceInterfaceQNames == null) {
        LOG.error("Possible error in code: cannot find factoryName {} in {}, {}", moduleIdentifier.getFactoryName(), factoryNamesToQNames, moduleIdentifier);
        throw new IllegalStateException("Possible error in code: cannot find annotations of existing factory " + moduleIdentifier.getFactoryName());
    }
    // supplied serviceInterfaceName must exist in this collection
    if (!serviceInterfaceQNames.contains(serviceReference.getServiceInterfaceQName())) {
        LOG.error("Cannot find qName {} with factory name {}, found {}", serviceReference.getServiceInterfaceQName(), moduleIdentifier.getFactoryName(), serviceInterfaceQNames);
        throw new IllegalArgumentException("Cannot find service interface " + serviceReference.getServiceInterfaceQName() + " within factory " + moduleIdentifier.getFactoryName());
    }
    // create service reference object name, put to mBeans
    ObjectName result = getServiceON(serviceReference);
    Entry<ServiceReferenceMXBeanImpl, ServiceReferenceJMXRegistration> mxBeanEntry = managementBeans.get(serviceReference);
    if (mxBeanEntry == null) {
        // create dummy mx bean
        ServiceReferenceMXBeanImpl dummyMXBean = new ServiceReferenceMXBeanImpl(moduleON);
        ServiceReferenceJMXRegistration dummyMXBeanRegistration;
        try {
            dummyMXBeanRegistration = serviceReferenceRegistrator.registerMBean(dummyMXBean, result);
        } catch (final InstanceAlreadyExistsException e) {
            throw new IllegalStateException("Possible error in code. Cannot register " + result, e);
        }
        managementBeans.put(serviceReference, new SimpleImmutableEntry<>(dummyMXBean, dummyMXBeanRegistration));
    } else {
        // update
        mxBeanEntry.getKey().setCurrentImplementation(moduleON);
    }
    // save to refNames
    refNames.put(serviceReference, moduleIdentifier);
    Map<ServiceInterfaceAnnotation, String> /* service ref name */
    refNamesToAnnotations = modulesToServiceRef.computeIfAbsent(moduleIdentifier, k -> new HashMap<>());
    ServiceInterfaceAnnotation annotation = serviceQNamesToAnnotations.get(serviceReference.getServiceInterfaceQName());
    Preconditions.checkNotNull(annotation, "Possible error in code, cannot find annotation for " + serviceReference);
    refNamesToAnnotations.put(annotation, serviceReference.getRefName());
    return result;
}
Also used : ServiceReferenceMXBeanImpl(org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceMXBeanImpl) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ServiceInterfaceAnnotation(org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation) ObjectName(javax.management.ObjectName) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) ServiceReferenceJMXRegistration(org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceRegistrator.ServiceReferenceJMXRegistration)

Aggregations

ModuleIdentifier (org.opendaylight.controller.config.api.ModuleIdentifier)30 Module (org.opendaylight.controller.config.spi.Module)11 ObjectName (javax.management.ObjectName)9 AbstractModule (org.opendaylight.controller.config.spi.AbstractModule)6 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)5 InstanceNotFoundException (javax.management.InstanceNotFoundException)5 ModuleFactory (org.opendaylight.controller.config.spi.ModuleFactory)5 DependencyResolver (org.opendaylight.controller.config.api.DependencyResolver)4 BundleContext (org.osgi.framework.BundleContext)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ValidationException (org.opendaylight.controller.config.api.ValidationException)3 ServiceInterfaceAnnotation (org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 ModuleFactoryNotFoundException (org.opendaylight.controller.config.api.ModuleFactoryNotFoundException)2 ModuleInternalTransactionalInfo (org.opendaylight.controller.config.manager.impl.dependencyresolver.ModuleInternalTransactionalInfo)2 RootRuntimeBeanRegistratorImpl (org.opendaylight.controller.config.manager.impl.jmx.RootRuntimeBeanRegistratorImpl)2 ServiceReference (org.opendaylight.controller.config.manager.impl.jmx.ServiceReference)2 ServiceReferenceMXBeanImpl (org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceMXBeanImpl)2