Remove DataStoreCache 98/82798/6
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 29 Jun 2019 10:18:54 +0000 (12:18 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 30 Jul 2019 22:39:46 +0000 (00:39 +0200)
Caches based on this class have been eradicated, with the only
user being CLI trying to find it. Remove the class and references
to it.

Change-Id: I9e4848ae9e491d04d9a2fa771fc8cdf5b3545e2f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/cli/TepCommandHelper.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/utils/cache/DataStoreCache.java [deleted file]

index 1ee4f361ddfa387581536dfef0408e8303e00fce..9a741c9a53d13feec4fd60a346dbbac2a31089ba 100644 (file)
@@ -36,7 +36,6 @@ import org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner;
 import org.opendaylight.genius.itm.cache.UnprocessedTunnelsStateCache;
 import org.opendaylight.genius.itm.globals.ITMConstants;
 import org.opendaylight.genius.itm.impl.ItmUtils;
-import org.opendaylight.genius.utils.cache.DataStoreCache;
 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.inet.types.rev130715.IpAddressBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBase;
@@ -302,58 +301,32 @@ public class TepCommandHelper {
 
     @SuppressWarnings("checkstyle:RegexpSinglelineJava")
     public void showCache(String cacheName) {
-        boolean dataStoreCache = DataStoreCache.isCacheValid(cacheName);
-        boolean inMemoryCache = isInMemoryCacheNameValid(cacheName);
-        if (!dataStoreCache && !inMemoryCache) {
-            System.out.println(" " + cacheName + " is not a valid Cache Name ");
-            return ;
+        final Collection<String> cacheContent;
+        switch (cacheName) {
+            case ITMConstants.INTERNAL_TUNNEL_CACHE_NAME:
+                cacheContent = ItmUtils.ITM_CACHE.getAllInternalInterfaces();
+                break;
+            case ITMConstants.EXTERNAL_TUNNEL_CACHE_NAME:
+                cacheContent = ItmUtils.ITM_CACHE.getAllExternalInterfaces();
+                break;
+            case ITMConstants.UNPROCESSED_TUNNELS_CACHE_NAME:
+                cacheContent = unprocessedTunnelsStateCache.getAllUnprocessedTunnels();
+                break;
+            default:
+                System.out.println(" " + cacheName + " is not a valid Cache Name ");
+                return;
         }
-        if (dataStoreCache) {
-            List<Object> keys = null;
-            keys = DataStoreCache.getKeys(cacheName);
-            if (keys != null && !keys.isEmpty()) {
-                System.out.println("Dumping the data in cache for " + cacheName);
-                for (Object key : keys) {
-                    System.out.println(" KEY:  " + key + " Value: " + DataStoreCache.get(cacheName, key));
-                }
-            } else {
-                System.out.println("No data in cache for " + cacheName);
-            }
-        } else if (inMemoryCache) {
-            System.out.println("Dumping the data in cache for " + cacheName);
-            Collection<String> cacheContent;
-            switch (cacheName) {
-                case ITMConstants.INTERNAL_TUNNEL_CACHE_NAME:
-                    cacheContent = ItmUtils.ITM_CACHE.getAllInternalInterfaces();
-                    break;
-                case ITMConstants.EXTERNAL_TUNNEL_CACHE_NAME:
-                    cacheContent = ItmUtils.ITM_CACHE.getAllExternalInterfaces();
-                    break;
-                case ITMConstants.UNPROCESSED_TUNNELS_CACHE_NAME:
-                    cacheContent = unprocessedTunnelsStateCache.getAllUnprocessedTunnels();
-                    break;
-                default:
-                    cacheContent = Collections.emptyList();
-            }
-            System.out.println("Number of data in cache " + cacheContent.size());
-            if (!cacheContent.isEmpty()) {
-                for (String key : cacheContent) {
-                    System.out.println(key + " ");
-                }
-            } else {
-                System.out.println("No data in cache for " + cacheName);
+        System.out.println("Dumping the data in cache for " + cacheName);
+        System.out.println("Number of data in cache " + cacheContent.size());
+        if (!cacheContent.isEmpty()) {
+            for (String key : cacheContent) {
+                System.out.println(key + " ");
             }
+        } else {
+            System.out.println("No data in cache for " + cacheName);
         }
     }
 
-    public boolean isInMemoryCacheNameValid(String name) {
-        boolean valid = false;
-        valid = name.equals(ITMConstants.INTERNAL_TUNNEL_CACHE_NAME)
-                || name.equals(ITMConstants.EXTERNAL_TUNNEL_CACHE_NAME)
-                || name.equals(ITMConstants.UNPROCESSED_TUNNELS_CACHE_NAME);
-        return valid;
-    }
-
     @SuppressWarnings("checkstyle:IllegalCatch")
     public void deleteVtep(BigInteger dpnId, String ipAddress,
                            String transportZone) throws TepException {
diff --git a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/utils/cache/DataStoreCache.java b/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/utils/cache/DataStoreCache.java
deleted file mode 100644 (file)
index 69a8796..0000000
+++ /dev/null
@@ -1,123 +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.genius.utils.cache;
-
-import com.google.common.base.Optional;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
-import org.opendaylight.genius.mdsalutil.cache.DataObjectCache;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-/**
- * "Per-blade" (?) Cache for DataBroker DataObject reads.
- *
- * <p>
- * We do not recommend that projects use this class; because of its following
- * design flaws:<ul>
- *
- * <li>no automatic cache invalidation logic on datastore change, manual remove() method
- *
- * <li>no cache expiration functionality, could grow very big and never purge if you cache a lot
- *
- * <li>mixes cache usage with monitoring and administration (used by
- * CLI command in ITM, which should be part of the cache infra; proper cache API
- * should have separate interface for those two orthogonal concerns
- *
- * <li>Cache key is sometimes Object and sometimes String; instead of
- * simply InstanceIdentifier identifier plus LogicalDatastoreType
- * (thus also uses no T extend DataObject generics but Object)
- *
- * <li>returns null everywhere instead of Optional (contrary to
- * DataBroker Transaction read()
- *
- * <li>static methods instead of OSGi service and dependency inject-able in tests; thus impossible to use
- * properly in component tests (no reset between tests)
- * </ul>
- *
- * @deprecated This class has a number of serious design flaws. Use {@link DataObjectCache} instead.
- *
- * @author unascribed (Ericsson India?) - original code
- * @author Michael Vorburger.ch - JavaDoc
- */
-@Deprecated
-public final class DataStoreCache {
-
-    private DataStoreCache() { }
-
-    public static void create(String cacheName) {
-        if (CacheUtil.getCache(cacheName) == null) {
-            CacheUtil.createCache(cacheName);
-        }
-    }
-
-    public static void add(String cacheName, Object key, Object value) {
-        getCache(cacheName).put(key, value);
-    }
-
-    public static <T extends DataObject> Object get(String cacheName, InstanceIdentifier<T> identifier, String key,
-            DataBroker broker, boolean isConfig) throws ReadFailedException {
-        Object dataObject = getCache(cacheName).get(key);
-        if (dataObject == null) {
-            Optional<T> datastoreObject = SingleTransactionDataBroker.syncReadOptional(broker,
-                    isConfig ? LogicalDatastoreType.CONFIGURATION : LogicalDatastoreType.OPERATIONAL, identifier);
-            if (datastoreObject.isPresent()) {
-                dataObject = datastoreObject.get();
-                add(cacheName, key, dataObject);
-            }
-        }
-        return dataObject;
-    }
-
-    public static Object get(String cacheName, Object key) {
-        return getCache(cacheName).get(key);
-    }
-
-    public static void remove(String cacheName, Object key) {
-        getCache(cacheName).remove(key);
-    }
-
-    @SuppressWarnings("unchecked")
-    private static ConcurrentMap<Object, Object> getCache(String cacheName) {
-        return (ConcurrentMap<Object, Object>) CacheUtil.getCache(cacheName);
-    }
-
-    public static boolean isCacheValid(String cacheName) {
-        return CacheUtil.isCacheValid(cacheName);
-    }
-
-    public static List<Object> getValues(String cacheName) {
-        ConcurrentHashMap<Object, Object> map = (ConcurrentHashMap<Object, Object>) DataStoreCache.getCache(cacheName);
-        List<Object> values = null;
-        if (map != null) {
-            values = new ArrayList<>();
-            for (Map.Entry<Object, Object> entry : map.entrySet()) {
-                values.add(entry.getValue());
-            }
-        }
-        return values;
-    }
-
-    public static List<Object> getKeys(String cacheName) {
-        ConcurrentHashMap<Object, Object> map = (ConcurrentHashMap<Object, Object>) DataStoreCache.getCache(cacheName);
-        List<Object> keys = null;
-        if (map != null) {
-            keys = Collections.list(map.keys());
-        }
-        return keys;
-    }
-
-}