WIP: Refactoring the Intent REST API.
NOTE: All changes are Work-in-Progress, and they are in the process
of being actively updated and refactored.
* The new implementation is in onos/core/intent/runtime/web
The old implementation in the onos/core/datagrid/web is kept until
the refactoring is completed.
* The new REST API base path is /wm/onos/intent
* The initial set of (new) APIs is the following:
- /wm/onos/intent/high
GET all high-level intent
POST (create) a collection of high-level intents
DELETE all intents
- /wm/onos/intent/high/{intent-id}
GET a high-level intent object
DELETE a high-level intent object
- /wm/onos/intent/low
GET all low-level intents
- /wm/onos/intent/low/{intent-id}
GET a low-level intent object
- /wm/onos/intent/path/switch/{src-dpid}/shortest-path/{dst-dpid}
GET a Shortest Path between two Switch DPIDs
* The Application-Level Intent object is specified in class
onos/api/intent/ApplicationIntent.java
TODO (list incomplete):
- Return the appropriate REST codes and return values for each REST operation
- Add the appropriate Java APIs so each REST call would make a single
Java call.
- If necessary, rename API class ApplicationIntent to something more
appropriate, and use it in the Java API.
- Re-think/refactor the ApplicationIntent so it becomes a more solid base for
all (high-level) intents.
- The corresponding Java APIs for each REST call should be synchronous
(for some definition of the expected operation outcome).
- Implement intent/intents Java API delete operation that requires a
single call instead of two calls (delete and purge)
- Refactor the High and Low Level intents, such that they don't use
inheritance from a common base class.
- Cleanup the return Intent objects representation in JSON. E.g.,
the Dpid JSON should be just "dpid": <value> instead of
"dpid": {
"value": <value>
}
Change-Id: Ia994a2026f57a1f176c5321c1952325e3b986097
diff --git a/src/test/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModuleTest.java b/src/test/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModuleTest.java
index 17f5788..5e1a11d 100644
--- a/src/test/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModuleTest.java
+++ b/src/test/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModuleTest.java
@@ -19,6 +19,8 @@
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.module.FloodlightModuleException;
+import net.floodlightcontroller.restserver.IRestApiService;
+
import net.onrc.onos.core.datagrid.IDatagridService;
import net.onrc.onos.core.datagrid.IEventChannel;
import net.onrc.onos.core.datagrid.IEventChannelListener;
@@ -29,6 +31,7 @@
import net.onrc.onos.core.intent.IntentOperationList;
import net.onrc.onos.core.intent.MockNetworkGraph;
import net.onrc.onos.core.intent.ShortestPathIntent;
+import net.onrc.onos.core.intent.runtime.web.IntentWebRoutable;
import net.onrc.onos.core.registry.IControllerRegistryService;
import net.onrc.onos.core.topology.DeviceEvent;
import net.onrc.onos.core.topology.INetworkGraphListener;
@@ -69,6 +72,7 @@
private INetworkGraphService networkGraphService;
private IControllerRegistryService controllerRegistryService;
private PersistIntent persistIntent;
+ private IRestApiService restApi;
private MockNetworkGraph graph;
private IEventChannel<Long, IntentOperationList> intentOperationChannel;
private IEventChannel<Long, IntentStateList> intentStateChannel;
@@ -86,6 +90,7 @@
intentOperationChannel = createMock(IEventChannel.class);
intentStateChannel = createMock(IEventChannel.class);
persistIntent = PowerMock.createMock(PersistIntent.class);
+ restApi = createMock(IRestApiService.class);
PowerMock.expectNew(PersistIntent.class,
anyObject(IControllerRegistryService.class)).andReturn(persistIntent);
@@ -100,6 +105,8 @@
expect(persistIntent.persistIfLeader(eq(1L),
anyObject(IntentOperationList.class))).andReturn(true)
.anyTimes();
+ expect(modContext.getServiceImpl(IRestApiService.class))
+ .andReturn(restApi).once();
expect(networkGraphService.getNetworkGraph()).andReturn(graph)
.anyTimes();
@@ -117,12 +124,14 @@
eq(Long.class),
eq(IntentStateList.class)))
.andReturn(intentStateChannel).once();
+ restApi.addRestletRoutable(anyObject(IntentWebRoutable.class));
replay(datagridService);
replay(networkGraphService);
replay(modContext);
replay(controllerRegistryService);
PowerMock.replay(persistIntent, PersistIntent.class);
+ replay(restApi);
}
@@ -235,6 +244,7 @@
verify(modContext);
verify(controllerRegistryService);
PowerMock.verify(persistIntent, PersistIntent.class);
+ verify(restApi);
}
/**
diff --git a/src/test/java/net/onrc/onos/core/intent/runtime/UseCaseTest.java b/src/test/java/net/onrc/onos/core/intent/runtime/UseCaseTest.java
index 4a0df3a..f3c9aaa 100644
--- a/src/test/java/net/onrc/onos/core/intent/runtime/UseCaseTest.java
+++ b/src/test/java/net/onrc/onos/core/intent/runtime/UseCaseTest.java
@@ -14,6 +14,8 @@
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.module.FloodlightModuleException;
+import net.floodlightcontroller.restserver.IRestApiService;
+
import net.onrc.onos.core.datagrid.IDatagridService;
import net.onrc.onos.core.datagrid.IEventChannel;
import net.onrc.onos.core.datagrid.IEventChannelListener;
@@ -27,6 +29,7 @@
import net.onrc.onos.core.intent.PathIntent;
import net.onrc.onos.core.intent.PathIntentMap;
import net.onrc.onos.core.intent.ShortestPathIntent;
+import net.onrc.onos.core.intent.runtime.web.IntentWebRoutable;
import net.onrc.onos.core.registry.IControllerRegistryService;
import net.onrc.onos.core.topology.DeviceEvent;
import net.onrc.onos.core.topology.INetworkGraphListener;
@@ -60,6 +63,7 @@
private INetworkGraphService networkGraphService;
private IControllerRegistryService controllerRegistryService;
private PersistIntent persistIntent;
+ private IRestApiService restApi;
private IEventChannel<Long, IntentOperationList> intentOperationChannel;
private IEventChannel<Long, IntentStateList> intentStateChannel;
@@ -79,6 +83,7 @@
intentOperationChannel = createMock(IEventChannel.class);
intentStateChannel = createMock(IEventChannel.class);
persistIntent = PowerMock.createMock(PersistIntent.class);
+ restApi = createMock(IRestApiService.class);
PowerMock.expectNew(PersistIntent.class,
anyObject(IControllerRegistryService.class)).andReturn(persistIntent);
@@ -92,6 +97,8 @@
expect(persistIntent.getKey()).andReturn(1L).anyTimes();
expect(persistIntent.persistIfLeader(eq(1L),
anyObject(IntentOperationList.class))).andReturn(true).anyTimes();
+ expect(modContext.getServiceImpl(IRestApiService.class))
+ .andReturn(restApi).once();
expect(networkGraphService.getNetworkGraph()).andReturn(g).anyTimes();
networkGraphService.registerNetworkGraphListener(anyObject(INetworkGraphListener.class));
@@ -106,12 +113,14 @@
eq(Long.class),
eq(IntentStateList.class)))
.andReturn(intentStateChannel).once();
+ restApi.addRestletRoutable(anyObject(IntentWebRoutable.class));
replay(datagridService);
replay(networkGraphService);
replay(modContext);
replay(controllerRegistryService);
PowerMock.replay(persistIntent, PersistIntent.class);
+ replay(restApi);
}
@After
@@ -121,6 +130,7 @@
verify(modContext);
verify(controllerRegistryService);
PowerMock.verify(persistIntent, PersistIntent.class);
+ verify(restApi);
}
private void showResult(PathIntentMap intents) {