Convert L2GatewayCacheUtils to non-static singleton service 37/66337/4
authorTom Pantelis <tompantelis@gmail.com>
Sat, 9 Dec 2017 17:35:13 +0000 (12:35 -0500)
committerSam Hague <shague@redhat.com>
Wed, 10 Jan 2018 23:42:15 +0000 (23:42 +0000)
Crrated an interface, L2GatewayCache, with an associated
L2GatewayCacheImpl that is advertised as an OSGI service.
The L2GatewayCacheUtils had a couple update* methods that
only had one call site so I just inlined the code in the
caller to keep L2GatewayCache as a simple cache.

To avoid perpetuating circular bundle dependencies and having to
use optional availability on reference import, I put the
L2GatewayCacheImpl in a new bundle, cache-impl.

Change-Id: I4c1dcc761afcdaa214e4bdcf53f9ddb85363539f
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
23 files changed:
vpnservice/cache/impl/pom.xml [new file with mode: 0644]
vpnservice/cache/impl/src/main/java/org/opendaylight/netvirt/cache/impl/l2gw/L2GatewayCacheImpl.java [new file with mode: 0644]
vpnservice/cache/impl/src/main/resources/org/opendaylight/blueprint/cache-impl.xml [new file with mode: 0644]
vpnservice/cache/pom.xml [new file with mode: 0644]
vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpExternalTunnelManager.java
vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpL2GwUtil.java
vpnservice/dhcpservice/dhcpservice-impl/src/main/resources/org/opendaylight/blueprint/dhcpservice.xml
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/L2GwUtilsCacheCli.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/L2GwValidateCli.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/HwvtepHAUtil.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepPhysicalSwitchListener.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepTerminationPointListener.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java
vpnservice/elanmanager/elanmanager-impl/src/main/resources/org/opendaylight/blueprint/commands.xml
vpnservice/elanmanager/elanmanager-impl/src/main/resources/org/opendaylight/blueprint/elanmanager.xml
vpnservice/features/odl-netvirt-impl/pom.xml
vpnservice/neutronvpn/neutronvpn-api/src/main/java/org/opendaylight/netvirt/neutronvpn/api/l2gw/L2GatewayCache.java [new file with mode: 0644]
vpnservice/neutronvpn/neutronvpn-api/src/main/java/org/opendaylight/netvirt/neutronvpn/api/l2gw/utils/L2GatewayCacheUtils.java [deleted file]
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/l2gw/AddL2GwDevicesToTransportZoneJob.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/l2gw/L2GatewayListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/l2gw/L2GwTransportZoneListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/resources/org/opendaylight/blueprint/neutronvpn.xml
vpnservice/pom.xml

diff --git a/vpnservice/cache/impl/pom.xml b/vpnservice/cache/impl/pom.xml
new file mode 100644 (file)
index 0000000..a8c911b
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2017 Inocybe Technologies and others.  All rights reserved.
+
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.opendaylight.netvirt</groupId>
+    <artifactId>binding-parent</artifactId>
+    <version>0.6.0-SNAPSHOT</version>
+    <relativePath>../../commons/binding-parent</relativePath>
+  </parent>
+
+  <artifactId>cache-impl</artifactId>
+  <name>ODL :: netvirt :: ${project.artifactId}</name>
+  <packaging>bundle</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>neutronvpn-api</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.cdi</groupId>
+      <artifactId>pax-cdi-api</artifactId>
+      <optional>true</optional>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.aries.blueprint</groupId>
+        <artifactId>blueprint-maven-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/vpnservice/cache/impl/src/main/java/org/opendaylight/netvirt/cache/impl/l2gw/L2GatewayCacheImpl.java b/vpnservice/cache/impl/src/main/java/org/opendaylight/netvirt/cache/impl/l2gw/L2GatewayCacheImpl.java
new file mode 100644 (file)
index 0000000..537ff1d
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2017 Inocybe Technologies and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netvirt.cache.impl.l2gw;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import javax.inject.Singleton;
+import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
+import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
+import org.ops4j.pax.cdi.api.OsgiServiceProvider;
+
+/**
+ * Implementation of L2GatewayCache.
+ *
+ * @author Thomas Pantelis
+ */
+@Singleton
+@OsgiServiceProvider(classes = L2GatewayCache.class)
+public class L2GatewayCacheImpl implements L2GatewayCache {
+    private final ConcurrentMap<String, L2GatewayDevice> cache = new ConcurrentHashMap<>();
+
+    @Override
+    public L2GatewayDevice addOrGet(String deviceName) {
+        return cache.computeIfAbsent(deviceName, key -> new L2GatewayDevice(deviceName));
+    }
+
+    @Override
+    public L2GatewayDevice remove(String deviceName) {
+        return deviceName != null ? cache.remove(deviceName) : null;
+    }
+
+    @Override
+    public L2GatewayDevice get(String deviceName) {
+        return deviceName != null ? cache.get(deviceName) : null;
+    }
+
+    @Override
+    public Collection<L2GatewayDevice> getAll() {
+        return Collections.unmodifiableCollection(cache.values());
+    }
+}
diff --git a/vpnservice/cache/impl/src/main/resources/org/opendaylight/blueprint/cache-impl.xml b/vpnservice/cache/impl/src/main/resources/org/opendaylight/blueprint/cache-impl.xml
new file mode 100644 (file)
index 0000000..d179001
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+  <!-- The bundle uses blueprint annotations but we still need an empty file here so the plugin
+       puts the generated xml file under org/opendaylight/blueprint.
+   -->
+</blueprint>
diff --git a/vpnservice/cache/pom.xml b/vpnservice/cache/pom.xml
new file mode 100644 (file)
index 0000000..d53905e
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2017 Inocybe Technologies and others.  All rights reserved.
+
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.opendaylight.odlparent</groupId>
+    <artifactId>odlparent-lite</artifactId>
+    <version>2.0.5</version>
+    <relativePath/>
+  </parent>
+
+  <groupId>org.opendaylight.netvirt</groupId>
+  <artifactId>cache</artifactId>
+  <version>0.6.0-SNAPSHOT</version>
+  <name>ODL :: netvirt :: ${project.artifactId}</name>
+  <packaging>pom</packaging>
+
+  <modules>
+    <module>impl</module>
+  </modules>
+
+  <!-- DO NOT install or deploy the repo root pom as it's only needed to initiate a build -->
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-deploy-plugin</artifactId>
+        <configuration>
+          <skip>true</skip>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-install-plugin</artifactId>
+        <configuration>
+          <skip>true</skip>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
index 18f3140f8f047a7add4a1e51b5e0875b3b904f2e..3efe583d5651cbf5d946e7c480ca261ef8efcafe 100644 (file)
@@ -47,8 +47,8 @@ import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
 import org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants;
 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
+import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
-import org.opendaylight.netvirt.neutronvpn.api.l2gw.utils.L2GatewayCacheUtils;
 import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
@@ -96,6 +96,7 @@ public class DhcpExternalTunnelManager {
     private final EntityOwnershipUtils entityOwnershipUtils;
     private final IInterfaceManager interfaceManager;
     private final JobCoordinator jobCoordinator;
+    private final L2GatewayCache l2GatewayCache;
 
     private final ConcurrentMap<BigInteger, Set<Pair<IpAddress, String>>> designatedDpnsToTunnelIpElanNameCache =
             new ConcurrentHashMap<>();
@@ -108,13 +109,14 @@ public class DhcpExternalTunnelManager {
     public DhcpExternalTunnelManager(final DataBroker broker,
             final IMdsalApiManager mdsalUtil, final ItmRpcService itmRpcService,
             final EntityOwnershipService entityOwnershipService, final IInterfaceManager interfaceManager,
-            final JobCoordinator jobCoordinator) {
+            final JobCoordinator jobCoordinator, final L2GatewayCache l2GatewayCache) {
         this.broker = broker;
         this.mdsalUtil = mdsalUtil;
         this.itmRpcService = itmRpcService;
         this.entityOwnershipUtils = new EntityOwnershipUtils(entityOwnershipService);
         this.interfaceManager = interfaceManager;
         this.jobCoordinator = jobCoordinator;
+        this.l2GatewayCache = l2GatewayCache;
     }
 
     @PostConstruct
@@ -719,9 +721,9 @@ public class DhcpExternalTunnelManager {
     }
 
     private L2GatewayDevice getDeviceFromTunnelIp(String elanInstanceName, IpAddress tunnelIp) {
-        ConcurrentMap<String, L2GatewayDevice> devices = L2GatewayCacheUtils.getCache();
+        Collection<L2GatewayDevice> devices = l2GatewayCache.getAll();
         LOG.trace("In getDeviceFromTunnelIp devices {}", devices);
-        for (L2GatewayDevice device : devices.values()) {
+        for (L2GatewayDevice device : devices) {
             if (tunnelIp.equals(device.getTunnelIp())) {
                 return device;
             }
index 962ba396af965c755e478d800d1649eb5a5d23b6..eaa52efbbcce51562c1e412bd0464c80fc2ecb69 100644 (file)
@@ -9,15 +9,14 @@ package org.opendaylight.netvirt.dhcpservice;
 
 import com.google.common.base.Optional;
 import java.util.List;
-import java.util.concurrent.ConcurrentMap;
 import java.util.function.Predicate;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
+import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
-import org.opendaylight.netvirt.neutronvpn.api.l2gw.utils.L2GatewayCacheUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
@@ -40,17 +39,18 @@ public class DhcpL2GwUtil {
     };
 
     private final DataBroker dataBroker;
+    private final L2GatewayCache l2GatewayCache;
 
     @Inject
-    public DhcpL2GwUtil(DataBroker dataBroker) {
+    public DhcpL2GwUtil(DataBroker dataBroker, L2GatewayCache l2GatewayCache) {
         this.dataBroker = dataBroker;
+        this.l2GatewayCache = l2GatewayCache;
     }
 
     public IpAddress getHwvtepNodeTunnelIp(InstanceIdentifier<Node> nodeIid) {
-        ConcurrentMap<String, L2GatewayDevice> devices = L2GatewayCacheUtils.getCache();
         String nodeId = nodeIid.firstKeyOf(Node.class).getNodeId().getValue();
         L2GatewayDevice targetDevice = null;
-        for (L2GatewayDevice device : devices.values()) {
+        for (L2GatewayDevice device : l2GatewayCache.getAll()) {
             if (nodeId.equals(device.getHwvtepNodeId())) {
                 targetDevice = device;
                 break;
index 2d72e7543de8480576e93026aa99d24f50b671d6..afc402bcd9054d6a54f1e74681c7489c710154d6 100644 (file)
@@ -18,6 +18,8 @@
              interface="org.opendaylight.netvirt.elanmanager.api.IElanService" />
   <reference id="jobCoordinator"
              interface="org.opendaylight.infrautils.jobcoordinator.JobCoordinator" />
+  <reference id="l2GatewayCache"
+             interface="org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache"/>
 
   <odl:rpc-service id="odlInterfaceRpcService"
     interface="org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService" />
index 6d118b9b1b1c81b687e440268616f19c059bf0eb..5fadb56c53acc1c32b28fdb189c23af816604c08 100644 (file)
@@ -13,6 +13,7 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.util.Collection;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentMap;
@@ -22,13 +23,14 @@ import org.apache.karaf.shell.console.OsgiCommandSupport;
 import org.opendaylight.genius.utils.cache.CacheUtil;
 import org.opendaylight.genius.utils.hwvtep.HwvtepHACache;
 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
+import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
-import org.opendaylight.netvirt.neutronvpn.api.l2gw.utils.L2GatewayCacheUtils;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 @Command(scope = "l2gw", name = "show-cache", description = "display l2gateways cache")
 public class L2GwUtilsCacheCli extends OsgiCommandSupport {
+    private static final String L2GATEWAY_CACHE_NAME = "L2GW";
     private static final String DEMARCATION = "=================================";
 
     @Option(name = "-cache", aliases = {"--cache"}, description = "cache name",
@@ -39,12 +41,18 @@ public class L2GwUtilsCacheCli extends OsgiCommandSupport {
             required = false, multiValued = false)
     String elanName;
 
+    private final L2GatewayCache l2GatewayCache;
+
+    public L2GwUtilsCacheCli(L2GatewayCache l2GatewayCache) {
+        this.l2GatewayCache = l2GatewayCache;
+    }
+
     @Override
     protected Object doExecute() throws IOException {
         if (cacheName == null) {
             session.getConsole().println("Available caches");
             session.getConsole().println(ElanL2GwCacheUtils.L2GATEWAY_CONN_CACHE_NAME);
-            session.getConsole().println(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
+            session.getConsole().println(L2GATEWAY_CACHE_NAME);
             session.getConsole().println("HA");
             session.getConsole().println("HA_EVENTS");
             return null;
@@ -53,7 +61,7 @@ public class L2GwUtilsCacheCli extends OsgiCommandSupport {
             case ElanL2GwCacheUtils.L2GATEWAY_CONN_CACHE_NAME:
                 dumpElanL2GwCache();
                 break;
-            case L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME:
+            case L2GATEWAY_CACHE_NAME:
                 dumpL2GwCache();
                 break;
             case "HA":
@@ -107,13 +115,12 @@ public class L2GwUtilsCacheCli extends OsgiCommandSupport {
     }
 
     private void dumpL2GwCache() {
-        ConcurrentMap<String, L2GatewayDevice> devices = (ConcurrentMap<String, L2GatewayDevice>) CacheUtil
-                .getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
-        if (devices == null) {
+        Collection<L2GatewayDevice> devices = l2GatewayCache.getAll();
+        if (devices.isEmpty()) {
             session.getConsole().println("no devices are present in cache");
             return;
         }
-        for (L2GatewayDevice device : devices.values()) {
+        for (L2GatewayDevice device : devices) {
             session.getConsole().println("device " + device);
         }
     }
index d097f36c26875de183ddf92cd1790567e8113f3a..298987a4bdd0e3b0c610c0707e5ef5faf4cdcdc7 100644 (file)
@@ -40,8 +40,8 @@ import org.opendaylight.netvirt.elan.l2gw.ha.commands.TerminationPointCmd;
 import org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayConnectionUtils;
 import org.opendaylight.netvirt.elan.utils.ElanConstants;
 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
+import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
-import org.opendaylight.netvirt.neutronvpn.api.l2gw.utils.L2GatewayCacheUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
@@ -91,14 +91,17 @@ public class L2GwValidateCli extends OsgiCommandSupport {
     private final Map<InstanceIdentifier<Node>, Map<InstanceIdentifier, DataObject>> configNodesData =
             new HashMap<>();
 
+    private final DataBroker dataBroker;
+    private final L2GatewayCache l2GatewayCache;
+
     private List<L2gateway> l2gateways;
     private List<L2gatewayConnection> l2gatewayConnections;
-    private DataBroker dataBroker;
 
     private PrintWriter pw;
 
-    public void setDataBroker(DataBroker dataBroker) {
+    public L2GwValidateCli(DataBroker dataBroker, L2GatewayCache l2GatewayCache) {
         this.dataBroker = dataBroker;
+        this.l2GatewayCache = l2GatewayCache;
     }
 
     @Override
@@ -383,7 +386,7 @@ public class L2GwValidateCli extends OsgiCommandSupport {
 
             for (Devices device : devices) {
 
-                L2GatewayDevice l2GatewayDevice = L2GatewayCacheUtils.getL2DeviceFromCache(device.getDeviceName());
+                L2GatewayDevice l2GatewayDevice = l2GatewayCache.get(device.getDeviceName());
                 isValid = verifyL2GatewayDevice(l2gateway, device, l2GatewayDevice);
                 if (!isValid) {
                     continue;
index aaec3a598c1c5826d12e5cc432690650334fa15d..05ced1f403aaec8b5b6cb1868394b75becd17c4e 100644 (file)
@@ -18,9 +18,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map.Entry;
 import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutionException;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
@@ -28,8 +26,6 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.genius.utils.hwvtep.HwvtepHACache;
 import org.opendaylight.netvirt.elan.l2gw.ha.commands.SwitchesCmd;
-import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
-import org.opendaylight.netvirt.neutronvpn.api.l2gw.utils.L2GatewayCacheUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
@@ -567,23 +563,6 @@ public final class HwvtepHAUtil {
         }
     }
 
-    public static void updateL2GwCacheNodeId(Node updatedChildNode, InstanceIdentifier<Node> iid) {
-        String haNodeIdVal = getNodeIdVal(iid);
-        ConcurrentMap<String, L2GatewayDevice> l2Devices = L2GatewayCacheUtils.getCache();
-        if (l2Devices != null) {
-            for (Entry<String, L2GatewayDevice> entry : l2Devices.entrySet()) {
-                String psName = entry.getKey();
-                L2GatewayDevice l2Device = entry.getValue();
-                if (updatedChildNode.getNodeId().getValue().equals(l2Device.getHwvtepNodeId())) {
-                    LOG.info("Replaced the l2gw device cache entry for device {} with val {}",
-                            l2Device.getDeviceName(), l2Device.getHwvtepNodeId());
-                    l2Device.setHwvtepNodeId(haNodeIdVal);
-                    L2GatewayCacheUtils.addL2DeviceToCache(psName, l2Device);
-                }
-            }
-        }
-    }
-
     /**
      * Delete switches from Node in Operational Data Tree .
      *
index 851d306a40b3314533961d05db7f4f704e415c44..f1e71f110acfc5c1da73442c1b6739a1e498aa95 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netvirt.elan.l2gw.listeners;
 
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
@@ -35,11 +36,12 @@ import org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayUtils;
 import org.opendaylight.netvirt.elan.l2gw.utils.L2gwServiceProvider;
 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
+import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
-import org.opendaylight.netvirt.neutronvpn.api.l2gw.utils.L2GatewayCacheUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelIps;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
@@ -122,6 +124,7 @@ public class HwvtepPhysicalSwitchListener
 
 
     private final HAOpClusteredListener haOpClusteredListener;
+    private final L2GatewayCache l2GatewayCache;
 
     /**
      * Instantiates a new hwvtep physical switch listener.
@@ -129,13 +132,14 @@ public class HwvtepPhysicalSwitchListener
     @Inject
     public HwvtepPhysicalSwitchListener(final DataBroker dataBroker, ItmRpcService itmRpcService,
             ElanClusterUtils elanClusterUtils, L2gwServiceProvider l2gwServiceProvider,
-            HAOpClusteredListener haListener) {
+            HAOpClusteredListener haListener, L2GatewayCache l2GatewayCache) {
         super(PhysicalSwitchAugmentation.class, HwvtepPhysicalSwitchListener.class);
         this.dataBroker = dataBroker;
         this.itmRpcService = itmRpcService;
         this.elanClusterUtils = elanClusterUtils;
         this.l2gwServiceProvider = l2gwServiceProvider;
         this.haOpClusteredListener = haListener;
+        this.l2GatewayCache = l2GatewayCache;
     }
 
     @Override
@@ -163,10 +167,10 @@ public class HwvtepPhysicalSwitchListener
         String psName = phySwitchDeleted.getHwvtepNodeName().getValue();
         LOG.info("Received physical switch {} removed event for node {}", psName, nodeId.getValue());
 
-        L2GatewayDevice l2GwDevice = L2GatewayCacheUtils.getL2DeviceFromCache(psName);
+        L2GatewayDevice l2GwDevice = l2GatewayCache.get(psName);
         if (l2GwDevice != null) {
             if (!L2GatewayConnectionUtils.isGatewayAssociatedToL2Device(l2GwDevice)) {
-                L2GatewayCacheUtils.removeL2DeviceFromCache(psName);
+                l2GatewayCache.remove(psName);
                 LOG.debug("{} details removed from L2Gateway Cache", psName);
                 MDSALUtil.syncDelete(this.dataBroker, LogicalDatastoreType.CONFIGURATION,
                         HwvtepSouthboundUtils.createInstanceIdentifier(nodeId));
@@ -203,7 +207,7 @@ public class HwvtepPhysicalSwitchListener
             LOG.error("Could not find the physical switch name for node {}", nodeId.getValue());
             return;
         }
-        L2GatewayDevice existingDevice = L2GatewayCacheUtils.getL2DeviceFromCache(psName);
+        L2GatewayDevice existingDevice = l2GatewayCache.get(psName);
         LOG.info("Received physical switch {} update event for node {}", psName, nodeId.getValue());
         InstanceIdentifier<Node> globalNodeIid = getManagedByNodeIid(identifier);
 
@@ -265,7 +269,7 @@ public class HwvtepPhysicalSwitchListener
                 return;
             }
             LOG.trace("Updating cache for node {}", globalNodeIid);
-            L2GatewayDevice l2GwDevice = L2GatewayCacheUtils.getL2DeviceFromCache(psName);
+            L2GatewayDevice l2GwDevice = l2GatewayCache.get(psName);
             if (childConnectedAfterParent.test(l2GwDevice, globalNodeIid)) {
                 LOG.trace("Device {} {} is already Connected by ",
                         psName, globalNodeId, l2GwDevice.getHwvtepNodeId());
@@ -282,8 +286,19 @@ public class HwvtepPhysicalSwitchListener
                           existingIid, psName, globalNodeIid);
                 ElanL2GwCacheUtils.removeL2GatewayDeviceFromAllElanCache(l2GwDevice.getHwvtepNodeId());
             }
-            l2GwDevice = L2GatewayCacheUtils.updateL2GatewayCache(
-                    psName, globalNodeId, phySwitchAdded.getTunnelIps());
+
+            l2GwDevice = l2GatewayCache.addOrGet(psName);
+            l2GwDevice.setConnected(true);
+            l2GwDevice.setHwvtepNodeId(globalNodeId);
+
+            List<TunnelIps> tunnelIps = phySwitchAdded.getTunnelIps();
+            if (tunnelIps != null) {
+                for (TunnelIps tunnelIp : tunnelIps) {
+                    IpAddress tunnelIpAddr = tunnelIp.getTunnelIpsKey();
+                    l2GwDevice.addTunnelIp(tunnelIpAddr);
+                }
+            }
+
             handleAdd(l2GwDevice);
             return;
         });
index 68e03731bde59a40c4ef974062e90345329b6e8c..12f8d1762671314d96840147d750771ce323ccac 100644 (file)
@@ -31,8 +31,8 @@ import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
 import org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayConnectionUtils;
 import org.opendaylight.netvirt.elan.l2gw.utils.SettableFutureCallback;
 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
+import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
-import org.opendaylight.netvirt.neutronvpn.api.l2gw.utils.L2GatewayCacheUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection;
@@ -63,15 +63,17 @@ public class HwvtepTerminationPointListener
     private final DataBroker broker;
     private final ElanL2GatewayUtils elanL2GatewayUtils;
     private final ElanClusterUtils elanClusterUtils;
+    private final L2GatewayCache l2GatewayCache;
 
     @Inject
     public HwvtepTerminationPointListener(DataBroker broker, ElanL2GatewayUtils elanL2GatewayUtils,
-            ElanClusterUtils elanClusterUtils) {
+            ElanClusterUtils elanClusterUtils, L2GatewayCache l2GatewayCache) {
         super(TerminationPoint.class, HwvtepTerminationPointListener.class);
 
         this.broker = broker;
         this.elanL2GatewayUtils = elanL2GatewayUtils;
         this.elanClusterUtils = elanClusterUtils;
+        this.l2GatewayCache = l2GatewayCache;
         //No longer needed as port reconciliation is added in plugin
         //registerListener(LogicalDatastoreType.OPERATIONAL, broker);
         LOG.debug("created HwvtepTerminationPointListener");
@@ -128,7 +130,7 @@ public class HwvtepTerminationPointListener
         Node psNode = HwvtepUtils.getHwVtepNode(broker, LogicalDatastoreType.OPERATIONAL, psNodeId);
         if (psNode != null) {
             String psName = psNode.getAugmentation(PhysicalSwitchAugmentation.class).getHwvtepNodeName().getValue();
-            L2GatewayDevice l2GwDevice = L2GatewayCacheUtils.getL2DeviceFromCache(psName);
+            L2GatewayDevice l2GwDevice = l2GatewayCache.get(psName);
             if (l2GwDevice != null) {
                 if (isL2GatewayConfigured(l2GwDevice)) {
                     List<L2gatewayConnection> l2GwConns = L2GatewayConnectionUtils.getAssociatedL2GwConnections(broker,
index e3785d0f916bac51941ef4e8bf8d8db3aceaf090..b927e67d6ae9836a19eb3c059376c77e171a697f 100644 (file)
@@ -38,8 +38,8 @@ import org.opendaylight.netvirt.elan.l2gw.listeners.HwvtepLocalUcastMacListener;
 import org.opendaylight.netvirt.elan.l2gw.listeners.HwvtepLogicalSwitchListener;
 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
+import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
-import org.opendaylight.netvirt.neutronvpn.api.l2gw.utils.L2GatewayCacheUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
@@ -68,18 +68,21 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
     private final ElanClusterUtils elanClusterUtils;
     private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
     private final JobCoordinator jobCoordinator;
+    private final L2GatewayCache l2GatewayCache;
     private final List<AutoCloseable> closeables = new CopyOnWriteArrayList<>();
 
     @Inject
     public L2GatewayConnectionUtils(DataBroker dataBroker, ElanInstanceManager elanInstanceManager,
             ElanClusterUtils elanClusterUtils, ElanL2GatewayUtils elanL2GatewayUtils,
-            JobCoordinator jobCoordinator, ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils) {
+            JobCoordinator jobCoordinator, ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
+            L2GatewayCache l2GatewayCache) {
         this.broker = dataBroker;
         this.elanInstanceManager = elanInstanceManager;
         this.elanL2GatewayUtils = elanL2GatewayUtils;
         this.elanClusterUtils = elanClusterUtils;
         this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
         this.jobCoordinator = jobCoordinator;
+        this.l2GatewayCache = l2GatewayCache;
     }
 
     @Override
@@ -235,7 +238,7 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
         }
         for (Devices l2Device : l2gwDevicesToBeDeleted) {
             String l2DeviceName = l2Device.getDeviceName();
-            L2GatewayDevice l2GatewayDevice = L2GatewayCacheUtils.getL2DeviceFromCache(l2DeviceName);
+            L2GatewayDevice l2GatewayDevice = l2GatewayCache.get(l2DeviceName);
             String hwvtepNodeId = l2GatewayDevice.getHwvtepNodeId();
             boolean isLastL2GwConnDeleted = false;
             L2GatewayDevice elanL2GwDevice = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elanName, hwvtepNodeId);
@@ -284,7 +287,7 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
                         l2DeviceName, l2GwDeviceName);
                 continue;
             }
-            L2GatewayDevice l2GatewayDevice = L2GatewayCacheUtils.getL2DeviceFromCache(l2DeviceName);
+            L2GatewayDevice l2GatewayDevice = l2GatewayCache.get(l2DeviceName);
             if (isL2GwDeviceConnected(l2GatewayDevice)) {
                 NodeId hwvtepNodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
 
index 3a884cff44866010eb8e411f8464be622a7dc639..b56d98fa09da1096b0495a7ae17fada5e0fdf1e0 100644 (file)
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
            xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0">
-    <reference id="elanProviderRef" interface="org.opendaylight.netvirt.elanmanager.api.IElanService"
-               availability="optional"/>
-    <reference id="interfaceManagerRef"
-               interface="org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager"
-               availability="optional"/>
-    <reference id="dataBrokerRef"
-               interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
-               odl:type="pingpong"/>
-
-
     <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.ElanAdd">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.ElanDelete">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.ElanUpdate">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.ElanInterfaceAdd">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.ElanInterfaceDelete">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.ElanInterfaceUpdate">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.StaticMacAdd">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.StaticMacDelete">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.ElanMacTableGet">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.ElanMacTableFlush">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.ElanGet">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.ElanInterfaceGet">
-                <property name="elanProvider" ref="elanProviderRef" />
-                <property name="interfaceManager" ref="interfaceManagerRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
+                <property name="interfaceManager" ref="iInterfaceManager" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.l2gw.L2GwUtilsCacheCli">
+              <argument ref="l2GatewayCache"/>
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.etree.EtreeDelete">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.etree.EtreeAdd">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.etree.EtreeGet">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.etree.EtreeInterfaceAdd">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.etree.EtreeInterfaceGet">
-                <property name="elanProvider" ref="elanProviderRef" />
-                <property name="interfaceManager" ref="interfaceManagerRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
+                <property name="interfaceManager" ref="iInterfaceManager" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.etree.EtreeInterfaceDelete">
-                <property name="elanProvider" ref="elanProviderRef" />
+                <property name="elanProvider" ref="elanServiceProvider" />
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.l2gw.NetworkL2gwDeviceInfoCli">
-                <property name="dataBroker" ref="dataBrokerRef"/>
+                <property name="dataBroker" ref="dataBroker"/>
             </action>
         </command>
         <command>
             <action class="org.opendaylight.netvirt.elan.cli.l2gw.L2GwValidateCli">
-                <property name="dataBroker" ref="dataBrokerRef"/>
+                <argument ref="dataBroker"/>
+                <argument ref="l2GatewayCache"/>
             </action>
         </command>
     </command-bundle>
-</blueprint>
\ No newline at end of file
+</blueprint>
index 43d931b654a532566063beb83cfeab74873aeecd..9bb697e5c1359fb4afbefd56e500922c0eaee023 100644 (file)
@@ -24,6 +24,8 @@
              interface="org.opendaylight.infrautils.diagstatus.DiagStatusService" />
   <reference id="jobCoordinator"
              interface="org.opendaylight.infrautils.jobcoordinator.JobCoordinator"/>
+  <reference id="l2GatewayCache"
+             interface="org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache"/>
 
   <odl:rpc-service id="odlInterfaceRpcService"
     interface="org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService" />
index 09163632f233fa177932ea08584d168041fe14a5..63a53a453fc4342ce047925a6514f1b12b2d888c 100644 (file)
             <artifactId>coe-impl</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>cache-impl</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         <dependency>
             <!-- finalname="etc/opendaylight/datastore/initial/config/netvirt-aclservice-config.xml" -->
             <groupId>${project.groupId}</groupId>
diff --git a/vpnservice/neutronvpn/neutronvpn-api/src/main/java/org/opendaylight/netvirt/neutronvpn/api/l2gw/L2GatewayCache.java b/vpnservice/neutronvpn/neutronvpn-api/src/main/java/org/opendaylight/netvirt/neutronvpn/api/l2gw/L2GatewayCache.java
new file mode 100644 (file)
index 0000000..71f35fc
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netvirt.neutronvpn.api.l2gw;
+
+import java.util.Collection;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+public interface L2GatewayCache {
+    @Nonnull
+    L2GatewayDevice addOrGet(@Nonnull String deviceName);
+
+    @Nullable
+    L2GatewayDevice remove(String deviceName);
+
+    @Nullable
+    L2GatewayDevice get(String deviceName);
+
+    @Nonnull
+    Collection<L2GatewayDevice> getAll();
+}
diff --git a/vpnservice/neutronvpn/neutronvpn-api/src/main/java/org/opendaylight/netvirt/neutronvpn/api/l2gw/utils/L2GatewayCacheUtils.java b/vpnservice/neutronvpn/neutronvpn-api/src/main/java/org/opendaylight/netvirt/neutronvpn/api/l2gw/utils/L2GatewayCacheUtils.java
deleted file mode 100644 (file)
index 8e8fd20..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netvirt.neutronvpn.api.l2gw.utils;
-
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelIps;
-
-public final class L2GatewayCacheUtils {
-    public static final String L2GATEWAY_CACHE_NAME = "L2GW";
-
-    private static final ConcurrentMap<String, L2GatewayDevice> CACHE = new ConcurrentHashMap<>();
-
-    private L2GatewayCacheUtils() { }
-
-    public static void addL2DeviceToCache(String devicename, L2GatewayDevice l2GwDevice) {
-        CACHE.put(devicename, l2GwDevice);
-    }
-
-    public static L2GatewayDevice removeL2DeviceFromCache(String devicename) {
-        return CACHE.remove(devicename);
-    }
-
-    public static L2GatewayDevice getL2DeviceFromCache(String devicename) {
-        return CACHE.get(devicename);
-    }
-
-    public static ConcurrentMap<String, L2GatewayDevice> getCache() {
-        return CACHE;
-    }
-
-    public static L2GatewayDevice updateCacheUponL2GatewayAdd(final String psName, final Uuid l2gwUuid) {
-        final L2GatewayDevice l2GwDevice = CACHE.computeIfAbsent(psName, key -> new L2GatewayDevice(psName));
-        l2GwDevice.addL2GatewayId(l2gwUuid);
-        return l2GwDevice;
-    }
-
-    public static L2GatewayDevice updateCacheUponSwitchConnect(final String psName, final String
-            hwvtepNodeId, final List<TunnelIps> tunnelIps) {
-        final L2GatewayDevice l2GwDevice = CACHE.computeIfAbsent(psName, key -> new L2GatewayDevice(psName));
-        l2GwDevice.setConnected(true);
-        l2GwDevice.setHwvtepNodeId(hwvtepNodeId);
-
-        if (tunnelIps != null) {
-            for (TunnelIps tunnelIp : tunnelIps) {
-                IpAddress tunnelIpAddr = tunnelIp.getTunnelIpsKey();
-                l2GwDevice.addTunnelIp(tunnelIpAddr);
-            }
-        }
-
-        return l2GwDevice;
-    }
-
-    public static L2GatewayDevice updateL2GatewayCache(String psName, String hwvtepNodeId, List<TunnelIps> tunnelIps) {
-        final L2GatewayDevice l2GwDevice = CACHE.computeIfAbsent(psName, key -> new L2GatewayDevice(psName));
-        l2GwDevice.setConnected(true);
-        l2GwDevice.setHwvtepNodeId(hwvtepNodeId);
-
-        if (tunnelIps != null) {
-            for (TunnelIps tunnelIp : tunnelIps) {
-                IpAddress tunnelIpAddr = tunnelIp.getTunnelIpsKey();
-                l2GwDevice.addTunnelIp(tunnelIpAddr);
-            }
-        }
-
-        return l2GwDevice;
-    }
-}
index e38bbe2cf5b9dde5e8efbc258f2e8102dc93d5b8..04a05a5bdaf88afe788a397da66fbf5031b5ab4a 100644 (file)
@@ -12,9 +12,8 @@ import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.Callable;
-import java.util.concurrent.ConcurrentMap;
+import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
-import org.opendaylight.netvirt.neutronvpn.api.l2gw.utils.L2GatewayCacheUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
 import org.slf4j.Logger;
@@ -28,6 +27,7 @@ public class AddL2GwDevicesToTransportZoneJob implements Callable<List<Listenabl
     private static final Logger LOG = LoggerFactory.getLogger(AddL2GwDevicesToTransportZoneJob.class);
     private final ItmRpcService itmRpcService;
     private final TransportZone transportZone;
+    private final L2GatewayCache l2GatewayCache;
 
     /**
      * Instantiates a new adds the l2 gw devices to transport zone job.
@@ -35,10 +35,11 @@ public class AddL2GwDevicesToTransportZoneJob implements Callable<List<Listenabl
      * @param itmRpcService the itm rpc service
      * @param transportZone the transport zone
      */
-    public AddL2GwDevicesToTransportZoneJob(ItmRpcService itmRpcService,
-                                            TransportZone transportZone) {
+    public AddL2GwDevicesToTransportZoneJob(ItmRpcService itmRpcService, TransportZone transportZone,
+            L2GatewayCache l2GatewayCache) {
         this.itmRpcService = itmRpcService;
         this.transportZone = transportZone;
+        this.l2GatewayCache = l2GatewayCache;
         LOG.debug("created AddL2GwDevicesToTransportZone Job for tZone {}", transportZone.getZoneName());
     }
 
@@ -63,8 +64,7 @@ public class AddL2GwDevicesToTransportZoneJob implements Callable<List<Listenabl
         try {
             // When vxlan transport zone is added, add all l2gw devices to that
             // transport zone. Doesn't matter if tz already has data or not.
-            ConcurrentMap<String, L2GatewayDevice> l2GwDevices = L2GatewayCacheUtils.getCache();
-            for (L2GatewayDevice l2gwDevice : l2GwDevices.values()) {
+            for (L2GatewayDevice l2gwDevice : l2GatewayCache.getAll()) {
                 if (!l2gwDevice.getL2GatewayIds().isEmpty()) {
                     LOG.debug("Adding l2gw device [{}] to transport zone [{}]", l2gwDevice.getDeviceName(),
                             this.transportZone.getZoneName());
index f12c08ea18f837163941e26bce8ad8080a149fec..dfcdbeaaa7945089950f881d44de726a063f1ca1 100644 (file)
@@ -34,8 +34,8 @@ import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
 import org.opendaylight.netvirt.elanmanager.api.IL2gwService;
+import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
-import org.opendaylight.netvirt.neutronvpn.api.l2gw.utils.L2GatewayCacheUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
@@ -58,16 +58,18 @@ public class L2GatewayListener extends AsyncClusteredDataTreeChangeListenerBase<
     private final IL2gwService l2gwService;
     private final EntityOwnershipUtils entityOwnershipUtils;
     private final JobCoordinator jobCoordinator;
+    private final L2GatewayCache l2GatewayCache;
 
     @Inject
     public L2GatewayListener(final DataBroker dataBroker, final EntityOwnershipService entityOwnershipService,
                              final ItmRpcService itmRpcService, final IL2gwService l2gwService,
-                             final JobCoordinator jobCoordinator) {
+                             final JobCoordinator jobCoordinator, final L2GatewayCache l2GatewayCache) {
         this.dataBroker = dataBroker;
         this.entityOwnershipUtils = new EntityOwnershipUtils(entityOwnershipService);
         this.itmRpcService = itmRpcService;
         this.l2gwService = l2gwService;
         this.jobCoordinator = jobCoordinator;
+        this.l2GatewayCache = l2GatewayCache;
     }
 
     @PostConstruct
@@ -141,7 +143,7 @@ public class L2GatewayListener extends AsyncClusteredDataTreeChangeListenerBase<
                     .filter((originalDevice) -> originalDevice.getInterfaces() != null)
                     .forEach((originalDevice) -> {
                         String deviceName = originalDevice.getDeviceName();
-                        L2GatewayDevice l2GwDevice = L2GatewayCacheUtils.getL2DeviceFromCache(deviceName);
+                        L2GatewayDevice l2GwDevice = l2GatewayCache.get(deviceName);
                         NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(
                                 new NodeId(l2GwDevice.getHwvtepNodeId()), deviceName);
                         originalDevice.getInterfaces()
@@ -186,7 +188,9 @@ public class L2GatewayListener extends AsyncClusteredDataTreeChangeListenerBase<
 
     private synchronized void addL2Device(Devices l2Device, L2gateway input) {
         String l2DeviceName = l2Device.getDeviceName();
-        L2GatewayDevice l2GwDevice = L2GatewayCacheUtils.updateCacheUponL2GatewayAdd(l2DeviceName, input.getUuid());
+
+        L2GatewayDevice l2GwDevice = l2GatewayCache.addOrGet(l2DeviceName);
+        l2GwDevice.addL2GatewayId(input.getUuid());
         if (l2GwDevice.getHwvtepNodeId() == null) {
             LOG.info("L2GW provisioning skipped for device {}",l2DeviceName);
         } else {
@@ -198,7 +202,7 @@ public class L2GatewayListener extends AsyncClusteredDataTreeChangeListenerBase<
 
     private void removeL2Device(Devices l2Device, L2gateway input) {
         final String l2DeviceName = l2Device.getDeviceName();
-        L2GatewayDevice l2GwDevice = L2GatewayCacheUtils.getL2DeviceFromCache(l2DeviceName);
+        L2GatewayDevice l2GwDevice = l2GatewayCache.get(l2DeviceName);
         if (l2GwDevice != null) {
             // Delete ITM tunnels if it's last Gateway deleted and device is connected
             // Also, do not delete device from cache if it's connected
@@ -224,7 +228,7 @@ public class L2GatewayListener extends AsyncClusteredDataTreeChangeListenerBase<
                         return null;
                     });
                 } else {
-                    L2GatewayCacheUtils.removeL2DeviceFromCache(l2DeviceName);
+                    l2GatewayCache.remove(l2DeviceName);
                     // Cleaning up the config DS
                     NodeId nodeId = new NodeId(l2GwDevice.getHwvtepNodeId());
                     NodeId psNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, l2DeviceName);
index ea8d02d8efa7c3218cbc6cc9d3ba906d4aaf03f6..fe2ad15c475b3493e25808a7aa3fed0066b2d4b2 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
@@ -33,6 +34,7 @@ public class L2GwTransportZoneListener
     private final DataBroker dataBroker;
     private final ItmRpcService itmRpcService;
     private final JobCoordinator jobCoordinator;
+    private final L2GatewayCache l2GatewayCache;
 
     /**
      * Instantiates a new l2 gw transport zone listener.
@@ -42,11 +44,12 @@ public class L2GwTransportZoneListener
      */
     @Inject
     public L2GwTransportZoneListener(final DataBroker dataBroker, final ItmRpcService itmRpcService,
-            final JobCoordinator jobCoordinator) {
+            final JobCoordinator jobCoordinator, final L2GatewayCache l2GatewayCache) {
         super(TransportZone.class, L2GwTransportZoneListener.class);
         this.dataBroker = dataBroker;
         this.itmRpcService = itmRpcService;
         this.jobCoordinator = jobCoordinator;
+        this.l2GatewayCache = l2GatewayCache;
     }
 
     @Override
@@ -108,7 +111,7 @@ public class L2GwTransportZoneListener
         LOG.trace("Received Transport Zone Add Event: {}", tzNew);
         if (tzNew.getTunnelType().equals(TunnelTypeVxlan.class)) {
             AddL2GwDevicesToTransportZoneJob job =
-                    new AddL2GwDevicesToTransportZoneJob(itmRpcService, tzNew);
+                    new AddL2GwDevicesToTransportZoneJob(itmRpcService, tzNew, l2GatewayCache);
             jobCoordinator.enqueueJob(job.getJobKey(), job);
         }
     }
index 7c7f30a7dc39f487ff714c210934c47b984d0db4..0cb04d1c136287dc2f89832ce8368f2a156f7ef7 100644 (file)
@@ -22,6 +22,8 @@
              interface="org.opendaylight.netvirt.vpnmanager.api.IVpnManager" />
   <reference id="jobCoordinator"
              interface="org.opendaylight.infrautils.jobcoordinator.JobCoordinator" />
+  <reference id="l2GatewayCache"
+             interface="org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache"/>
 
   <odl:rpc-service id="idManagerService"
                    interface="org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService" />
index c596083e493f859f35272274cd54255ffc5b5f72..9da3b9ad5cfc16f06db44123f773efa60d471e6b 100644 (file)
@@ -20,6 +20,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
   <packaging>pom</packaging>
   <modelVersion>4.0.0</modelVersion>
   <modules>
+    <module>cache</module>
     <module>coe</module>
     <module>commons</module>
     <module>model-bgp</module>