Search in sources :

Example 1 with SchemaContextProvider

use of org.opendaylight.yangtools.yang.model.api.SchemaContextProvider 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 2 with SchemaContextProvider

use of org.opendaylight.yangtools.yang.model.api.SchemaContextProvider in project controller by opendaylight.

the class YangStoreActivator method start.

@Override
@SuppressWarnings("checkstyle:hiddenField")
public void start(final BundleContext context) throws Exception {
    LOG.debug("ConfigPersister starting");
    this.context = context;
    final ServiceTrackerCustomizer<SchemaContextProvider, YangStoreService> schemaServiceTrackerCustomizer = new ServiceTrackerCustomizer<SchemaContextProvider, YangStoreService>() {

        private final AtomicBoolean alreadyStarted = new AtomicBoolean(false);

        @Override
        public YangStoreService addingService(final ServiceReference<SchemaContextProvider> reference) {
            LOG.debug("Got addingService(SchemaContextProvider) event");
            if (reference.getProperty(SchemaSourceProvider.class.getName()) == null && reference.getProperty(BindingRuntimeContext.class.getName()) == null) {
                LOG.debug("SchemaContextProvider not from config-manager. Ignoring");
                return null;
            }
            // Yang store service should not be registered multiple times
            if (!this.alreadyStarted.compareAndSet(false, true)) {
                LOG.warn("Starting yang store service multiple times. Received new service {}", reference);
                throw new RuntimeException("Starting yang store service multiple times");
            }
            final SchemaContextProvider schemaContextProvider = reference.getBundle().getBundleContext().getService(reference);
            final Object sourceProvider = Preconditions.checkNotNull(reference.getProperty(SchemaSourceProvider.class.getName()), "Source provider not found");
            Preconditions.checkArgument(sourceProvider instanceof SchemaSourceProvider);
            // TODO avoid cast
            final YangStoreService yangStoreService = new YangStoreService(schemaContextProvider, (SchemaSourceProvider<YangTextSchemaSource>) sourceProvider);
            final BindingRuntimeContext runtimeContext = (BindingRuntimeContext) reference.getProperty(BindingRuntimeContext.class.getName());
            LOG.debug("BindingRuntimeContext retrieved as {}", runtimeContext);
            if (runtimeContext != null) {
                yangStoreService.refresh(runtimeContext);
            }
            YangStoreActivator.this.yangStoreServiceServiceRegistration = context.registerService(YangStoreService.class, yangStoreService, new Hashtable<>());
            YangStoreActivator.this.configRegistryLookup = new ConfigRegistryLookupThread(yangStoreService);
            YangStoreActivator.this.configRegistryLookup.start();
            return yangStoreService;
        }

        @Override
        public void modifiedService(final ServiceReference<SchemaContextProvider> reference, final YangStoreService service) {
            if (service == null) {
                return;
            }
            LOG.debug("Got modifiedService(SchemaContextProvider) event");
            final BindingRuntimeContext runtimeContext = (BindingRuntimeContext) reference.getProperty(BindingRuntimeContext.class.getName());
            LOG.debug("BindingRuntimeContext retrieved as {}", runtimeContext);
            service.refresh(runtimeContext);
        }

        @Override
        public void removedService(final ServiceReference<SchemaContextProvider> reference, final YangStoreService service) {
            if (service == null) {
                return;
            }
            LOG.debug("Got removedService(SchemaContextProvider) event");
            this.alreadyStarted.set(false);
            YangStoreActivator.this.configRegistryLookup.interrupt();
            YangStoreActivator.this.yangStoreServiceServiceRegistration.unregister();
            YangStoreActivator.this.yangStoreServiceServiceRegistration = null;
        }
    };
    final ServiceTracker<SchemaContextProvider, YangStoreService> schemaContextProviderServiceTracker = new ServiceTracker<>(context, SchemaContextProvider.class, schemaServiceTrackerCustomizer);
    schemaContextProviderServiceTracker.open();
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) SchemaSourceProvider(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) Hashtable(java.util.Hashtable) SchemaContextProvider(org.opendaylight.yangtools.yang.model.api.SchemaContextProvider) ServiceReference(org.osgi.framework.ServiceReference) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BindingRuntimeContext(org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext)

Example 3 with SchemaContextProvider

use of org.opendaylight.yangtools.yang.model.api.SchemaContextProvider in project controller by opendaylight.

the class AbstractConfigTest method initConfigTransactionManagerImpl.

// this method should be called in @Before
protected void initConfigTransactionManagerImpl(final ModuleFactoriesResolver resolver) {
    final MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
    this.configRegistryJMXRegistrator = new ConfigRegistryJMXRegistrator(platformMBeanServer);
    initBundleContext();
    this.baseJmxRegistrator = new BaseJMXRegistrator(platformMBeanServer);
    this.configRegistry = new ConfigRegistryImpl(resolver, platformMBeanServer, this.baseJmxRegistrator, new BindingContextProvider() {

        @Override
        public synchronized void update(final ClassLoadingStrategy classLoadingStrategy, final SchemaContextProvider ctxProvider) {
        // NOOP
        }

        @Override
        public synchronized BindingRuntimeContext getBindingContext() {
            return getBindingRuntimeContext();
        }
    });
    this.notifyingConfigRegistry = new JMXNotifierConfigRegistry(this.configRegistry, platformMBeanServer);
    try {
        this.configRegistryJMXRegistrator.registerToJMXNoNotifications(this.configRegistry);
        this.configRegistryJMXRegistrator.registerToJMX(this.notifyingConfigRegistry);
    } catch (final InstanceAlreadyExistsException e) {
        throw new RuntimeException(e);
    }
    this.configRegistryClient = new ConfigRegistryJMXClient(platformMBeanServer);
    this.currentBundleContextServiceRegistrationHandler = new RecordingBundleContextServiceRegistrationHandler();
}
Also used : JMXNotifierConfigRegistry(org.opendaylight.controller.config.manager.impl.jmx.JMXNotifierConfigRegistry) BindingContextProvider(org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider) BaseJMXRegistrator(org.opendaylight.controller.config.manager.impl.jmx.BaseJMXRegistrator) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ClassLoadingStrategy(org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy) SchemaContextProvider(org.opendaylight.yangtools.yang.model.api.SchemaContextProvider) ConfigRegistryJMXRegistrator(org.opendaylight.controller.config.manager.impl.jmx.ConfigRegistryJMXRegistrator) ConfigRegistryJMXClient(org.opendaylight.controller.config.util.ConfigRegistryJMXClient) MBeanServer(javax.management.MBeanServer)

Aggregations

SchemaContextProvider (org.opendaylight.yangtools.yang.model.api.SchemaContextProvider)3 BindingContextProvider (org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider)2 ClassLoadingStrategy (org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy)2 BindingRuntimeContext (org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext)2 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 MBeanServer (javax.management.MBeanServer)1 Test (org.junit.Test)1 BaseJMXRegistrator (org.opendaylight.controller.config.manager.impl.jmx.BaseJMXRegistrator)1 ConfigRegistryJMXRegistrator (org.opendaylight.controller.config.manager.impl.jmx.ConfigRegistryJMXRegistrator)1 JMXNotifierConfigRegistry (org.opendaylight.controller.config.manager.impl.jmx.JMXNotifierConfigRegistry)1 RefreshingSCPModuleInfoRegistry (org.opendaylight.controller.config.manager.impl.osgi.mapping.RefreshingSCPModuleInfoRegistry)1 ConfigRegistryJMXClient (org.opendaylight.controller.config.util.ConfigRegistryJMXClient)1 ModuleInfoRegistry (org.opendaylight.mdsal.binding.generator.api.ModuleInfoRegistry)1 YangModuleInfo (org.opendaylight.yangtools.yang.binding.YangModuleInfo)1 YangTextSchemaSource (org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource)1 SchemaSourceProvider (org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider)1 BundleContext (org.osgi.framework.BundleContext)1