X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2FConfigTransactionControllerImpl.java;h=ca318f32c9efbf94c1fdd1683d5ebdaeced7d93f;hb=493c4f70a0a315d77927e4c0d90a90acbbcb2897;hp=bb61c4acc70aa6506b6d3093748a519d5fa036be;hpb=2294805f83434db1d248e629767da6a563ce595f;p=controller.git diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImpl.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImpl.java index bb61c4acc7..ca318f32c9 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImpl.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImpl.java @@ -10,6 +10,7 @@ package org.opendaylight.controller.config.manager.impl; import static com.google.common.base.Preconditions.checkNotNull; import static java.lang.String.format; +import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -28,6 +29,7 @@ import javax.management.ObjectName; import org.opendaylight.controller.config.api.DependencyResolver; import org.opendaylight.controller.config.api.ModuleIdentifier; import org.opendaylight.controller.config.api.ValidationException; +import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation; import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; import org.opendaylight.controller.config.manager.impl.dependencyresolver.DependencyResolverManager; import org.opendaylight.controller.config.manager.impl.dependencyresolver.ModuleInternalTransactionalInfo; @@ -37,10 +39,11 @@ import org.opendaylight.controller.config.manager.impl.dynamicmbean.ReadOnlyAtom import org.opendaylight.controller.config.manager.impl.factoriesresolver.HierarchicalConfigMBeanFactoriesHolder; import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator; import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator.TransactionModuleJMXRegistration; +import org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider; +import org.opendaylight.controller.config.manager.impl.util.InterfacesHelper; import org.opendaylight.controller.config.spi.Module; import org.opendaylight.controller.config.spi.ModuleFactory; import org.opendaylight.yangtools.concepts.Identifiable; -import org.opendaylight.yangtools.yang.data.impl.codec.CodecRegistry; import org.osgi.framework.BundleContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -82,7 +85,7 @@ class ConfigTransactionControllerImpl implements private final SearchableServiceReferenceWritableRegistry writableSRRegistry; public ConfigTransactionControllerImpl(ConfigTransactionLookupRegistry txLookupRegistry, - long parentVersion, CodecRegistry codecRegistry, long currentVersion, + long parentVersion, BindingContextProvider bindingContextProvider, long currentVersion, Map> currentlyRegisteredFactories, MBeanServer transactionsMBeanServer, MBeanServer configMBeanServer, boolean blankTransaction, SearchableServiceReferenceWritableRegistry writableSRRegistry) { @@ -95,7 +98,7 @@ class ConfigTransactionControllerImpl implements this.factoriesHolder = new HierarchicalConfigMBeanFactoriesHolder(currentlyRegisteredFactories); this.transactionStatus = new TransactionStatus(); this.dependencyResolverManager = new DependencyResolverManager(txLookupRegistry.getTransactionIdentifier(), - transactionStatus, writableSRRegistry, codecRegistry, transactionsMBeanServer); + transactionStatus, writableSRRegistry, bindingContextProvider, transactionsMBeanServer); this.transactionsMBeanServer = transactionsMBeanServer; this.configMBeanServer = configMBeanServer; this.blankTransaction = blankTransaction; @@ -142,13 +145,24 @@ class ConfigTransactionControllerImpl implements 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; - putConfigBeanToJMXAndInternalMaps(module.getIdentifier(), module, moduleFactory, null, + objectName = putConfigBeanToJMXAndInternalMaps(module.getIdentifier(), module, moduleFactory, null, dependencyResolver, defaultBean, bundleContext); } catch (InstanceAlreadyExistsException e) { throw new IllegalStateException(e); } + + // register default module as every possible service + final Set serviceInterfaceAnnotations = InterfacesHelper.getServiceInterfaceAnnotations(moduleFactory); + for (String qname : InterfacesHelper.getQNames(serviceInterfaceAnnotations)) { + try { + saveServiceReference(qname, module.getIdentifier().getInstanceName(), objectName); + } catch (InstanceNotFoundException e) { + throw new IllegalStateException("Unable to register default module instance " + module + " as a service of " + qname, e); + } + } } } @@ -156,6 +170,18 @@ class ConfigTransactionControllerImpl implements for (ModuleFactory removedFactory : toBeRemoved) { List modulesOfRemovedFactory = dependencyResolverManager.findAllByFactory(removedFactory); for (ModuleIdentifier name : modulesOfRemovedFactory) { + // remove service refs + final ModuleFactory moduleFactory = dependencyResolverManager.findModuleInternalTransactionalInfo(name).getModuleFactory(); + final Set serviceInterfaceAnnotations = InterfacesHelper.getServiceInterfaceAnnotations(moduleFactory); + for (String qname : InterfacesHelper.getQNames(serviceInterfaceAnnotations)) { + try { + removeServiceReference(qname, name.getInstanceName()); + } catch (InstanceNotFoundException e) { + throw new IllegalStateException("Unable to UNregister default module instance " + name + " as a service of " + qname, e); + } + } + + // close module destroyModule(name); } } @@ -383,32 +409,34 @@ class ConfigTransactionControllerImpl implements LOG.trace("Committing transaction {}", getTransactionIdentifier()); - // call getInstance() - for (Entry entry : dependencyResolverManager - .getAllModules().entrySet()) { - Module module = entry.getValue(); - ModuleIdentifier name = entry.getKey(); + Map 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 sortedModuleIdentifiers = Lists.reverse(dependencyResolverManager.getSortedModuleIdentifiers()); + for (ModuleIdentifier moduleIdentifier : sortedModuleIdentifiers) { + Module module = allModules.get(moduleIdentifier); + try { LOG.debug("About to commit {} in transaction {}", - name, getTransactionIdentifier()); + moduleIdentifier, getTransactionIdentifier()); AutoCloseable instance = module.getInstance(); - checkNotNull(instance, "Instance is null:{} in transaction {}", name, getTransactionIdentifier()); + checkNotNull(instance, "Instance is null:{} in transaction {}", moduleIdentifier, getTransactionIdentifier()); } catch (Exception e) { - LOG.error("Commit failed on {} in transaction {}", name, + LOG.error("Commit failed on {} in transaction {}", moduleIdentifier, getTransactionIdentifier(), e); internalAbort(); throw new IllegalStateException( format("Error - getInstance() failed for %s in transaction %s", - name, getTransactionIdentifier()), e); + moduleIdentifier, getTransactionIdentifier()), e); } } - // count dependency order - LOG.trace("Committed configuration {}", getTransactionIdentifier()); transactionStatus.setCommitted(); - return dependencyResolverManager.getSortedModuleIdentifiers(); + return sortedModuleIdentifiers; } @Override @@ -479,6 +507,25 @@ class ConfigTransactionControllerImpl implements public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException { txLookupRegistry.checkConfigBeanExists(objectName); } + + + /** + * {@inheritDoc} + */ + @Override + public Set lookupRuntimeBeans() { + return txLookupRegistry.lookupRuntimeBeans(); + } + + /** + * {@inheritDoc} + */ + @Override + public Set lookupRuntimeBeans(String moduleName, + String instanceName) { + return txLookupRegistry.lookupRuntimeBeans(moduleName, instanceName); + } + // -- /**