Add getAll to DatabaseService

Change-Id: I5fb9d52244b005dfc22e7faaa68341be3c3f3725
diff --git a/core/api/src/main/java/org/onlab/onos/store/service/DatabaseService.java b/core/api/src/main/java/org/onlab/onos/store/service/DatabaseService.java
index a82bd70..b5a56a1 100644
--- a/core/api/src/main/java/org/onlab/onos/store/service/DatabaseService.java
+++ b/core/api/src/main/java/org/onlab/onos/store/service/DatabaseService.java
@@ -1,5 +1,7 @@
 package org.onlab.onos.store.service;
 
+import java.util.Map;
+
 /**
  * Service interface for a strongly consistent and durable
  * key value data store.
@@ -15,6 +17,14 @@
     VersionedValue get(String tableName, String key);
 
     /**
+     * Reads the whole table.
+     *
+     * @param tableName name of the table associated with this operation.
+     * @return the whole table
+     */
+    Map<String, VersionedValue> getAll(String tableName);
+
+    /**
      * Associate the key with a value.
      * @param tableName table name in which this key/value resides.
      * @param key key with which the specified value is to be associated
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseClient.java b/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseClient.java
index a6320ed..d512635 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseClient.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseClient.java
@@ -3,6 +3,7 @@
 import static com.google.common.base.Preconditions.checkNotNull;
 
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
@@ -13,6 +14,7 @@
 import org.onlab.onos.store.service.BatchWriteRequest;
 import org.onlab.onos.store.service.DatabaseException;
 import org.onlab.onos.store.service.ReadResult;
+import org.onlab.onos.store.service.VersionedValue;
 import org.onlab.onos.store.service.WriteResult;
 
 /**
@@ -95,4 +97,13 @@
             throw new DatabaseException(e);
         }
     }
+
+    public Map<String, VersionedValue> getAll(String tableName) {
+        CompletableFuture<Map<String, VersionedValue>> future = copycat.submit("getAll", tableName);
+        try {
+            return future.get();
+        } catch (InterruptedException | ExecutionException e) {
+            throw new DatabaseException(e);
+        }
+    }
 }
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseManager.java b/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseManager.java
index ad1ef853..d84df22 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseManager.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseManager.java
@@ -226,6 +226,12 @@
     }
 
     @Override
+    public Map<String, VersionedValue> getAll(String tableName) {
+        return client.getAll(tableName);
+    }
+
+
+    @Override
     public BatchReadResult batchRead(BatchReadRequest batchRequest) {
         return new BatchReadResult(client.batchRead(batchRequest));
     }
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseStateMachine.java b/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseStateMachine.java
index cdf66af..6031c2c 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseStateMachine.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/DatabaseStateMachine.java
@@ -31,6 +31,7 @@
 import org.slf4j.Logger;
 
 import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
@@ -148,6 +149,12 @@
         return results;
     }
 
+    @Query
+    public Map<String, VersionedValue> getAll(String tableName) {
+        return ImmutableMap.copyOf(state.getTable(tableName));
+    }
+
+
     WriteStatus checkIfApplicable(WriteRequest request,
                                         VersionedValue value) {