Clustering - adding to LispSouthboundPlugin. 87/40587/24
authorJozef Gloncak <jgloncak@cisco.com>
Tue, 21 Jun 2016 08:09:17 +0000 (10:09 +0200)
committerLorand Jakab <lojakab@cisco.com>
Thu, 21 Jul 2016 18:19:13 +0000 (13:19 -0500)
Added code for cluster aware behaviour to LfmMappingServiceSb.

Change-Id: I06e89cf08fe531e1e53eab08b9f8d5204ba2603f
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
mappingservice/southbound/pom.xml
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPlugin.java
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/lisp/LispSouthboundHandler.java
mappingservice/southbound/src/main/resources/org/opendaylight/blueprint/mappingservice-southbound.xml
mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPluginTest.java

index 575e4f34e96a7e785447502543d76c3fdbe1b5e5..acdfe0f23ef13f5496643c28ac0c99b106b8f6aa 100644 (file)
       <groupId>${project.groupId}</groupId>
       <artifactId>mappingservice.api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>mappingservice.clustering</artifactId>
+    </dependency>
     <dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>mappingservice.inmemorydb</artifactId>
index bf22172e8f2b67eafdd5de85b04eea7121d47e26..4557bb387cc097e9fa0d289b52ce342bff57ce23 100644 (file)
@@ -31,7 +31,10 @@ import java.util.concurrent.ThreadFactory;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
+import org.opendaylight.lispflowmapping.clustering.ClusterNodeModulSwitcherImpl;
+import org.opendaylight.lispflowmapping.clustering.api.ClusterNodeModuleSwitcher;
 import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
 import org.opendaylight.lispflowmapping.southbound.lisp.LispSouthboundHandler;
 import org.opendaylight.lispflowmapping.southbound.lisp.LispXtrSouthboundHandler;
@@ -44,10 +47,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCloseable {
+public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCloseable, ClusterNodeModuleSwitcher {
     protected static final Logger LOG = LoggerFactory.getLogger(LispSouthboundPlugin.class);
 
     private static Object startLock = new Object();
+    private final ClusterNodeModulSwitcherImpl clusterNodeModulSwitcher;
     private LispSouthboundHandler lispSouthboundHandler;
     private LispXtrSouthboundHandler lispXtrSouthboundHandler;
     private NotificationPublishService notificationPublishService;
@@ -67,11 +71,13 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
 
     public LispSouthboundPlugin(final DataBroker dataBroker,
             final NotificationPublishService notificationPublishService,
-            final LispSbConfig lispSbConfig) {
+            final LispSbConfig lispSbConfig, final EntityOwnershipService entityOwnershipService) {
         this.dataBroker = dataBroker;
         this.notificationPublishService = notificationPublishService;
         this.bindingAddress = lispSbConfig.getBindAddress();
         this.mapRegisterCacheEnabled = lispSbConfig.isMapRegisterCache();
+        clusterNodeModulSwitcher = new ClusterNodeModulSwitcherImpl(entityOwnershipService);
+        clusterNodeModulSwitcher.setModule(this);
     }
 
     public void init() {
@@ -100,6 +106,7 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
 
             LOG.info("LISP (RFC6830) Southbound Plugin is up!");
         }
+        clusterNodeModulSwitcher.switchModuleByEntityOwnership();
     }
 
     private void start() {
@@ -269,4 +276,27 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
         lispSouthboundHandler.close();
         unloadActions();
     }
+
+    @Override
+    public void stopModule() {
+        if (lispSouthboundHandler != null) {
+            lispSouthboundHandler.setNotificationProvider(null);
+            lispSouthboundHandler.setIsReadFromChannelEnabled(false);
+        }
+        if (lispXtrSouthboundHandler != null) {
+            lispXtrSouthboundHandler.setNotificationProvider(null);
+        }
+    }
+
+    @Override
+    public void startModule() {
+        if (lispSouthboundHandler != null) {
+            lispSouthboundHandler.setNotificationProvider(notificationPublishService);
+            lispSouthboundHandler.restoreDaoFromDatastore();
+            lispSouthboundHandler.setIsReadFromChannelEnabled(true);
+        }
+        if (lispXtrSouthboundHandler != null) {
+            lispXtrSouthboundHandler.setNotificationProvider(notificationPublishService);
+        }
+    }
 }
index 1ac782723c57f2f48f6256600bafca2abdba693e..2b4cef6af38fd0d26f9b5047fd585575544ca3c7 100644 (file)
@@ -100,6 +100,7 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
     private SimpleMapCache smc;
     private AuthenticationKeyDataListener authenticationKeyDataListener;
     private DataStoreBackEnd dsbe;
+    private boolean isReadFromChannelEnabled = true;
 
     public LispSouthboundHandler(LispSouthboundPlugin lispSbPlugin) {
         this.lispSbPlugin = lispSbPlugin;
@@ -504,11 +505,13 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
 
     @Override
     protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("Received UDP packet from {}:{} with content:\n{}", msg.sender().getHostString(),
-                    msg.sender().getPort(), ByteBufUtil.prettyHexDump(msg.content()));
+        if (isReadFromChannelEnabled) {
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Received UDP packet from {}:{} with content:\n{}", msg.sender().getHostString(),
+                        msg.sender().getPort(), ByteBufUtil.prettyHexDump(msg.content()));
+            }
+            handlePacket(msg);
         }
-        handlePacket(msg);
     }
 
     @Override
@@ -569,4 +572,8 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
         this.authenticationKeyDataListener = new AuthenticationKeyDataListener(dataBroker, smc);
         dsbe = new DataStoreBackEnd(dataBroker);
     }
+
+    public void setIsReadFromChannelEnabled(boolean isReadFromChannelEnabled) {
+        this.isReadFromChannelEnabled = isReadFromChannelEnabled;
+    }
 }
index 6b324e38ba166efd3cf035244e4ad9ff06357fb5..68aeb794ad0d3e0c8345b2e0ef22328409feb587 100644 (file)
@@ -8,6 +8,8 @@
     odl:type="pingpong" />
   <reference id="notificationPublishService"
     interface="org.opendaylight.controller.md.sal.binding.api.NotificationPublishService" />
+  <reference id="entityOwnershipService"
+     interface="org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService" />
 
   <odl:clustered-app-config id="lispSbConfig"
     binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.lisp.sb.config.rev150517.LispSbConfig">
@@ -19,6 +21,7 @@
     <argument ref="dataBroker" />
     <argument ref="notificationPublishService" />
     <argument ref="lispSbConfig" />
+    <argument ref="entityOwnershipService" />
   </bean>
   <service ref="lispSouthboundPlugin"
     interface="org.opendaylight.lispflowmapping.type.sbplugin.IConfigLispSouthboundPlugin"
@@ -30,4 +33,4 @@
   </bean>
   <odl:rpc-implementation ref="sbRpcHandler" />
 
-</blueprint>
\ No newline at end of file
+</blueprint>
index 6ce1b07b1a8de3455d1c9ab7dcefd66af61118e6..75a7cbd75ffdf313350df0d1660229892b8dfaa4 100644 (file)
@@ -28,6 +28,7 @@ import org.mockito.ArgumentCaptor;
 import org.mockito.Mockito;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
 import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
 import org.opendaylight.lispflowmapping.southbound.lisp.LispSouthboundHandler;
@@ -79,7 +80,8 @@ public class LispSouthboundPluginTest {
         lispSouthboundPlugin = new LispSouthboundPlugin(
                 Mockito.mock(DataBroker.class),
                 Mockito.mock(NotificationPublishService.class),
-                config);
+                config,
+                Mockito.mock(EntityOwnershipService.class));
         channel = PowerMockito.mock(NioDatagramChannel.class);
         xtrChannel = PowerMockito.mock(NioDatagramChannel.class);
         injectChannel();