Use the memorized service reference
authorStephen Kitt <skitt@redhat.com>
Mon, 28 Sep 2015 16:06:54 +0000 (18:06 +0200)
committerStephen Kitt <skitt@redhat.com>
Tue, 29 Sep 2015 06:56:11 +0000 (08:56 +0200)
Currently when dispatching "event handler added" events we retrieve
the appropriate service reference from the bundle context, but this
seems to cause problems when multiple services are registered for the
same interfaces. Since we know the service reference we got when
registering the service involved, we can just pass that.

Some more debugging information should help track down other issues of
this type.

Change-Id: Iac54595aed388165711a7c4a3d86577646c59d4f
Signed-off-by: Stephen Kitt <skitt@redhat.com>
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/ConfigActivator.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/NetworkHandler.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/PortHandler.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/SubnetHandler.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/EventDispatcherImpl.java

index 53dbd7c9e688cdc8c241c48bfdecaff172e6ac8a..6e163c5355b703f86a398d9ead3dc5bac9b4bb0b 100644 (file)
@@ -4,6 +4,7 @@ import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.List;
+
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.neutron.spi.*;
@@ -69,21 +70,21 @@ public class ConfigActivator implements BundleActivator {
         Dictionary<String, Object> networkHandlerProperties = new Hashtable<>();
         networkHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_NETWORK);
         final NetworkHandler networkHandler = new NetworkHandler();
-        registerService(context,
+        ServiceRegistration networkHandlerRegistration = registerService(context,
                 new String[]{INeutronNetworkAware.class.getName(), AbstractHandler.class.getName()},
                 networkHandlerProperties, networkHandler);
 
         Dictionary<String, Object> subnetHandlerProperties = new Hashtable<>();
         subnetHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_SUBNET);
         SubnetHandler subnetHandler = new SubnetHandler();
-        registerService(context,
+        ServiceRegistration subnetHandlerRegistration = registerService(context,
                 new String[] {INeutronSubnetAware.class.getName(), AbstractHandler.class.getName()},
                 subnetHandlerProperties, subnetHandler);
 
         Dictionary<String, Object> portHandlerProperties = new Hashtable<>();
         portHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_PORT);
         PortHandler portHandler = new PortHandler();
-        registerService(context,
+        ServiceRegistration portHandlerRegistration = registerService(context,
                 new String[]{INeutronPortAware.class.getName(), AbstractHandler.class.getName()},
                 portHandlerProperties, portHandler);
 
@@ -173,7 +174,7 @@ public class ConfigActivator implements BundleActivator {
         nodeCacheManagerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NODE);
         NodeCacheManagerImpl nodeCacheManager = new NodeCacheManagerImpl();
         registerService(context,
-                new String[]{NodeCacheManager.class.getName(), AbstractHandler.class.getName()},
+                new String[] {NodeCacheManager.class.getName(), AbstractHandler.class.getName()},
                 nodeCacheManagerProperties, nodeCacheManager);
 
         OvsdbInventoryServiceImpl ovsdbInventoryService = new OvsdbInventoryServiceImpl(providerContext);
@@ -194,9 +195,9 @@ public class ConfigActivator implements BundleActivator {
         lBaaSHandler.setDependencies(context, null);
         southboundHandler.setDependencies(context, null);
         routerHandler.setDependencies(context, null);
-        portHandler.setDependencies(context, null);
-        subnetHandler.setDependencies(context, null);
-        networkHandler.setDependencies(context, null);
+        portHandler.setDependencies(context, portHandlerRegistration.getReference());
+        subnetHandler.setDependencies(context, subnetHandlerRegistration.getReference());
+        networkHandler.setDependencies(context, networkHandlerRegistration.getReference());
         floatingIPHandler.setDependencies(context, null);
         vlanConfigurationCache.setDependencies(context, null);
         tenantNetworkManager.setDependencies(context, null);
@@ -447,6 +448,8 @@ public class ConfigActivator implements BundleActivator {
         ServiceRegistration<?> serviceRegistration = bundleContext.registerService(interfaces, impl, properties);
         if (serviceRegistration != null) {
             registrations.add(serviceRegistration);
+        } else {
+            LOG.warn("Service registration for {} failed to return a ServiceRegistration instance", impl.getClass());
         }
         return serviceRegistration;
     }
index 43150c4da5b52fe3e9ecde8eae8142c998fe52b8..f84ed343ede6fbfe9077e7c8cc40351a1c7ca7ed 100644 (file)
@@ -208,8 +208,7 @@ public class NetworkHandler extends AbstractHandler implements INeutronNetworkAw
                 (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
         eventDispatcher =
                 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
-        eventDispatcher.eventHandlerAdded(
-                bundleContext.getServiceReference(INeutronNetworkAware.class.getName()), this);
+        eventDispatcher.eventHandlerAdded(serviceReference, this);
     }
 
     @Override
index 2ecf1090b851d1caa658a4a93852a6d7fb32498a..aa9ba240059a3449b5b065febcf6f9a32e800893 100644 (file)
@@ -185,8 +185,7 @@ public class PortHandler extends AbstractHandler implements INeutronPortAware, C
                 (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
         eventDispatcher =
                 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
-        eventDispatcher.eventHandlerAdded(
-                bundleContext.getServiceReference(INeutronPortAware.class.getName()), this);
+        eventDispatcher.eventHandlerAdded(serviceReference, this);
     }
 
     @Override
index 8c63f0ad0be50b646030bd14270a42a49fa74d6e..343a728f3dfe56879c482a94796a5f3798fba73e 100644 (file)
@@ -96,8 +96,7 @@ public class SubnetHandler extends AbstractHandler implements INeutronSubnetAwar
                 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
         eventDispatcher =
                 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
-        eventDispatcher.eventHandlerAdded(
-                bundleContext.getServiceReference(INeutronSubnetAware.class.getName()), this);
+        eventDispatcher.eventHandlerAdded(serviceReference, this);
     }
 
     @Override
index 129276c32efa4fda8f2aae63b0acc44d9d4df790..e342c231dd6bb21adece461f6f76d72076877f92 100644 (file)
@@ -101,8 +101,10 @@ public class EventDispatcherImpl implements EventDispatcher, ConfigInterface {
         Long pid = (Long) ref.getProperty(org.osgi.framework.Constants.SERVICE_ID);
         Object handlerTypeObject = ref.getProperty(Constants.EVENT_HANDLER_TYPE_PROPERTY);
         if (!(handlerTypeObject instanceof AbstractEvent.HandlerType)){
+            // The exception should give us a stacktrace
             logger.error("Abstract handler reg failed to provide a valid handler type: {} ref: {} handler: {}",
-                    handlerTypeObject, ref.getClass().getName(), handler.getClass().getName());
+                    handlerTypeObject, ref.getClass().getName(), handler.getClass().getName(),
+                    new IllegalArgumentException("Missing handler type"));
             return;
         }
         AbstractEvent.HandlerType handlerType = (AbstractEvent.HandlerType) handlerTypeObject;