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/main/java/net/onrc/onos/core/intent/runtime/web/IntentLowResource.java b/src/main/java/net/onrc/onos/core/intent/runtime/web/IntentLowResource.java
new file mode 100644
index 0000000..bf0b527
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/intent/runtime/web/IntentLowResource.java
@@ -0,0 +1,39 @@
+package net.onrc.onos.core.intent.runtime.web;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import net.onrc.onos.core.intent.Intent;
+import net.onrc.onos.core.intent.IntentMap;
+import net.onrc.onos.core.intent.runtime.IPathCalcRuntimeService;
+
+import org.restlet.resource.Get;
+import org.restlet.resource.ServerResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A class to access the low-level intents.
+ */
+public class IntentLowResource extends ServerResource {
+ private static final Logger log = LoggerFactory.getLogger(IntentLowResource.class);
+
+ /**
+ * Gets all low-level intents.
+ *
+ * @return a collection of all low-leve intents.
+ */
+ @Get("json")
+ public Collection<Intent> retrieve() throws IOException {
+ IPathCalcRuntimeService pathRuntime = (IPathCalcRuntimeService) getContext().
+ getAttributes().get(IPathCalcRuntimeService.class.getCanonicalName());
+
+ //
+ // Get all low-level intents
+ //
+ IntentMap intentMap = pathRuntime.getPathIntents();
+ Collection<Intent> intents = intentMap.getAllIntents();
+
+ return intents;
+ }
+}