BUG-2633 - Added Operation Service Factory Filtering for Netconf. 90/15190/9
authorMaros Marsalek <mmarsale@cisco.com>
Mon, 16 Feb 2015 09:36:38 +0000 (10:36 +0100)
committerMaros Marsalek <mmarsale@cisco.com>
Tue, 17 Feb 2015 08:07:41 +0000 (09:07 +0100)
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 <tcere@cisco.com>
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/osgi/Activator.java
opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/util/NetconfConstants.java [new file with mode: 0644]
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java
opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java
opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringServiceTracker.java
opendaylight/netconf/netconf-notifications-impl/src/main/java/org/opendaylight/controller/netconf/notifications/impl/osgi/Activator.java

index 1579d1927fef673b116f2827940970e9cf9ab103..f39a21d16b558e917cb7a86b145e5193c89345ff 100644 (file)
@@ -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<String, String> 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 (file)
index 0000000..b9c4dca
--- /dev/null
@@ -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";
+}
index c1d9317c294ca96938dbd0ccec843eb7d5991d0f..9a077a6130bb630cf9fdf5923e78a46eaaf6933b 100644 (file)
@@ -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<NetconfOperationServiceFactory> 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<NetconfOperationServiceFactory> reference,
             NetconfOperationServiceFactory netconfOperationServiceFactory) {
-        factoriesListener.onRemoveNetconfOperationServiceFactory(netconfOperationServiceFactory);
+        if (netconfOperationServiceFactory != null)
+            factoriesListener.onRemoveNetconfOperationServiceFactory(netconfOperationServiceFactory);
     }
 
 }
index d744504bb2aa4160dfb6b57229a29e2623cad864..8cb569eaa283a974726ce3fab657f663fc72abb5 100644 (file)
@@ -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));
index 0b4d1c2688d64307b51815b0d3b441f0ff9722ec..9e7c105aa4e0cf53f95ebeb290b181866e54cc8a 100644 (file)
@@ -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<NetconfMonit
         final NetconfOperationServiceFactory factory = new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(
                 operationService);
 
-        reg = context.registerService(NetconfOperationServiceFactory.class, factory, new Hashtable<String, Object>());
+        Dictionary<String, String> properties = new Hashtable<>();
+        properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING);
+        reg = context.registerService(NetconfOperationServiceFactory.class, factory, properties);
 
         return netconfMonitoringService;
     }
index ef950f8a788d768509749e3138afd3d3120e6a93..9eab5caff74fe3411d0ccaa847594d1834e574ea 100644 (file)
@@ -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<String, Object>());
+        Dictionary<String, String> properties = new Hashtable<>();
+        properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING);
+        operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, properties);
 
     }