Bug 6396: Integrate l2-l3-domain-extension with clustering singleton service 00/43600/5
authorVladimir Lavor <vlavor@cisco.com>
Wed, 10 Aug 2016 10:09:23 +0000 (12:09 +0200)
committerVladimir Lavor <vlavor@cisco.com>
Thu, 1 Sep 2016 11:05:25 +0000 (13:05 +0200)
Change-Id: Ic5a357fc77a75168c6dac898b3db4daa39cd5770
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
domain-extensions/l2-l3/src/main/java/org/opendaylight/controller/config/yang/config/domain_extension/l2_l3/impl/L2L3DomainExtensionInstance.java
domain-extensions/l2-l3/src/main/java/org/opendaylight/controller/config/yang/config/domain_extension/l2_l3/impl/L2L3DomainExtensionModule.java
domain-extensions/l2-l3/src/main/java/org/opendaylight/controller/config/yang/config/domain_extension/l2_l3/impl/L2L3DomainExtensionModuleFactory.java
domain-extensions/l2-l3/src/main/java/org/opendaylight/groupbasedpolicy/domain_extension/l2_l3/L2L3NetworkDomainAugmentor.java
domain-extensions/l2-l3/src/main/resources/org/opendaylight/blueprint/l2-l3-domain-extensions.xml

index b43ba9a0430d28f7fa0acd88629a343fece6c728..51d7c4c971ea16fb031349d76f8755b4ccc95d9c 100644 (file)
@@ -8,19 +8,69 @@
 
 package org.opendaylight.controller.config.yang.config.domain_extension.l2_l3.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.groupbasedpolicy.api.DomainSpecificRegistry;
 import org.opendaylight.groupbasedpolicy.domain_extension.l2_l3.L2L3NetworkDomainAugmentor;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-public class L2L3DomainExtensionInstance implements AutoCloseable {
+public class L2L3DomainExtensionInstance implements ClusterSingletonService, AutoCloseable {
 
+    private static final Logger LOG = LoggerFactory.getLogger(L2L3DomainExtensionInstance.class);
+
+    private static final ServiceGroupIdentifier IDENTIFIER =
+            ServiceGroupIdentifier.create(GroupbasedpolicyInstance.GBP_SERVICE_GROUP_IDENTIFIER);
+    private final DomainSpecificRegistry domainSpecificRegistry;
+    private ClusterSingletonServiceProvider clusterSingletonService;
+    private ClusterSingletonServiceRegistration singletonServiceRegistration;
     private L2L3NetworkDomainAugmentor l2l3NetworkDomainAugmentor;
 
-    public L2L3DomainExtensionInstance (DomainSpecificRegistry domainSpecificRegistry) {
-         l2l3NetworkDomainAugmentor = new L2L3NetworkDomainAugmentor(domainSpecificRegistry.getNetworkDomainAugmentorRegistry());
+    public L2L3DomainExtensionInstance(final DomainSpecificRegistry domainSpecificRegistry,
+                                       final ClusterSingletonServiceProvider clusterSingletonService) {
+        this.domainSpecificRegistry = Preconditions.checkNotNull(domainSpecificRegistry);
+        this.clusterSingletonService = Preconditions.checkNotNull(clusterSingletonService);
+    }
+
+    public void initialize() {
+        LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
+        singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
+    }
+
+    @Override
+    public void instantiateServiceInstance() {
+        LOG.info("Instantiating {}", this.getClass().getSimpleName());
+        l2l3NetworkDomainAugmentor = new L2L3NetworkDomainAugmentor(domainSpecificRegistry.getNetworkDomainAugmentorRegistry());
     }
 
     @Override
-    public void close() throws Exception {
+    public ListenableFuture<Void> closeServiceInstance() {
+        LOG.info("Instance {} closed", this.getClass().getSimpleName());
         l2l3NetworkDomainAugmentor.close();
+        return Futures.immediateFuture(null);
+    }
+
+    @Override
+    public void close() {
+        LOG.info("Clustering provider closed for {}", this.getClass().getSimpleName());
+        if (singletonServiceRegistration != null) {
+            try {
+                singletonServiceRegistration.close();
+            } catch (Exception e) {
+                LOG.warn("{} closed unexpectedly", this.getClass().getSimpleName(), e.getMessage());
+            }
+            singletonServiceRegistration = null;
+        }
+    }
+
+    @Override
+    public ServiceGroupIdentifier getIdentifier() {
+        return IDENTIFIER;
     }
 }
index 8dd8a5e0a708239b85aa083ed5712086e332817c..484f9d825e587c5b96a747e49218ff2dc33c3d22 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.controller.config.yang.config.domain_extension.l2_l3.im
 import org.opendaylight.controller.sal.common.util.NoopAutoCloseable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
+@Deprecated
 public class L2L3DomainExtensionModule extends org.opendaylight.controller.config.yang.config.domain_extension.l2_l3.impl.AbstractL2L3DomainExtensionModule {
 
     private static final Logger LOG = LoggerFactory.getLogger(L2L3DomainExtensionModule.class);
index 61bfa0285e42c4b2653ae74d5eecfc2b4b538d4e..644a3bf865e302ef8b9948de1485873225c0a6e6 100644 (file)
@@ -7,6 +7,7 @@
  */
 
 package org.opendaylight.controller.config.yang.config.domain_extension.l2_l3.impl;
+@Deprecated
 public class L2L3DomainExtensionModuleFactory extends org.opendaylight.controller.config.yang.config.domain_extension.l2_l3.impl.AbstractL2L3DomainExtensionModuleFactory {
 
 }
index 9b8fe278637801142a2456e0af5ffc606dc84014..a7f9099efafcb4052d137fe81e8a5ca41eef6e1a 100644 (file)
@@ -43,7 +43,7 @@ public class L2L3NetworkDomainAugmentor implements NetworkDomainAugmentor, AutoC
     }
 
     @Override
-    public void close() throws Exception {
+    public void close() {
         networkDomainAugmentorRegistry.unregister(this);
     }
 
index 8ef2b50d0345c810c39dde012d981913a744ce58..99d3c4dde59aadb3c63beac31658afa23b85f2e5 100644 (file)
@@ -4,9 +4,11 @@
            odl:use-default-for-reference-types="true">
 
     <reference id="domainSpecificRegistry" interface="org.opendaylight.groupbasedpolicy.api.DomainSpecificRegistry"/>
+    <reference id="clusterSingletonService" interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider"/>
 
     <bean id="l2l3DomainExtensions" class="org.opendaylight.controller.config.yang.config.domain_extension.l2_l3.impl.L2L3DomainExtensionInstance"
-        destroy-method="close">
+        init-method="initialize" destroy-method="close">
         <argument ref="domainSpecificRegistry"/>
+        <argument ref="clusterSingletonService"/>
     </bean>
 </blueprint>
\ No newline at end of file