Search in sources :

Example 1 with ConfigRegistryImpl

use of org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl in project controller by opendaylight.

the class ConfigRegistryImplTest method testFailOnTwoFactoriesExportingSameImpl.

@Test
@SuppressWarnings("IllegalCatch")
public void testFailOnTwoFactoriesExportingSameImpl() {
    ModuleFactory factory = new TestingFixedThreadPoolModuleFactory();
    BundleContext context = mock(BundleContext.class);
    ConfigRegistryImpl configRegistry = null;
    try {
        ModuleFactoriesResolver resolver = new HardcodedModuleFactoriesResolver(mock(BundleContext.class), factory, factory);
        configRegistry = new ConfigRegistryImpl(resolver, ManagementFactory.getPlatformMBeanServer(), null);
        configRegistry.beginConfig();
        fail();
    } catch (final IllegalArgumentException e) {
        assertTrue(e.getMessage(), e.getMessage().startsWith("Module name is not unique. Found two conflicting factories with same name " + "'fixed':"));
        verifyZeroInteractions(context);
    } finally {
        try {
            configRegistry.close();
        } catch (final Exception e) {
            // ignore
            LOG.warn("Ignoring exception", e);
        }
    }
}
Also used : TestingFixedThreadPoolModuleFactory(org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolModuleFactory) ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) TestingFixedThreadPoolModuleFactory(org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolModuleFactory) ModuleFactoriesResolver(org.opendaylight.controller.config.manager.impl.factoriesresolver.ModuleFactoriesResolver) HardcodedModuleFactoriesResolver(org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver) ConfigRegistryImpl(org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl) HardcodedModuleFactoriesResolver(org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test) AbstractLockedPlatformMBeanServerTest(org.opendaylight.controller.config.manager.impl.AbstractLockedPlatformMBeanServerTest)

Example 2 with ConfigRegistryImpl

use of org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl in project controller by opendaylight.

the class ConfigManagerActivator method start.

@Override
public void start(final BundleContext context) {
    LOG.info("Config manager starting...");
    try {
        // the inner strategy is backed by thread context cl?
        final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
        final BindingContextProvider bindingContextProvider = new BindingContextProvider();
        final RefreshingSCPModuleInfoRegistry moduleInfoRegistryWrapper = new RefreshingSCPModuleInfoRegistry(moduleInfoBackedContext, moduleInfoBackedContext, moduleInfoBackedContext, moduleInfoBackedContext, bindingContextProvider, context);
        final ModuleInfoBundleTracker moduleInfoBundleTracker = new ModuleInfoBundleTracker(moduleInfoRegistryWrapper);
        // start config registry
        final BundleContextBackedModuleFactoriesResolver bundleContextBackedModuleFactoriesResolver = new BundleContextBackedModuleFactoriesResolver(context);
        this.configRegistry = new ConfigRegistryImpl(bundleContextBackedModuleFactoriesResolver, this.configMBeanServer, bindingContextProvider);
        // track bundles containing factories
        final BlankTransactionServiceTracker blankTransactionServiceTracker = new BlankTransactionServiceTracker(this.configRegistry);
        final ModuleFactoryBundleTracker moduleFactoryTracker = new ModuleFactoryBundleTracker(blankTransactionServiceTracker);
        BundleTracker<Collection<ObjectRegistration<YangModuleInfo>>> moduleInfoResolvedBundleTracker = new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE, moduleInfoBundleTracker);
        ExtensibleBundleTracker<?> moduleFactoryBundleTracker = new ExtensibleBundleTracker<>(context, moduleFactoryTracker);
        moduleInfoBundleTracker.open(moduleInfoResolvedBundleTracker);
        // start extensible tracker
        moduleFactoryBundleTracker.open();
        // Wrap config registry with JMX notification publishing adapter
        final JMXNotifierConfigRegistry notifyingConfigRegistry = new JMXNotifierConfigRegistry(this.configRegistry, this.configMBeanServer);
        // register config registry to OSGi
        final AutoCloseable clsReg = OsgiRegistrationUtil.registerService(context, moduleInfoBackedContext, ClassLoadingStrategy.class);
        final AutoCloseable configRegReg = OsgiRegistrationUtil.registerService(context, notifyingConfigRegistry, ConfigRegistry.class);
        // register config registry to jmx
        final ConfigRegistryJMXRegistrator configRegistryJMXRegistrator = new ConfigRegistryJMXRegistrator(this.configMBeanServer);
        try {
            configRegistryJMXRegistrator.registerToJMXNoNotifications(this.configRegistry);
        } catch (final InstanceAlreadyExistsException e) {
            configRegistryJMXRegistrator.close();
            throw new IllegalStateException("Config Registry was already registered to JMX", e);
        }
        // register config registry to jmx
        final ConfigRegistryJMXRegistrator configRegistryJMXRegistratorWithNotifications = new ConfigRegistryJMXRegistrator(this.configMBeanServer);
        try {
            configRegistryJMXRegistrator.registerToJMX(notifyingConfigRegistry);
        } catch (final InstanceAlreadyExistsException e) {
            configRegistryJMXRegistrator.close();
            configRegistryJMXRegistratorWithNotifications.close();
            throw new IllegalStateException("Config Registry was already registered to JMX", e);
        }
        // TODO wire directly via moduleInfoBundleTracker
        final ServiceTracker<ModuleFactory, Object> serviceTracker = new ServiceTracker<>(context, ModuleFactory.class, blankTransactionServiceTracker);
        serviceTracker.open();
        final AutoCloseable configMgrReg = OsgiRegistrationUtil.registerService(context, this, ConfigSystemService.class);
        final List<AutoCloseable> list = Arrays.asList(bindingContextProvider, clsReg, OsgiRegistrationUtil.wrap(moduleFactoryBundleTracker), moduleInfoBundleTracker, configRegReg, configRegistryJMXRegistrator, configRegistryJMXRegistratorWithNotifications, OsgiRegistrationUtil.wrap(serviceTracker), moduleInfoRegistryWrapper, notifyingConfigRegistry, configMgrReg);
        this.autoCloseable = OsgiRegistrationUtil.aggregate(list);
        context.addBundleListener(this);
    } catch (final IllegalStateException e) {
        LOG.error("Error starting config manager", e);
    }
    LOG.info("Config manager start complete");
}
Also used : ModuleInfoBundleTracker(org.opendaylight.controller.config.manager.impl.osgi.mapping.ModuleInfoBundleTracker) JMXNotifierConfigRegistry(org.opendaylight.controller.config.manager.impl.jmx.JMXNotifierConfigRegistry) ServiceTracker(org.osgi.util.tracker.ServiceTracker) BindingContextProvider(org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ConfigRegistryJMXRegistrator(org.opendaylight.controller.config.manager.impl.jmx.ConfigRegistryJMXRegistrator) ModuleInfoBundleTracker(org.opendaylight.controller.config.manager.impl.osgi.mapping.ModuleInfoBundleTracker) BundleTracker(org.osgi.util.tracker.BundleTracker) ModuleInfoBackedContext(org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext) ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) ConfigRegistryImpl(org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl) YangModuleInfo(org.opendaylight.yangtools.yang.binding.YangModuleInfo) RefreshingSCPModuleInfoRegistry(org.opendaylight.controller.config.manager.impl.osgi.mapping.RefreshingSCPModuleInfoRegistry) Collection(java.util.Collection)

Aggregations

ConfigRegistryImpl (org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl)2 ModuleFactory (org.opendaylight.controller.config.spi.ModuleFactory)2 Collection (java.util.Collection)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 Test (org.junit.Test)1 AbstractLockedPlatformMBeanServerTest (org.opendaylight.controller.config.manager.impl.AbstractLockedPlatformMBeanServerTest)1 HardcodedModuleFactoriesResolver (org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver)1 ModuleFactoriesResolver (org.opendaylight.controller.config.manager.impl.factoriesresolver.ModuleFactoriesResolver)1 ConfigRegistryJMXRegistrator (org.opendaylight.controller.config.manager.impl.jmx.ConfigRegistryJMXRegistrator)1 JMXNotifierConfigRegistry (org.opendaylight.controller.config.manager.impl.jmx.JMXNotifierConfigRegistry)1 BindingContextProvider (org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider)1 ModuleInfoBundleTracker (org.opendaylight.controller.config.manager.impl.osgi.mapping.ModuleInfoBundleTracker)1 RefreshingSCPModuleInfoRegistry (org.opendaylight.controller.config.manager.impl.osgi.mapping.RefreshingSCPModuleInfoRegistry)1 TestingFixedThreadPoolModuleFactory (org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolModuleFactory)1 ModuleInfoBackedContext (org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext)1 YangModuleInfo (org.opendaylight.yangtools.yang.binding.YangModuleInfo)1 BundleContext (org.osgi.framework.BundleContext)1 BundleTracker (org.osgi.util.tracker.BundleTracker)1 ServiceTracker (org.osgi.util.tracker.ServiceTracker)1