Yuta HIGUCHI

Add getAll to DatabaseService

Change-Id: I5fb9d52244b005dfc22e7faaa68341be3c3f3725
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 @@ public interface DatabaseService {
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
......
......@@ -3,6 +3,7 @@ package org.onlab.onos.store.service.impl;
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.BatchReadRequest;
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 @@ public class DatabaseClient {
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);
}
}
}
......
......@@ -226,6 +226,12 @@ public class DatabaseManager implements DatabaseService, DatabaseAdminService {
}
@Override
public Map<String, VersionedValue> getAll(String tableName) {
return client.getAll(tableName);
}
@Override
public BatchReadResult batchRead(BatchReadRequest batchRequest) {
return new BatchReadResult(client.batchRead(batchRequest));
}
......
......@@ -31,6 +31,7 @@ import org.onlab.util.KryoNamespace;
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 @@ public class DatabaseStateMachine implements StateMachine {
return results;
}
@Query
public Map<String, VersionedValue> getAll(String tableName) {
return ImmutableMap.copyOf(state.getTable(tableName));
}
WriteStatus checkIfApplicable(WriteRequest request,
VersionedValue value) {
......