From: Jozef Gloncak Date: Tue, 21 Jun 2016 08:09:17 +0000 (+0200) Subject: Clustering - adding to LispSouthboundPlugin. X-Git-Tag: release/boron~37 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=c174d5b216d6824714480c8e40a9d1655022c1f7;p=lispflowmapping.git Clustering - adding to LispSouthboundPlugin. Added code for cluster aware behaviour to LfmMappingServiceSb. Change-Id: I06e89cf08fe531e1e53eab08b9f8d5204ba2603f Signed-off-by: Jozef Gloncak --- diff --git a/mappingservice/southbound/pom.xml b/mappingservice/southbound/pom.xml index 575e4f34e..acdfe0f23 100644 --- a/mappingservice/southbound/pom.xml +++ b/mappingservice/southbound/pom.xml @@ -17,6 +17,10 @@ ${project.groupId} mappingservice.api + + ${project.groupId} + mappingservice.clustering + ${project.groupId} mappingservice.inmemorydb diff --git a/mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPlugin.java b/mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPlugin.java index bf22172e8..4557bb387 100644 --- a/mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPlugin.java +++ b/mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPlugin.java @@ -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); + } + } } diff --git a/mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/lisp/LispSouthboundHandler.java b/mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/lisp/LispSouthboundHandler.java index 1ac782723..2b4cef6af 100644 --- a/mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/lisp/LispSouthboundHandler.java +++ b/mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/lisp/LispSouthboundHandler.java @@ -100,6 +100,7 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler + @@ -19,6 +21,7 @@ + - \ No newline at end of file + diff --git a/mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPluginTest.java b/mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPluginTest.java index 6ce1b07b1..75a7cbd75 100644 --- a/mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPluginTest.java +++ b/mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPluginTest.java @@ -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();