X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2FConfigRegistryImpl.java;h=e3311c747f872f601b0448e01d7e864163a15a75;hp=0fd6c5279409e3412de86a33735c3dc4daddf058;hb=1257b6b217ae7fb2fca640b5991eac2a0266a93f;hpb=089bfc0f3f32322b54dba2bf9402769638c09e06 diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java index 0fd6c52794..e3311c747f 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java @@ -10,6 +10,8 @@ package org.opendaylight.controller.config.manager.impl; import org.opendaylight.controller.config.api.ConflictingVersionException; import org.opendaylight.controller.config.api.ModuleIdentifier; import org.opendaylight.controller.config.api.RuntimeBeanRegistratorAwareModule; +import org.opendaylight.controller.config.api.ServiceReferenceReadableRegistry; +import org.opendaylight.controller.config.api.ServiceReferenceWritableRegistry; import org.opendaylight.controller.config.api.ValidationException; import org.opendaylight.controller.config.api.jmx.CommitStatus; import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; @@ -23,6 +25,7 @@ import org.opendaylight.controller.config.manager.impl.jmx.TransactionJMXRegistr import org.opendaylight.controller.config.manager.impl.osgi.BeanToOsgiServiceManager; import org.opendaylight.controller.config.manager.impl.osgi.BeanToOsgiServiceManager.OsgiRegistration; import org.opendaylight.controller.config.manager.impl.util.LookupBeansUtil; +import org.opendaylight.controller.config.manager.impl.util.ModuleQNameUtil; import org.opendaylight.controller.config.spi.Module; import org.opendaylight.controller.config.spi.ModuleFactory; import org.osgi.framework.BundleContext; @@ -59,9 +62,6 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe private final ModuleFactoriesResolver resolver; private final MBeanServer configMBeanServer; - @GuardedBy("this") - private final BundleContext bundleContext; - @GuardedBy("this") private long version = 0; @GuardedBy("this") @@ -99,23 +99,26 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe // internal jmx server shared by all transactions private final MBeanServer transactionsMBeanServer; + // Used for finding new factory instances for default module functionality @GuardedBy("this") private List lastListOfFactories = Collections.emptyList(); + @GuardedBy("this") // switched in every 2ndPC + private ServiceReferenceReadableRegistry readableSRRegistry = ServiceReferenceRegistryImpl.createInitialSRLookupRegistry(); + // constructor public ConfigRegistryImpl(ModuleFactoriesResolver resolver, - BundleContext bundleContext, MBeanServer configMBeanServer) { - this(resolver, bundleContext, configMBeanServer, + MBeanServer configMBeanServer) { + this(resolver, configMBeanServer, new BaseJMXRegistrator(configMBeanServer)); } // constructor public ConfigRegistryImpl(ModuleFactoriesResolver resolver, - BundleContext bundleContext, MBeanServer configMBeanServer, + MBeanServer configMBeanServer, BaseJMXRegistrator baseJMXRegistrator) { this.resolver = resolver; this.beanToOsgiServiceManager = new BeanToOsgiServiceManager(); - this.bundleContext = bundleContext; this.configMBeanServer = configMBeanServer; this.baseJMXRegistrator = baseJMXRegistrator; this.registryMBeanServer = MBeanServerFactory @@ -129,26 +132,45 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe */ @Override public synchronized ObjectName beginConfig() { - return beginConfigInternal().getControllerObjectName(); + return beginConfig(false); + } + + /** + * @param blankTransaction true if this transaction is created automatically by + * org.opendaylight.controller.config.manager.impl.osgi.BlankTransactionServiceTracker + */ + public synchronized ObjectName beginConfig(boolean blankTransaction) { + return beginConfigInternal(blankTransaction).getControllerObjectName(); } - private synchronized ConfigTransactionControllerInternal beginConfigInternal() { + private synchronized ConfigTransactionControllerInternal beginConfigInternal(boolean blankTransaction) { versionCounter++; - String transactionName = "ConfigTransaction-" + version + "-" + versionCounter; - TransactionJMXRegistrator transactionRegistrator = baseJMXRegistrator - .createTransactionJMXRegistrator(transactionName); - Map> allCurrentFactories = Collections.unmodifiableMap(resolver.getAllFactories()); + final String transactionName = "ConfigTransaction-" + version + "-" + versionCounter; + + TransactionJMXRegistratorFactory factory = new TransactionJMXRegistratorFactory() { + @Override + public TransactionJMXRegistrator create() { + return baseJMXRegistrator.createTransactionJMXRegistrator(transactionName); + } + }; + + Map> allCurrentFactories = Collections.unmodifiableMap( + resolver.getAllFactories()); + ConfigTransactionLookupRegistry txLookupRegistry = new ConfigTransactionLookupRegistry(new TransactionIdentifier( + transactionName), factory, allCurrentFactories); + ServiceReferenceWritableRegistry writableRegistry = ServiceReferenceRegistryImpl.createSRWritableRegistry( + readableSRRegistry, txLookupRegistry, allCurrentFactories); + ConfigTransactionControllerInternal transactionController = new ConfigTransactionControllerImpl( - transactionName, transactionRegistrator, version, - versionCounter, allCurrentFactories, transactionsMBeanServer, configMBeanServer, bundleContext); + txLookupRegistry, version, + versionCounter, allCurrentFactories, transactionsMBeanServer, + configMBeanServer, blankTransaction, writableRegistry); try { - transactionRegistrator.registerMBean(transactionController, transactionController.getControllerObjectName()); + txLookupRegistry.registerMBean(transactionController, transactionController.getControllerObjectName()); } catch (InstanceAlreadyExistsException e) { throw new IllegalStateException(e); } - transactionController.copyExistingModulesAndProcessFactoryDiff(currentConfig.getEntries(), lastListOfFactories); - transactionsHolder.add(transactionName, transactionController); return transactionController; } @@ -223,7 +245,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator; if (entry.hasOldModule() == false) { runtimeBeanRegistrator = baseJMXRegistrator - .createRuntimeBeanRegistrator(entry.getName()); + .createRuntimeBeanRegistrator(entry.getIdentifier()); } else { // reuse old JMX registrator runtimeBeanRegistrator = entry.getOldInternalInfo() @@ -236,7 +258,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe .setRuntimeBeanRegistrator(runtimeBeanRegistrator); } // save it to info so it is accessible afterwards - runtimeRegistrators.put(entry.getName(), runtimeBeanRegistrator); + runtimeRegistrators.put(entry.getIdentifier(), runtimeBeanRegistrator); } // can register runtime beans @@ -264,8 +286,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe // determine if current instance was recreated or reused or is new // rules for closing resources: - // osgi registration - will be (re)created every time, so it needs - // to be closed here + // osgi registration - will be reused if possible. // module jmx registration - will be (re)created every time, needs // to be closed here // runtime jmx registration - should be taken care of by module @@ -279,7 +300,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe ModuleInternalInfo oldInternalInfo = entry.getOldInternalInfo(); DynamicReadableWrapper oldReadableConfigBean = oldInternalInfo .getReadableModule(); - currentConfig.remove(entry.getName()); + currentConfig.remove(entry.getIdentifier()); // test if old instance == new instance if (oldReadableConfigBean.getInstance().equals(module.getInstance())) { @@ -324,7 +345,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe BundleContext bc = configTransactionController. getModuleFactoryBundleContext(moduleFactory.getImplementationName()); osgiRegistration = beanToOsgiServiceManager.registerToOsgi(module.getClass(), - newReadableConfigBean.getInstance(), entry.getName(), bc); + newReadableConfigBean.getInstance(), entry.getIdentifier(), bc); } else { throw new NullPointerException(entry.getIdentifier().getFactoryName() + " ModuleFactory not found."); } @@ -332,11 +353,11 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe } RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator = runtimeRegistrators - .get(entry.getName()); + .get(entry.getIdentifier()); ModuleInternalInfo newInfo = new ModuleInternalInfo( - entry.getName(), newReadableConfigBean, osgiRegistration, + entry.getIdentifier(), newReadableConfigBean, osgiRegistration, runtimeBeanRegistrator, newModuleJMXRegistrator, - orderingIdx); + orderingIdx, entry.isDefaultBean()); newConfigEntries.put(module, newInfo); orderingIdx++; @@ -345,6 +366,10 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe // update version version = configTransactionController.getVersion(); + + // switch readable Service Reference Registry + this.readableSRRegistry = ServiceReferenceRegistryImpl.createSRReadableRegistry(configTransactionController.getWritableRegistry(), this); + return new CommitStatus(newInstances, reusedInstances, recreatedInstances); } @@ -367,7 +392,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe /** * Abort open transactions and unregister read only modules. Since this * class is not responsible for registering itself under - * {@link ConfigRegistryMXBean#OBJECT_NAME}, it will not unregister itself + * {@link org.opendaylight.controller.config.api.ConfigRegistry#OBJECT_NAME}, it will not unregister itself * here. */ @Override @@ -486,6 +511,49 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe return baseJMXRegistrator.queryNames(namePattern, null); } + @Override + public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException { + ObjectNameUtil.checkDomain(objectName); + ObjectNameUtil.checkType(objectName, ObjectNameUtil.TYPE_MODULE); + String transactionName = ObjectNameUtil.getTransactionName(objectName); + if (transactionName != null) { + throw new IllegalArgumentException("Transaction attribute not supported in registry, wrong ObjectName: " + objectName); + } + // make sure exactly one match is found: + LookupBeansUtil.lookupConfigBean(this, ObjectNameUtil.getFactoryName(objectName), ObjectNameUtil.getInstanceName(objectName)); + } + + // service reference functionality: + @Override + public synchronized ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceName, String refName) { + return readableSRRegistry.lookupConfigBeanByServiceInterfaceName(serviceInterfaceName, refName); + } + + @Override + public synchronized Map> getServiceMapping() { + return readableSRRegistry.getServiceMapping(); + } + + @Override + public synchronized Map lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceName) { + return readableSRRegistry.lookupServiceReferencesByServiceInterfaceName(serviceInterfaceName); + } + + @Override + public synchronized Set lookupServiceInterfaceNames(ObjectName objectName) throws InstanceNotFoundException { + return readableSRRegistry.lookupServiceInterfaceNames(objectName); + } + + @Override + public synchronized String getServiceInterfaceName(String namespace, String localName) { + return readableSRRegistry.getServiceInterfaceName(namespace, localName); + } + + @Override + public Set getAvailableModuleFactoryQNames() { + return ModuleQNameUtil.getQNames(resolver.getAllFactories()); + } + } /** @@ -543,6 +611,8 @@ class ConfigHolder { Collections.sort(result); return result; } + + } /**