From 2676e61ec5958736753c5345cd31fd48ea3e5a05 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Mon, 16 Feb 2015 10:36:38 +0100 Subject: [PATCH 1/1] BUG-2633 - Added Operation Service Factory Filtering for Netconf. Since getting services is done by class name, we needed to add additional filtering by name to not get controller subsystem netconf operations mixed up with md-sal northbound. Change-Id: I6aeb161ae0ace977f590d73e4fcb98c0898b1956 Signed-off-by: Tomas Cere Signed-off-by: Maros Marsalek --- .../osgi/Activator.java | 3 ++- .../netconf/api/util/NetconfConstants.java | 19 +++++++++++++++++++ ...NetconfOperationServiceFactoryTracker.java | 17 +++++++++++++---- ...onfOperationServiceFactoryTrackerTest.java | 2 ++ .../osgi/NetconfMonitoringServiceTracker.java | 6 +++++- .../notifications/impl/osgi/Activator.java | 6 +++++- 6 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/util/NetconfConstants.java diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/Activator.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/Activator.java index 1579d1927f..f39a21d16b 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/Activator.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/Activator.java @@ -12,6 +12,7 @@ import static com.google.common.base.Preconditions.checkState; import java.util.Dictionary; import java.util.Hashtable; +import org.opendaylight.controller.netconf.api.util.NetconfConstants; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider; import org.osgi.framework.BundleActivator; @@ -91,7 +92,7 @@ public class Activator implements BundleActivator { NetconfOperationServiceFactoryImpl factory = new NetconfOperationServiceFactoryImpl(yangStoreService); LOG.debug("Registering into OSGi"); Dictionary properties = new Hashtable<>(); - properties.put("name", "config-netconf-connector"); + properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.CONFIG_NETCONF_CONNECTOR); osgiRegistration = context.registerService(NetconfOperationServiceFactory.class, factory, properties); } } diff --git a/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/util/NetconfConstants.java b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/util/NetconfConstants.java new file mode 100644 index 0000000000..b9c4dcaf4a --- /dev/null +++ b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/util/NetconfConstants.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.api.util; + +public final class NetconfConstants { + /* + * TODO define marker interface in mapping-api that the serviceFactories in cofing subsystem + * will implement so we can check for services with instanceof instead of constants + */ + public static final String SERVICE_NAME = "name"; + public static final String CONFIG_NETCONF_CONNECTOR = "config-netconf-connector"; + public static final String NETCONF_MONITORING = "ietf-netconf-monitoring"; +} diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java index c1d9317c29..9a077a6130 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.netconf.impl.osgi; +import org.opendaylight.controller.netconf.api.util.NetconfConstants; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -24,15 +25,23 @@ class NetconfOperationServiceFactoryTracker extends @Override public NetconfOperationServiceFactory addingService(ServiceReference reference) { - NetconfOperationServiceFactory netconfOperationServiceFactory = super.addingService(reference); - factoriesListener.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory); - return netconfOperationServiceFactory; + Object property = reference.getProperty(NetconfConstants.SERVICE_NAME); + if (property != null + && (property.equals(NetconfConstants.CONFIG_NETCONF_CONNECTOR) + || property.equals(NetconfConstants.NETCONF_MONITORING))) { + NetconfOperationServiceFactory netconfOperationServiceFactory = super.addingService(reference); + factoriesListener.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory); + return netconfOperationServiceFactory; + } + + return null; } @Override public void removedService(ServiceReference reference, NetconfOperationServiceFactory netconfOperationServiceFactory) { - factoriesListener.onRemoveNetconfOperationServiceFactory(netconfOperationServiceFactory); + if (netconfOperationServiceFactory != null) + factoriesListener.onRemoveNetconfOperationServiceFactory(netconfOperationServiceFactory); } } diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java index d744504bb2..8cb569eaa2 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java @@ -20,6 +20,7 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.netconf.api.util.NetconfConstants; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; import org.osgi.framework.BundleContext; import org.osgi.framework.Filter; @@ -46,6 +47,7 @@ public class NetconfOperationServiceFactoryTrackerTest { doNothing().when(listener).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class)); doReturn(filter).when(context).createFilter(anyString()); doReturn("").when(reference).toString(); + doReturn(NetconfConstants.CONFIG_NETCONF_CONNECTOR).when(reference).getProperty(NetconfConstants.SERVICE_NAME); doReturn(factory).when(context).getService(any(ServiceReference.class)); doReturn("").when(factory).toString(); doNothing().when(listener).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class)); diff --git a/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringServiceTracker.java b/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringServiceTracker.java index 0b4d1c2688..9e7c105aa4 100644 --- a/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringServiceTracker.java +++ b/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringServiceTracker.java @@ -8,8 +8,10 @@ package org.opendaylight.controller.netconf.monitoring.osgi; import com.google.common.base.Preconditions; +import java.util.Dictionary; import java.util.Hashtable; import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; +import org.opendaylight.controller.netconf.api.util.NetconfConstants; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -39,7 +41,9 @@ public class NetconfMonitoringServiceTracker extends ServiceTracker()); + Dictionary properties = new Hashtable<>(); + properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING); + reg = context.registerService(NetconfOperationServiceFactory.class, factory, properties); return netconfMonitoringService; } diff --git a/opendaylight/netconf/netconf-notifications-impl/src/main/java/org/opendaylight/controller/netconf/notifications/impl/osgi/Activator.java b/opendaylight/netconf/netconf-notifications-impl/src/main/java/org/opendaylight/controller/netconf/notifications/impl/osgi/Activator.java index ef950f8a78..9eab5caff7 100644 --- a/opendaylight/netconf/netconf-notifications-impl/src/main/java/org/opendaylight/controller/netconf/notifications/impl/osgi/Activator.java +++ b/opendaylight/netconf/netconf-notifications-impl/src/main/java/org/opendaylight/controller/netconf/notifications/impl/osgi/Activator.java @@ -12,8 +12,10 @@ import com.google.common.base.Optional; import com.google.common.collect.Sets; import java.util.Collection; import java.util.Collections; +import java.util.Dictionary; import java.util.Hashtable; import java.util.Set; +import org.opendaylight.controller.netconf.api.util.NetconfConstants; import org.opendaylight.controller.netconf.mapping.api.Capability; import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; @@ -66,7 +68,9 @@ public class Activator implements BundleActivator { } }; - operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, new Hashtable()); + Dictionary properties = new Hashtable<>(); + properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING); + operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, properties); } -- 2.36.6