Yuta HIGUCHI

Add getAll to DatabaseService

Change-Id: I5fb9d52244b005dfc22e7faaa68341be3c3f3725
1 package org.onlab.onos.store.service; 1 package org.onlab.onos.store.service;
2 2
3 +import java.util.Map;
4 +
3 /** 5 /**
4 * Service interface for a strongly consistent and durable 6 * Service interface for a strongly consistent and durable
5 * key value data store. 7 * key value data store.
...@@ -15,6 +17,14 @@ public interface DatabaseService { ...@@ -15,6 +17,14 @@ public interface DatabaseService {
15 VersionedValue get(String tableName, String key); 17 VersionedValue get(String tableName, String key);
16 18
17 /** 19 /**
20 + * Reads the whole table.
21 + *
22 + * @param tableName name of the table associated with this operation.
23 + * @return the whole table
24 + */
25 + Map<String, VersionedValue> getAll(String tableName);
26 +
27 + /**
18 * Associate the key with a value. 28 * Associate the key with a value.
19 * @param tableName table name in which this key/value resides. 29 * @param tableName table name in which this key/value resides.
20 * @param key key with which the specified value is to be associated 30 * @param key key with which the specified value is to be associated
......
...@@ -3,6 +3,7 @@ package org.onlab.onos.store.service.impl; ...@@ -3,6 +3,7 @@ package org.onlab.onos.store.service.impl;
3 import static com.google.common.base.Preconditions.checkNotNull; 3 import static com.google.common.base.Preconditions.checkNotNull;
4 4
5 import java.util.List; 5 import java.util.List;
6 +import java.util.Map;
6 import java.util.Set; 7 import java.util.Set;
7 import java.util.concurrent.CompletableFuture; 8 import java.util.concurrent.CompletableFuture;
8 import java.util.concurrent.ExecutionException; 9 import java.util.concurrent.ExecutionException;
...@@ -13,6 +14,7 @@ import org.onlab.onos.store.service.BatchReadRequest; ...@@ -13,6 +14,7 @@ import org.onlab.onos.store.service.BatchReadRequest;
13 import org.onlab.onos.store.service.BatchWriteRequest; 14 import org.onlab.onos.store.service.BatchWriteRequest;
14 import org.onlab.onos.store.service.DatabaseException; 15 import org.onlab.onos.store.service.DatabaseException;
15 import org.onlab.onos.store.service.ReadResult; 16 import org.onlab.onos.store.service.ReadResult;
17 +import org.onlab.onos.store.service.VersionedValue;
16 import org.onlab.onos.store.service.WriteResult; 18 import org.onlab.onos.store.service.WriteResult;
17 19
18 /** 20 /**
...@@ -95,4 +97,13 @@ public class DatabaseClient { ...@@ -95,4 +97,13 @@ public class DatabaseClient {
95 throw new DatabaseException(e); 97 throw new DatabaseException(e);
96 } 98 }
97 } 99 }
100 +
101 + public Map<String, VersionedValue> getAll(String tableName) {
102 + CompletableFuture<Map<String, VersionedValue>> future = copycat.submit("getAll", tableName);
103 + try {
104 + return future.get();
105 + } catch (InterruptedException | ExecutionException e) {
106 + throw new DatabaseException(e);
107 + }
108 + }
98 } 109 }
......
...@@ -226,6 +226,12 @@ public class DatabaseManager implements DatabaseService, DatabaseAdminService { ...@@ -226,6 +226,12 @@ public class DatabaseManager implements DatabaseService, DatabaseAdminService {
226 } 226 }
227 227
228 @Override 228 @Override
229 + public Map<String, VersionedValue> getAll(String tableName) {
230 + return client.getAll(tableName);
231 + }
232 +
233 +
234 + @Override
229 public BatchReadResult batchRead(BatchReadRequest batchRequest) { 235 public BatchReadResult batchRead(BatchReadRequest batchRequest) {
230 return new BatchReadResult(client.batchRead(batchRequest)); 236 return new BatchReadResult(client.batchRead(batchRequest));
231 } 237 }
......
...@@ -31,6 +31,7 @@ import org.onlab.util.KryoNamespace; ...@@ -31,6 +31,7 @@ import org.onlab.util.KryoNamespace;
31 import org.slf4j.Logger; 31 import org.slf4j.Logger;
32 32
33 import com.google.common.base.MoreObjects; 33 import com.google.common.base.MoreObjects;
34 +import com.google.common.collect.ImmutableMap;
34 import com.google.common.collect.ImmutableSet; 35 import com.google.common.collect.ImmutableSet;
35 import com.google.common.collect.Lists; 36 import com.google.common.collect.Lists;
36 import com.google.common.collect.Maps; 37 import com.google.common.collect.Maps;
...@@ -148,6 +149,12 @@ public class DatabaseStateMachine implements StateMachine { ...@@ -148,6 +149,12 @@ public class DatabaseStateMachine implements StateMachine {
148 return results; 149 return results;
149 } 150 }
150 151
152 + @Query
153 + public Map<String, VersionedValue> getAll(String tableName) {
154 + return ImmutableMap.copyOf(state.getTable(tableName));
155 + }
156 +
157 +
151 WriteStatus checkIfApplicable(WriteRequest request, 158 WriteStatus checkIfApplicable(WriteRequest request,
152 VersionedValue value) { 159 VersionedValue value) {
153 160
......