Removed Floodlight storage framework
diff --git a/conf/onos-embedded.properties b/conf/onos-embedded.properties
index e280e41..44af87f 100644
--- a/conf/onos-embedded.properties
+++ b/conf/onos-embedded.properties
@@ -1,5 +1,4 @@
-floodlight.modules = net.floodlightcontroller.storage.memory.MemoryStorageSource,\
-net.floodlightcontroller.core.FloodlightProvider,\
+floodlight.modules = net.floodlightcontroller.core.FloodlightProvider,\
net.floodlightcontroller.threadpool.ThreadPool,\
net.onrc.onos.ofcontroller.floodlightlistener.NetworkGraphPublisher, \
net.floodlightcontroller.devicemanager.internal.DeviceManagerImpl,\
diff --git a/conf/onos.properties b/conf/onos.properties
index f7bffb2..00e6279 100644
--- a/conf/onos.properties
+++ b/conf/onos.properties
@@ -1,5 +1,4 @@
-floodlight.modules = net.floodlightcontroller.storage.memory.MemoryStorageSource,\
-net.floodlightcontroller.core.FloodlightProvider,\
+floodlight.modules = net.floodlightcontroller.core.FloodlightProvider,\
net.floodlightcontroller.threadpool.ThreadPool,\
net.onrc.onos.ofcontroller.floodlightlistener.NetworkGraphPublisher, \
net.floodlightcontroller.devicemanager.internal.DeviceManagerImpl,\
diff --git a/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java b/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java
index 95daf96..3541fc9 100644
--- a/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java
+++ b/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java
@@ -13,7 +13,6 @@
import net.floodlightcontroller.counter.ICounterStoreService;
import net.floodlightcontroller.perfmon.IPktInProcessingTimeService;
import net.floodlightcontroller.restserver.IRestApiService;
-import net.floodlightcontroller.storage.IStorageSourceService;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import net.onrc.onos.registry.controller.IControllerRegistryService;
@@ -44,8 +43,7 @@
@Override
public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
Collection<Class<? extends IFloodlightService>> dependencies =
- new ArrayList<Class<? extends IFloodlightService>>(4);
- dependencies.add(IStorageSourceService.class);
+ new ArrayList<Class<? extends IFloodlightService>>(5);
dependencies.add(IPktInProcessingTimeService.class);
dependencies.add(IRestApiService.class);
dependencies.add(ICounterStoreService.class);
@@ -58,8 +56,6 @@
@Override
public void init(FloodlightModuleContext context) throws FloodlightModuleException {
- controller.setStorageSourceService(
- context.getServiceImpl(IStorageSourceService.class));
controller.setPktInProcessingService(
context.getServiceImpl(IPktInProcessingTimeService.class));
controller.setCounterStore(
diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
index 17f1be8..7f788b1 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
@@ -19,18 +19,14 @@
import java.io.FileInputStream;
import java.io.IOException;
-import java.net.InetAddress;
import java.net.InetSocketAddress;
-import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.nio.channels.ClosedChannelException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -68,11 +64,6 @@
import net.floodlightcontroller.packet.Ethernet;
import net.floodlightcontroller.perfmon.IPktInProcessingTimeService;
import net.floodlightcontroller.restserver.IRestApiService;
-import net.floodlightcontroller.storage.IResultSet;
-import net.floodlightcontroller.storage.IStorageSourceListener;
-import net.floodlightcontroller.storage.IStorageSourceService;
-import net.floodlightcontroller.storage.OperatorPredicate;
-import net.floodlightcontroller.storage.StorageException;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import net.onrc.onos.ofcontroller.core.IOFSwitchPortListener;
import net.onrc.onos.registry.controller.IControllerRegistryService;
@@ -82,7 +73,6 @@
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.ChannelStateEvent;
@@ -128,8 +118,6 @@
import org.openflow.protocol.vendor.OFBasicVendorId;
import org.openflow.protocol.vendor.OFVendorId;
import org.openflow.util.HexString;
-import org.openflow.util.U16;
-import org.openflow.util.U32;
import org.openflow.vendor.nicira.OFNiciraVendorData;
import org.openflow.vendor.nicira.OFRoleReplyVendorData;
import org.openflow.vendor.nicira.OFRoleRequestVendorData;
@@ -149,8 +137,7 @@
* - Additional DEBUG logs
* - Try using hostname as controller ID, when ID was not explicitly given.
*/
-public class Controller implements IFloodlightProviderService,
- IStorageSourceListener {
+public class Controller implements IFloodlightProviderService {
protected final static Logger log = LoggerFactory.getLogger(Controller.class);
@@ -184,7 +171,6 @@
// Module dependencies
protected IRestApiService restApi;
protected ICounterStoreService counterStore = null;
- protected IStorageSourceService storageSource;
protected IPktInProcessingTimeService pktinProcTime;
protected IThreadPoolService threadPool;
protected IControllerRegistryService registryService;
@@ -208,6 +194,7 @@
// Flag to always flush flow table on switch reconnect (HA or otherwise)
protected boolean alwaysClearFlowsOnSwAdd = false;
+ /*
// Storage table names
protected static final String CONTROLLER_TABLE_NAME = "controller_controller";
protected static final String CONTROLLER_ID = "id";
@@ -246,7 +233,7 @@
protected static final String CONTROLLER_INTERFACE_TYPE = "type";
protected static final String CONTROLLER_INTERFACE_NUMBER = "number";
protected static final String CONTROLLER_INTERFACE_DISCOVERED_IP = "discovered_ip";
-
+ */
// Perf. related configuration
@@ -383,10 +370,6 @@
// Getters/Setters
// ***************
- public void setStorageSourceService(IStorageSourceService storageSource) {
- this.storageSource = storageSource;
- }
-
public void setCounterStore(ICounterStoreService counterStore) {
this.counterStore = counterStore;
}
@@ -417,10 +400,10 @@
@Override
public void setRole(Role role) {
if (role == null) throw new NullPointerException("Role can not be null.");
- if (role == Role.MASTER && this.role == Role.SLAVE) {
+ //if (role == Role.MASTER && this.role == Role.SLAVE) {
// Reset db state to Inactive for all switches.
- updateAllInactiveSwitchInfo();
- }
+ //updateAllInactiveSwitchInfo();
+ //}
// Need to synchronize to ensure a reliable ordering on role request
// messages send and to ensure the list of connected switches is stable
@@ -639,10 +622,6 @@
" due to message parse failure",
e.getCause());
ctx.getChannel().close();
- } else if (e.getCause() instanceof StorageException) {
- log.error("Terminating controller due to storage exception",
- e.getCause());
- terminate();
} else if (e.getCause() instanceof RejectedExecutionException) {
log.warn("Could not process message: queue full");
} else {
@@ -715,40 +694,8 @@
description);
sw.setSwitchProperties(description);
data = null;
-
- // At this time, also set other switch properties from storage
- boolean is_core_switch = false;
- IResultSet resultSet = null;
- try {
- String swid = sw.getStringId();
- resultSet =
- storageSource.getRow(SWITCH_CONFIG_TABLE_NAME, swid);
- for (Iterator<IResultSet> it =
- resultSet.iterator(); it.hasNext();) {
- // In case of multiple rows, use the status
- // in last row?
- Map<String, Object> row = it.next().getRow();
- if (row.containsKey(SWITCH_CONFIG_CORE_SWITCH)) {
- if (log.isDebugEnabled()) {
- log.debug("Reading SWITCH_IS_CORE_SWITCH " +
- "config for switch={}, is-core={}",
- sw, row.get(SWITCH_CONFIG_CORE_SWITCH));
- }
- String ics =
- (String)row.get(SWITCH_CONFIG_CORE_SWITCH);
- is_core_switch = ics.equals("true");
- }
- }
- }
- finally {
- if (resultSet != null)
- resultSet.close();
- }
- if (is_core_switch) {
- sw.setAttribute(IOFSwitch.SWITCH_IS_CORE_SWITCH,
- true);
- }
}
+
sw.removeAttribute(IOFSwitch.SWITCH_DESCRIPTION_FUTURE);
state.hasDescription = true;
checkSwitchReady();
@@ -961,7 +908,7 @@
// Some switches don't seem to update us with port
// status messages while in slave role.
- readSwitchPortStateFromStorage(sw);
+ //readSwitchPortStateFromStorage(sw);
// Only add the switch to the active switch list if
// we're not in the slave role. Note that if the role
@@ -1079,7 +1026,7 @@
// return results to rest api caller
sw.deliverOFFeaturesReply(m);
// update database */
- updateActiveSwitchInfo(sw);
+ //updateActiveSwitchInfo(sw);
}
break;
case GET_CONFIG_REPLY:
@@ -1294,8 +1241,8 @@
log.error("Failure adding update to queue", e);
}
}
- if (updateStorage)
- updatePortInfo(sw, port);
+ //if (updateStorage)
+ //updatePortInfo(sw, port);
log.debug("Port #{} modified for {}", portNumber, sw);
} else if (m.getReason() == (byte)OFPortReason.OFPPR_ADD.ordinal()) {
sw.setPort(port);
@@ -1305,8 +1252,8 @@
} catch (InterruptedException e) {
log.error("Failure adding update to queue", e);
}
- if (updateStorage)
- updatePortInfo(sw, port);
+ //if (updateStorage)
+ //updatePortInfo(sw, port);
log.debug("Port #{} added for {}", portNumber, sw);
} else if (m.getReason() ==
(byte)OFPortReason.OFPPR_DELETE.ordinal()) {
@@ -1317,8 +1264,8 @@
} catch (InterruptedException e) {
log.error("Failure adding update to queue", e);
}
- if (updateStorage)
- removePortInfo(sw, portNumber);
+ //if (updateStorage)
+ //removePortInfo(sw, portNumber);
log.debug("Port #{} deleted for {}", portNumber, sw);
}
SwitchUpdate update = new SwitchUpdate(sw, SwitchUpdateType.PORTCHANGED);
@@ -1561,7 +1508,7 @@
oldSw.cancelAllStatisticsReplies();
- updateInactiveSwitchInfo(oldSw);
+ //updateInactiveSwitchInfo(oldSw);
// we need to clean out old switch state definitively
// before adding the new switch
@@ -1589,7 +1536,7 @@
}
}
- updateActiveSwitchInfo(sw);
+ //updateActiveSwitchInfo(sw);
SwitchUpdate update = new SwitchUpdate(sw, SwitchUpdateType.ADDED);
try {
this.updates.put(update);
@@ -1628,7 +1575,7 @@
// written out by the new master. Maybe need to revisit how we handle all
// of the switch state that's written to storage.
- updateInactiveSwitchInfo(sw);
+ //updateInactiveSwitchInfo(sw);
SwitchUpdate update = new SwitchUpdate(sw, SwitchUpdateType.REMOVED);
try {
this.updates.put(update);
@@ -1812,6 +1759,7 @@
// Initialization
// **************
+ /*
protected void updateAllInactiveSwitchInfo() {
if (role == Role.SLAVE) {
return;
@@ -1861,7 +1809,9 @@
switchResultSet.close();
}
}
+ */
+ /*
protected void updateControllerInfo() {
updateAllInactiveSwitchInfo();
@@ -1871,7 +1821,9 @@
controllerInfo.put(CONTROLLER_ID, id);
storageSource.updateRow(CONTROLLER_TABLE_NAME, controllerInfo);
}
+ */
+ /*
protected void updateActiveSwitchInfo(IOFSwitch sw) {
if (role == Role.SLAVE) {
return;
@@ -1917,7 +1869,9 @@
updatePortInfo(sw, port);
}
}
+ */
+ /*
protected void updateInactiveSwitchInfo(IOFSwitch sw) {
if (role == Role.SLAVE) {
return;
@@ -1931,7 +1885,9 @@
switchInfo.put(SWITCH_ACTIVE, Boolean.FALSE);
storageSource.updateRowAsync(SWITCH_TABLE_NAME, switchInfo);
}
+ */
+ /*
protected void updatePortInfo(IOFSwitch sw, OFPhysicalPort port) {
if (role == Role.SLAVE) {
return;
@@ -1962,11 +1918,13 @@
portInfo.put(PORT_PEER_FEATURES, peerFeatures);
storageSource.updateRowAsync(PORT_TABLE_NAME, portInfo);
}
+ */
/**
* Read switch port data from storage and write it into a switch object
* @param sw the switch to update
*/
+ /*
protected void readSwitchPortStateFromStorage(OFSwitchImpl sw) {
OperatorPredicate op =
new OperatorPredicate(PORT_SWITCH,
@@ -2009,7 +1967,9 @@
log.error("Failure adding update to queue", e);
}
}
+ */
+ /*
protected void removePortInfo(IOFSwitch sw, short portNumber) {
if (role == Role.SLAVE) {
return;
@@ -2018,6 +1978,7 @@
String id = datapathIdString + "|" + portNumber;
storageSource.deleteRowAsync(PORT_TABLE_NAME, id);
}
+ */
/**
* Sets the initial role based on properties in the config params.
@@ -2134,10 +2095,6 @@
update.dispatch();
} catch (InterruptedException e) {
return;
- } catch (StorageException e) {
- log.error("Storage exception in controller " +
- "updates loop; terminating process", e);
- return;
} catch (Exception e) {
log.error("Exception in controller updates loop", e);
}
@@ -2246,6 +2203,7 @@
log.warn("Registry service error: {}", e2.getMessage());
}
+ /*
// Create the table names we use
storageSource.createTable(CONTROLLER_TABLE_NAME, null);
storageSource.createTable(SWITCH_TABLE_NAME, null);
@@ -2274,6 +2232,7 @@
}
}
}
+ */
// Add our REST API
restApi.addRestletRoutable(new CoreWebRoutable());
@@ -2322,6 +2281,7 @@
/**
* Handle changes to the controller nodes IPs and dispatch update.
*/
+ /*
@SuppressWarnings("unchecked")
protected void handleControllerNodeIPChanges() {
HashMap<String,String> curControllerNodeIPs = new HashMap<String,String>();
@@ -2380,6 +2340,7 @@
}
}
}
+ */
@Override
public Map<String, String> getControllerNodeIPs() {
@@ -2393,6 +2354,7 @@
return retval;
}
+ /*
@Override
public void rowsModified(String tableName, Set<Object> rowKeys) {
if (tableName.equals(CONTROLLER_INTERFACE_TABLE_NAME)) {
@@ -2407,6 +2369,7 @@
handleControllerNodeIPChanges();
}
}
+ */
@Override
public long getSystemStartTime() {
diff --git a/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java b/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java
index 7604d7c..67f226c 100644
--- a/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java
+++ b/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java
@@ -58,7 +58,6 @@
EventHistoryTopologyLinkResource.class);
router.attach("/event-history/topology-cluster/{count}/json",
EventHistoryTopologyClusterResource.class);
- router.attach("/storage/tables/json", StorageSourceTablesResource.class);
router.attach("/controller/summary/json", ControllerSummaryResource.class);
router.attach("/role/json", ControllerRoleResource.class);
router.attach("/health/json", HealthCheckResource.class);
diff --git a/src/main/java/net/floodlightcontroller/core/web/StorageSourceTablesResource.java b/src/main/java/net/floodlightcontroller/core/web/StorageSourceTablesResource.java
deleted file mode 100644
index 51f514f..0000000
--- a/src/main/java/net/floodlightcontroller/core/web/StorageSourceTablesResource.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package net.floodlightcontroller.core.web;
-
-import java.util.Set;
-
-import net.floodlightcontroller.storage.IStorageSourceService;
-
-import org.restlet.resource.Get;
-import org.restlet.resource.ServerResource;
-
-public class StorageSourceTablesResource extends ServerResource {
- @Get("json")
- public Set<String> retrieve() {
- IStorageSourceService storageSource = (IStorageSourceService)getContext().
- getAttributes().get(IStorageSourceService.class.getCanonicalName());
- Set<String> allTableNames = storageSource.getAllTableNames();
- return allTableNames;
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java
index 087756c..3fd109c 100755
--- a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java
+++ b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java
@@ -66,7 +66,6 @@
import net.floodlightcontroller.packet.IPv4;
import net.floodlightcontroller.packet.UDP;
import net.floodlightcontroller.restserver.IRestApiService;
-import net.floodlightcontroller.storage.IStorageSourceService;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import net.floodlightcontroller.topology.ITopologyListener;
import net.floodlightcontroller.topology.ITopologyService;
@@ -95,7 +94,6 @@
protected IFloodlightProviderService floodlightProvider;
protected ITopologyService topology;
- protected IStorageSourceService storageSource;
protected IRestApiService restApi;
protected IThreadPoolService threadPool;
protected IFlowReconcileService flowReconcileMgr;
@@ -686,7 +684,6 @@
Collection<Class<? extends IFloodlightService>> l =
new ArrayList<Class<? extends IFloodlightService>>();
l.add(IFloodlightProviderService.class);
- l.add(IStorageSourceService.class);
l.add(ITopologyService.class);
l.add(IRestApiService.class);
l.add(IThreadPoolService.class);
@@ -707,8 +704,6 @@
this.floodlightProvider =
fmc.getServiceImpl(IFloodlightProviderService.class);
- this.storageSource =
- fmc.getServiceImpl(IStorageSourceService.class);
this.topology =
fmc.getServiceImpl(ITopologyService.class);
this.restApi = fmc.getServiceImpl(IRestApiService.class);
diff --git a/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java b/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java
index d816d66..89664a4 100644
--- a/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java
+++ b/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java
@@ -5,13 +5,10 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
-import java.util.Iterator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
import net.floodlightcontroller.core.FloodlightContext;
import net.floodlightcontroller.core.IFloodlightProviderService;
@@ -29,12 +26,7 @@
import net.floodlightcontroller.core.util.AppCookie;
import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.staticflowentry.web.StaticFlowEntryWebRoutable;
-import net.floodlightcontroller.staticflowentry.IStaticFlowEntryPusherService;
-import net.floodlightcontroller.storage.IResultSet;
-import net.floodlightcontroller.storage.IStorageSourceService;
-import net.floodlightcontroller.storage.IStorageSourceListener;
-import net.floodlightcontroller.storage.StorageException;
import org.openflow.protocol.OFFlowMod;
import org.openflow.protocol.OFFlowRemoved;
import org.openflow.protocol.OFMatch;
@@ -54,7 +46,7 @@
*/
public class StaticFlowEntryPusher
implements IOFSwitchListener, IFloodlightModule, IStaticFlowEntryPusherService,
- IStorageSourceListener, IOFMessageListener, IHAListener {
+ /*IStorageSourceListener,*/ IOFMessageListener, IHAListener {
protected final static Logger log = LoggerFactory.getLogger(StaticFlowEntryPusher.class);
public static final String StaticFlowName = "staticflowentry";
@@ -93,7 +85,7 @@
protected IFloodlightProviderService floodlightProvider;
- protected IStorageSourceService storageSource;
+ //protected IStorageSourceService storageSource;
protected IRestApiService restApi;
// Map<DPID, Map<Name, FlowMod>> ; FlowMod can be null to indicate non-active
@@ -140,9 +132,11 @@
this.floodlightProvider = floodlightProvider;
}
+ /*
public void setStorageSource(IStorageSourceService storageSource) {
this.storageSource = storageSource;
}
+ */
/**
* Reads from our entriesFromStorage for the specified switch and
@@ -201,6 +195,7 @@
*
* @return
*/
+ /*
@LogMessageDoc(level="ERROR",
message="failed to access storage: {reason}",
explanation="Could not retrieve static flows from the system " +
@@ -224,6 +219,7 @@
}
return entries;
}
+ */
/**
* Take a single row, turn it into a flowMod, and add it to the
@@ -341,7 +337,7 @@
/**
* This handles both rowInsert() and rowUpdate()
*/
-
+ /*
@Override
public void rowsModified(String tableName, Set<Object> rowKeys) {
log.debug("Modifying Table {}", tableName);
@@ -396,6 +392,7 @@
deleteStaticFlowEntry((String) obj);
}
}
+ */
@LogMessageDoc(level="ERROR",
message="inconsistent internal state: no switch has rule {rule}",
@@ -564,7 +561,7 @@
Collection<Class<? extends IFloodlightService>> l =
new ArrayList<Class<? extends IFloodlightService>>();
l.add(IFloodlightProviderService.class);
- l.add(IStorageSourceService.class);
+ //l.add(IStorageSourceService.class);
l.add(IRestApiService.class);
return l;
}
@@ -574,8 +571,8 @@
throws FloodlightModuleException {
floodlightProvider =
context.getServiceImpl(IFloodlightProviderService.class);
- storageSource =
- context.getServiceImpl(IStorageSourceService.class);
+ //storageSource =
+ //context.getServiceImpl(IStorageSourceService.class);
restApi =
context.getServiceImpl(IRestApiService.class);
}
@@ -587,11 +584,11 @@
floodlightProvider.addHAListener(this);
// assumes no switches connected at startup()
- storageSource.createTable(TABLE_NAME, null);
- storageSource.setTablePrimaryKeyName(TABLE_NAME, COLUMN_NAME);
- storageSource.addListener(TABLE_NAME, this);
- entriesFromStorage = readEntriesFromStorage();
- entry2dpid = computeEntry2DpidMap(entriesFromStorage);
+ //storageSource.createTable(TABLE_NAME, null);
+ //storageSource.setTablePrimaryKeyName(TABLE_NAME, COLUMN_NAME);
+ //storageSource.addListener(TABLE_NAME, this);
+ //entriesFromStorage = readEntriesFromStorage();
+ //entry2dpid = computeEntry2DpidMap(entriesFromStorage);
restApi.addRestletRoutable(new StaticFlowEntryWebRoutable());
}
@@ -607,12 +604,12 @@
entriesFromStorage.put(swDpid, switchEntries);
}
switchEntries.put(name, fm);
- storageSource.insertRowAsync(TABLE_NAME, fmMap);
+ //storageSource.insertRowAsync(TABLE_NAME, fmMap);
}
@Override
public void deleteFlow(String name) {
- storageSource.deleteRowAsync(TABLE_NAME, name);
+ //storageSource.deleteRowAsync(TABLE_NAME, name);
// TODO - What if there is a delay in storage?
}
@@ -653,7 +650,7 @@
if (oldRole == Role.SLAVE) {
log.debug("Re-reading static flows from storage due " +
"to HA change from SLAVE->MASTER");
- entriesFromStorage = readEntriesFromStorage();
+ //entriesFromStorage = readEntriesFromStorage();
entry2dpid = computeEntry2DpidMap(entriesFromStorage);
}
break;
diff --git a/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryPusherResource.java b/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryPusherResource.java
index 2886a58..1db262d 100644
--- a/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryPusherResource.java
+++ b/src/main/java/net/floodlightcontroller/staticflowentry/web/StaticFlowEntryPusherResource.java
@@ -17,22 +17,15 @@
package net.floodlightcontroller.staticflowentry.web;
-import java.io.IOException;
import java.util.Map;
-import org.restlet.resource.Delete;
-import org.restlet.resource.Post;
+import net.floodlightcontroller.core.annotations.LogMessageCategory;
+import net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher;
+
import org.restlet.resource.ServerResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-import net.floodlightcontroller.core.annotations.LogMessageCategory;
-import net.floodlightcontroller.core.annotations.LogMessageDoc;
-import net.floodlightcontroller.staticflowentry.StaticFlowEntries;
-import net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher;
-import net.floodlightcontroller.storage.IStorageSourceService;
-
/**
* Pushes a static flow entry to the storage source
* @author alexreimers
@@ -81,6 +74,7 @@
* @param fmJson The Static Flow Pusher entry in JSON format.
* @return A string status message
*/
+ /*
@Post
@LogMessageDoc(level="ERROR",
message="Error parsing push flow mod request: {request}",
@@ -139,4 +133,5 @@
storageSource.deleteRowAsync(StaticFlowEntryPusher.TABLE_NAME, fmName);
return "{\"status\" : \"Entry " + fmName + " deleted\"}";
}
+ */
}
diff --git a/src/main/java/net/floodlightcontroller/storage/AbstractStorageSource.java b/src/main/java/net/floodlightcontroller/storage/AbstractStorageSource.java
deleted file mode 100644
index 20d6599..0000000
--- a/src/main/java/net/floodlightcontroller/storage/AbstractStorageSource.java
+++ /dev/null
@@ -1,534 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-import net.floodlightcontroller.core.annotations.LogMessageCategory;
-import net.floodlightcontroller.core.annotations.LogMessageDoc;
-import net.floodlightcontroller.core.module.FloodlightModuleContext;
-import net.floodlightcontroller.core.module.FloodlightModuleException;
-import net.floodlightcontroller.core.module.IFloodlightModule;
-import net.floodlightcontroller.core.module.IFloodlightService;
-import net.floodlightcontroller.counter.ICounter;
-import net.floodlightcontroller.counter.CounterStore;
-import net.floodlightcontroller.counter.ICounterStoreService;
-import net.floodlightcontroller.counter.CounterValue.CounterType;
-import net.floodlightcontroller.restserver.IRestApiService;
-import net.floodlightcontroller.storage.web.StorageWebRoutable;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@LogMessageCategory("System Database")
-public abstract class AbstractStorageSource
- implements IStorageSourceService, IFloodlightModule {
- protected final static Logger logger = LoggerFactory.getLogger(AbstractStorageSource.class);
-
- // Shared instance of the executor to use to execute the storage tasks.
- // We make this a single threaded executor, because if we used a thread pool
- // then storage operations could be executed out of order which would cause
- // problems in some cases (e.g. delete and update of a row getting reordered).
- // If we wanted to make this more multi-threaded we could have multiple
- // worker threads/executors with affinity of operations on a given table
- // to a single worker thread. But for now, we'll keep it simple and just have
- // a single thread for all operations.
- protected static ExecutorService defaultExecutorService = Executors.newSingleThreadExecutor();
-
- protected final static String STORAGE_QUERY_COUNTER_NAME = "StorageQuery";
- protected final static String STORAGE_UPDATE_COUNTER_NAME = "StorageUpdate";
- protected final static String STORAGE_DELETE_COUNTER_NAME = "StorageDelete";
-
- protected Set<String> allTableNames = new CopyOnWriteArraySet<String>();
- protected ICounterStoreService counterStore;
- protected ExecutorService executorService = defaultExecutorService;
- protected IStorageExceptionHandler exceptionHandler;
-
- private Map<String, Set<IStorageSourceListener>> listeners =
- new ConcurrentHashMap<String, Set<IStorageSourceListener>>();
-
- // Our dependencies
- protected IRestApiService restApi = null;
-
- protected static final String DB_ERROR_EXPLANATION =
- "An unknown error occurred while executing asynchronous " +
- "database operation";
-
- @LogMessageDoc(level="ERROR",
- message="Failure in asynchronous call to executeQuery",
- explanation=DB_ERROR_EXPLANATION,
- recommendation=LogMessageDoc.GENERIC_ACTION)
- abstract class StorageCallable<V> implements Callable<V> {
- public V call() {
- try {
- return doStorageOperation();
- }
- catch (StorageException e) {
- logger.error("Failure in asynchronous call to executeQuery", e);
- if (exceptionHandler != null)
- exceptionHandler.handleException(e);
- throw e;
- }
- }
- abstract protected V doStorageOperation();
- }
-
- @LogMessageDoc(level="ERROR",
- message="Failure in asynchronous call to updateRows",
- explanation=DB_ERROR_EXPLANATION,
- recommendation=LogMessageDoc.GENERIC_ACTION)
- abstract class StorageRunnable implements Runnable {
- public void run() {
- try {
- doStorageOperation();
- }
- catch (StorageException e) {
- logger.error("Failure in asynchronous call to updateRows", e);
- if (exceptionHandler != null)
- exceptionHandler.handleException(e);
- throw e;
- }
- }
- abstract void doStorageOperation();
- }
-
- public AbstractStorageSource() {
- this.executorService = defaultExecutorService;
- }
-
- public void setExecutorService(ExecutorService executorService) {
- this.executorService = (executorService != null) ?
- executorService : defaultExecutorService;
- }
-
- @Override
- public void setExceptionHandler(IStorageExceptionHandler exceptionHandler) {
- this.exceptionHandler = exceptionHandler;
- }
-
- @Override
- public abstract void setTablePrimaryKeyName(String tableName, String primaryKeyName);
-
- @Override
- public void createTable(String tableName, Set<String> indexedColumns) {
- allTableNames.add(tableName);
- }
-
- @Override
- public Set<String> getAllTableNames() {
- return allTableNames;
- }
-
- public void setCounterStore(CounterStore counterStore) {
- this.counterStore = counterStore;
- }
-
- protected void updateCounters(String baseName, String tableName) {
- if (counterStore != null) {
- String counterName;
- if (tableName != null) {
- updateCounters(baseName, null);
- counterName = baseName + CounterStore.TitleDelimitor + tableName;
- } else {
- counterName = baseName;
- }
- ICounter counter = counterStore.getCounter(counterName);
- if (counter == null) {
- counter = counterStore.createCounter(counterName, CounterType.LONG);
- }
- counter.increment();
- }
- }
-
- @Override
- public abstract IQuery createQuery(String tableName, String[] columnNames,
- IPredicate predicate, RowOrdering ordering);
-
- @Override
- public IResultSet executeQuery(IQuery query) {
- updateCounters(STORAGE_QUERY_COUNTER_NAME, query.getTableName());
- return executeQueryImpl(query);
- }
-
- protected abstract IResultSet executeQueryImpl(IQuery query);
-
- @Override
- public IResultSet executeQuery(String tableName, String[] columnNames,
- IPredicate predicate, RowOrdering ordering) {
- IQuery query = createQuery(tableName, columnNames, predicate, ordering);
- IResultSet resultSet = executeQuery(query);
- return resultSet;
- }
-
- @Override
- public Object[] executeQuery(String tableName, String[] columnNames,
- IPredicate predicate, RowOrdering ordering, IRowMapper rowMapper) {
- List<Object> objectList = new ArrayList<Object>();
- IResultSet resultSet = executeQuery(tableName, columnNames, predicate, ordering);
- while (resultSet.next()) {
- Object object = rowMapper.mapRow(resultSet);
- objectList.add(object);
- }
- return objectList.toArray();
- }
-
- @Override
- public Future<IResultSet> executeQueryAsync(final IQuery query) {
- Future<IResultSet> future = executorService.submit(
- new StorageCallable<IResultSet>() {
- public IResultSet doStorageOperation() {
- return executeQuery(query);
- }
- });
- return future;
- }
-
- @Override
- public Future<IResultSet> executeQueryAsync(final String tableName,
- final String[] columnNames, final IPredicate predicate,
- final RowOrdering ordering) {
- Future<IResultSet> future = executorService.submit(
- new StorageCallable<IResultSet>() {
- public IResultSet doStorageOperation() {
- return executeQuery(tableName, columnNames,
- predicate, ordering);
- }
- });
- return future;
- }
-
- @Override
- public Future<Object[]> executeQueryAsync(final String tableName,
- final String[] columnNames, final IPredicate predicate,
- final RowOrdering ordering, final IRowMapper rowMapper) {
- Future<Object[]> future = executorService.submit(
- new StorageCallable<Object[]>() {
- public Object[] doStorageOperation() {
- return executeQuery(tableName, columnNames, predicate,
- ordering, rowMapper);
- }
- });
- return future;
- }
-
- @Override
- public Future<?> insertRowAsync(final String tableName,
- final Map<String,Object> values) {
- Future<?> future = executorService.submit(
- new StorageRunnable() {
- public void doStorageOperation() {
- insertRow(tableName, values);
- }
- }, null);
- return future;
- }
-
- @Override
- public Future<?> updateRowsAsync(final String tableName, final List<Map<String,Object>> rows) {
- Future<?> future = executorService.submit(
- new StorageRunnable() {
- public void doStorageOperation() {
- updateRows(tableName, rows);
- }
- }, null);
- return future;
- }
-
- @Override
- public Future<?> updateMatchingRowsAsync(final String tableName,
- final IPredicate predicate, final Map<String,Object> values) {
- Future<?> future = executorService.submit(
- new StorageRunnable() {
- public void doStorageOperation() {
- updateMatchingRows(tableName, predicate, values);
- }
- }, null);
- return future;
- }
-
- @Override
- public Future<?> updateRowAsync(final String tableName,
- final Object rowKey, final Map<String,Object> values) {
- Future<?> future = executorService.submit(
- new StorageRunnable() {
- public void doStorageOperation() {
- updateRow(tableName, rowKey, values);
- }
- }, null);
- return future;
- }
-
- @Override
- public Future<?> updateRowAsync(final String tableName,
- final Map<String,Object> values) {
- Future<?> future = executorService.submit(
- new StorageRunnable() {
- public void doStorageOperation() {
- updateRow(tableName, values);
- }
- }, null);
- return future;
- }
-
- @Override
- public Future<?> deleteRowAsync(final String tableName, final Object rowKey) {
- Future<?> future = executorService.submit(
- new StorageRunnable() {
- public void doStorageOperation() {
- deleteRow(tableName, rowKey);
- }
- }, null);
- return future;
- }
-
- @Override
- public Future<?> deleteRowsAsync(final String tableName, final Set<Object> rowKeys) {
- Future<?> future = executorService.submit(
- new StorageRunnable() {
- public void doStorageOperation() {
- deleteRows(tableName, rowKeys);
- }
- }, null);
- return future;
- }
-
- @Override
- public Future<?> deleteMatchingRowsAsync(final String tableName, final IPredicate predicate) {
- Future<?> future = executorService.submit(
- new StorageRunnable() {
- public void doStorageOperation() {
- deleteMatchingRows(tableName, predicate);
- }
- }, null);
- return future;
- }
-
- @Override
- public Future<?> getRowAsync(final String tableName, final Object rowKey) {
- Future<?> future = executorService.submit(
- new StorageRunnable() {
- public void doStorageOperation() {
- getRow(tableName, rowKey);
- }
- }, null);
- return future;
- }
-
- @Override
- public Future<?> saveAsync(final IResultSet resultSet) {
- Future<?> future = executorService.submit(
- new StorageRunnable() {
- public void doStorageOperation() {
- resultSet.save();
- }
- }, null);
- return future;
- }
-
- @Override
- public void insertRow(String tableName, Map<String, Object> values) {
- updateCounters(STORAGE_UPDATE_COUNTER_NAME, tableName);
- insertRowImpl(tableName, values);
- }
-
- protected abstract void insertRowImpl(String tableName, Map<String, Object> values);
-
-
- @Override
- public void updateRows(String tableName, List<Map<String,Object>> rows) {
- updateCounters(STORAGE_UPDATE_COUNTER_NAME, tableName);
- updateRowsImpl(tableName, rows);
- }
-
- protected abstract void updateRowsImpl(String tableName, List<Map<String,Object>> rows);
-
- @Override
- public void updateMatchingRows(String tableName, IPredicate predicate,
- Map<String, Object> values) {
- updateCounters(STORAGE_UPDATE_COUNTER_NAME, tableName);
- updateMatchingRowsImpl(tableName, predicate, values);
- }
-
- protected abstract void updateMatchingRowsImpl(String tableName, IPredicate predicate,
- Map<String, Object> values);
-
- @Override
- public void updateRow(String tableName, Object rowKey,
- Map<String, Object> values) {
- updateCounters(STORAGE_UPDATE_COUNTER_NAME, tableName);
- updateRowImpl(tableName, rowKey, values);
- }
-
- protected abstract void updateRowImpl(String tableName, Object rowKey,
- Map<String, Object> values);
-
- @Override
- public void updateRow(String tableName, Map<String, Object> values) {
- updateCounters(STORAGE_UPDATE_COUNTER_NAME, tableName);
- updateRowImpl(tableName, values);
- }
-
- protected abstract void updateRowImpl(String tableName, Map<String, Object> values);
-
- @Override
- public void deleteRow(String tableName, Object rowKey) {
- updateCounters(STORAGE_DELETE_COUNTER_NAME, tableName);
- deleteRowImpl(tableName, rowKey);
- }
-
- protected abstract void deleteRowImpl(String tableName, Object rowKey);
-
- @Override
- public void deleteRows(String tableName, Set<Object> rowKeys) {
- updateCounters(STORAGE_DELETE_COUNTER_NAME, tableName);
- deleteRowsImpl(tableName, rowKeys);
- }
-
- protected abstract void deleteRowsImpl(String tableName, Set<Object> rowKeys);
-
- @Override
- public void deleteMatchingRows(String tableName, IPredicate predicate) {
- IResultSet resultSet = null;
- try {
- resultSet = executeQuery(tableName, null, predicate, null);
- while (resultSet.next()) {
- resultSet.deleteRow();
- }
- resultSet.save();
- }
- finally {
- if (resultSet != null)
- resultSet.close();
- }
- }
-
- @Override
- public IResultSet getRow(String tableName, Object rowKey) {
- updateCounters(STORAGE_QUERY_COUNTER_NAME, tableName);
- return getRowImpl(tableName, rowKey);
- }
-
- protected abstract IResultSet getRowImpl(String tableName, Object rowKey);
-
- @Override
- public synchronized void addListener(String tableName, IStorageSourceListener listener) {
- Set<IStorageSourceListener> tableListeners = listeners.get(tableName);
- if (tableListeners == null) {
- tableListeners = new CopyOnWriteArraySet<IStorageSourceListener>();
- listeners.put(tableName, tableListeners);
- }
- tableListeners.add(listener);
- }
-
- @Override
- public synchronized void removeListener(String tableName, IStorageSourceListener listener) {
- Set<IStorageSourceListener> tableListeners = listeners.get(tableName);
- if (tableListeners != null) {
- tableListeners.remove(listener);
- }
- }
-
- @LogMessageDoc(level="ERROR",
- message="Exception caught handling storage notification",
- explanation="An unknown error occured while trying to notify" +
- " storage listeners",
- recommendation=LogMessageDoc.GENERIC_ACTION)
- protected synchronized void notifyListeners(StorageSourceNotification notification) {
- String tableName = notification.getTableName();
- Set<Object> keys = notification.getKeys();
- Set<IStorageSourceListener> tableListeners = listeners.get(tableName);
- if (tableListeners != null) {
- for (IStorageSourceListener listener : tableListeners) {
- try {
- switch (notification.getAction()) {
- case MODIFY:
- listener.rowsModified(tableName, keys);
- break;
- case DELETE:
- listener.rowsDeleted(tableName, keys);
- break;
- }
- }
- catch (Exception e) {
- logger.error("Exception caught handling storage notification", e);
- }
- }
- }
- }
-
- @Override
- public void notifyListeners(List<StorageSourceNotification> notifications) {
- for (StorageSourceNotification notification : notifications)
- notifyListeners(notification);
- }
-
- // IFloodlightModule
-
- @Override
- public Collection<Class<? extends IFloodlightService>> getModuleServices() {
- Collection<Class<? extends IFloodlightService>> l =
- new ArrayList<Class<? extends IFloodlightService>>();
- l.add(IStorageSourceService.class);
- return l;
- }
-
- @Override
- public Map<Class<? extends IFloodlightService>,
- IFloodlightService> getServiceImpls() {
- Map<Class<? extends IFloodlightService>,
- IFloodlightService> m =
- new HashMap<Class<? extends IFloodlightService>,
- IFloodlightService>();
- m.put(IStorageSourceService.class, this);
- return m;
- }
-
- @Override
- public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
- Collection<Class<? extends IFloodlightService>> l =
- new ArrayList<Class<? extends IFloodlightService>>();
- l.add(IRestApiService.class);
- l.add(ICounterStoreService.class);
- return l;
- }
-
- @Override
- public void init(FloodlightModuleContext context)
- throws FloodlightModuleException {
- restApi =
- context.getServiceImpl(IRestApiService.class);
- counterStore =
- context.getServiceImpl(ICounterStoreService.class);
- }
-
- @Override
- public void startUp(FloodlightModuleContext context) {
- restApi.addRestletRoutable(new StorageWebRoutable());
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/CompoundPredicate.java b/src/main/java/net/floodlightcontroller/storage/CompoundPredicate.java
deleted file mode 100644
index a23e560..0000000
--- a/src/main/java/net/floodlightcontroller/storage/CompoundPredicate.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-/** Predicate class to handle AND and OR combinations of a number
- * of child predicates. The result of the logical combination of the
- * child predicates can also be negated to support a NOT operation.
- *
- * @author rob
- *
- */
-public class CompoundPredicate implements IPredicate {
-
- public enum Operator { AND, OR };
-
- private Operator operator;
- private boolean negated;
- private IPredicate[] predicateList;
-
- public CompoundPredicate(Operator operator, boolean negated, IPredicate... predicateList) {
- this.operator = operator;
- this.negated = negated;
- this.predicateList = predicateList;
- }
-
- public Operator getOperator() {
- return operator;
- }
-
- public boolean isNegated() {
- return negated;
- }
-
- public IPredicate[] getPredicateList() {
- return predicateList;
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/IPredicate.java b/src/main/java/net/floodlightcontroller/storage/IPredicate.java
deleted file mode 100644
index 291edff..0000000
--- a/src/main/java/net/floodlightcontroller/storage/IPredicate.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-/** Common base interface for the OperatorPredicate and CompoundPredicate classes.
- * It's necessary so that you can use either type of predicate as child
- * predicates of a CompoundPredicate.
- * @author rob
- */
-public interface IPredicate {
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/IQuery.java b/src/main/java/net/floodlightcontroller/storage/IQuery.java
deleted file mode 100644
index b75b8ae..0000000
--- a/src/main/java/net/floodlightcontroller/storage/IQuery.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-/** Representation of a database query. For SQL queries this maps to
- * a prepared statement, so it will be more efficient than if you use the
- * methods in IStorageSource that bypass the IQuery. For many NoSQL
- * storage sources there won't be any performance improvement from keeping
- * around the query.
- *
- * The query interface also supports parameterized queries (i.e. which maps
- * to using ? values in a SQL query). The values of the parameters are set
- * using the setParameter method. In the storage source API the parameters
- * are named rather than positional. The format of the parameterized values
- * in the query predicates is the parameter name bracketed with question marks
- * (e.g. ?MinimumSalary? ).
- *
- * @author rob
- *
- */
-public interface IQuery {
- String getTableName();
- void setParameter(String name, Object value);
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/IResultSet.java b/src/main/java/net/floodlightcontroller/storage/IResultSet.java
deleted file mode 100644
index fbd2a4a..0000000
--- a/src/main/java/net/floodlightcontroller/storage/IResultSet.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-import java.util.Date;
-import java.util.Map;
-
-/** Interface to iterate over the results from a storage query.
- *
- * @author rob
- *
- */
-public interface IResultSet extends Iterable<IResultSet> {
-
- /** This should be called when the client is done using the result set.
- * This will release any underlying resources (e.g. a database connection),
- * which you don't want to wait for or rely on finalizers to release.
- */
- public void close();
-
- /** Advance to the next row in the result set.
- * @return Returns true if there are more rows to process
- * (i.e. if there's a valid current row) and false if there are no more
- * rows in the result set.
- */
- public boolean next();
-
- /** Save/commit any pending updates to the data in the result set.
- * This must be called after any calls to the set methods or deleting rows
- * for the changes to be applied/committed to the storage source. Note that
- * this doesn't need to be called after each set method or even after each
- * row. It is typically called at the end after updating all of the
- * rows in the result set.
- */
- public void save();
-
- /** Get the current row in the result set. This returns all of the
- * columns in the current row.
- * @return Map containing all of the columns in the current row, indexed
- * by the column name.
- */
- public Map<String,Object> getRow();
-
- /** Delete the current row in the result set.
- */
- public void deleteRow();
-
- public boolean containsColumn(String columnName);
-
- public String getString(String columnName);
- public short getShort(String columnName);
- public int getInt(String columnName);
- public long getLong(String columnName);
- public float getFloat(String columnName);
- public double getDouble(String columnName);
- public boolean getBoolean(String columnName);
- public byte getByte(String columnName);
- public byte[] getByteArray(String columnName);
- public Date getDate(String columnName);
-
- public Short getShortObject(String columnName);
- public Integer getIntegerObject(String columnName);
- public Long getLongObject(String columnName);
- public Float getFloatObject(String columnName);
- public Double getDoubleObject(String columnName);
- public Boolean getBooleanObject(String columnName);
- public Byte getByteObject(String columnName);
-
- public boolean isNull(String columnName);
-
- public void setString(String columnName, String value);
- public void setShort(String columnName, short value);
- public void setInt(String columnName, int value);
- public void setLong(String columnName, long value);
- public void setFloat(String columnName, float value);
- public void setDouble(String columnName, double value);
- public void setBoolean(String columnName, boolean value);
- public void setByte(String columnName, byte value);
- public void setByteArray(String columnName, byte[] byteArray);
- public void setDate(String columnName, Date date);
-
- public void setShortObject(String columnName, Short value);
- public void setIntegerObject(String columnName, Integer value);
- public void setLongObject(String columnName, Long value);
- public void setFloatObject(String columnName, Float value);
- public void setDoubleObject(String columnName, Double value);
- public void setBooleanObject(String columnName, Boolean value);
- public void setByteObject(String columnName, Byte value);
-
- public void setNull(String columnName);
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/IRowMapper.java b/src/main/java/net/floodlightcontroller/storage/IRowMapper.java
deleted file mode 100644
index 6c4502b..0000000
--- a/src/main/java/net/floodlightcontroller/storage/IRowMapper.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-/**
- * Interface for mapping the current row in a result set to an object.
- * This is based on the Spring JDBC support.
- *
- * @author rob
- */
-public interface IRowMapper {
-
- /** This method must be implemented by the client of the storage API
- * to map the current row in the result set to a Java object.
- *
- * @param resultSet The result set obtained from a storage source query
- * @return The object created from the data in the result set
- */
- Object mapRow(IResultSet resultSet);
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/IStorageExceptionHandler.java b/src/main/java/net/floodlightcontroller/storage/IStorageExceptionHandler.java
deleted file mode 100644
index e3c8e94..0000000
--- a/src/main/java/net/floodlightcontroller/storage/IStorageExceptionHandler.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-public interface IStorageExceptionHandler {
- public void handleException(Exception exc);
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/IStorageSourceListener.java b/src/main/java/net/floodlightcontroller/storage/IStorageSourceListener.java
deleted file mode 100644
index ea3764d..0000000
--- a/src/main/java/net/floodlightcontroller/storage/IStorageSourceListener.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-import java.util.Set;
-
-public interface IStorageSourceListener {
-
- /**
- * Called when rows are inserted or updated in the table.
- *
- * @param tableName The table where the rows were inserted
- * @param rowKeys The keys of the rows that were inserted
- */
- public void rowsModified(String tableName, Set<Object> rowKeys);
-
- /**
- * Called when a new row is deleted from the table.
- *
- * @param tableName The table where the rows were deleted
- * @param rowKeys The keys of the rows that were deleted
- */
- public void rowsDeleted(String tableName, Set<Object> rowKeys);
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/IStorageSourceService.java b/src/main/java/net/floodlightcontroller/storage/IStorageSourceService.java
deleted file mode 100644
index b8a1be8..0000000
--- a/src/main/java/net/floodlightcontroller/storage/IStorageSourceService.java
+++ /dev/null
@@ -1,331 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Future;
-
-import net.floodlightcontroller.core.module.IFloodlightService;
-
-public interface IStorageSourceService extends IFloodlightService {
-
- /** Set the column to be used as the primary key for a table. This should
- * be guaranteed to be unique for all of the rows in the table, although the
- * storage API does not necessarily enforce this requirement. If no primary
- * key name is specified for a table then the storage API assumes there is
- * a column named "id" that is used as the primary key. In this case when
- * a new row is inserted using the storage API and no id is specified
- * explictly in the row data, the storage API automatically generates a
- * unique ID (typically a UUID) for the id column. To work across all
- * possible implementations of the storage API it is safest, though, to
- * specify the primary key column explicitly.
- * FIXME: It's sort of a kludge to have to specify the primary key column
- * here. Ideally there would be some sort of metadata -- perhaps stored
- * directly in the table, at least in the NoSQL case -- that the
- * storage API could query to obtain the primary key info.
- * @param tableName The name of the table for which we're setting the key
- * @param primaryKeyName The name of column to be used as the primary key
- */
- public void setTablePrimaryKeyName(String tableName, String primaryKeyName);
-
- /** Create a new table if one does not already exist with the given name.
- *
- * @param tableName The name of the table to create.
- * @param indexedColumns Which columns should be indexed
- */
- void createTable(String tableName, Set<String> indexedColumns);
-
- /**
- * @return the set of all tables that have been created via createTable
- */
- Set<String> getAllTableNames();
-
- /** Create a query object representing the given query parameters. The query
- * object can be passed to executeQuery to actually perform the query and obtain
- * a result set.
- *
- * @param tableName The name of the table to query.
- * @param columnNames The list of columns to return in the result set.
- * @param predicate The predicate that specifies which rows to return in the result set.
- * @param ordering Specification of order that rows are returned from the result set
- * returned from executing the query. If the ordering is null, then rows are returned
- * in an implementation-specific order.
- * @return Query object to be passed to executeQuery.
- */
- IQuery createQuery(String tableName, String[] columnNames, IPredicate predicate, RowOrdering ordering);
-
- /** Execute a query created with createQuery.
- *
- * @param query The query to execute
- * @return The result set containing the rows/columns specified in the query.
- */
- IResultSet executeQuery(IQuery query);
-
- /** Execute a query created with the given query parameters.
- *
- * @param tableName The name of the table to query.
- * @param columnNames The list of columns to return in the result set.
- * @param predicate The predicate that specifies which rows to return in the result set.
- * @param ordering Specification of order that rows are returned from the result set
- * returned from executing the query. If the ordering is null, then rows are returned
- * in an implementation-specific order.
- * @return The result set containing the rows/columns specified in the query.
- */
- IResultSet executeQuery(String tableName, String[] columnNames, IPredicate predicate,
- RowOrdering ordering);
-
- /** Execute a query and call the row mapper to map the results to Java objects.
- *
- * @param tableName The name of the table to query.
- * @param columnNames The list of columns to return in the result set.
- * @param predicate The predicate that specifies which rows to return in the result set.
- * @param ordering Specification of order that rows are returned from the result set
- * returned from executing the query. If the ordering is null, then rows are returned
- * in an implementation-specific order.
- * @param rowMapper The client-supplied object that maps the data in a row in the result
- * set to a client object.
- * @return The result set containing the rows/columns specified in the query.
- */
- Object[] executeQuery(String tableName, String[] columnNames, IPredicate predicate,
- RowOrdering ordering, IRowMapper rowMapper);
-
- /** Insert a new row in the table with the given column data.
- * If the primary key is the default value of "id" and is not specified in the
- * then a unique id will be automatically assigned to the row.
- * @param tableName The name of the table to which to add the row
- * @param values The map of column names/values to add to the table.
- */
- void insertRow(String tableName, Map<String,Object> values);
-
- /** Update or insert a list of rows in the table.
- * The primary key must be included in the map of values for each row.
- * @param tableName The table to update or insert into
- * @param values The map of column names/values to update the rows
- */
- void updateRows(String tableName, List<Map<String,Object>> rows);
-
- /** Update the rows in the given table. Any rows matching the predicate
- * are updated with the column names/values specified in the values map.
- * (The values map should not contain the special column "id".)
- * @param tableName The table to update
- * @param predicate The predicate to use to select which rows to update
- * @param values The map of column names/values to update the rows.
- */
- void updateMatchingRows(String tableName, IPredicate predicate, Map<String,Object> values);
-
- /** Update or insert a row in the table with the given row key (primary
- * key) and column names/values. (If the values map contains the special
- * column "id", its value must match rowId.)
- * @param tableName The table to update or insert into
- * @param rowKey The ID (primary key) of the row to update
- * @param values The map of column names/values to update the rows
- */
- void updateRow(String tableName, Object rowKey, Map<String,Object> values);
-
- /** Update or insert a row in the table with the given column data.
- * The primary key must be included in the map of values.
- * @param tableName The table to update or insert into
- * @param values The map of column names/values to update the rows
- */
- void updateRow(String tableName, Map<String,Object> values);
-
- /** Delete the row with the given primary key.
- *
- * @param tableName The table from which to delete the row
- * @param rowKey The primary key of the row to delete.
- */
- void deleteRow(String tableName, Object rowKey);
-
- /** Delete the rows with the given keys.
- *
- * @param tableName The table from which to delete the rows
- * @param rowKeys The set of primary keys of the rows to delete.
- */
- void deleteRows(String tableName, Set<Object> rowKeys);
-
- /**
- * Delete the rows that match the predicate
- * @param tableName
- * @param predicate
- */
- void deleteMatchingRows(String tableName, IPredicate predicate);
-
- /** Query for a row with the given ID (primary key).
- *
- * @param tableName The name of the table to query
- * @param rowKey The primary key of the row
- * @return The result set containing the row with the given ID
- */
- IResultSet getRow(String tableName, Object rowKey);
-
- /**
- * Set exception handler to use for asynchronous operations.
- * @param exceptionHandler
- */
- void setExceptionHandler(IStorageExceptionHandler exceptionHandler);
-
- /**
- * Asynchronous variant of executeQuery.
- *
- * @param query
- * @return
- */
- public Future<IResultSet> executeQueryAsync(final IQuery query);
-
- /**
- * Asynchronous variant of executeQuery.
- *
- * @param tableName
- * @param columnNames
- * @param predicate
- * @param ordering
- * @return
- */
- public Future<IResultSet> executeQueryAsync(final String tableName,
- final String[] columnNames, final IPredicate predicate,
- final RowOrdering ordering);
-
- /**
- * Asynchronous variant of executeQuery
- *
- * @param tableName
- * @param columnNames
- * @param predicate
- * @param ordering
- * @param rowMapper
- * @return
- */
- public Future<Object[]> executeQueryAsync(final String tableName,
- final String[] columnNames, final IPredicate predicate,
- final RowOrdering ordering, final IRowMapper rowMapper);
-
- /**
- * Asynchronous variant of insertRow.
- *
- * @param tableName
- * @param values
- * @return
- */
- public Future<?> insertRowAsync(final String tableName, final Map<String,Object> values);
-
- /**
- * Asynchronous variant of updateRows
- * @param tableName
- * @param rows
- */
- public Future<?> updateRowsAsync(final String tableName, final List<Map<String,Object>> rows);
-
- /**
- * Asynchronous variant of updateMatchingRows
- *
- * @param tableName
- * @param predicate
- * @param values
- * @return
- */
- public Future<?> updateMatchingRowsAsync(final String tableName, final IPredicate predicate,
- final Map<String,Object> values);
-
- /**
- * Asynchronous variant of updateRow
- *
- * @param tableName
- * @param rowKey
- * @param values
- * @return
- */
- public Future<?> updateRowAsync(final String tableName, final Object rowKey,
- final Map<String,Object> values);
-
- /**
- * Asynchronous version of updateRow
- *
- * @param tableName
- * @param values
- * @return
- */
- public Future<?> updateRowAsync(final String tableName, final Map<String,Object> values);
-
- /**
- * Asynchronous version of deleteRow
- *
- * @param tableName
- * @param rowKey
- * @return
- */
- public Future<?> deleteRowAsync(final String tableName, final Object rowKey);
-
- /**
- * Asynchronous version of deleteRows
- *
- * @param tableName
- * @param rowKeys
- * @return
- */
- public Future<?> deleteRowsAsync(final String tableName, final Set<Object> rowKeys);
-
- /**
- * Asynchronous version of deleteRows
- *
- * @param tableName
- * @param predicate
- * @return
- */
- public Future<?> deleteMatchingRowsAsync(final String tableName, final IPredicate predicate);
-
- /**
- * Asynchronous version of getRow
- *
- * @param tableName
- * @param rowKey
- * @return
- */
- public Future<?> getRowAsync(final String tableName, final Object rowKey);
-
- /**
- * Asynchronous version of save
- *
- * @param resultSet
- * @return
- */
- public Future<?> saveAsync(final IResultSet resultSet);
-
- /** Add a listener to the specified table. The listener is called
- * when any modifications are made to the table. You can add the same
- * listener instance to multiple tables, since the table name is
- * included as a parameter in the listener methods.
- * @param tableName The name of the table to listen for modifications
- * @param listener The listener instance to call
- */
- public void addListener(String tableName, IStorageSourceListener listener);
-
- /** Remove a listener from the specified table. The listener should
- * have been previously added to the table with addListener.
- * @param tableName The name of the table with the listener
- * @param listener The previously installed listener instance
- */
- public void removeListener(String tableName, IStorageSourceListener listener);
-
- /** This is logically a private method and should not be called by
- * clients of this interface.
- * @param notifications the notifications to dispatch
- */
- public void notifyListeners(List<StorageSourceNotification> notifications);
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/NullValueStorageException.java b/src/main/java/net/floodlightcontroller/storage/NullValueStorageException.java
deleted file mode 100644
index 0c148b8..0000000
--- a/src/main/java/net/floodlightcontroller/storage/NullValueStorageException.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-public class NullValueStorageException extends StorageException {
-
- private static final long serialVersionUID = 897572085681189926L;
-
- private static String makeExceptionMessage(String columnName) {
- String message = "Null column value could not be converted to built-in type";
- if (columnName != null) {
- message += ": column name = ";
- message += columnName;
- }
- return message;
- }
-
- public NullValueStorageException() {
- super(makeExceptionMessage(null));
- }
-
- public NullValueStorageException(String columnName) {
- super(makeExceptionMessage(columnName));
- }
-
- public NullValueStorageException(String columnName, Throwable exc) {
- super(makeExceptionMessage(columnName), exc);
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/OperatorPredicate.java b/src/main/java/net/floodlightcontroller/storage/OperatorPredicate.java
deleted file mode 100644
index dc78260..0000000
--- a/src/main/java/net/floodlightcontroller/storage/OperatorPredicate.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-/** Predicate class to specify rows by equality or comparison operations
- * of column values. The Storage API uses the special column name of "id"
- * to specify the primary key values for the row.
- *
- * @author rob
- */
-public class OperatorPredicate implements IPredicate {
-
- public enum Operator { EQ, LT, LTE, GT, GTE };
-
- private String columnName;
- private Operator operator;
- private Comparable<?> value;
-
- public OperatorPredicate(String columnName, Operator operator, Comparable<?> value) {
- this.columnName = columnName;
- this.operator = operator;
- this.value = value;
- }
-
- public String getColumnName() {
- return columnName;
- }
-
- public Operator getOperator() {
- return operator;
- }
-
- public Comparable<?> getValue() {
- return value;
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/ResultSetIterator.java b/src/main/java/net/floodlightcontroller/storage/ResultSetIterator.java
deleted file mode 100644
index 669833d..0000000
--- a/src/main/java/net/floodlightcontroller/storage/ResultSetIterator.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/** Iterator wrapper for an IResultSet, useful for iterating through query
- * results in an enhanced for (foreach) loop.
- *
- * Note that the iterator manipulates the state of the underlying IResultSet.
- */
-public class ResultSetIterator implements Iterator<IResultSet> {
- private IResultSet resultSet;
- private boolean hasAnother;
- private boolean peekedAtNext;
-
- public ResultSetIterator(IResultSet resultSet) {
- this.resultSet = resultSet;
- this.peekedAtNext = false;
- }
-
- @Override
- public IResultSet next() {
- if (!peekedAtNext) {
- hasAnother = resultSet.next();
- }
- peekedAtNext = false;
- if (!hasAnother)
- throw new NoSuchElementException();
- return resultSet;
- }
-
- @Override
- public boolean hasNext() {
- if (!peekedAtNext) {
- hasAnother = resultSet.next();
- peekedAtNext = true;
- }
- return hasAnother;
- }
-
- /** Row removal is not supported; use IResultSet.deleteRow instead.
- */
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/RowOrdering.java b/src/main/java/net/floodlightcontroller/storage/RowOrdering.java
deleted file mode 100644
index f9e61ed..0000000
--- a/src/main/java/net/floodlightcontroller/storage/RowOrdering.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class RowOrdering {
-
- public enum Direction { ASCENDING, DESCENDING };
-
- public class Item {
-
- private String column;
- private Direction direction;
-
- public Item(String column, Direction direction) {
- assert(column != null);
- assert(direction != null);
- this.column = column;
- this.direction = direction;
- }
-
- public String getColumn() {
- return column;
- }
-
- public Direction getDirection() {
- return direction;
- }
- }
-
- private List<Item> itemList = new ArrayList<Item>();
-
- public RowOrdering() {
- }
-
- public RowOrdering(String column) {
- add(column);
- }
-
- public RowOrdering(String column, Direction direction) {
- add(column, direction);
- }
-
- public RowOrdering(Item item) {
- add(item);
- }
-
- public RowOrdering(Item[] itemArray) {
- add(itemArray);
- }
-
- public RowOrdering(List<Item> itemList) {
- add(itemList);
- }
-
- public void add(String column) {
- itemList.add(new Item(column, Direction.ASCENDING));
- }
-
- public void add(String column, Direction direction) {
- itemList.add(new Item(column, direction));
- }
-
- public void add(Item item) {
- assert(item != null);
- itemList.add(item);
- }
-
- public void add(Item[] itemArray) {
- for (Item item: itemArray) {
- itemList.add(item);
- }
- }
-
- public void add(List<Item> itemList) {
- this.itemList.addAll(itemList);
- }
-
- public List<Item> getItemList() {
- return itemList;
- }
-
- public boolean equals(RowOrdering rowOrdering) {
- if (rowOrdering == null)
- return false;
-
- int len1 = itemList.size();
- int len2 = rowOrdering.getItemList().size();
- if (len1 != len2)
- return false;
-
- for (int i = 0; i < len1; i++) {
- Item item1 = itemList.get(i);
- Item item2 = rowOrdering.getItemList().get(i);
- if (!item1.getColumn().equals(item2.getColumn()) ||
- item1.getDirection() != item2.getDirection())
- return false;
- }
-
- return true;
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/StorageException.java b/src/main/java/net/floodlightcontroller/storage/StorageException.java
deleted file mode 100644
index f5dea23..0000000
--- a/src/main/java/net/floodlightcontroller/storage/StorageException.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-public class StorageException extends RuntimeException {
-
- static final long serialVersionUID = 7839989010156155681L;
-
- static private String makeExceptionMessage(String s) {
- String message = "Storage Exception";
- if (s != null) {
- message += ": ";
- message += s;
- }
- return message;
- }
-
- public StorageException() {
- super(makeExceptionMessage(null));
- }
-
- public StorageException(String s) {
- super(makeExceptionMessage(s));
- }
-
- public StorageException(String s, Throwable exc) {
- super(makeExceptionMessage(s), exc);
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/StorageNotificationFormatException.java b/src/main/java/net/floodlightcontroller/storage/StorageNotificationFormatException.java
deleted file mode 100644
index f6ce565..0000000
--- a/src/main/java/net/floodlightcontroller/storage/StorageNotificationFormatException.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-public class StorageNotificationFormatException extends StorageException {
- private static final long serialVersionUID = 504758477518283156L;
-
- public StorageNotificationFormatException() {
- super("Invalid storage notification format");
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/StorageSourceNotification.java b/src/main/java/net/floodlightcontroller/storage/StorageSourceNotification.java
deleted file mode 100644
index c9a5450..0000000
--- a/src/main/java/net/floodlightcontroller/storage/StorageSourceNotification.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-import java.util.Set;
-
-public class StorageSourceNotification {
-
- public enum Action { MODIFY, DELETE };
-
- private String tableName;
- private Action action;
- private Set<Object> keys;
-
- public StorageSourceNotification() {
- }
-
- public StorageSourceNotification(String tableName, Action action, Set<Object> keys) {
- this.tableName = tableName;
- this.action = action;
- this.keys = keys;
- }
-
- public String getTableName() {
- return tableName;
- }
-
- public Action getAction() {
- return action;
- }
-
- public Set<Object> getKeys() {
- return keys;
- }
-
- public void setTableName(String tableName) {
- this.tableName = tableName;
- }
-
- public void setAction(Action action) {
- this.action = action;
- }
-
- public void setKeys(Set<Object> keys) {
- this.keys = keys;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 7867;
- int result = 1;
- result = prime * result + tableName.hashCode();
- result = prime * result + action.hashCode();
- result = prime * result + keys.hashCode();
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof StorageSourceNotification))
- return false;
- StorageSourceNotification other = (StorageSourceNotification) obj;
- if (tableName == null) {
- if (other.tableName != null)
- return false;
- } else if (!tableName.equals(other.tableName))
- return false;
- if (action == null) {
- if (other.action != null)
- return false;
- } else if (action != other.action)
- return false;
- if (keys == null) {
- if (other.keys != null)
- return false;
- } else if (!keys.equals(other.keys))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return ("StorageNotification[table=" + tableName + "; action=" +
- action.toString() + "; keys=" + keys.toString() + "]");
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/SynchronousExecutorService.java b/src/main/java/net/floodlightcontroller/storage/SynchronousExecutorService.java
deleted file mode 100644
index f1e7cd3..0000000
--- a/src/main/java/net/floodlightcontroller/storage/SynchronousExecutorService.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-public class SynchronousExecutorService implements ExecutorService {
-
- class SynchronousFuture<T> implements Future<T> {
-
- T result;
- Exception exc;
-
- public SynchronousFuture() {
- }
-
- public SynchronousFuture(T result) {
- this.result = result;
- }
-
- public SynchronousFuture(Exception exc) {
- this.exc = exc;
- }
-
- @Override
- public boolean cancel(boolean mayInterruptIfRunning) {
- return false;
- }
-
- @Override
- public boolean isCancelled() {
- return false;
- }
-
- @Override
- public boolean isDone() {
- return true;
- }
-
- @Override
- public T get() throws InterruptedException, ExecutionException {
- if (exc != null)
- throw new ExecutionException(exc);
- return result;
- }
-
- @Override
- public T get(long timeout, TimeUnit unit) throws InterruptedException,
- ExecutionException, TimeoutException {
- return get();
- }
- }
-
- @Override
- public void shutdown() {
- }
-
- @Override
- public List<Runnable> shutdownNow() {
- return null;
- }
-
- @Override
- public boolean isShutdown() {
- return false;
- }
-
- @Override
- public boolean isTerminated() {
- return false;
- }
-
- @Override
- public boolean awaitTermination(long timeout, TimeUnit unit)
- throws InterruptedException {
- return false;
- }
-
- @Override
- public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
- throws InterruptedException {
- List<Future<T>> l = new ArrayList<Future<T>>();
- for (Callable<T> task : tasks) {
- Future<T> future = submit(task);
- l.add(future);
- }
- return l;
- }
-
- @Override
- public <T> List<Future<T>> invokeAll(
- Collection<? extends Callable<T>> tasks, long timeout, TimeUnit units)
- throws InterruptedException {
- return invokeAll(tasks);
- }
-
- @Override
- public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
- throws InterruptedException, ExecutionException {
- for (Callable<T> task : tasks) {
- try {
- task.call();
- } catch (Exception e) {
-
- }
- }
- throw new ExecutionException(new Exception("no task completed successfully"));
- }
-
- @Override
- public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout,
- TimeUnit units) throws InterruptedException, ExecutionException,
- TimeoutException {
- return invokeAny(tasks);
- }
-
- @Override
- public <T> Future<T> submit(Callable<T> callable) {
- try {
- T result = callable.call();
- return new SynchronousFuture<T>(result);
- }
- catch (Exception exc) {
- return new SynchronousFuture<T>(exc);
- }
- }
-
- @Override
- public Future<?> submit(Runnable runnable) {
- try {
- runnable.run();
- return new SynchronousFuture<Void>();
- }
- catch (Exception exc) {
- return new SynchronousFuture<Void>(exc);
- }
- }
-
- @Override
- public <T> Future<T> submit(Runnable runnable, T result) {
- try {
- runnable.run();
- return new SynchronousFuture<T>(result);
- }
- catch (Exception exc) {
- return new SynchronousFuture<T>(exc);
- }
- }
-
- @Override
- public void execute(Runnable command) {
- command.run();
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/TypeMismatchStorageException.java b/src/main/java/net/floodlightcontroller/storage/TypeMismatchStorageException.java
deleted file mode 100644
index 5643140..0000000
--- a/src/main/java/net/floodlightcontroller/storage/TypeMismatchStorageException.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage;
-
-public class TypeMismatchStorageException extends StorageException {
-
- private static final long serialVersionUID = -7923586656854871345L;
-
- private static String makeExceptionMessage(String requestedType, String actualType, String columnName) {
- if (requestedType == null)
- requestedType = "???";
- if (actualType == null)
- actualType = "???";
- if (columnName == null)
- columnName = "???";
- String message = "The requested type (" + requestedType + ") does not match the actual type (" + actualType + ") of the value for column \"" + columnName + "\".";
- return message;
- }
-
- public TypeMismatchStorageException() {
- super(makeExceptionMessage(null, null, null));
- }
-
- public TypeMismatchStorageException(String requestedType, String actualType, String columnName) {
- super(makeExceptionMessage(requestedType, actualType, columnName));
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/memory/MemoryStorageSource.java b/src/main/java/net/floodlightcontroller/storage/memory/MemoryStorageSource.java
deleted file mode 100644
index 8a69eca..0000000
--- a/src/main/java/net/floodlightcontroller/storage/memory/MemoryStorageSource.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage.memory;
-
-import net.floodlightcontroller.core.module.FloodlightModuleContext;
-import net.floodlightcontroller.perfmon.IPktInProcessingTimeService;
-import net.floodlightcontroller.storage.nosql.NoSqlStorageSource;
-import net.floodlightcontroller.storage.SynchronousExecutorService;
-import net.floodlightcontroller.storage.IStorageSourceService;
-import net.floodlightcontroller.core.module.IFloodlightService;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import net.floodlightcontroller.storage.StorageException;
-
-public class MemoryStorageSource extends NoSqlStorageSource {
-
- private Map<String, MemoryTable> tableMap = new HashMap<String,MemoryTable>();
- IPktInProcessingTimeService pktinProcessingTime;
-
- synchronized private MemoryTable getTable(String tableName, boolean create) {
- MemoryTable table = tableMap.get(tableName);
- if (table == null) {
- if (!create)
- throw new StorageException("Table " + tableName + " does not exist");
- table = new MemoryTable(tableName);
- tableMap.put(tableName, table);
- }
- return table;
- }
-
- @Override
- protected Collection<Map<String,Object>> getAllRows(String tableName, String[] columnNameList) {
- MemoryTable table = getTable(tableName, false);
- return table.getAllRows();
- }
-
- @Override
- protected Map<String,Object> getRow(String tableName, String[] columnNameList, Object rowKey) {
- MemoryTable table = getTable(tableName, false);
- return table.getRow(rowKey);
- }
-
- @Override
- protected List<Map<String,Object>> executeEqualityQuery(String tableName,
- String[] columnNameList, String predicateColumnName, Comparable<?> value) {
- MemoryTable table = getTable(tableName, false);
- List<Map<String,Object>> result = new ArrayList<Map<String,Object>>();
- synchronized (table) {
- Collection<Map<String,Object>> allRows = table.getAllRows();
- for (Map<String,Object> row : allRows) {
- Object v = row.get(predicateColumnName);
- if (value.equals(v)) {
- result.add(row);
- }
- }
- }
- return result;
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @Override
- protected List<Map<String,Object>> executeRangeQuery(String tableName,
- String[] columnNameList, String predicateColumnName,
- Comparable<?> startValue, boolean startInclusive, Comparable<?> endValue, boolean endInclusive) {
- MemoryTable table = getTable(tableName, false);
- List<Map<String,Object>> result = new ArrayList<Map<String,Object>>();
- synchronized (table) {
- Collection<Map<String,Object>> allRows = table.getAllRows();
- for (Map<String,Object> row : allRows) {
- Comparable value = (Comparable) row.get(predicateColumnName);
- if (value != null) {
- int compareResult = value.compareTo(startValue);
- if ((compareResult > 0) || (startInclusive && (compareResult >= 0))) {
- compareResult = value.compareTo(endValue);
- if ((compareResult < 0) || (startInclusive && (compareResult <= 0))) {
- result.add(row);
- }
- }
- }
- }
- }
- return result;
- }
-
- @Override
- protected void insertRows(String tableName, List<Map<String,Object>> insertRowList) {
- MemoryTable table = getTable(tableName, false);
- String primaryKeyName = getTablePrimaryKeyName(tableName);
- synchronized (table) {
- for (Map<String,Object> row : insertRowList) {
- Object primaryKey = row.get(primaryKeyName);
- if (primaryKey == null) {
- if (primaryKeyName.equals(DEFAULT_PRIMARY_KEY_NAME)) {
- row = new HashMap<String,Object>(row);
- primaryKey = table.getNextId();
- row.put(primaryKeyName, primaryKey);
- }
- }
- table.insertRow(primaryKey, row);
- }
- }
- }
-
- @Override
- protected void updateRows(String tableName, Set<Object> rowKeys, Map<String,Object> updateRowList) {
- MemoryTable table = getTable(tableName, false);
- synchronized (table) {
- for (Object rowKey : rowKeys) {
- Map<String,Object> row = table.getRow(rowKey);
- if (row == null)
- row = table.newRow(rowKey);
- for (Map.Entry<String,Object> entry: updateRowList.entrySet()) {
- row.put(entry.getKey(), entry.getValue());
- }
- }
- }
- }
-
- @Override
- protected void updateRowsImpl(String tableName, List<Map<String,Object>> updateRowList) {
- MemoryTable table = getTable(tableName, false);
- String primaryKeyName = getTablePrimaryKeyName(tableName);
- synchronized (table) {
- for (Map<String,Object> updateRow : updateRowList) {
- Object rowKey = updateRow.get(primaryKeyName);
- if (rowKey == null)
- throw new StorageException("Primary key not found.");
- Map<String,Object> row = table.getRow(rowKey);
- if (row == null)
- row = table.newRow(rowKey);
- for (Map.Entry<String,Object> entry: updateRow.entrySet()) {
- row.put(entry.getKey(), entry.getValue());
- }
- }
- }
- }
-
- @Override
- protected void deleteRowsImpl(String tableName, Set<Object> rowKeys) {
- MemoryTable table = getTable(tableName, false);
- synchronized (table) {
- for (Object rowKey : rowKeys) {
- table.deleteRow(rowKey);
- }
- }
- }
-
- @Override
- public void createTable(String tableName, Set<String> indexedColumnNames) {
- super.createTable(tableName, indexedColumnNames);
- getTable(tableName, true);
- }
-
- public void setPktinProcessingTime(
- IPktInProcessingTimeService pktinProcessingTime) {
- this.pktinProcessingTime = pktinProcessingTime;
- }
-
- // IFloodlightModule methods
-
- @Override
- public void startUp(FloodlightModuleContext context) {
- super.startUp(context);
- executorService = new SynchronousExecutorService();
- }
-
- @Override
- public Map<Class<? extends IFloodlightService>,
- IFloodlightService> getServiceImpls() {
- Map<Class<? extends IFloodlightService>,
- IFloodlightService> m =
- new HashMap<Class<? extends IFloodlightService>,
- IFloodlightService>();
- m.put(IStorageSourceService.class, this);
- return m;
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/memory/MemoryTable.java b/src/main/java/net/floodlightcontroller/storage/memory/MemoryTable.java
deleted file mode 100644
index f87ee45..0000000
--- a/src/main/java/net/floodlightcontroller/storage/memory/MemoryTable.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage.memory;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.TreeMap;
-
-public class MemoryTable {
-
- private String tableName;
- private Map<Object,Map<String,Object>> rowMap;
- private int nextId;
-
- MemoryTable(String tableName) {
- this.tableName = tableName;
- rowMap = new TreeMap<Object,Map<String,Object>>();
- nextId = 0;
- }
-
- String getTableName() {
- return tableName;
- }
-
- Collection<Map<String,Object>> getAllRows() {
- return rowMap.values();
- }
-
- Map<String,Object> getRow(Object key) {
- Map<String,Object> row = rowMap.get(key);
- return row;
- }
-
- // rkv: Do we still need this? Probably needs to be tweaked a bit
- // to work with the support for specifying which column to use as the
- // primary key
- Map<String,Object> newRow(Object key) {
- Map<String,Object> row = new HashMap<String, Object>();
- row.put("id", key);
- rowMap.put(key, row);
- return row;
- }
-
- void insertRow(Object key, Map<String,Object> rowValues) {
- assert(key != null);
- rowMap.put(key, rowValues);
- }
-
- void deleteRow(Object rowKey) {
- rowMap.remove(rowKey);
- }
-
- Integer getNextId() {
- return new Integer(++nextId);
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/nosql/NoSqlQuery.java b/src/main/java/net/floodlightcontroller/storage/nosql/NoSqlQuery.java
deleted file mode 100644
index 05f8fc7..0000000
--- a/src/main/java/net/floodlightcontroller/storage/nosql/NoSqlQuery.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage.nosql;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import net.floodlightcontroller.storage.IPredicate;
-import net.floodlightcontroller.storage.IQuery;
-import net.floodlightcontroller.storage.RowOrdering;
-
-public class NoSqlQuery implements IQuery {
-
- private String tableName;
- private String[] columnNameList;
- private IPredicate predicate;
- private RowOrdering rowOrdering;
- private Map<String,Comparable<?>> parameterMap;
-
- NoSqlQuery(String className, String[] columnNameList, IPredicate predicate, RowOrdering rowOrdering) {
- this.tableName = className;
- this.columnNameList = columnNameList;
- this.predicate = predicate;
- this.rowOrdering = rowOrdering;
- }
-
- @Override
- public void setParameter(String name, Object value) {
- if (parameterMap == null)
- parameterMap = new HashMap<String,Comparable<?>>();
- parameterMap.put(name, (Comparable<?>)value);
- }
-
- @Override
- public String getTableName() {
- return tableName;
- }
-
- String[] getColumnNameList() {
- return columnNameList;
- }
-
- IPredicate getPredicate() {
- return predicate;
- }
-
- RowOrdering getRowOrdering() {
- return rowOrdering;
- }
-
- Comparable<?> getParameter(String name) {
- Comparable<?> value = null;
- if (parameterMap != null) {
- value = parameterMap.get(name);
- }
- return value;
- }
-
- Map<String,Comparable<?>> getParameterMap() {
- return parameterMap;
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/nosql/NoSqlResultSet.java b/src/main/java/net/floodlightcontroller/storage/nosql/NoSqlResultSet.java
deleted file mode 100644
index b3a8c20..0000000
--- a/src/main/java/net/floodlightcontroller/storage/nosql/NoSqlResultSet.java
+++ /dev/null
@@ -1,487 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage.nosql;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.TimeZone;
-
-import net.floodlightcontroller.storage.IResultSet;
-import net.floodlightcontroller.storage.NullValueStorageException;
-import net.floodlightcontroller.storage.ResultSetIterator;
-import net.floodlightcontroller.storage.StorageException;
-import net.floodlightcontroller.storage.TypeMismatchStorageException;
-
-public class NoSqlResultSet implements IResultSet {
-
- NoSqlStorageSource storageSource;
- String tableName;
- String primaryKeyName;
- List<Map<String,Object>> rowList;
- int currentIndex;
- Map<String,Object> currentRowUpdate;
- List<Map<String,Object>> rowUpdateList;
- Set<Object> rowDeleteSet;
- Iterator<IResultSet> resultSetIterator;
-
- NoSqlResultSet(NoSqlStorageSource storageSource, String tableName, List<Map<String,Object>> rowList) {
- this.storageSource = storageSource;
- this.primaryKeyName = storageSource.getTablePrimaryKeyName(tableName);
- this.tableName = tableName;
- if (rowList == null)
- rowList = new ArrayList<Map<String,Object>>();
- this.rowList = rowList;
- currentIndex = -1;
- }
-
- void addRow(Map<String,Object> row) {
- rowList.add(row);
- }
-
- @Override
- public Map<String,Object> getRow() {
- if ((currentIndex < 0) || (currentIndex >= rowList.size())) {
- throw new StorageException("No current row in result set.");
- }
-
- return rowList.get(currentIndex);
- }
-
- @Override
- public boolean containsColumn(String columnName) {
- return getObject(columnName) != null;
- }
-
- @Override
- public void close() {
- }
-
- private void endCurrentRowUpdate() {
- if (currentRowUpdate != null) {
- if (rowUpdateList == null)
- rowUpdateList = new ArrayList<Map<String,Object>>();
- rowUpdateList.add(currentRowUpdate);
- currentRowUpdate = null;
- }
- }
-
- @Override
- public boolean next() {
- endCurrentRowUpdate();
- currentIndex++;
- return currentIndex < rowList.size();
- }
-
- @Override
- public void save() {
- endCurrentRowUpdate();
-
- if (rowUpdateList != null) {
- storageSource.updateRows(tableName, rowUpdateList);
- rowUpdateList = null;
- }
-
- if (rowDeleteSet != null) {
- storageSource.deleteRows(tableName, rowDeleteSet);
- rowDeleteSet = null;
- }
- }
-
- Object getObject(String columnName) {
- Map<String,Object> row = rowList.get(currentIndex);
- Object value = row.get(columnName);
- return value;
- }
-
- @Override
- public boolean getBoolean(String columnName) {
- Boolean b = getBooleanObject(columnName);
- if (b == null)
- throw new NullValueStorageException(columnName);
- return b.booleanValue();
- }
-
- @Override
- public byte getByte(String columnName) {
- Byte b = getByteObject(columnName);
- if (b == null)
- throw new NullValueStorageException(columnName);
- return b.byteValue();
- }
-
- @Override
- public byte[] getByteArray(String columnName) {
- byte[] b = null;
- Object obj = getObject(columnName);
- if (obj != null) {
- if (!(obj instanceof byte[]))
- throw new StorageException("Invalid byte array value");
- b = (byte[])obj;
- }
- return b;
- }
-
- @Override
- public double getDouble(String columnName) {
- Double d = getDoubleObject(columnName);
- if (d == null)
- throw new NullValueStorageException(columnName);
- return d.doubleValue();
- }
-
- @Override
- public float getFloat(String columnName) {
- Float f = getFloatObject(columnName);
- if (f == null)
- throw new NullValueStorageException(columnName);
- return f.floatValue();
- }
-
- @Override
- public int getInt(String columnName) {
- Integer i = getIntegerObject(columnName);
- if (i == null)
- throw new NullValueStorageException(columnName);
- return i.intValue();
- }
-
- @Override
- public long getLong(String columnName) {
- Long l = getLongObject(columnName);
- if (l == null)
- throw new NullValueStorageException(columnName);
- return l.longValue();
- }
-
- @Override
- public short getShort(String columnName) {
- Short s = getShortObject(columnName);
- if (s == null)
- throw new NullValueStorageException(columnName);
- return s.shortValue();
- }
-
- @Override
- public String getString(String columnName) {
- Object obj = getObject(columnName);
- if (obj == null)
- return null;
- return obj.toString();
- }
-
- @Override
- public Date getDate(String column) {
- Date d;
- Object obj = getObject(column);
- if (obj == null) {
- d = null;
- } else if (obj instanceof Date) {
- d = (Date) obj;
- } else {
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
- dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
- try {
- d = dateFormat.parse(obj.toString());
- }
- catch (ParseException exc) {
- throw new TypeMismatchStorageException(Date.class.getName(), obj.getClass().getName(), column);
- }
- }
- return d;
- }
-
-
- @Override
- public Short getShortObject(String columnName)
- {
- Short s;
- Object obj = getObject(columnName);
- if (obj instanceof Short) {
- s = (Short)obj;
- } else if (obj != null) {
- try {
- s = Short.parseShort(obj.toString());
- }
- catch (NumberFormatException exc) {
- throw new TypeMismatchStorageException(Short.class.getName(), obj.getClass().getName(), columnName);
- }
- } else {
- s = null;
- }
- return s;
- }
-
- @Override
- public Integer getIntegerObject(String columnName)
- {
- Integer i;
- Object obj = getObject(columnName);
- if (obj instanceof Integer) {
- i = (Integer)obj;
- } else if (obj != null) {
- try {
- i = Integer.parseInt(obj.toString());
- }
- catch (NumberFormatException exc) {
- throw new TypeMismatchStorageException(Integer.class.getName(), obj.getClass().getName(), columnName);
- }
- } else {
- i = null;
- }
- return i;
- }
-
- @Override
- public Long getLongObject(String columnName)
- {
- Long l;
- Object obj = getObject(columnName);
- if (obj instanceof Long) {
- l = (Long)obj;
- } else if (obj != null) {
- try {
- l = Long.parseLong(obj.toString());
- }
- catch (NumberFormatException exc) {
- throw new TypeMismatchStorageException(Long.class.getName(), obj.getClass().getName(), columnName);
- }
- } else {
- l = null;
- }
- return l;
- }
-
- @Override
- public Float getFloatObject(String columnName)
- {
- Float f;
- Object obj = getObject(columnName);
- if (obj instanceof Float) {
- f = (Float)obj;
- } else if (obj != null) {
- try {
- f = Float.parseFloat(obj.toString());
- }
- catch (NumberFormatException exc) {
- throw new TypeMismatchStorageException(Float.class.getName(), obj.getClass().getName(), columnName);
- }
- } else {
- f = null;
- }
- return f;
- }
-
- @Override
- public Double getDoubleObject(String columnName)
- {
- Double d;
- Object obj = getObject(columnName);
- if (obj instanceof Double) {
- d = (Double)obj;
- } else if (obj != null) {
- try {
- d = Double.parseDouble(obj.toString());
- }
- catch (NumberFormatException exc) {
- throw new TypeMismatchStorageException(Double.class.getName(), obj.getClass().getName(), columnName);
- }
- } else {
- d = null;
- }
- return d;
- }
-
- @Override
- public Boolean getBooleanObject(String columnName)
- {
- Boolean b;
- Object obj = getObject(columnName);
- if (obj instanceof Boolean) {
- b = (Boolean)obj;
- } else if (obj != null) {
- try {
- b = Boolean.parseBoolean(obj.toString());
- }
- catch (NumberFormatException exc) {
- throw new TypeMismatchStorageException(Boolean.class.getName(), obj.getClass().getName(), columnName);
- }
- } else {
- b = null;
- }
- return b;
- }
-
- @Override
- public Byte getByteObject(String columnName)
- {
- Byte b;
- Object obj = getObject(columnName);
- if (obj instanceof Byte) {
- b = (Byte)obj;
- } else if (obj != null) {
- try {
- b = Byte.parseByte(obj.toString());
- }
- catch (NumberFormatException exc) {
- throw new TypeMismatchStorageException(Byte.class.getName(), obj.getClass().getName(), columnName);
- }
- } else {
- b = null;
- }
- return b;
- }
-
-
- @Override
- public boolean isNull(String columnName)
- {
- Object obj = getObject(columnName);
- return (obj == null);
- }
-
- private void addRowUpdate(String column, Object value) {
- if (currentRowUpdate == null) {
- currentRowUpdate = new HashMap<String,Object>();
- Object key = rowList.get(currentIndex).get(primaryKeyName);
- currentRowUpdate.put(primaryKeyName, key);
- }
- currentRowUpdate.put(column, value);
- }
-
- @Override
- public void setBoolean(String columnName, boolean value) {
- addRowUpdate(columnName, value);
- }
-
- @Override
- public void setByte(String columnName, byte value) {
- addRowUpdate(columnName, value);
- }
-
- @Override
- public void setByteArray(String columnName, byte[] byteArray) {
- addRowUpdate(columnName, byteArray);
- }
-
- @Override
- public void setDouble(String columnName, double value) {
- addRowUpdate(columnName, value);
- }
-
- @Override
- public void setFloat(String columnName, float value) {
- addRowUpdate(columnName, value);
- }
-
- @Override
- public void setInt(String columnName, int value) {
- addRowUpdate(columnName, value);
- }
-
- @Override
- public void setLong(String columnName, long value) {
- addRowUpdate(columnName, value);
- }
-
- @Override
- public void setShort(String columnName, short value) {
- addRowUpdate(columnName, value);
- }
-
- @Override
- public void setString(String columnName, String value) {
- addRowUpdate(columnName, value);
- }
-
- @Override
- public void setShortObject(String columnName, Short value)
- {
- addRowUpdate(columnName, value);
- }
-
- @Override
- public void setIntegerObject(String columnName, Integer value)
- {
- addRowUpdate(columnName, value);
- }
-
- @Override
- public void setLongObject(String columnName, Long value)
- {
- addRowUpdate(columnName, value);
- }
-
- @Override
- public void setFloatObject(String columnName, Float value)
- {
- addRowUpdate(columnName, value);
- }
-
- @Override
- public void setDoubleObject(String columnName, Double value)
- {
- addRowUpdate(columnName, value);
- }
-
- @Override
- public void setBooleanObject(String columnName, Boolean value)
- {
- addRowUpdate(columnName, value);
- }
-
- @Override
- public void setByteObject(String columnName, Byte value)
- {
- addRowUpdate(columnName, value);
- }
-
- @Override
- public void setDate(String column, Date value) {
- addRowUpdate(column, value);
- }
-
-
- public void setNull(String columnName)
- {
- addRowUpdate(columnName, null);
- }
-
-
- @Override
- public void deleteRow() {
- Object key = (String) rowList.get(currentIndex).get(primaryKeyName);
- if (rowDeleteSet == null)
- rowDeleteSet = new HashSet<Object>();
- rowDeleteSet.add(key);
- }
-
- @Override
- public Iterator<IResultSet> iterator() {
- if (resultSetIterator == null)
- resultSetIterator = new ResultSetIterator(this);
- return resultSetIterator;
- }
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/nosql/NoSqlStorageSource.java b/src/main/java/net/floodlightcontroller/storage/nosql/NoSqlStorageSource.java
deleted file mode 100644
index 6624932..0000000
--- a/src/main/java/net/floodlightcontroller/storage/nosql/NoSqlStorageSource.java
+++ /dev/null
@@ -1,823 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage.nosql;
-
-import java.lang.Class;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TimeZone;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import net.floodlightcontroller.storage.AbstractStorageSource;
-import net.floodlightcontroller.storage.CompoundPredicate;
-import net.floodlightcontroller.storage.IPredicate;
-import net.floodlightcontroller.storage.IQuery;
-import net.floodlightcontroller.storage.IResultSet;
-import net.floodlightcontroller.storage.OperatorPredicate;
-import net.floodlightcontroller.storage.RowOrdering;
-import net.floodlightcontroller.storage.StorageException;
-import net.floodlightcontroller.storage.StorageSourceNotification;
-import net.floodlightcontroller.storage.TypeMismatchStorageException;
-
-public abstract class NoSqlStorageSource extends AbstractStorageSource {
- protected final static Logger log = LoggerFactory.getLogger(NoSqlStorageSource.class);
-
- public enum ColumnIndexMode { NOT_INDEXED, RANGE_INDEXED, EQUALITY_INDEXED };
-
- protected static final String DEFAULT_PRIMARY_KEY_NAME = "id";
-
- private Map<String,String> tablePrimaryKeyMap = new HashMap<String,String>();
- private Map<String, Map<String,ColumnIndexMode>> tableIndexedColumnMap =
- new HashMap<String,Map<String,ColumnIndexMode>>();
-
- abstract class NoSqlPredicate {
-
- public boolean incorporateComparison(String columnName,
- OperatorPredicate.Operator operator, Comparable<?> value,
- CompoundPredicate.Operator parentOperator) {
- return false;
- }
-
- public boolean canExecuteEfficiently() {
- return false;
- }
-
- public List<Map<String,Object>> execute(String[] columnNames) {
- assert(false);
- return null;
- }
-
- abstract public boolean matchesRow(Map<String,Object> row);
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- class NoSqlRangePredicate extends NoSqlPredicate {
- NoSqlStorageSource storageSource;
- String tableName;
- String columnName;
- Comparable<?> startValue;
- boolean startInclusive;
- Comparable<?> endValue;
- boolean endInclusive;
-
- NoSqlRangePredicate(NoSqlStorageSource storageSource, String tableName,
- String columnName, Comparable<?> startValue, boolean startInclusive,
- Comparable<?> endValue, boolean endInclusive) {
- this.storageSource = storageSource;
- this.tableName = tableName;
- this.columnName = columnName;
- this.startValue = startValue;
- this.startInclusive = startInclusive;
- this.endValue = endValue;
- this.endInclusive = endInclusive;
- }
-
- public boolean incorporateComparison(String columnName,
- OperatorPredicate.Operator operator, Comparable<?> value,
- CompoundPredicate.Operator parentOperator) {
-
- assert(operator != null);
- assert(parentOperator != null);
-
- // Must be the same column to incorporate
- if (!this.columnName.equals(columnName))
- return false;
-
- // The only time we allow a null value is if it's an EQ operator.
- // In that case we can only incorporate if this predicate is also
- // a null equality predicate.
- if (value == null) {
- return ((operator == OperatorPredicate.Operator.EQ) &&
- (startValue == null) && (endValue == null) &&
- startInclusive && endInclusive);
- }
-
- // Don't incorporate parameterized values
- if (value instanceof String) {
- String s = (String)value;
- if (s.startsWith("?") && s.endsWith("?")) {
- return false;
- }
- }
-
- if (parentOperator == CompoundPredicate.Operator.AND) {
- switch (operator) {
- case EQ:
- if (matchesValue(value)) {
- startValue = endValue = value;
- startInclusive = endInclusive = true;
- return true;
- }
- break;
- case LT:
- if ((endValue == null) || (((Comparable)value).compareTo(endValue) <= 0)) {
- endValue = value;
- endInclusive = false;
- return true;
- }
- break;
- case LTE:
- if ((endValue == null) || (((Comparable)value).compareTo(endValue) < 0)) {
- endValue = value;
- endInclusive = true;
- return true;
- }
- break;
- case GT:
- if ((startValue == null) || (((Comparable)value).compareTo(startValue) >= 0)) {
- startValue = value;
- startInclusive = false;
- return true;
- }
- break;
- case GTE:
- if ((startValue == null) || (((Comparable)value).compareTo(startValue) > 0)) {
- startValue = value;
- startInclusive = true;
- return true;
- }
- break;
- }
- } else {
- switch (operator) {
- case EQ:
- if (matchesValue(value))
- return true;
- break;
- case LT:
- if ((endValue == null) || (((Comparable)value).compareTo(endValue) > 0)) {
- endValue = value;
- endInclusive = false;
- return true;
- }
- break;
- case LTE:
- if ((endValue == null) || (((Comparable)value).compareTo(endValue) >= 0)) {
- endValue = value;
- endInclusive = true;
- return true;
- }
- break;
- case GT:
- if ((startValue == null) || (((Comparable)value).compareTo(startValue) < 0)) {
- startValue = value;
- startInclusive = false;
- return true;
- }
- break;
- case GTE:
- if ((startValue == null) || (((Comparable)value).compareTo(startValue) <= 0)) {
- startValue = value;
- startInclusive = true;
- return true;
- }
- break;
- }
- }
-
- return false;
- }
-
- private boolean isEqualityRange() {
- return (startValue == endValue) && startInclusive && endInclusive;
- }
-
- public boolean canExecuteEfficiently() {
- ColumnIndexMode indexMode = storageSource.getColumnIndexMode(tableName, columnName);
- switch (indexMode) {
- case NOT_INDEXED:
- return false;
- case RANGE_INDEXED:
- return true;
- case EQUALITY_INDEXED:
- return isEqualityRange();
- }
- return true;
- }
-
- public List<Map<String,Object>> execute(String columnNameList[]) {
- List<Map<String,Object>> rowList;
- if (isEqualityRange())
- rowList = storageSource.executeEqualityQuery(tableName, columnNameList, columnName, startValue);
- else
- rowList = storageSource.executeRangeQuery(tableName, columnNameList, columnName,
- startValue, startInclusive, endValue, endInclusive);
-
- return rowList;
- }
-
- Comparable<?> coerceValue(Comparable<?> value, Class targetClass) {
-
- if (value == null)
- return null;
-
- if (value.getClass() == targetClass)
- return value;
-
- // FIXME: For now we convert by first converting the source value to a
- // string and then converting to the target type. This logic probably needs
- // another pass to make it more robust/optimized.
-
- String s = value.toString();
- Comparable<?> obj = null;
-
- try {
- if (targetClass == Integer.class) {
- obj = new Integer(s);
- } else if (targetClass == Long.class) {
- obj = new Long(s);
- } else if (targetClass == Short.class) {
- obj = new Short(s);
- } else if (targetClass == Boolean.class) {
- obj = new Boolean(s);
- } else if (targetClass == Float.class) {
- obj = new Float(s);
- } else if (targetClass == Double.class) {
- obj = new Double(s);
- } else if (targetClass == Byte.class) {
- obj = new Byte(s);
- } else if (targetClass == String.class) {
- obj = s;
- } else if (targetClass == Date.class) {
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
- dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
- try {
- obj = dateFormat.parse(s);
- }
- catch (ParseException exc) {
- throw new TypeMismatchStorageException(Date.class.getName(), value.getClass().getName(), "???");
- }
- }
- }
- catch (Exception exc) {
- // Ignore the exception here. In this case obj will not be set, so we'll
- // throw the StorageException below when we check for a null obj.
- }
-
- if (obj == null)
- throw new StorageException("Column value could not be coerced to the correct type");
-
- return obj;
- }
-
- boolean matchesValue(Comparable<?> value) {
- boolean isNullEqPredicate = (startValue == null) && (endValue == null) && startInclusive && endInclusive;
- if (value == null)
- return isNullEqPredicate;
-
- if (isNullEqPredicate)
- return false;
-
- int result;
- Comparable<?> coercedValue;
- if (startValue != null) {
- coercedValue = coerceValue(value, startValue.getClass());
- result = ((Comparable)coercedValue).compareTo(startValue);
- if ((result < 0) || (!startInclusive && (result == 0)))
- return false;
- }
- if (endValue != null) {
- coercedValue = coerceValue(value, endValue.getClass());
- result = ((Comparable)coercedValue).compareTo(endValue);
- if ((result > 0) || (!endInclusive && (result == 0)))
- return false;
- }
- return true;
- }
-
- public boolean matchesRow(Map<String,Object> row) {
- Comparable value = (Comparable)row.get(columnName);
- return matchesValue(value);
- }
- }
-
- class NoSqlOperatorPredicate extends NoSqlPredicate {
-
- NoSqlStorageSource storageSource;
- String columnName;
- OperatorPredicate.Operator operator;
- Object value;
-
- NoSqlOperatorPredicate(NoSqlStorageSource storageSource, String columnName,
- OperatorPredicate.Operator operator, Object value) {
- this.storageSource = storageSource;
- this.columnName = columnName;
- this.operator = operator;
- this.value = value;
- }
-
- public boolean incorporateComparison(String columnName,
- OperatorPredicate.Operator operator, Comparable<?> value,
- CompoundPredicate.Operator parentOperator) {
- return false;
- }
-
- public boolean canExecuteEfficiently() {
- return false;
- }
-
- public List<Map<String,Object>> execute(String columnNames[]) {
- throw new StorageException("Unimplemented predicate.");
- }
-
- public boolean matchesRow(Map<String,Object> row) {
- return false;
- }
- }
-
- class NoSqlCompoundPredicate extends NoSqlPredicate {
-
- NoSqlStorageSource storageSource;
- CompoundPredicate.Operator operator;
- boolean negated;
- List<NoSqlPredicate> predicateList;
-
- NoSqlCompoundPredicate(NoSqlStorageSource storageSource, CompoundPredicate.Operator operator,
- boolean negated, List<NoSqlPredicate> predicateList) {
- this.storageSource = storageSource;
- this.operator = operator;
- this.negated = negated;
- this.predicateList = predicateList;
- }
-
- public boolean incorporateComparison(String columnName,
- OperatorPredicate.Operator operator, Comparable<?> value,
- CompoundPredicate.Operator parentOperator) {
- // It may be possible to incorporate other operator predicate into this one,
- // but it would need to take into account the negated attribute and I'd need
- // to think about it some more to make sure it was correct, so for now we just
- // disallow incorporation
- //if (parentOperator == this.operator) {
- // for (NoSqlPredicate predicate: predicateList) {
- // if (predicate.incorporateComparison(columnName, operator, value, parentOperator))
- // return true;
- // }
- //}
- return false;
- }
-
- public boolean canExecuteEfficiently() {
- if (operator == CompoundPredicate.Operator.AND) {
- for (NoSqlPredicate predicate: predicateList) {
- if (predicate.canExecuteEfficiently()) {
- return true;
- }
- }
- return false;
- } else {
- for (NoSqlPredicate predicate: predicateList) {
- if (!predicate.canExecuteEfficiently()) {
- return false;
- }
- }
- return true;
- }
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- class RowComparator implements Comparator<Map<String,Object>> {
- private String primaryKeyName;
-
- public RowComparator(String primaryKeyName) {
- this.primaryKeyName = primaryKeyName;
- }
-
- public int compare(Map<String,Object> row1, Map<String,Object> row2) {
- Comparable key1 = (Comparable)row1.get(primaryKeyName);
- Comparable key2 = (Comparable)row2.get(primaryKeyName);
- return key1.compareTo(key2);
- }
-
- public boolean equals(Object obj) {
- if (!(obj instanceof RowComparator))
- return false;
- RowComparator rc = (RowComparator)obj;
- if (rc.primaryKeyName == null)
- return this.primaryKeyName == null;
- return rc.primaryKeyName.equals(this.primaryKeyName);
- }
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private List<Map<String,Object>> combineRowLists(String primaryKeyName,
- List<Map<String,Object>> list1, List<Map<String,Object>> list2,
- CompoundPredicate.Operator operator) {
- ArrayList<Map<String,Object>> combinedRowList = new ArrayList<Map<String,Object>>();
- RowComparator rc = new RowComparator(primaryKeyName);
- Collections.sort(list1, rc);
- Collections.sort(list2,rc);
-
- Iterator<Map<String,Object>> iterator1 = list1.iterator();
- Iterator<Map<String,Object>> iterator2 = list2.iterator();
- boolean update1 = true;
- boolean update2 = true;
- Map<String,Object> row1 = null;
- Map<String,Object> row2 = null;
- Comparable<?> key1 = null;
- Comparable<?> key2 = null;
-
- while (true) {
- if (update1) {
- if (iterator1.hasNext()) {
- row1 = iterator1.next();
- key1 = (Comparable<?>)row1.get(primaryKeyName);
- } else {
- row1 = null;
- }
- }
- if (update2) {
- if (iterator2.hasNext()) {
- row2 = iterator1.next();
- key2 = (Comparable<?>)row2.get(primaryKeyName);
- } else {
- row2 = null;
- }
- }
- if (operator == CompoundPredicate.Operator.AND) {
- if ((row1 == null) || (row2 == null))
- break;
- if (key1.equals(key2))
- combinedRowList.add(row1);
- } else {
- if (row1 == null) {
- if (row2 == null)
- break;
- combinedRowList.add(row2);
- } else if ((row2 == null) || (((Comparable)key1).compareTo(key2) <= 0)) {
- combinedRowList.add(row2);
- } else {
- combinedRowList.add(row1);
- }
- }
-
- update1 = (key2 == null) || (((Comparable)key1).compareTo(key2) <= 0);
- update2 = (key1 == null) || (((Comparable)key2).compareTo(key1) <= 0);
- }
-
- return combinedRowList;
- }
-
- public List<Map<String,Object>> execute(String columnNames[]) {
- List<Map<String,Object>> combinedRowList = null;
- for (NoSqlPredicate predicate: predicateList) {
- List<Map<String,Object>> rowList = predicate.execute(columnNames);
- if (combinedRowList != null) {
- combinedRowList = combineRowLists("id", combinedRowList, rowList, operator);
- } else {
- combinedRowList = rowList;
- }
- }
- return combinedRowList;
- }
-
- public boolean matchesRow(Map<String,Object> row) {
- if (operator == CompoundPredicate.Operator.AND) {
- for (NoSqlPredicate predicate : predicateList) {
- if (!predicate.matchesRow(row)) {
- return false;
- }
- }
- return true;
- } else {
- for (NoSqlPredicate predicate : predicateList) {
- if (predicate.matchesRow(row)) {
- return true;
- }
- }
- return false;
-
- }
- }
- }
-
- public NoSqlStorageSource() {
- super();
- }
-
- @Override
- public void createTable(String tableName, Set<String> indexedColumns) {
- super.createTable(tableName, indexedColumns);
- if (indexedColumns == null) return;
- for (String columnName : indexedColumns) {
- setColumnIndexMode(tableName, columnName,
- ColumnIndexMode.EQUALITY_INDEXED);
- }
- }
-
- public void setTablePrimaryKeyName(String tableName, String primaryKeyName) {
- if ((tableName == null) || (primaryKeyName == null))
- throw new NullPointerException();
- tablePrimaryKeyMap.put(tableName, primaryKeyName);
- }
-
- protected String getTablePrimaryKeyName(String tableName) {
- String primaryKeyName = tablePrimaryKeyMap.get(tableName);
- if (primaryKeyName == null)
- primaryKeyName = DEFAULT_PRIMARY_KEY_NAME;
- return primaryKeyName;
- }
-
- protected ColumnIndexMode getColumnIndexMode(String tableName, String columnName) {
- ColumnIndexMode columnIndexMode = null;
- Map<String, ColumnIndexMode> indexedColumnMap = tableIndexedColumnMap.get(tableName);
- if (indexedColumnMap != null)
- columnIndexMode = indexedColumnMap.get(columnName);
- if (columnIndexMode == null)
- return ColumnIndexMode.NOT_INDEXED;
- return columnIndexMode;
- }
-
- public void setColumnIndexMode(String tableName, String columnName, ColumnIndexMode indexMode) {
- Map<String, ColumnIndexMode> indexedColumnMap = tableIndexedColumnMap.get(tableName);
- if (indexedColumnMap == null) {
- indexedColumnMap = new HashMap<String,ColumnIndexMode>();
- tableIndexedColumnMap.put(tableName, indexedColumnMap);
- }
- indexedColumnMap.put(columnName, indexMode);
- }
-
- Comparable<?> getOperatorPredicateValue(OperatorPredicate predicate, Map<String,Comparable<?>> parameterMap) {
- Comparable<?> value = predicate.getValue();
- if (value instanceof String) {
- String stringValue = (String) value;
- if ((stringValue.charAt(0) == '?') && (stringValue.charAt(stringValue.length()-1) == '?')) {
- String parameterName = stringValue.substring(1,stringValue.length()-1);
- value = parameterMap.get(parameterName);
- }
- }
- return value;
- }
-
- NoSqlPredicate convertPredicate(IPredicate predicate, String tableName, Map<String,Comparable<?>> parameterMap) {
- if (predicate == null)
- return null;
- NoSqlPredicate convertedPredicate = null;
- if (predicate instanceof CompoundPredicate) {
- CompoundPredicate compoundPredicate = (CompoundPredicate)predicate;
- ArrayList<NoSqlPredicate> noSqlPredicateList = new ArrayList<NoSqlPredicate>();
- for (IPredicate childPredicate: compoundPredicate.getPredicateList()) {
- boolean incorporated = false;
- if (childPredicate instanceof OperatorPredicate) {
- OperatorPredicate childOperatorPredicate = (OperatorPredicate)childPredicate;
- for (NoSqlPredicate childNoSqlPredicate: noSqlPredicateList) {
- incorporated = childNoSqlPredicate.incorporateComparison(
- childOperatorPredicate.getColumnName(), childOperatorPredicate.getOperator(),
- getOperatorPredicateValue(childOperatorPredicate, parameterMap),
- compoundPredicate.getOperator());
- if (incorporated)
- break;
- }
- }
- if (!incorporated) {
- NoSqlPredicate noSqlPredicate = convertPredicate(childPredicate, tableName, parameterMap);
- noSqlPredicateList.add(noSqlPredicate);
- }
- }
- convertedPredicate = new NoSqlCompoundPredicate(this, compoundPredicate.getOperator(),
- compoundPredicate.isNegated(), noSqlPredicateList);
- } else if (predicate instanceof OperatorPredicate) {
- OperatorPredicate operatorPredicate = (OperatorPredicate) predicate;
- Comparable<?> value = getOperatorPredicateValue(operatorPredicate, parameterMap);
- switch (operatorPredicate.getOperator()) {
- case EQ:
- convertedPredicate = new NoSqlRangePredicate(this, tableName,
- operatorPredicate.getColumnName(), value, true, value, true);
- break;
- case LT:
- convertedPredicate = new NoSqlRangePredicate(this, tableName,
- operatorPredicate.getColumnName(), null, false, value, false);
- break;
- case LTE:
- convertedPredicate = new NoSqlRangePredicate(this, tableName,
- operatorPredicate.getColumnName(), null, false, value, true);
- break;
- case GT:
- convertedPredicate = new NoSqlRangePredicate(this, tableName,
- operatorPredicate.getColumnName(), value, false, null, false);
- break;
- case GTE:
- convertedPredicate = new NoSqlRangePredicate(this, tableName,
- operatorPredicate.getColumnName(), value, true, null, false);
- break;
- default:
- convertedPredicate = new NoSqlOperatorPredicate(this, operatorPredicate.getColumnName(),
- operatorPredicate.getOperator(), value);
- }
- } else {
- throw new StorageException("Unknown predicate type");
- }
-
- return convertedPredicate;
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- class RowComparator implements Comparator<Map<String,Object>> {
- private RowOrdering rowOrdering;
-
- public RowComparator(RowOrdering rowOrdering) {
- this.rowOrdering = rowOrdering;
- }
-
- public int compare(Map<String,Object> row1, Map<String,Object> row2) {
- if (rowOrdering == null)
- return 0;
-
- for (RowOrdering.Item item: rowOrdering.getItemList()) {
- Comparable key1 = (Comparable)row1.get(item.getColumn());
- Comparable key2 = (Comparable)row2.get(item.getColumn());
- int result = key1.compareTo(key2);
- if (result != 0) {
- if (item.getDirection() == RowOrdering.Direction.DESCENDING)
- result = -result;
- return result;
- }
- }
-
- return 0;
- }
-
- public boolean equals(Object obj) {
- if (!(obj instanceof RowComparator))
- return false;
- RowComparator rc = (RowComparator)obj;
- if (rc.rowOrdering == null)
- return this.rowOrdering == null;
- return rc.rowOrdering.equals(this.rowOrdering);
- }
- }
-
- private NoSqlResultSet executeParameterizedQuery(String tableName, String[] columnNameList,
- IPredicate predicate, RowOrdering rowOrdering, Map<String,Comparable<?>> parameterMap) {
- NoSqlPredicate noSqlPredicate = convertPredicate(predicate, tableName, parameterMap);
- List<Map<String,Object>> rowList;
- if ((noSqlPredicate != null) && noSqlPredicate.canExecuteEfficiently()) {
- rowList = noSqlPredicate.execute(columnNameList);
- } else {
- rowList = new ArrayList<Map<String,Object>>();
- Collection<Map<String,Object>> allRowList = getAllRows(tableName, columnNameList);
- for (Map<String,Object> row: allRowList) {
- if ((noSqlPredicate == null) || noSqlPredicate.matchesRow(row)) {
- rowList.add(row);
- }
- }
- }
- if (rowOrdering != null)
- Collections.sort(rowList, new RowComparator(rowOrdering));
-
- return new NoSqlResultSet(this, tableName, rowList);
- }
-
- @Override
- public IQuery createQuery(String tableName, String[] columnNameList,
- IPredicate predicate, RowOrdering rowOrdering) {
- return new NoSqlQuery(tableName, columnNameList, predicate, rowOrdering);
- }
-
- @Override
- public IResultSet executeQueryImpl(IQuery query) {
- NoSqlQuery noSqlQuery = (NoSqlQuery) query;
- return executeParameterizedQuery(noSqlQuery.getTableName(),
- noSqlQuery.getColumnNameList(), noSqlQuery.getPredicate(),
- noSqlQuery.getRowOrdering(), noSqlQuery.getParameterMap());
- }
-
- protected void sendNotification(String tableName, StorageSourceNotification.Action action,
- List<Map<String,Object>> rows) {
- Set<Object> rowKeys = new HashSet<Object>();
- String primaryKeyName = getTablePrimaryKeyName(tableName);
- for (Map<String,Object> row : rows) {
- Object rowKey = row.get(primaryKeyName);
- rowKeys.add(rowKey);
- }
- StorageSourceNotification notification =
- new StorageSourceNotification(tableName, action, rowKeys);
- notifyListeners(notification);
- }
-
- protected void sendNotification(String tableName,
- StorageSourceNotification.Action action, Set<Object> rowKeys) {
- StorageSourceNotification notification =
- new StorageSourceNotification(tableName, action, rowKeys);
- notifyListeners(notification);
- }
-
- protected void insertRowsAndNotify(String tableName, List<Map<String,Object>> insertRowList) {
- insertRows(tableName, insertRowList);
- sendNotification(tableName, StorageSourceNotification.Action.MODIFY, insertRowList);
- }
-
- @Override
- public void insertRowImpl(String tableName, Map<String, Object> values) {
- ArrayList<Map<String,Object>> rowList = new ArrayList<Map<String,Object>>();
- rowList.add(values);
- insertRowsAndNotify(tableName, rowList);
- }
-
- protected void updateRowsAndNotify(String tableName, Set<Object> rowKeys, Map<String,Object> updateRowList) {
- updateRows(tableName, rowKeys, updateRowList);
- sendNotification(tableName, StorageSourceNotification.Action.MODIFY, rowKeys);
- }
-
- protected void updateRowsAndNotify(String tableName, List<Map<String,Object>> updateRowList) {
- updateRows(tableName, updateRowList);
- sendNotification(tableName, StorageSourceNotification.Action.MODIFY, updateRowList);
- }
-
- @Override
- public void updateMatchingRowsImpl(String tableName, IPredicate predicate, Map<String,Object> values) {
- String primaryKeyName = getTablePrimaryKeyName(tableName);
- String[] columnNameList = {primaryKeyName};
- IResultSet resultSet = executeQuery(tableName, columnNameList, predicate, null);
- Set<Object> rowKeys = new HashSet<Object>();
- while (resultSet.next()) {
- String rowKey = resultSet.getString(primaryKeyName);
- rowKeys.add(rowKey);
- }
- updateRowsAndNotify(tableName, rowKeys, values);
- }
-
- @Override
- public void updateRowImpl(String tableName, Object rowKey, Map<String,Object> values) {
- Map<String,Object> valuesWithKey = new HashMap<String,Object>(values);
- String primaryKeyName = getTablePrimaryKeyName(tableName);
- valuesWithKey.put(primaryKeyName, rowKey);
- List<Map<String,Object>> rowList = new ArrayList<Map<String,Object>>();
- rowList.add(valuesWithKey);
- updateRowsAndNotify(tableName, rowList);
- }
-
- @Override
- public void updateRowImpl(String tableName, Map<String,Object> values) {
- List<Map<String,Object>> rowKeys = new ArrayList<Map<String,Object>>();
- rowKeys.add(values);
- updateRowsAndNotify(tableName, rowKeys);
- }
-
- protected void deleteRowsAndNotify(String tableName, Set<Object> rowKeyList) {
- deleteRows(tableName, rowKeyList);
- sendNotification(tableName, StorageSourceNotification.Action.DELETE, rowKeyList);
- }
-
- @Override
- public void deleteRowImpl(String tableName, Object key) {
- HashSet<Object> keys = new HashSet<Object>();
- keys.add(key);
- deleteRowsAndNotify(tableName, keys);
- }
-
- @Override
- public IResultSet getRowImpl(String tableName, Object rowKey) {
- List<Map<String,Object>> rowList = new ArrayList<Map<String,Object>>();
- Map<String,Object> row = getRow(tableName, null, rowKey);
- if (row != null)
- rowList.add(row);
- NoSqlResultSet resultSet = new NoSqlResultSet(this, tableName, rowList);
- return resultSet;
- }
-
- // Below are the methods that must be implemented by the subclasses
-
- protected abstract Collection<Map<String,Object>> getAllRows(String tableName, String[] columnNameList);
-
- protected abstract Map<String,Object> getRow(String tableName, String[] columnNameList, Object rowKey);
-
- protected abstract List<Map<String,Object>> executeEqualityQuery(String tableName,
- String[] columnNameList, String predicateColumnName, Comparable<?> value);
-
- protected abstract List<Map<String,Object>> executeRangeQuery(String tableName,
- String[] columnNameList, String predicateColumnName,
- Comparable<?> startValue, boolean startInclusive, Comparable<?> endValue, boolean endInclusive);
-
- protected abstract void insertRows(String tableName, List<Map<String,Object>> insertRowList);
-
- protected abstract void updateRows(String tableName, Set<Object> rowKeys, Map<String,Object> updateColumnMap);
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/web/StorageNotifyResource.java b/src/main/java/net/floodlightcontroller/storage/web/StorageNotifyResource.java
deleted file mode 100644
index 081c7f9..0000000
--- a/src/main/java/net/floodlightcontroller/storage/web/StorageNotifyResource.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage.web;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import net.floodlightcontroller.storage.IStorageSourceService;
-import net.floodlightcontroller.storage.StorageSourceNotification;
-
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.type.TypeReference;
-import org.restlet.resource.Post;
-import org.restlet.resource.ServerResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class StorageNotifyResource extends ServerResource {
- protected final static Logger log = LoggerFactory.getLogger(StorageNotifyResource.class);
-
- @Post("json")
- public Map<String,Object> notify(String entity) throws Exception {
- List<StorageSourceNotification> notifications = null;
- ObjectMapper mapper = new ObjectMapper();
- notifications =
- mapper.readValue(entity,
- new TypeReference<List<StorageSourceNotification>>(){});
-
- IStorageSourceService storageSource =
- (IStorageSourceService)getContext().getAttributes().
- get(IStorageSourceService.class.getCanonicalName());
- storageSource.notifyListeners(notifications);
-
- HashMap<String, Object> model = new HashMap<String,Object>();
- model.put("output", "OK");
- return model;
- }
-
-}
diff --git a/src/main/java/net/floodlightcontroller/storage/web/StorageWebRoutable.java b/src/main/java/net/floodlightcontroller/storage/web/StorageWebRoutable.java
deleted file mode 100644
index 681847d..0000000
--- a/src/main/java/net/floodlightcontroller/storage/web/StorageWebRoutable.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage.web;
-
-import org.restlet.Context;
-import org.restlet.Restlet;
-import org.restlet.routing.Router;
-
-import net.floodlightcontroller.restserver.RestletRoutable;
-
-/**
- * Creates a router to handle the storage web URIs
- * @author readams
- *
- */
-public class StorageWebRoutable implements RestletRoutable {
-
- @Override
- public String basePath() {
- return "/wm/storage";
- }
-
- @Override
- public Restlet getRestlet(Context context) {
- Router router = new Router(context);
- router.attach("/notify/json", StorageNotifyResource.class);
- return router;
- }
-
-}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/linkdiscovery/internal/LinkDiscoveryManager.java b/src/main/java/net/onrc/onos/ofcontroller/linkdiscovery/internal/LinkDiscoveryManager.java
index c03b266..1a890cb 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/linkdiscovery/internal/LinkDiscoveryManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/linkdiscovery/internal/LinkDiscoveryManager.java
@@ -18,7 +18,6 @@
package net.onrc.onos.ofcontroller.linkdiscovery.internal;
import java.io.IOException;
-
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.NetworkInterface;
@@ -63,24 +62,17 @@
import net.floodlightcontroller.packet.LLDPTLV;
import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.routing.Link;
-import net.floodlightcontroller.storage.IResultSet;
-import net.floodlightcontroller.storage.IStorageSourceListener;
-import net.floodlightcontroller.storage.IStorageSourceService;
-import net.floodlightcontroller.storage.OperatorPredicate;
-import net.floodlightcontroller.storage.StorageException;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import net.floodlightcontroller.topology.NodePortTuple;
import net.floodlightcontroller.util.EventHistory;
import net.floodlightcontroller.util.EventHistory.EvAction;
import net.onrc.onos.ofcontroller.core.IOnosRemoteSwitch;
import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscovery;
+import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscovery.LDUpdate;
+import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscovery.UpdateOperation;
import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryListener;
import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService;
import net.onrc.onos.ofcontroller.linkdiscovery.LinkInfo;
-import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscovery.LDUpdate;
-import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscovery.LinkType;
-import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscovery.SwitchType;
-import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscovery.UpdateOperation;
import net.onrc.onos.ofcontroller.linkdiscovery.web.LinkDiscoveryWebRoutable;
import net.onrc.onos.registry.controller.IControllerRegistryService;
@@ -124,11 +116,12 @@
@LogMessageCategory("Network Topology")
public class LinkDiscoveryManager
implements IOFMessageListener, IOFSwitchListener,
-IStorageSourceListener, ILinkDiscoveryService,
+ILinkDiscoveryService,
IFloodlightModule, IInfoProvider, IHAListener {
protected IFloodlightProviderService controller;
protected final static Logger log = LoggerFactory.getLogger(LinkDiscoveryManager.class);
+ /*
// Names of table/fields for links in the storage API
private static final String LINK_TABLE_NAME = "controller_link";
private static final String LINK_ID = "id";
@@ -142,9 +135,9 @@
private static final String LINK_TYPE = "link_type";
private static final String SWITCH_CONFIG_TABLE_NAME = "controller_switchconfig";
private static final String SWITCH_CONFIG_CORE_SWITCH = "core_switch";
+ */
protected IFloodlightProviderService floodlightProvider;
- protected IStorageSourceService storageSource;
protected IThreadPoolService threadPool;
protected IRestApiService restApi;
// Registry Service for ONOS
@@ -1063,8 +1056,6 @@
// Add to portNOFLinks if the unicast valid time is null
if (newInfo.getUnicastValidTime() == null)
addLinkToBroadcastDomain(lt);
-
- writeLinkToStorage(lt, newInfo);
// ONOS: Distinguish added event separately from updated event
updateOperation = UpdateOperation.LINK_ADDED;
@@ -1118,11 +1109,6 @@
oldInfo.getDstPortState().intValue())
linkChanged = true;
- // Write changes to storage. This will always write the updated
- // valid time, plus the port states if they've changed (i.e. if
- // they weren't set to null in the previous block of code.
- writeLinkToStorage(lt, newInfo);
-
if (linkChanged) {
updateOperation = getUpdateOperation(newInfo.getSrcPortState(),
newInfo.getDstPortState());
@@ -1209,9 +1195,6 @@
ILinkDiscovery.LinkType.INVALID_LINK,
EvAction.LINK_DELETED, reason);
- // remove link from storage.
- removeLinkFromStorage(lt);
-
// TODO Whenever link is removed, it has to checked if
// the switchports must be added to quarantine.
@@ -1304,7 +1287,7 @@
getLinkType(lt, linkInfo),
operation));
controller.publishUpdate(update);
- writeLinkToStorage(lt, linkInfo);
+
linkInfoChanged = true;
}
}
@@ -1582,9 +1565,11 @@
/**
* Deletes all links from storage
*/
+ /*
void clearAllLinks() {
storageSource.deleteRowsAsync(LINK_TABLE_NAME, null);
}
+ */
/**
* Gets the storage key for a LinkTuple
@@ -1603,6 +1588,7 @@
* @param lt The LinkTuple to write
* @param linkInfo The LinkInfo to write
*/
+ /*
protected void writeLinkToStorage(Link lt, LinkInfo linkInfo) {
LinkType type = getLinkType(lt, linkInfo);
@@ -1661,39 +1647,18 @@
}
storageSource.updateRowAsync(LINK_TABLE_NAME, rowValues);
}
-
- public Long readLinkValidTime(Link lt) {
- // FIXME: We're not currently using this right now, but if we start
- // to use this again, we probably shouldn't use it in its current
- // form, because it's doing synchronous storage calls. Depending
- // on the context this may still be OK, but if it's being called
- // on the packet in processing thread it should be reworked to
- // use asynchronous storage calls.
- Long validTime = null;
- IResultSet resultSet = null;
- try {
- String[] columns = { LINK_VALID_TIME };
- String id = getLinkId(lt);
- resultSet = storageSource.executeQuery(LINK_TABLE_NAME, columns,
- new OperatorPredicate(LINK_ID, OperatorPredicate.Operator.EQ, id), null);
- if (resultSet.next())
- validTime = resultSet.getLong(LINK_VALID_TIME);
- }
- finally {
- if (resultSet != null)
- resultSet.close();
- }
- return validTime;
- }
+ */
/**
* Removes a link from storage using an asynchronous call.
* @param lt The LinkTuple to delete.
*/
+ /*
protected void removeLinkFromStorage(Link lt) {
String id = getLinkId(lt);
storageSource.deleteRowAsync(LINK_TABLE_NAME, id);
}
+ */
@Override
public void addListener(ILinkDiscoveryListener listener) {
@@ -1718,22 +1683,6 @@
this.linkDiscoveryAware.remove(linkDiscoveryAwareComponent);
}
- /**
- * Sets the IStorageSource to use for ITology
- * @param storageSource the storage source to use
- */
- public void setStorageSource(IStorageSourceService storageSource) {
- this.storageSource = storageSource;
- }
-
- /**
- * Gets the storage source for this ITopology
- * @return The IStorageSource ITopology is writing to
- */
- public IStorageSourceService getStorageSource() {
- return storageSource;
- }
-
@Override
public boolean isCallbackOrderingPrereq(OFType type, String name) {
return false;
@@ -1744,6 +1693,7 @@
return false;
}
+ /*
@Override
public void rowsModified(String tableName, Set<Object> rowKeys) {
Map<Long, IOFSwitch> switches = floodlightProvider.getSwitches();
@@ -1804,11 +1754,14 @@
}
}
}
+ */
+ /*
@Override
public void rowsDeleted(String tableName, Set<Object> rowKeys) {
// Ignore delete events, the switch delete will do the right thing on it's own
}
+ */
// IFloodlightModule classes
@@ -1838,7 +1791,6 @@
Collection<Class<? extends IFloodlightService>> l =
new ArrayList<Class<? extends IFloodlightService>>();
l.add(IFloodlightProviderService.class);
- l.add(IStorageSourceService.class);
l.add(IThreadPoolService.class);
l.add(IRestApiService.class);
// Added by ONOS
@@ -1850,7 +1802,6 @@
public void init(FloodlightModuleContext context)
throws FloodlightModuleException {
floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
- storageSource = context.getServiceImpl(IStorageSourceService.class);
threadPool = context.getServiceImpl(IThreadPoolService.class);
restApi = context.getServiceImpl(IRestApiService.class);
// Added by ONOS
@@ -1906,23 +1857,6 @@
recommendation=LogMessageDoc.CHECK_SWITCH)
})
public void startUp(FloodlightModuleContext context) {
- // Create our storage tables
- if (storageSource == null) {
- log.error("No storage source found.");
- return;
- }
-
- storageSource.createTable(LINK_TABLE_NAME, null);
- storageSource.setTablePrimaryKeyName(LINK_TABLE_NAME, LINK_ID);
- storageSource.deleteMatchingRows(LINK_TABLE_NAME, null);
- // Register for storage updates for the switch table
- try {
- storageSource.addListener(SWITCH_CONFIG_TABLE_NAME, this);
- } catch (StorageException ex) {
- log.error("Error in installing listener for " +
- "switch table {}", SWITCH_CONFIG_TABLE_NAME);
- }
-
ScheduledExecutorService ses = threadPool.getScheduledExecutor();
controller =
context.getServiceImpl(IFloodlightProviderService.class);
@@ -1933,10 +1867,6 @@
public void run() {
try {
discoverLinks();
- } catch (StorageException e) {
- log.error("Storage exception in LLDP send timer; " +
- "terminating process", e);
- floodlightProvider.terminate();
} catch (Exception e) {
log.error("Exception in LLDP send timer.", e);
} finally {
@@ -2085,7 +2015,7 @@
log.trace("Sending LLDPs " +
"to HA change from SLAVE->MASTER");
}
- clearAllLinks();
+ //clearAllLinks();
log.debug("Role Change to Master: Rescheduling discovery task.");
discoveryTask.reschedule(1, TimeUnit.MICROSECONDS);
}
diff --git a/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule b/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule
index fcdd6b5..12fd261 100644
--- a/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule
+++ b/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule
@@ -1,5 +1,4 @@
net.floodlightcontroller.core.FloodlightProvider
-net.floodlightcontroller.storage.memory.MemoryStorageSource
net.onrc.onos.ofcontroller.floodlightlistener.NetworkGraphPublisher
net.floodlightcontroller.devicemanager.internal.DeviceManagerImpl
net.onrc.onos.ofcontroller.linkdiscovery.internal.LinkDiscoveryManager
diff --git a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java
index 21788af..a3f3859 100644
--- a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java
+++ b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java
@@ -33,9 +33,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -44,7 +42,6 @@
import net.floodlightcontroller.core.FloodlightProvider;
import net.floodlightcontroller.core.IFloodlightProviderService;
import net.floodlightcontroller.core.IFloodlightProviderService.Role;
-import net.floodlightcontroller.core.IHAListener;
import net.floodlightcontroller.core.IListener.Command;
import net.floodlightcontroller.core.IOFMessageListener;
import net.floodlightcontroller.core.IOFSwitch;
@@ -65,8 +62,6 @@
import net.floodlightcontroller.perfmon.PktInProcessingTime;
import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.restserver.RestApiServer;
-import net.floodlightcontroller.storage.IStorageSourceService;
-import net.floodlightcontroller.storage.memory.MemoryStorageSource;
import net.floodlightcontroller.test.FloodlightTestCase;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import net.onrc.onos.ofcontroller.core.IOFSwitchPortListener;
@@ -121,8 +116,8 @@
controller = (Controller)cm.getServiceImpls().get(IFloodlightProviderService.class);
fmc.addService(IFloodlightProviderService.class, controller);
- MemoryStorageSource memstorage = new MemoryStorageSource();
- fmc.addService(IStorageSourceService.class, memstorage);
+ //MemoryStorageSource memstorage = new MemoryStorageSource();
+ //fmc.addService(IStorageSourceService.class, memstorage);
RestApiServer restApi = new RestApiServer();
fmc.addService(IRestApiService.class, restApi);
@@ -146,13 +141,13 @@
ppt.init(fmc);
restApi.init(fmc);
- memstorage.init(fmc);
+ //memstorage.init(fmc);
cm.init(fmc);
tp.init(fmc);
sr.init(fmc);
ppt.startUp(fmc);
restApi.startUp(fmc);
- memstorage.startUp(fmc);
+ //memstorage.startUp(fmc);
cm.startUp(fmc);
tp.startUp(fmc);
sr.startUp(fmc);
@@ -183,10 +178,12 @@
expect(sw.getId()).andReturn(dpid).anyTimes();
expect(sw.getStringId()).andReturn(dpidString).anyTimes();
- expect(sw.getConnectedSince()).andReturn(new Date());
- Channel channel = createMock(Channel.class);
- expect(sw.getChannel()).andReturn(channel);
- expect(channel.getRemoteAddress()).andReturn(null);
+
+ //Now we don't write to storage these methods aren't called
+ //expect(sw.getConnectedSince()).andReturn(new Date());
+ //Channel channel = createMock(Channel.class);
+ //expect(sw.getChannel()).andReturn(channel);
+ //expect(channel.getRemoteAddress()).andReturn(null);
expect(sw.getCapabilities()).andReturn(0).anyTimes();
expect(sw.getBuffers()).andReturn(0).anyTimes();
@@ -403,21 +400,22 @@
IOFSwitch newsw = createMock(IOFSwitch.class);
expect(newsw.getId()).andReturn(0L).anyTimes();
expect(newsw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes();
- expect(newsw.getConnectedSince()).andReturn(new Date());
- Channel channel2 = createMock(Channel.class);
- expect(newsw.getChannel()).andReturn(channel2);
- expect(channel2.getRemoteAddress()).andReturn(null);
- expect(newsw.getPorts()).andReturn(new ArrayList<OFPhysicalPort>());
+ //Now we don't write to storage, these methods aren't called
+ //expect(newsw.getConnectedSince()).andReturn(new Date());
+ //Channel channel2 = createMock(Channel.class);
+ //expect(newsw.getChannel()).andReturn(channel2);
+ //expect(channel2.getRemoteAddress()).andReturn(null);
+ //expect(newsw.getPorts()).andReturn(new ArrayList<OFPhysicalPort>());
expect(newsw.getCapabilities()).andReturn(0).anyTimes();
expect(newsw.getBuffers()).andReturn(0).anyTimes();
expect(newsw.getTables()).andReturn((byte)0).anyTimes();
expect(newsw.getActions()).andReturn(0).anyTimes();
controller.activeSwitches.put(0L, oldsw);
- replay(newsw, channel, channel2);
+ replay(newsw, channel);//, channel2);
controller.addSwitch(newsw);
- verify(newsw, channel, channel2);
+ verify(newsw, channel);//, channel2);
}
@Test
@@ -483,7 +481,7 @@
}
}
-
+ /*
private Map<String,Object> getFakeControllerIPRow(String id, String controllerId,
String type, int number, String discoveredIP ) {
HashMap<String, Object> row = new HashMap<String,Object>();
@@ -494,6 +492,7 @@
row.put(Controller.CONTROLLER_INTERFACE_DISCOVERED_IP, discoveredIP);
return row;
}
+ */
/**
* Test notifications for controller node IP changes. This requires
@@ -507,6 +506,7 @@
*
* @throws Exception
*/
+ /*
@Test
public void testControllerNodeIPChanges() throws Exception {
class DummyHAListener implements IHAListener {
@@ -617,7 +617,9 @@
listener.do_assert(4, expectedCurMap, expectedAddedMap, expectedRemovedMap);
}
}
+ */
+ /*
@Test
public void testGetControllerNodeIPs() {
HashMap<String,String> expectedCurMap = new HashMap<String, String>();
@@ -633,6 +635,7 @@
assertEquals("expectedControllerNodeIPs is not as expected",
expectedCurMap, controller.getControllerNodeIPs());
}
+ */
@Test
public void testSetRoleNull() {
diff --git a/src/test/java/net/floodlightcontroller/core/module/FloodlightTestModuleLoader.java b/src/test/java/net/floodlightcontroller/core/module/FloodlightTestModuleLoader.java
index be43a8b..6bef8c1 100644
--- a/src/test/java/net/floodlightcontroller/core/module/FloodlightTestModuleLoader.java
+++ b/src/test/java/net/floodlightcontroller/core/module/FloodlightTestModuleLoader.java
@@ -4,26 +4,23 @@
import java.util.Collection;
import java.util.Iterator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import net.floodlightcontroller.core.module.FloodlightModuleLoader;
-import net.floodlightcontroller.core.module.IFloodlightModule;
import net.floodlightcontroller.core.test.MockFloodlightProvider;
import net.floodlightcontroller.core.test.MockThreadPoolService;
import net.floodlightcontroller.counter.NullCounterStore;
import net.floodlightcontroller.devicemanager.internal.DefaultEntityClassifier;
import net.floodlightcontroller.devicemanager.test.MockDeviceManager;
import net.floodlightcontroller.perfmon.NullPktInProcessingTime;
-import net.floodlightcontroller.storage.memory.MemoryStorageSource;
import net.floodlightcontroller.topology.TopologyManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class FloodlightTestModuleLoader extends FloodlightModuleLoader {
protected final static Logger log = LoggerFactory.getLogger(FloodlightTestModuleLoader.class);
// List of default modules to use unless specified otherwise
- public static final Class<? extends IFloodlightModule> DEFAULT_STORAGE_SOURCE =
- MemoryStorageSource.class;
+ //public static final Class<? extends IFloodlightModule> DEFAULT_STORAGE_SOURCE =
+ //MemoryStorageSource.class;
public static final Class<? extends IFloodlightModule> DEFAULT_FLOODLIGHT_PRPOVIDER =
MockFloodlightProvider.class;
public static final Class<? extends IFloodlightModule> DEFAULT_TOPOLOGY_PROVIDER =
@@ -45,7 +42,7 @@
DEFAULT_MODULE_LIST = new ArrayList<Class<? extends IFloodlightModule>>();
DEFAULT_MODULE_LIST.add(DEFAULT_DEVICE_SERVICE);
DEFAULT_MODULE_LIST.add(DEFAULT_FLOODLIGHT_PRPOVIDER);
- DEFAULT_MODULE_LIST.add(DEFAULT_STORAGE_SOURCE);
+ //DEFAULT_MODULE_LIST.add(DEFAULT_STORAGE_SOURCE);
DEFAULT_MODULE_LIST.add(DEFAULT_TOPOLOGY_PROVIDER);
DEFAULT_MODULE_LIST.add(DEFAULT_COUNTER_STORE);
DEFAULT_MODULE_LIST.add(DEFAULT_THREADPOOL);
diff --git a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java
index 7afb78a..3fccd0f 100644
--- a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java
+++ b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java
@@ -18,7 +18,17 @@
package net.floodlightcontroller.devicemanager.internal;
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.anyLong;
+import static org.easymock.EasyMock.anyShort;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertArrayEquals;
import java.util.ArrayList;
import java.util.Arrays;
@@ -31,18 +41,17 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import static org.easymock.EasyMock.expectLastCall;
import net.floodlightcontroller.core.IFloodlightProviderService;
import net.floodlightcontroller.core.IOFSwitch;
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.test.MockFloodlightProvider;
import net.floodlightcontroller.core.test.MockThreadPoolService;
-import net.floodlightcontroller.devicemanager.IDeviceListener;
import net.floodlightcontroller.devicemanager.IDevice;
+import net.floodlightcontroller.devicemanager.IDeviceListener;
+import net.floodlightcontroller.devicemanager.IDeviceService;
import net.floodlightcontroller.devicemanager.IEntityClass;
import net.floodlightcontroller.devicemanager.IEntityClassifierService;
import net.floodlightcontroller.devicemanager.SwitchPort;
-import net.floodlightcontroller.devicemanager.IDeviceService;
import net.floodlightcontroller.devicemanager.SwitchPort.ErrorStatus;
import net.floodlightcontroller.devicemanager.internal.DeviceManagerImpl.ClassState;
import net.floodlightcontroller.devicemanager.test.MockEntityClassifier;
@@ -56,21 +65,18 @@
import net.floodlightcontroller.packet.IPv4;
import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.restserver.RestApiServer;
-import net.floodlightcontroller.storage.IStorageSourceService;
-import net.floodlightcontroller.storage.memory.MemoryStorageSource;
import net.floodlightcontroller.test.FloodlightTestCase;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import net.floodlightcontroller.topology.ITopologyService;
-import static org.junit.Assert.*;
import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.openflow.protocol.OFPacketIn;
+import org.openflow.protocol.OFPacketIn.OFPacketInReason;
import org.openflow.protocol.OFPhysicalPort;
import org.openflow.protocol.OFType;
-import org.openflow.protocol.OFPacketIn.OFPacketInReason;
import org.openflow.util.HexString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -89,7 +95,7 @@
private byte[] testARPReplyPacket_3_Serialized;
MockFloodlightProvider mockFloodlightProvider;
DeviceManagerImpl deviceManager;
- MemoryStorageSource storageSource;
+ //MemoryStorageSource storageSource;
FlowReconcileManager flowReconcileMgr;
private IOFSwitch makeSwitchMock(long id) {
@@ -118,8 +124,8 @@
flowReconcileMgr = new FlowReconcileManager();
DefaultEntityClassifier entityClassifier = new DefaultEntityClassifier();
fmc.addService(IDeviceService.class, deviceManager);
- storageSource = new MemoryStorageSource();
- fmc.addService(IStorageSourceService.class, storageSource);
+ //storageSource = new MemoryStorageSource();
+ //fmc.addService(IStorageSourceService.class, storageSource);
fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider);
fmc.addService(IRestApiService.class, restApi);
fmc.addService(IFlowReconcileService.class, flowReconcileMgr);
@@ -127,11 +133,11 @@
fmc.addService(ITopologyService.class, topology);
tp.init(fmc);
restApi.init(fmc);
- storageSource.init(fmc);
+ //storageSource.init(fmc);
deviceManager.init(fmc);
flowReconcileMgr.init(fmc);
entityClassifier.init(fmc);
- storageSource.startUp(fmc);
+ //storageSource.startUp(fmc);
deviceManager.startUp(fmc);
flowReconcileMgr.startUp(fmc);
tp.startUp(fmc);
diff --git a/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowTests.java b/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowTests.java
index 186fd69..4f53342 100644
--- a/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowTests.java
+++ b/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowTests.java
@@ -1,49 +1,16 @@
package net.floodlightcontroller.staticflowentry;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.easymock.Capture;
-import org.easymock.CaptureType;
-import org.junit.Test;
-import org.openflow.protocol.OFFlowMod;
-import org.openflow.protocol.OFMatch;
-import org.openflow.protocol.OFMessage;
-import org.openflow.protocol.OFPort;
-import org.openflow.protocol.action.OFAction;
-import org.openflow.protocol.action.OFActionOutput;
-import org.openflow.util.HexString;
-
-
-import net.floodlightcontroller.core.FloodlightContext;
-import net.floodlightcontroller.core.IFloodlightProviderService.Role;
-import net.floodlightcontroller.core.IOFSwitch;
-import net.floodlightcontroller.core.module.FloodlightModuleContext;
-import net.floodlightcontroller.core.module.FloodlightModuleException;
-import net.floodlightcontroller.core.test.MockFloodlightProvider;
-import net.floodlightcontroller.test.FloodlightTestCase;
-import net.floodlightcontroller.restserver.RestApiServer;
-import net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher;
-import net.floodlightcontroller.storage.IStorageSourceService;
-import net.floodlightcontroller.storage.memory.MemoryStorageSource;
-import static net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher.*;
-import static org.easymock.EasyMock.*;
-
+/*
public class StaticFlowTests extends FloodlightTestCase {
static String TestSwitch1DPID = "00:00:00:00:00:00:00:01";
static int TotalTestRules = 3;
- /***
- * Create TestRuleXXX and the corresponding FlowModXXX
- * for X = 1..3
- */
+ //
+ // Create TestRuleXXX and the corresponding FlowModXXX
+ // for X = 1..3
+ //
static Map<String,Object> TestRule1;
static OFFlowMod FlowMod1;
static {
@@ -332,3 +299,4 @@
assert(staticFlowEntryPusher.entriesFromStorage.containsValue(FlowMod3));
}
}
+*/
diff --git a/src/test/java/net/floodlightcontroller/storage/memory/tests/MemoryStorageTest.java b/src/test/java/net/floodlightcontroller/storage/memory/tests/MemoryStorageTest.java
deleted file mode 100644
index c250066..0000000
--- a/src/test/java/net/floodlightcontroller/storage/memory/tests/MemoryStorageTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage.memory.tests;
-
-import net.floodlightcontroller.core.module.FloodlightModuleContext;
-import net.floodlightcontroller.restserver.IRestApiService;
-import net.floodlightcontroller.restserver.RestApiServer;
-import net.floodlightcontroller.storage.memory.MemoryStorageSource;
-import net.floodlightcontroller.storage.tests.StorageTest;
-import org.junit.Before;
-
-public class MemoryStorageTest extends StorageTest {
-
- @Before
- public void setUp() throws Exception {
- storageSource = new MemoryStorageSource();
- restApi = new RestApiServer();
- FloodlightModuleContext fmc = new FloodlightModuleContext();
- fmc.addService(IRestApiService.class, restApi);
- restApi.init(fmc);
- storageSource.init(fmc);
- restApi.startUp(fmc);
- storageSource.startUp(fmc);
- super.setUp();
- }
-}
diff --git a/src/test/java/net/floodlightcontroller/storage/tests/StorageTest.java b/src/test/java/net/floodlightcontroller/storage/tests/StorageTest.java
deleted file mode 100644
index 29cc15b..0000000
--- a/src/test/java/net/floodlightcontroller/storage/tests/StorageTest.java
+++ /dev/null
@@ -1,743 +0,0 @@
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package net.floodlightcontroller.storage.tests;
-
-import static org.easymock.EasyMock.*;
-
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.TimeUnit;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import net.floodlightcontroller.restserver.RestApiServer;
-import net.floodlightcontroller.storage.CompoundPredicate;
-import net.floodlightcontroller.storage.IStorageExceptionHandler;
-import net.floodlightcontroller.storage.IPredicate;
-import net.floodlightcontroller.storage.IQuery;
-import net.floodlightcontroller.storage.IResultSet;
-import net.floodlightcontroller.storage.IRowMapper;
-import net.floodlightcontroller.storage.IStorageSourceListener;
-import net.floodlightcontroller.storage.NullValueStorageException;
-import net.floodlightcontroller.storage.OperatorPredicate;
-import net.floodlightcontroller.storage.RowOrdering;
-import net.floodlightcontroller.storage.nosql.NoSqlStorageSource;
-import net.floodlightcontroller.test.FloodlightTestCase;
-
-import org.junit.Test;
-
-public abstract class StorageTest extends FloodlightTestCase {
-
- protected NoSqlStorageSource storageSource;
- protected RestApiServer restApi;
-
- protected String PERSON_TABLE_NAME = "Person";
-
- protected String PERSON_SSN = "SSN";
- protected String PERSON_FIRST_NAME = "FirstName";
- protected String PERSON_LAST_NAME = "LastName";
- protected String PERSON_AGE = "Age";
- protected String PERSON_REGISTERED = "Registered";
-
- protected String[] PERSON_COLUMN_LIST = {PERSON_SSN, PERSON_FIRST_NAME, PERSON_LAST_NAME, PERSON_AGE, PERSON_REGISTERED};
-
- class Person {
- private String ssn;
- private String firstName;
- private String lastName;
- int age;
- boolean registered;
-
- public Person(String ssn, String firstName, String lastName, int age, boolean registered) {
- this.ssn = ssn;
- this.firstName = firstName;
- this.lastName = lastName;
- this.age = age;
- this.registered = registered;
- }
-
- public String getSSN() {
- return ssn;
- }
-
- public String getFirstName() {
- return firstName;
- }
-
- public String getLastName() {
- return lastName;
-
- }
-
- public int getAge() {
- return age;
- }
-
- public boolean isRegistered() {
- return registered;
- }
- }
-
- class PersonRowMapper implements IRowMapper {
- public Object mapRow(IResultSet resultSet) {
- String ssn = resultSet.getString(PERSON_SSN);
- String firstName = resultSet.getString(PERSON_FIRST_NAME);
- String lastName = resultSet.getString(PERSON_LAST_NAME);
- int age = resultSet.getInt(PERSON_AGE);
- boolean registered = resultSet.getBoolean(PERSON_REGISTERED);
- return new Person(ssn, firstName, lastName, age, registered);
- }
- }
-
- Object[][] PERSON_INIT_DATA = {
- {"111-11-1111", "John", "Smith", 40, true},
- {"222-22-2222", "Jim", "White", 24, false},
- {"333-33-3333", "Lisa", "Jones", 27, true},
- {"444-44-4444", "Susan", "Jones", 14, false},
- {"555-55-5555", "Jose", "Garcia", 31, true},
- {"666-66-6666", "Abigail", "Johnson", 35, false},
- {"777-77-7777", "Bjorn", "Borg", 55, true},
- {"888-88-8888", "John", "McEnroe", 53, false}
- };
-
- Map<String,Object> createPersonRowValues(Object[] personData) {
- Map<String,Object> rowValues = new HashMap<String,Object>();
- for (int i = 0; i < PERSON_COLUMN_LIST.length; i++) {
- rowValues.put(PERSON_COLUMN_LIST[i], personData[i]);
- }
- return rowValues;
- }
-
- public void insertPerson(Object[] personData) {
- Map<String,Object> rowValues = createPersonRowValues(personData);
- storageSource.insertRow(PERSON_TABLE_NAME, rowValues);
- }
-
- public void initPersons() {
- for (Object[] row: PERSON_INIT_DATA) {
- insertPerson(row);
- }
- }
-
- public void setUp() throws Exception {
- super.setUp();
- Set<String> indexedColumnNames = new HashSet<String>();
- indexedColumnNames.add(PERSON_LAST_NAME);
- storageSource.setExceptionHandler(null);
- storageSource.createTable(PERSON_TABLE_NAME, indexedColumnNames);
- storageSource.setTablePrimaryKeyName(PERSON_TABLE_NAME, PERSON_SSN);
- initPersons();
- }
-
- public void checkExpectedResults(IResultSet resultSet, String[] columnNameList, Object[][] expectedRowList) {
- boolean nextResult;
- for (Object[] expectedRow: expectedRowList) {
- nextResult = resultSet.next();
- assertEquals(nextResult,true);
- assertEquals(expectedRow.length, columnNameList.length);
- for (int i = 0; i < expectedRow.length; i++) {
- Object expectedObject = expectedRow[i];
- String columnName = columnNameList[i];
- if (expectedObject instanceof Boolean)
- assertEquals(((Boolean)expectedObject).booleanValue(), resultSet.getBoolean(columnName));
- else if (expectedObject instanceof Byte)
- assertEquals(((Byte)expectedObject).byteValue(), resultSet.getByte(columnName));
- else if (expectedObject instanceof Short)
- assertEquals(((Short)expectedObject).shortValue(), resultSet.getShort(columnName));
- else if (expectedObject instanceof Integer)
- assertEquals(((Integer)expectedObject).intValue(), resultSet.getInt(columnName));
- else if (expectedObject instanceof Long)
- assertEquals(((Long)expectedObject).longValue(), resultSet.getLong(columnName));
- else if (expectedObject instanceof Float)
- assertEquals(((Float)expectedObject).floatValue(), resultSet.getFloat(columnName), 0.00001);
- else if (expectedObject instanceof Double)
- assertEquals(((Double)expectedObject).doubleValue(), resultSet.getDouble(columnName), 0.00001);
- else if (expectedObject instanceof byte[])
- assertEquals((byte[])expectedObject, resultSet.getByteArray(columnName));
- else if (expectedObject instanceof String)
- assertEquals((String)expectedObject, resultSet.getString(columnName));
- else
- assertTrue("Unexpected column value type", false);
- }
- }
- nextResult = resultSet.next();
- assertEquals(nextResult,false);
- resultSet.close();
- }
-
- @Test
- public void testInsertRows() {
- IResultSet resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, null, null, new RowOrdering(PERSON_SSN));
- checkExpectedResults(resultSet, PERSON_COLUMN_LIST, PERSON_INIT_DATA);
- }
-
- @Test
- public void testOperatorQuery() {
- Object[][] expectedResults = {
- {"John", "Smith", 40},
- {"Jim", "White", 24},
- };
- String[] columnList = {PERSON_FIRST_NAME,PERSON_LAST_NAME,PERSON_AGE};
- IResultSet resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, columnList,
- new OperatorPredicate(PERSON_LAST_NAME, OperatorPredicate.Operator.GTE, "Sm"),
- new RowOrdering(PERSON_SSN));
- checkExpectedResults(resultSet, columnList, expectedResults);
- }
-
- @Test
- public void testAndQuery() {
- String[] columnList = {PERSON_FIRST_NAME,PERSON_LAST_NAME};
- Object[][] expectedResults = {
- {"Lisa", "Jones"},
- {"Susan", "Jones"},
- {"Jose", "Garcia"},
- {"Abigail", "Johnson"},
- {"John", "McEnroe"}
- };
- IResultSet resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, columnList,
- new CompoundPredicate(CompoundPredicate.Operator.AND, false,
- new OperatorPredicate(PERSON_LAST_NAME, OperatorPredicate.Operator.GTE, "G"),
- new OperatorPredicate(PERSON_LAST_NAME, OperatorPredicate.Operator.LT, "N")
- ),
- new RowOrdering(PERSON_SSN));
- checkExpectedResults(resultSet, columnList, expectedResults);
- }
-
- @Test
- public void testOrQuery() {
- String[] columnList = {PERSON_FIRST_NAME,PERSON_LAST_NAME, PERSON_AGE};
- Object[][] expectedResults = {
- {"John", "Smith", 40},
- {"Lisa", "Jones", 27},
- {"Abigail", "Johnson", 35},
- {"Bjorn", "Borg", 55},
- {"John", "McEnroe", 53}
- };
- IResultSet resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, columnList,
- new CompoundPredicate(CompoundPredicate.Operator.OR, false,
- new OperatorPredicate(PERSON_AGE, OperatorPredicate.Operator.GTE, 35),
- new OperatorPredicate(PERSON_FIRST_NAME, OperatorPredicate.Operator.EQ, "Lisa")
- ),
- new RowOrdering(PERSON_SSN));
- checkExpectedResults(resultSet, columnList, expectedResults);
-}
-
- @Test
- public void testCreateQuery() {
- String[] columnList = {PERSON_FIRST_NAME,PERSON_LAST_NAME};
- Object[][] expectedResults = {
- {"Lisa", "Jones"},
- {"Susan", "Jones"}
- };
- IPredicate predicate = new OperatorPredicate(PERSON_LAST_NAME, OperatorPredicate.Operator.EQ, "Jones");
- IQuery query = storageSource.createQuery(PERSON_TABLE_NAME, columnList, predicate, new RowOrdering(PERSON_SSN));
- IResultSet resultSet = storageSource.executeQuery(query);
- checkExpectedResults(resultSet, columnList, expectedResults);
- }
-
- @Test
- public void testQueryParameters() {
- String[] columnList = {PERSON_FIRST_NAME,PERSON_LAST_NAME, PERSON_AGE};
- Object[][] expectedResults = {
- {"John", "Smith", 40},
- {"Bjorn", "Borg", 55},
- {"John", "McEnroe", 53}
- };
- IPredicate predicate = new OperatorPredicate(PERSON_AGE, OperatorPredicate.Operator.GTE, "?MinimumAge?");
- IQuery query = storageSource.createQuery(PERSON_TABLE_NAME, columnList, predicate, new RowOrdering(PERSON_SSN));
- query.setParameter("MinimumAge", 40);
- IResultSet resultSet = storageSource.executeQuery(query);
- checkExpectedResults(resultSet, columnList, expectedResults);
- }
-
- private void checkPerson(Person person, Object[] expectedValues) {
- assertEquals(person.getSSN(), expectedValues[0]);
- assertEquals(person.getFirstName(), expectedValues[1]);
- assertEquals(person.getLastName(), expectedValues[2]);
- assertEquals(person.getAge(), expectedValues[3]);
- assertEquals(person.isRegistered(), expectedValues[4]);
- }
-
- @Test
- public void testRowMapper() {
- Object[][] expectedResults = {
- PERSON_INIT_DATA[2],
- PERSON_INIT_DATA[3]
- };
- IPredicate predicate = new OperatorPredicate(PERSON_LAST_NAME, OperatorPredicate.Operator.EQ, "Jones");
- IRowMapper rowMapper = new PersonRowMapper();
- Object[] personList = storageSource.executeQuery(PERSON_TABLE_NAME, null, predicate, new RowOrdering(PERSON_SSN), rowMapper);
- assertEquals(personList.length, 2);
- for (int i = 0; i < personList.length; i++)
- checkPerson((Person)personList[i], expectedResults[i]);
- }
-
- @Test
- public void testDeleteRowsDirect() {
-
- storageSource.deleteRow(PERSON_TABLE_NAME, "111-11-1111");
- storageSource.deleteRow(PERSON_TABLE_NAME, "222-22-2222");
- storageSource.deleteRow(PERSON_TABLE_NAME, "333-33-3333");
- storageSource.deleteRow(PERSON_TABLE_NAME, "444-44-4444");
-
- Object[][] expectedResults = {
- {"555-55-5555", "Jose", "Garcia", 31, true},
- {"666-66-6666", "Abigail", "Johnson", 35, false},
- {"777-77-7777", "Bjorn", "Borg", 55, true},
- {"888-88-8888", "John", "McEnroe", 53, false}
- };
- IResultSet resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, PERSON_COLUMN_LIST, null, new RowOrdering(PERSON_SSN));
- checkExpectedResults(resultSet, PERSON_COLUMN_LIST, expectedResults);
- }
-
- @Test
- public void testDeleteRowsFromResultSet() {
- Object[][] expectedResults = {
- {"555-55-5555", "Jose", "Garcia", 31, true},
- {"666-66-6666", "Abigail", "Johnson", 35, false},
- {"777-77-7777", "Bjorn", "Borg", 55, true},
- {"888-88-8888", "John", "McEnroe", 53, false}
- };
-
- // Query once to delete the rows
- IResultSet resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, PERSON_COLUMN_LIST, null, new RowOrdering(PERSON_SSN));
- for (int i = 0; i < 4; i++) {
- resultSet.next();
- resultSet.deleteRow();
- }
- resultSet.save();
- resultSet.close();
-
- // Now query again to verify that the rows were deleted
- resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, PERSON_COLUMN_LIST, null, new RowOrdering(PERSON_SSN));
- checkExpectedResults(resultSet, PERSON_COLUMN_LIST, expectedResults);
- }
-
- @Test
- public void testDeleteMatchingRows() {
- Object[][] expectedResults = {
- {"111-11-1111", "John", "Smith", 40, true},
- {"777-77-7777", "Bjorn", "Borg", 55, true},
- {"888-88-8888", "John", "McEnroe", 53, false}
- };
- storageSource.deleteMatchingRows(PERSON_TABLE_NAME, new OperatorPredicate(PERSON_AGE, OperatorPredicate.Operator.LT, 40));
-
- // Now query again to verify that the rows were deleted
- IResultSet resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, PERSON_COLUMN_LIST, null, new RowOrdering(PERSON_SSN));
- checkExpectedResults(resultSet, PERSON_COLUMN_LIST, expectedResults);
-
- storageSource.deleteMatchingRows(PERSON_TABLE_NAME, null);
-
- // Now query again to verify that all rows were deleted
- resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, PERSON_COLUMN_LIST, null, new RowOrdering(PERSON_SSN));
- checkExpectedResults(resultSet, PERSON_COLUMN_LIST, new Object[0][]);
- }
-
- @Test
- public void testUpdateRowsDirect() {
-
- Object[][] expectedResults = {
- {"777-77-7777", "Tennis", "Borg", 60, true},
- {"888-88-8888", "Tennis", "McEnroe", 60, false}
- };
- Map<String,Object> updateValues = new HashMap<String,Object>();
- updateValues.put(PERSON_FIRST_NAME, "Tennis");
- updateValues.put(PERSON_AGE, 60);
-
- IPredicate predicate = new OperatorPredicate(PERSON_AGE, OperatorPredicate.Operator.GT, 50);
- IResultSet resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, null, predicate, new RowOrdering(PERSON_SSN));
- while (resultSet.next()) {
- String key = resultSet.getString(PERSON_SSN);
- storageSource.updateRow(PERSON_TABLE_NAME, key, updateValues);
- }
- resultSet.close();
-
- resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, PERSON_COLUMN_LIST, predicate, new RowOrdering(PERSON_SSN));
- checkExpectedResults(resultSet, PERSON_COLUMN_LIST, expectedResults);
- }
-
- @Test
- public void testUpdateRowsFromResultSet() {
-
- Object[][] expectedResults = {
- {"777-77-7777", "Tennis", "Borg", 60, true},
- {"888-88-8888", "Tennis", "McEnroe", 60, false}
- };
-
- IPredicate predicate = new OperatorPredicate(PERSON_AGE, OperatorPredicate.Operator.GT, 50);
- IResultSet resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, null, predicate, null);
- while (resultSet.next()) {
- resultSet.setString(PERSON_FIRST_NAME, "Tennis");
- resultSet.setInt(PERSON_AGE, 60);
- }
- resultSet.save();
- resultSet.close();
-
- resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, PERSON_COLUMN_LIST, predicate, new RowOrdering(PERSON_SSN));
- checkExpectedResults(resultSet, PERSON_COLUMN_LIST, expectedResults);
- }
-
- @Test
- public void testNullValues() {
-
- IPredicate predicate = new OperatorPredicate(PERSON_LAST_NAME, OperatorPredicate.Operator.EQ, "Jones");
- IResultSet resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, null, predicate, new RowOrdering(PERSON_SSN));
- while (resultSet.next()) {
- resultSet.setNull(PERSON_FIRST_NAME);
- resultSet.setIntegerObject(PERSON_AGE, null);
- }
- resultSet.save();
- resultSet.close();
-
- resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, null, predicate, new RowOrdering(PERSON_SSN));
- int count = 0;
- while (resultSet.next()) {
- boolean checkNull = resultSet.isNull(PERSON_FIRST_NAME);
- assertTrue(checkNull);
- String s = resultSet.getString(PERSON_FIRST_NAME);
- assertEquals(s, null);
- checkNull = resultSet.isNull(PERSON_AGE);
- assertTrue(checkNull);
- Integer intObj = resultSet.getIntegerObject(PERSON_AGE);
- assertEquals(intObj, null);
- Short shortObj = resultSet.getShortObject(PERSON_AGE);
- assertEquals(shortObj, null);
- boolean excThrown = false;
- try {
- resultSet.getInt(PERSON_AGE);
- }
- catch (NullValueStorageException exc) {
- excThrown = true;
- }
- assertTrue(excThrown);
- count++;
- }
- resultSet.close();
- assertEquals(count, 2);
-
- predicate = new OperatorPredicate(PERSON_FIRST_NAME, OperatorPredicate.Operator.EQ, null);
- resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, null, predicate, new RowOrdering(PERSON_SSN));
- count = 0;
- while (resultSet.next()) {
- boolean checkNull = resultSet.isNull(PERSON_FIRST_NAME);
- assertTrue(checkNull);
- count++;
- checkNull = resultSet.isNull(PERSON_AGE);
- assertTrue(checkNull);
- }
- resultSet.close();
- assertEquals(count, 2);
- }
-
- @Test
- public void testInsertNotification() {
- // Set up the listener and record the expected notification
- IStorageSourceListener mockListener = createNiceMock(IStorageSourceListener.class);
- Set<Object> expectedKeys = new HashSet<Object>();
- expectedKeys.add("999-99-9999");
- mockListener.rowsModified(PERSON_TABLE_NAME, expectedKeys);
-
- replay(mockListener);
-
- // Now try it for real
- storageSource.addListener(PERSON_TABLE_NAME, mockListener);
-
- // Create a new person, which should trigger the listener
- Object[] newPerson = {"999-99-9999", "Serena", "Williams", 22, true};
- insertPerson(newPerson);
-
- verify(mockListener);
- }
-
- @Test
- public void testUpdateNotification() {
- // Set up the listener and record the expected notification
- IStorageSourceListener mockListener = createNiceMock(IStorageSourceListener.class);
- Set<Object> expectedKeys = new HashSet<Object>();
- expectedKeys.add("111-11-1111");
- mockListener.rowsModified(PERSON_TABLE_NAME, expectedKeys);
-
- replay(mockListener);
-
- // Now try it for real
- storageSource.addListener(PERSON_TABLE_NAME, mockListener);
-
- // Create a new person, which should trigger the listener
- Map<String,Object> updateValues = new HashMap<String,Object>();
- updateValues.put(PERSON_FIRST_NAME, "Tennis");
- storageSource.updateRow(PERSON_TABLE_NAME, "111-11-1111", updateValues);
-
- verify(mockListener);
- }
-
- @Test
- public void testDeleteNotification() {
- IStorageSourceListener mockListener = createNiceMock(IStorageSourceListener.class);
- Set<Object> expectedKeys = new HashSet<Object>();
- expectedKeys.add("111-11-1111");
- mockListener.rowsDeleted(PERSON_TABLE_NAME, expectedKeys);
-
- replay(mockListener);
-
- // Now try it for real
- storageSource.addListener(PERSON_TABLE_NAME, mockListener);
-
- // Create a new person, which should trigger the listener
- storageSource.deleteRow(PERSON_TABLE_NAME, "111-11-1111");
-
- verify(mockListener);
- }
-
- public void waitForFuture(Future<?> future) {
- try
- {
- future.get(10, TimeUnit.SECONDS);
- }
- catch (InterruptedException exc)
- {
- fail("Async storage operation interrupted");
- }
- catch (ExecutionException exc) {
- fail("Async storage operation failed");
- }
- catch (TimeoutException exc) {
- fail("Async storage operation timed out");
- }
- }
-
- @Test
- public void testAsyncQuery1() {
- Object[][] expectedResults = {
- {"John", "Smith", 40},
- {"Jim", "White", 24},
- };
- String[] columnList = {PERSON_FIRST_NAME,PERSON_LAST_NAME,PERSON_AGE};
- IPredicate predicate = new OperatorPredicate(PERSON_LAST_NAME, OperatorPredicate.Operator.GTE, "Sm");
- IQuery query = storageSource.createQuery(PERSON_TABLE_NAME, columnList, predicate, new RowOrdering(PERSON_SSN));
- Future<IResultSet> future = storageSource.executeQueryAsync(query);
- waitForFuture(future);
- try {
- IResultSet resultSet = future.get();
- checkExpectedResults(resultSet, columnList, expectedResults);
- }
- catch (Exception e) {
- fail("Exception thrown in async storage operation: " + e.toString());
- }
- }
-
- @Test
- public void testAsyncQuery2() {
- Object[][] expectedResults = {
- {"John", "Smith", 40},
- {"Jim", "White", 24},
- };
- String[] columnList = {PERSON_FIRST_NAME,PERSON_LAST_NAME,PERSON_AGE};
- IPredicate predicate = new OperatorPredicate(PERSON_LAST_NAME, OperatorPredicate.Operator.GTE, "Sm");
- Future<IResultSet> future = storageSource.executeQueryAsync(PERSON_TABLE_NAME,
- columnList, predicate, new RowOrdering(PERSON_SSN));
- waitForFuture(future);
- try {
- IResultSet resultSet = future.get();
- checkExpectedResults(resultSet, columnList, expectedResults);
- }
- catch (Exception e) {
- fail("Exception thrown in async storage operation: " + e.toString());
- }
- }
-
- @Test
- public void testAsyncQuery3() {
- Object[][] expectedResults = {
- PERSON_INIT_DATA[2],
- PERSON_INIT_DATA[3]
- };
- IPredicate predicate = new OperatorPredicate(PERSON_LAST_NAME, OperatorPredicate.Operator.EQ, "Jones");
- IRowMapper rowMapper = new PersonRowMapper();
- Future<Object[]> future = storageSource.executeQueryAsync(PERSON_TABLE_NAME,
- null, predicate, new RowOrdering(PERSON_SSN), rowMapper);
- waitForFuture(future);
- try {
- Object[] personList = future.get();
- assertEquals(personList.length, 2);
- for (int i = 0; i < personList.length; i++)
- checkPerson((Person)personList[i], expectedResults[i]);
- }
- catch (Exception e) {
- fail("Exception thrown in async storage operation: " + e.toString());
- }
- }
-
- @Test
- public void testAsyncException() {
- class TestExceptionHandler implements IStorageExceptionHandler {
- public int exceptionCount = 0;
- @Override
- public void handleException(Exception exception) {
- exceptionCount++;
- }
- }
- TestExceptionHandler exceptionHandler = new TestExceptionHandler();
- storageSource.setExceptionHandler(exceptionHandler);
-
- // Use an invalid table name, which should cause the storage API call to throw
- // an exception, which should then be converted to an ExecutionException.
- Future<IResultSet> future = storageSource.executeQueryAsync("InvalidTableName",
- null, null, null);
- try {
- future.get(10, TimeUnit.SECONDS);
- fail("Expected ExecutionException was not thrown");
- }
- catch (ExecutionException e) {
- assertTrue(true);
- }
- catch (Exception e) {
- fail("Exception thrown in async storage operation: " + e.toString());
- }
- assertEquals(exceptionHandler.exceptionCount, 1);
- }
-
- @Test
- public void testAsyncInsertRow() {
- Object[][] newPersonInfo = {{"999-99-9999", "Ellen", "Wilson", 40, true}};
- Map<String,Object> rowValues = createPersonRowValues(newPersonInfo[0]);
- Future<?> future = storageSource.insertRowAsync(PERSON_TABLE_NAME, rowValues);
- waitForFuture(future);
- try {
- IResultSet resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, null, null, new RowOrdering(PERSON_SSN));
- Object[][] expectedPersons = Arrays.copyOf(PERSON_INIT_DATA, PERSON_INIT_DATA.length + newPersonInfo.length);
- System.arraycopy(newPersonInfo, 0, expectedPersons, PERSON_INIT_DATA.length, newPersonInfo.length);
- checkExpectedResults(resultSet, PERSON_COLUMN_LIST, expectedPersons);
- }
- catch (Exception e) {
- fail("Exception thrown in async storage operation: " + e.toString());
- }
- }
-
- @Test
- public void testAsyncUpdateRow() {
- Map<String,Object> updateValues = new HashMap<String,Object>();
- updateValues.put(PERSON_SSN, "777-77-7777");
- updateValues.put(PERSON_FIRST_NAME, "Tennis");
- updateValues.put(PERSON_AGE, 60);
-
- Future<?> future = storageSource.updateRowAsync(PERSON_TABLE_NAME, updateValues);
- waitForFuture(future);
-
- try {
- IResultSet resultSet = storageSource.getRow(PERSON_TABLE_NAME, "777-77-7777");
- Object[][] expectedPersons = {{"777-77-7777", "Tennis", "Borg", 60, true}};
- checkExpectedResults(resultSet, PERSON_COLUMN_LIST, expectedPersons);
- }
- catch (Exception e) {
- fail("Exception thrown in async storage operation: " + e.toString());
- }
- }
-
- @Test
- public void testAsyncUpdateRow2() {
- Map<String,Object> updateValues = new HashMap<String,Object>();
- updateValues.put(PERSON_FIRST_NAME, "Tennis");
- updateValues.put(PERSON_AGE, 60);
-
- Future<?> future = storageSource.updateRowAsync(PERSON_TABLE_NAME, "777-77-7777", updateValues);
- waitForFuture(future);
-
- try {
- IResultSet resultSet = storageSource.getRow(PERSON_TABLE_NAME, "777-77-7777");
- Object[][] expectedPersons = {{"777-77-7777", "Tennis", "Borg", 60, true}};
- checkExpectedResults(resultSet, PERSON_COLUMN_LIST, expectedPersons);
- }
- catch (Exception e) {
- fail("Exception thrown in async storage operation: " + e.toString());
- }
- }
-
- @Test
- public void testAsyncUpdateMatchingRows() {
- Map<String,Object> updateValues = new HashMap<String,Object>();
- updateValues.put(PERSON_FIRST_NAME, "Tennis");
- updateValues.put(PERSON_AGE, 60);
-
- IPredicate predicate = new OperatorPredicate(PERSON_SSN, OperatorPredicate.Operator.EQ, "777-77-7777");
- Future<?> future = storageSource.updateMatchingRowsAsync(PERSON_TABLE_NAME, predicate, updateValues);
- waitForFuture(future);
- try {
- IResultSet resultSet = storageSource.getRow(PERSON_TABLE_NAME, "777-77-7777");
- Object[][] expectedPersons = {{"777-77-7777", "Tennis", "Borg", 60, true}};
- checkExpectedResults(resultSet, PERSON_COLUMN_LIST, expectedPersons);
- }
- catch (Exception e) {
- fail("Exception thrown in async storage operation: " + e.toString());
- }
- }
-
- @Test
- public void testAsyncDeleteRow() {
- Future<?> future = storageSource.deleteRowAsync(PERSON_TABLE_NAME, "111-11-1111");
- waitForFuture(future);
- try {
- IResultSet resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, null, null, new RowOrdering(PERSON_SSN));
- Object[][] expectedPersons = Arrays.copyOfRange(PERSON_INIT_DATA, 1, PERSON_INIT_DATA.length);
- checkExpectedResults(resultSet, PERSON_COLUMN_LIST, expectedPersons);
- }
- catch (Exception e) {
- fail("Exception thrown in async storage operation: " + e.toString());
- }
- }
-
- @Test
- public void testAsyncDeleteMatchingRows() {
- Future<?> future = storageSource.deleteMatchingRowsAsync(PERSON_TABLE_NAME, null);
- waitForFuture(future);
- try {
- IResultSet resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, null, null, new RowOrdering(PERSON_SSN));
- checkExpectedResults(resultSet, PERSON_COLUMN_LIST, new Object[0][]);
- }
- catch (Exception e) {
- fail("Exception thrown in async storage operation: " + e.toString());
- }
- }
-
- @Test
- public void testAsyncSave() {
- // Get a result set and make some changes to it
- IResultSet resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, null, null, new RowOrdering(PERSON_SSN));
- resultSet.next();
- resultSet.deleteRow();
- resultSet.next();
- resultSet.setString(PERSON_FIRST_NAME, "John");
-
- Future<?> future = storageSource.saveAsync(resultSet);
- waitForFuture(future);
- try {
- resultSet = storageSource.executeQuery(PERSON_TABLE_NAME, null, null, new RowOrdering(PERSON_SSN));
- Object[][] expectedPersons = Arrays.copyOfRange(PERSON_INIT_DATA, 1, PERSON_INIT_DATA.length);
- expectedPersons[0][1] = "John";
- checkExpectedResults(resultSet, PERSON_COLUMN_LIST, expectedPersons);
- }
- catch (Exception e) {
- fail("Exception thrown in async storage operation: " + e.toString());
- }
-
- }
-}
diff --git a/src/test/java/net/onrc/onos/ofcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java b/src/test/java/net/onrc/onos/ofcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java
index c3647f2..b2689a4 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java
@@ -17,19 +17,16 @@
package net.onrc.onos.ofcontroller.linkdiscovery.internal;
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
-import java.util.Collections;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import net.floodlightcontroller.core.IFloodlightProviderService;
import net.floodlightcontroller.core.IFloodlightProviderService.Role;
import net.floodlightcontroller.core.IOFSwitch;
@@ -39,8 +36,6 @@
import net.floodlightcontroller.restserver.RestApiServer;
import net.floodlightcontroller.routing.IRoutingService;
import net.floodlightcontroller.routing.Link;
-import net.floodlightcontroller.storage.IStorageSourceService;
-import net.floodlightcontroller.storage.memory.MemoryStorageSource;
import net.floodlightcontroller.test.FloodlightTestCase;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import net.floodlightcontroller.topology.ITopologyService;
@@ -49,7 +44,11 @@
import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryListener;
import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService;
import net.onrc.onos.ofcontroller.linkdiscovery.LinkInfo;
-import net.onrc.onos.ofcontroller.linkdiscovery.internal.LinkDiscoveryManager;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
@@ -75,11 +74,12 @@
isClearLinksCalled = false;
}
+ /*
@Override
protected void clearAllLinks() {
isClearLinksCalled = true;
super.clearAllLinks();
- }
+ }*/
}
public LinkDiscoveryManager getTopology() {
@@ -106,7 +106,7 @@
cntx.addService(IRoutingService.class, routingEngine);
cntx.addService(ILinkDiscoveryService.class, ldm);
cntx.addService(ITopologyService.class, ldm);
- cntx.addService(IStorageSourceService.class, new MemoryStorageSource());
+ //cntx.addService(IStorageSourceService.class, new MemoryStorageSource());
cntx.addService(IFloodlightProviderService.class, getMockFloodlightProvider());
restApi.init(cntx);
tp.init(cntx);
@@ -426,7 +426,7 @@
getMockFloodlightProvider().dispatchRoleChanged(Role.SLAVE, Role.MASTER);
// check that lldps were sent
assertTrue(ldm.isSendLLDPsCalled);
- assertTrue(ldm.isClearLinksCalled);
+ //assertTrue(ldm.isClearLinksCalled);
ldm.reset();
}
}