Bug 6396: Integrate neutron mapper with clustering singleton service 50/43850/3
authorVladimir Lavor <vlavor@cisco.com>
Fri, 12 Aug 2016 13:10:38 +0000 (15:10 +0200)
committerVladimir Lavor <vlavor@cisco.com>
Thu, 1 Sep 2016 13:16:41 +0000 (15:16 +0200)
Change-Id: I560f0539cc74b40e451a58aff7d1d8ac41fe6ffd
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
neutron-mapper/src/main/java/org/opendaylight/controller/config/yang/config/neutron_mapper/impl/NeutronMapperInstance.java
neutron-mapper/src/main/java/org/opendaylight/controller/config/yang/config/neutron_mapper/impl/NeutronMapperModule.java
neutron-mapper/src/main/java/org/opendaylight/controller/config/yang/config/neutron_mapper/impl/NeutronMapperModuleFactory.java
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/NeutronMapper.java
neutron-mapper/src/main/resources/org/opendaylight/blueprint/neutron-mapper.xml

index dc03214a910c7a70af38c3b424508adffbb3ea1a..a220e5018fe14e0c899f4f3d1182dd4cbb88a6ef 100644 (file)
@@ -8,21 +8,78 @@
 
 package org.opendaylight.controller.config.yang.config.neutron_mapper.impl;
 
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.controller.config.yang.config.groupbasedpolicy.GroupbasedpolicyInstance;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.groupbasedpolicy.neutron.mapper.NeutronMapper;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
+import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.BaseEndpointService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-public class NeutronMapperInstance implements AutoCloseable{
+public class NeutronMapperInstance implements ClusterSingletonService, AutoCloseable {
 
+    private static final Logger LOG = LoggerFactory.getLogger(NeutronMapperInstance.class);
+
+    private static final ServiceGroupIdentifier IDENTIFIER =
+            ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
+    private final DataBroker dataBroker;
+    private final EndpointService epService;
+    private final BaseEndpointService baseEndpointService;
+    private final ClusterSingletonServiceProvider clusterSingletonService;
+    private ClusterSingletonServiceRegistration singletonServiceRegistration;
     private NeutronMapper mapper;
 
-    public NeutronMapperInstance (DataBroker dataBroker, EndpointService epService,
-            BaseEndpointService baseEndpointService) {
+    public NeutronMapperInstance(final DataBroker dataBroker,
+                                 final EndpointService epService,
+                                 final BaseEndpointService baseEndpointService,
+                                 final ClusterSingletonServiceProvider clusterSingletonService) {
+        this.dataBroker = Preconditions.checkNotNull(dataBroker);
+        this.epService = Preconditions.checkNotNull(epService);
+        this.baseEndpointService = Preconditions.checkNotNull(baseEndpointService);
+        this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
+    }
+
+    public void instantiate() {
+        LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
+        singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
+    }
+
+    @Override
+    public void instantiateServiceInstance() {
+        LOG.info("Instantiating {}", this.getClass().getSimpleName());
         mapper = new NeutronMapper(dataBroker, epService, baseEndpointService);
     }
+
     @Override
-    public void close() throws Exception {
+    public ListenableFuture<Void> closeServiceInstance() {
+        LOG.info("Instance {} closed", this.getClass().getSimpleName());
         mapper.close();
+        return Futures.immediateFuture(null);
     }
+
+    @Override
+    public void close() throws Exception {
+        LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
+        if (singletonServiceRegistration != null) {
+            try {
+                singletonServiceRegistration.close();
+            } catch (Exception e) {
+                LOG.warn("{} closed unexpectedly", e.getMessage());
+            }
+            singletonServiceRegistration = null;
+        }
+    }
+
+    @Override
+    public ServiceGroupIdentifier getIdentifier() {
+        return IDENTIFIER;
+    }
+
 }
index c3d97adac26dc9d51e1f9b9c0ae281763f7575f9..2a3f90a45981eae3526d3d2288b74942c6fe6949 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.controller.config.yang.config.neutron_mapper.impl;
 import org.opendaylight.controller.sal.common.util.NoopAutoCloseable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
+@Deprecated
 public class NeutronMapperModule extends org.opendaylight.controller.config.yang.config.neutron_mapper.impl.AbstractNeutronMapperModule {
 
     private final Logger LOG = LoggerFactory.getLogger(NeutronMapperModule.class);
index 8d9ae820a2e96ac598c143a98b27259d5dee9112..194f750245831824fed3b569f6820bb80f70d483 100644 (file)
@@ -22,7 +22,7 @@ import org.opendaylight.controller.config.api.DependencyResolver;
 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
 import org.opendaylight.controller.config.spi.Module;
 import org.osgi.framework.BundleContext;
-
+@Deprecated
 public class NeutronMapperModuleFactory extends org.opendaylight.controller.config.yang.config.neutron_mapper.impl.AbstractNeutronMapperModuleFactory {
 
     /**
index ea1ea847c51de79d647e818b5787c842f46e2ca5..515ef05a6d3b7ea7a4b43c065e5e1532b0eea39e 100644 (file)
@@ -308,7 +308,7 @@ public class NeutronMapper implements DataTreeChangeListener<Neutron>, AutoClose
     }
 
     @Override
-    public void close() throws IOException {
+    public void close() {
         registerDataTreeChangeListener.close();
     }
 
index 513b844abb5c9474e9e85b7ff4d9d02e4d270c33..305bcc51eaa5bb935494ca3c937ba8ec2936d9e5 100644 (file)
@@ -6,11 +6,13 @@
     <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
     <odl:rpc-service id="epService" interface="org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService"/>
     <odl:rpc-service id="baseEpService" interface="org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.BaseEndpointService"/>
+    <reference id="clusterSingletonService" interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider"/>
 
     <bean id="neutronMapper" class="org.opendaylight.controller.config.yang.config.neutron_mapper.impl.NeutronMapperInstance"
-        destroy-method="close">
+        init-method="instantiate" destroy-method="close">
         <argument ref="dataBroker"/>
         <argument ref="epService"/>
         <argument ref="baseEpService"/>
+        <argument ref="clusterSingletonService" />
     </bean>
 </blueprint>
\ No newline at end of file