Search in sources :

Example 1 with YangModuleInfo

use of org.opendaylight.yangtools.yang.binding.YangModuleInfo 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)

Example 2 with YangModuleInfo

use of org.opendaylight.yangtools.yang.binding.YangModuleInfo in project controller by opendaylight.

the class AbstractSchemaAwareTest method getSchemaContext.

protected SchemaContext getSchemaContext() throws Exception {
    final Iterable<YangModuleInfo> moduleInfos = getModuleInfos();
    final ModuleInfoBackedContext moduleContext = ModuleInfoBackedContext.create();
    moduleContext.addModuleInfos(moduleInfos);
    return moduleContext.tryToCreateSchemaContext().get();
}
Also used : YangModuleInfo(org.opendaylight.yangtools.yang.binding.YangModuleInfo) ModuleInfoBackedContext(org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext)

Example 3 with YangModuleInfo

use of org.opendaylight.yangtools.yang.binding.YangModuleInfo in project controller by opendaylight.

the class RefreshingSCPModuleInfoRegistryTest method testConstructor.

@Test
public void testConstructor() throws Exception {
    final ModuleInfoRegistry reg = mock(ModuleInfoRegistry.class);
    final SchemaContextProvider prov = mock(SchemaContextProvider.class);
    doReturn("string").when(prov).toString();
    final BundleContext ctxt = mock(BundleContext.class);
    final ServiceRegistration<?> servReg = mock(ServiceRegistration.class);
    doReturn(servReg).when(ctxt).registerService(any(Class.class), any(SchemaContextProvider.class), any(Dictionary.class));
    doReturn(servReg).when(ctxt).registerService(Mockito.anyString(), any(Object.class), any(Dictionary.class));
    doNothing().when(servReg).setProperties(any(Dictionary.class));
    final ClassLoadingStrategy classLoadingStrat = mock(ClassLoadingStrategy.class);
    final BindingContextProvider codecRegistryProvider = mock(BindingContextProvider.class);
    doNothing().when(codecRegistryProvider).update(classLoadingStrat, prov);
    final BindingRuntimeContext bindingRuntimeContext = mock(BindingRuntimeContext.class);
    doReturn("B-runtime-context").when(bindingRuntimeContext).toString();
    doReturn(bindingRuntimeContext).when(codecRegistryProvider).getBindingContext();
    final RefreshingSCPModuleInfoRegistry scpreg = new RefreshingSCPModuleInfoRegistry(reg, prov, classLoadingStrat, this.sourceProvider, codecRegistryProvider, ctxt);
    doNothing().when(servReg).unregister();
    final YangModuleInfo modInfo = mock(YangModuleInfo.class);
    doReturn("").when(modInfo).toString();
    final ObjectRegistration<YangModuleInfo> ymi = mock(ObjectRegistration.class);
    doReturn(ymi).when(reg).registerModuleInfo(modInfo);
    scpreg.registerModuleInfo(modInfo);
    scpreg.updateService();
    verify(codecRegistryProvider).update(classLoadingStrat, prov);
    scpreg.close();
    Mockito.verify(servReg, Mockito.times(1)).setProperties(any(Dictionary.class));
    Mockito.verify(servReg, Mockito.times(1)).unregister();
}
Also used : Dictionary(java.util.Dictionary) BindingContextProvider(org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider) RefreshingSCPModuleInfoRegistry(org.opendaylight.controller.config.manager.impl.osgi.mapping.RefreshingSCPModuleInfoRegistry) ModuleInfoRegistry(org.opendaylight.mdsal.binding.generator.api.ModuleInfoRegistry) SchemaContextProvider(org.opendaylight.yangtools.yang.model.api.SchemaContextProvider) ClassLoadingStrategy(org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy) BindingRuntimeContext(org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext) YangModuleInfo(org.opendaylight.yangtools.yang.binding.YangModuleInfo) RefreshingSCPModuleInfoRegistry(org.opendaylight.controller.config.manager.impl.osgi.mapping.RefreshingSCPModuleInfoRegistry) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 4 with YangModuleInfo

use of org.opendaylight.yangtools.yang.binding.YangModuleInfo in project controller by opendaylight.

the class SchemaUpdateForTransactionTest method loadSchemas.

public void loadSchemas(final Class<?>... classes) throws Exception {
    final ModuleInfoBackedContext context = ModuleInfoBackedContext.create();
    for (final Class<?> clz : classes) {
        YangModuleInfo moduleInfo = BindingReflections.getModuleInfo(clz);
        context.registerModuleInfo(moduleInfo);
    }
    this.schemaContext = context.tryToCreateSchemaContext().get();
    this.domStore.onGlobalContextUpdated(this.schemaContext);
}
Also used : YangModuleInfo(org.opendaylight.yangtools.yang.binding.YangModuleInfo) ModuleInfoBackedContext(org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext)

Example 5 with YangModuleInfo

use of org.opendaylight.yangtools.yang.binding.YangModuleInfo in project controller by opendaylight.

the class DOMRpcServiceTestBugfix560 method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
    testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
    testFactory.setStartWithParsedSchema(true);
    testContext = testFactory.getTestContext();
    testContext.start();
    domMountPointService = testContext.getDomMountProviderService();
    bindingMountPointService = testContext.getBindingMountPointService();
    assertNotNull(domMountPointService);
    final YangModuleInfo moduleInfo = BindingReflections.getModuleInfo(OpendaylightTestRpcServiceService.class);
    assertNotNull(moduleInfo);
    schemaContext = YangParserTestUtils.parseYangSources(StatementParserMode.DEFAULT_MODE, null, YangTextSchemaSource.delegateForByteSource(RevisionSourceIdentifier.create(moduleInfo.getName().getLocalName(), moduleInfo.getName().getRevision()), moduleInfo.getYangTextByteSource()));
}
Also used : YangModuleInfo(org.opendaylight.yangtools.yang.binding.YangModuleInfo) BindingBrokerTestFactory(org.opendaylight.controller.sal.binding.test.util.BindingBrokerTestFactory) Before(org.junit.Before)

Aggregations

YangModuleInfo (org.opendaylight.yangtools.yang.binding.YangModuleInfo)7 ModuleInfoBackedContext (org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext)4 Before (org.junit.Before)2 BindingContextProvider (org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider)2 RefreshingSCPModuleInfoRegistry (org.opendaylight.controller.config.manager.impl.osgi.mapping.RefreshingSCPModuleInfoRegistry)2 IOException (java.io.IOException)1 URL (java.net.URL)1 Collection (java.util.Collection)1 Dictionary (java.util.Dictionary)1 LinkedList (java.util.LinkedList)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 Test (org.junit.Test)1 ConfigRegistryImpl (org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl)1 ConfigRegistryJMXRegistrator (org.opendaylight.controller.config.manager.impl.jmx.ConfigRegistryJMXRegistrator)1 JMXNotifierConfigRegistry (org.opendaylight.controller.config.manager.impl.jmx.JMXNotifierConfigRegistry)1 ModuleInfoBundleTracker (org.opendaylight.controller.config.manager.impl.osgi.mapping.ModuleInfoBundleTracker)1 ModuleFactory (org.opendaylight.controller.config.spi.ModuleFactory)1 BindingBrokerTestFactory (org.opendaylight.controller.sal.binding.test.util.BindingBrokerTestFactory)1 ClassLoadingStrategy (org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy)1 ModuleInfoRegistry (org.opendaylight.mdsal.binding.generator.api.ModuleInfoRegistry)1