Remove expiration code from HashMapDb 04/48104/2
authorLorand Jakab <lojakab@cisco.com>
Tue, 8 Nov 2016 08:19:53 +0000 (10:19 +0200)
committerLorand Jakab <lojakab@cisco.com>
Tue, 8 Nov 2016 09:28:15 +0000 (11:28 +0200)
It wasn't used anywhere, and it didn't belong there architecturally.

Change-Id: Id94a6b7e730215b910e7fc4ca41bde537ede35c8
Signed-off-by: Lorand Jakab <lojakab@cisco.com>
mappingservice/inmemorydb/pom.xml
mappingservice/inmemorydb/src/main/java/org/opendaylight/lispflowmapping/inmemorydb/HashMapDb.java
mappingservice/inmemorydb/src/main/resources/org/opendaylight/blueprint/mappingservice-inmemory-db.xml
mappingservice/inmemorydb/src/main/yang/odl-mappingservice-dao-inmemorydb-config.yang [deleted file]
mappingservice/inmemorydb/src/test/java/org/opendaylight/lispflowmapping/inmemorydb/HashMapDbTest.java

index 421355da42dff4149cb9f4092df15b81c28ed1f0..a2bef61d6a0e50a8dcc41847663670ee370c1ae7 100644 (file)
@@ -3,15 +3,12 @@
   <modelVersion>4.0.0</modelVersion>
 
   <parent>
-    <groupId>org.opendaylight.mdsal</groupId>
-    <artifactId>binding-parent</artifactId>
-    <version>0.10.0-SNAPSHOT</version>
-    <relativePath/>
+    <groupId>org.opendaylight.lispflowmapping</groupId>
+    <artifactId>mappingservice-parent</artifactId>
+    <version>1.5.0-SNAPSHOT</version>
   </parent>
 
-  <groupId>org.opendaylight.lispflowmapping</groupId>
   <artifactId>mappingservice.inmemorydb</artifactId>
-  <version>1.5.0-SNAPSHOT</version>
   <packaging>bundle</packaging>
   <name>Mapping Service Inmemory Mappings Database</name>
 
       <artifactId>mappingservice.api</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>compile</scope>
+    </dependency>
   </dependencies>
 
   <build>
index bc558456e87f7e961b5eeed2b9780f1059d676b0..3e41dbf16ad3665e47090528fd2fa443c47b4710 100644 (file)
@@ -9,21 +9,17 @@
 package org.opendaylight.lispflowmapping.inmemorydb;
 
 import java.util.AbstractMap.SimpleImmutableEntry;
-import java.util.Date;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.TimeUnit;
 import org.opendaylight.lispflowmapping.inmemorydb.radixtrie.RadixTrie;
 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
 import org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor;
 import org.opendaylight.lispflowmapping.interfaces.dao.MappingEntry;
-import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinary;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.lfm.mappingservice.dao.inmemorydb.config.rev151007.InmemorydbConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -31,22 +27,7 @@ public class HashMapDb implements ILispDAO, AutoCloseable {
 
     protected static final Logger LOG = LoggerFactory.getLogger(HashMapDb.class);
     private static final Object TABLES = (Object) "tables";
-    private static final int DEFAULT_RECORD_TIMEOUT = 240;   // SB registered mapping entries time out after 4 min
     private ConcurrentMap<Object, ConcurrentMap<String, Object>> data = new ConcurrentHashMap<>();
-    private TimeUnit timeUnit = TimeUnit.SECONDS;
-    private int recordTimeOut;
-
-    public HashMapDb() {
-        this.recordTimeOut = DEFAULT_RECORD_TIMEOUT;
-    }
-
-    public HashMapDb(final InmemorydbConfig inmemoryConfig) {
-        if (inmemoryConfig.getRecordTimeout() <= 0) {
-            this.recordTimeOut = DEFAULT_RECORD_TIMEOUT;
-        } else {
-            this.recordTimeOut = inmemoryConfig.getRecordTimeout();
-        }
-    }
 
     // IPv4 and IPv6 radix tries used for longest prefix matching
     private RadixTrie<Object> ip4Trie = new RadixTrie<>(32, true);
@@ -90,19 +71,22 @@ public class HashMapDb implements ILispDAO, AutoCloseable {
         return data.get(key);
     }
 
+    private RadixTrie<Object>.TrieNode lookupBestNode(Eid eid) {
+        if (eid.getAddress() instanceof Ipv4PrefixBinary) {
+            Ipv4PrefixBinary prefix = (Ipv4PrefixBinary) eid.getAddress();
+            return ip4Trie.lookupBest(prefix.getIpv4AddressBinary().getValue(), prefix.getIpv4MaskLength());
+        } else if (eid.getAddress() instanceof Ipv6PrefixBinary) {
+            Ipv6PrefixBinary prefix = (Ipv6PrefixBinary) eid.getAddress();
+            return ip6Trie.lookupBest(prefix.getIpv6AddressBinary().getValue(), prefix.getIpv6MaskLength());
+        }
+        return null;
+    }
+
     @Override
     public Map<String, Object> getBest(Object key) {
         if (key instanceof Eid) {
             Eid eid = (Eid) key;
-            RadixTrie<Object>.TrieNode node = null;
-
-            if (eid.getAddress() instanceof Ipv4PrefixBinary) {
-                Ipv4PrefixBinary prefix = (Ipv4PrefixBinary) eid.getAddress();
-                node = ip4Trie.lookupBest(prefix.getIpv4AddressBinary().getValue(), prefix.getIpv4MaskLength());
-            } else if (eid.getAddress() instanceof Ipv6PrefixBinary) {
-                Ipv6PrefixBinary prefix = (Ipv6PrefixBinary) eid.getAddress();
-                node = ip6Trie.lookupBest(prefix.getIpv6AddressBinary().getValue(), prefix.getIpv6MaskLength());
-            }
+            RadixTrie<Object>.TrieNode node = lookupBestNode(eid);
             if (node == null) {
                 return get(key);
             }
@@ -117,15 +101,7 @@ public class HashMapDb implements ILispDAO, AutoCloseable {
 
         if (key instanceof Eid) {
             Eid eid = (Eid) key;
-            RadixTrie<Object>.TrieNode node = null;
-
-            if (eid.getAddress() instanceof Ipv4PrefixBinary) {
-                Ipv4PrefixBinary prefix = (Ipv4PrefixBinary) eid.getAddress();
-                node = ip4Trie.lookupBest(prefix.getIpv4AddressBinary().getValue(), prefix.getIpv4MaskLength());
-            } else if (eid.getAddress() instanceof Ipv6PrefixBinary) {
-                Ipv6PrefixBinary prefix = (Ipv6PrefixBinary) eid.getAddress();
-                node = ip6Trie.lookupBest(prefix.getIpv6AddressBinary().getValue(), prefix.getIpv6MaskLength());
-            }
+            RadixTrie<Object>.TrieNode node = lookupBestNode(eid);
             if (node == null) {
                 data = get(key);
                 return (data == null) ? null : new SimpleImmutableEntry<>((Eid)key, data);
@@ -198,41 +174,6 @@ public class HashMapDb implements ILispDAO, AutoCloseable {
         data.clear();
     }
 
-    // TODO: this should be moved outside of DAO implementation
-    public void cleanOld() {
-        getAll(new IRowVisitor() {
-            public void visitRow(Object keyId, String valueKey, Object value) {
-                if (value != null && valueKey instanceof String && ((String) valueKey).equals(SubKeys.REGDATE)) {
-                    Date date = (Date) value;
-                    if (isExpired(date)) {
-                        removeSpecific(keyId, SubKeys.RECORD);
-                    }
-                }
-            }
-
-            private boolean isExpired(Date date) {
-                return System.currentTimeMillis() - date.getTime()
-                        >= TimeUnit.MILLISECONDS.convert(recordTimeOut, timeUnit);
-            }
-        });
-    }
-
-    public TimeUnit getTimeUnit() {
-        return timeUnit;
-    }
-
-    public void setRecordTimeOut(int recordTimeOut) {
-        this.recordTimeOut = recordTimeOut;
-    }
-
-    public int getRecordTimeOut() {
-        return recordTimeOut;
-    }
-
-    public void setTimeUnit(TimeUnit timeUnit) {
-        this.timeUnit = timeUnit;
-    }
-
     public void close() throws Exception {
         data.clear();
     }
index 6d479e19a28b35ea7bbfe8752bc4cd16d039ea4c..c117f7ac0edf630fa11bcc34ea889338041177f2 100644 (file)
@@ -3,15 +3,10 @@
   xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
   odl:use-default-for-reference-types="true">
 
-  <odl:clustered-app-config id="inmemorydbConfig"
-    binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.lfm.mappingservice.dao.inmemorydb.config.rev151007.InmemorydbConfig">
-  </odl:clustered-app-config>
+  <bean id="hashMapDb" class="org.opendaylight.lispflowmapping.inmemorydb.HashMapDb" />
 
-  <bean id="hashMapDb" class="org.opendaylight.lispflowmapping.inmemorydb.HashMapDb">
-    <argument ref="inmemorydbConfig" />
-  </bean>
   <service ref="hashMapDb"
     interface="org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO"
     odl:type="default" />
 
-</blueprint>
+</blueprint>
\ No newline at end of file
diff --git a/mappingservice/inmemorydb/src/main/yang/odl-mappingservice-dao-inmemorydb-config.yang b/mappingservice/inmemorydb/src/main/yang/odl-mappingservice-dao-inmemorydb-config.yang
deleted file mode 100644 (file)
index 10d1aa2..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-module odl-mappingservice-dao-inmemorydb-config {
-    yang-version 1;
-    namespace "urn:opendaylight:params:xml:ns:yang:controller:config:lfm:mappingservice-dao:inmemorydb:config";
-    prefix "inmemorydb";
-
-    description
-        "InMemoryDb Mapping Service DAO config.";
-
-    revision "2015-10-07" {
-        description
-                "Config file for inmemorydb";
-    }
-
-    container inmemorydb-config {
-        leaf record-timeout {
-            type uint16;
-            default 240;
-            description "Mapping record timeout";
-        }
-    }
-}
index 4ff474ba5d13c58f72678d5d5b52b4534c8a02c6..a6b42d9ff32f283abd85cde6d018543ae903a0e3 100644 (file)
@@ -10,16 +10,13 @@ package org.opendaylight.lispflowmapping.inmemorydb;
 
 import java.util.AbstractMap.SimpleImmutableEntry;
 import java.util.Collections;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.concurrent.TimeUnit;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
 import org.opendaylight.lispflowmapping.interfaces.dao.MappingEntry;
-import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
 
@@ -269,53 +266,6 @@ public class HashMapDbTest {
         map.getAll((keyId, valueKey, value) -> Assert.fail("DB should be empty"));
     }
 
-    @Test
-    public void testCleanOld() throws Exception {
-        map.setRecordTimeOut(240);
-        map.setTimeUnit(TimeUnit.SECONDS);
-
-        Object entry1Key = "entry1Key";
-        String entry1recordKey = SubKeys.RECORD;
-        String entry1recordValue = "record1";
-        String entry1regdateKey = SubKeys.REGDATE;
-        Date entry1regdateValue = new Date();
-
-        Object entry2Key = "entry2Key";
-        String entry2recordKey = SubKeys.RECORD;
-        String entry2recordValue = "record2";
-        String entry2regdateKey = SubKeys.REGDATE;
-        Date entry2regdateValue = new Date(
-                System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(map.getRecordTimeOut(), map.getTimeUnit()));
-
-        map.put(entry1Key,
-                new MappingEntry<>(entry1recordKey, entry1recordValue),
-                new MappingEntry<>(entry1regdateKey, entry1regdateValue));
-        map.put(entry2Key,
-                new MappingEntry<>(entry2recordKey, entry2recordValue),
-                new MappingEntry<>(entry2regdateKey, entry2regdateValue));
-        map.cleanOld();
-
-        Assert.assertEquals("Entry should be present in the DB due to its time didn't expired",
-                entry1recordValue, map.getSpecific(entry1Key, entry1recordKey));
-        Assert.assertNull("Entry should not be present in the DB due to its time expired",
-                map.getSpecific(entry2Key, entry2recordKey));
-
-    }
-
-    @Test
-    public void testSetGetTimeUnit() throws Exception {
-        TimeUnit timeUnit = TimeUnit.DAYS;
-        map.setTimeUnit(timeUnit);
-        Assert.assertEquals(timeUnit, map.getTimeUnit());
-    }
-
-    @Test
-    public void testSetGetRecordTimeOut() throws Exception {
-        int recordTimeOut = 12345;
-        map.setRecordTimeOut(recordTimeOut);
-        Assert.assertEquals(recordTimeOut, map.getRecordTimeOut());
-    }
-
     @Test
     public void testClose() throws Exception {
         Object dbEntryKey1 = "dbEntryKey";