1)Add log time retrieval from rest
2) mesh_topology.py can run without ONOS
Change-Id: Ibc17d963478ab298b2472347828a360465384c3d
diff --git a/src/main/java/net/onrc/onos/datagrid/web/DatagridWebRoutable.java b/src/main/java/net/onrc/onos/datagrid/web/DatagridWebRoutable.java
index a8c3f5b..7015d44 100755
--- a/src/main/java/net/onrc/onos/datagrid/web/DatagridWebRoutable.java
+++ b/src/main/java/net/onrc/onos/datagrid/web/DatagridWebRoutable.java
@@ -21,6 +21,8 @@
router.attach("/get/intents/json", IntentResource.class);
router.attach("/get/intent/{intent_id}/json", IntentResource.class);
router.attach("/get/ng-events/json", GetNGEventsResource.class);
+ router.attach("/get/intents/{category}/json", IntentResource.class);
+ router.attach("/get/intent/{category}/{intent_id}/json", IntentResource.class);
return router;
}
diff --git a/src/main/java/net/onrc/onos/datagrid/web/IntentResource.java b/src/main/java/net/onrc/onos/datagrid/web/IntentResource.java
index 2fc78f0..bd420e3 100755
--- a/src/main/java/net/onrc/onos/datagrid/web/IntentResource.java
+++ b/src/main/java/net/onrc/onos/datagrid/web/IntentResource.java
@@ -23,6 +23,7 @@
import org.codehaus.jackson.map.ObjectMapper;
import net.floodlightcontroller.util.MACAddress;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.Map;
import org.codehaus.jackson.node.ArrayNode;
import org.codehaus.jackson.node.ObjectNode;
@@ -104,12 +105,19 @@
public String retrieve() throws IOException {
IPathCalcRuntimeService pathRuntime = (IPathCalcRuntimeService)getContext().
getAttributes().get(IPathCalcRuntimeService.class.getCanonicalName());
+
+ String intentCategory = (String) getRequestAttributes().get("category");
+ IntentMap intentMap = null;
+ if (intentCategory.equals("high")) {
+ intentMap = pathRuntime.getHighLevelIntents();
+ } else {
+ intentMap = pathRuntime.getPathIntents();
+ }
ObjectMapper mapper = new ObjectMapper();
String restStr = "";
String intentId = (String) getRequestAttributes().get("intent_id");
ArrayNode arrayNode = mapper.createArrayNode();
- IntentMap intentMap = pathRuntime.getHighLevelIntents();
Collection<Intent> intents = intentMap.getAllIntents();
if (!intents.isEmpty()) {
if ((intentId != null )) {
@@ -117,8 +125,15 @@
Intent intent = intentMap.getIntent(applnIntentId);
if (intent != null) {
ObjectNode node = mapper.createObjectNode();
+ // TODO refactor/remove duplicate code.
node.put("intent_id", intentId);
node.put("status", intent.getState().toString());
+ LinkedList<String> logs = intent.getLogs();
+ ArrayNode logNode = mapper.createArrayNode();
+ for (String intentLog :logs) {
+ logNode.add(intentLog);
+ }
+ node.put("log", logNode);
arrayNode.add(node);
}
} else {
@@ -128,6 +143,12 @@
intentId = applnIntentId.split(":")[1];
node.put("intent_id", intentId);
node.put("status", intent.getState().toString());
+ LinkedList<String> logs = intent.getLogs();
+ ArrayNode logNode = mapper.createArrayNode();
+ for (String intentLog :logs) {
+ logNode.add(intentLog);
+ }
+ node.put("log", logNode);
arrayNode.add(node);
}
}
@@ -152,26 +173,32 @@
data = node.get(fieldName);
parseFields(data, fieldName, fields);
}
- String status = processIntent(fields, operations);
- appendIntentStatus(status, (String)fields.get("intent_id"), mapper, arrayNode);
+ Intent intent = processIntent(fields, operations);
+ appendIntentStatus(intent, (String)fields.get("intent_id"), mapper, arrayNode);
}
}
pathRuntime.executeIntentOperations(operations);
return mapper.writeValueAsString(arrayNode);
}
- private void appendIntentStatus(String status, final String intentId,
+ private void appendIntentStatus(Intent intent, final String intentId,
ObjectMapper mapper, ArrayNode arrayNode) throws IOException {
ObjectNode node = mapper.createObjectNode();
node.put("intent_id", intentId);
- node.put("status", status);
+ node.put("status", intent.getState().toString());
+ LinkedList<String> logs = intent.getLogs();
+ ArrayNode logNode = mapper.createArrayNode();
+ for (String intentLog : logs) {
+ logNode.add(intentLog);
+ }
+ node.put("log", logNode);
arrayNode.add(node);
}
- private String processIntent(Map<String, Object> fields, IntentOperationList operations) {
+ private Intent processIntent(Map<String, Object> fields, IntentOperationList operations) {
String intentType = (String)fields.get("intent_type");
String intentOp = (String)fields.get("intent_op");
- String status = null;
+ Intent intent;
String applnIntentId = APPLN_ID + ":" + (String)fields.get("intent_id");
IntentOperation.Operator operation = IntentOperation.Operator.ADD;
@@ -187,7 +214,7 @@
(long) fields.get("dstPort"),
MACAddress.valueOf((String) fields.get("dstMac")).toLong());
operations.add(new IntentOperation(operation, spi));
- status = (spi.getState()).toString();
+ intent = spi;
} else {
ConstrainedShortestPathIntent cspi = new ConstrainedShortestPathIntent(applnIntentId,
Long.decode((String) fields.get("srcSwitch")),
@@ -198,9 +225,9 @@
MACAddress.valueOf((String) fields.get("dstMac")).toLong(),
(double) fields.get("bandwidth"));
operations.add(new IntentOperation(operation, cspi));
- status = (cspi.getState()).toString();
+ intent = cspi;
}
- return status;
+ return intent;
}
private void parseFields(JsonNode node, String fieldName, Map<String, Object> fields) {
diff --git a/src/main/java/net/onrc/onos/intent/persist/PersistIntent.java b/src/main/java/net/onrc/onos/intent/persist/PersistIntent.java
index 691a656..4f77883 100755
--- a/src/main/java/net/onrc/onos/intent/persist/PersistIntent.java
+++ b/src/main/java/net/onrc/onos/intent/persist/PersistIntent.java
@@ -14,7 +14,6 @@
import net.onrc.onos.intent.IntentOperationList;
import net.onrc.onos.ofcontroller.networkgraph.INetworkGraphService;
import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
-import net.onrc.onos.ofcontroller.util.serializers.KryoFactory;
import net.onrc.onos.registry.controller.IControllerRegistryService;
import net.onrc.onos.registry.controller.IdBlock;
import org.slf4j.Logger;
diff --git a/test-network/mininet/mesh_topology.py b/test-network/mininet/mesh_topology.py
index 5cd8091..73a3d07 100755
--- a/test-network/mininet/mesh_topology.py
+++ b/test-network/mininet/mesh_topology.py
@@ -95,7 +95,6 @@
switches = 4
if max_switches != "":
switches = int(max_switches)
- topos = { 'mytopo': ( lambda: MyTopo(switches) ) }
net = Mininet(topo=MyTopo(switches), controller=MyController, link=TCLink)
print dumpNodeConnections(net.switches)
diff --git a/web/rest-intent/add-get-intent.rb b/web/rest-intent/add-get-intent.rb
index 59dea82..91554f5 100644
--- a/web/rest-intent/add-get-intent.rb
+++ b/web/rest-intent/add-get-intent.rb
@@ -3,7 +3,8 @@
options = {
:rest_op => "add",
- :intent_id => 123,
+ :intent_id => 1,
+ :intent_category => "high",
:intent_type => "shortest_intent_type",
:max_switches => 4,
:intent_op => "add"
@@ -30,6 +31,9 @@
opts.on('-t', '--max_intents max_intents', 'max. number of intents') do |max_intents|
options[:max_intents] = max_intents
end
+ opts.on('-e', '--intent_category intent_category', 'intent category high|low') do |intent_category|
+ options[:intent_category] = intent_category
+ end
opts.on('-i', '--intent_id intent_id', 'global intent id') do |id|
options[:intent_id] = id.to_i
end
@@ -67,6 +71,7 @@
end
parser.parse!
+
class Intent
attr_reader :switches, :ports, :intent_id
attr_reader :intent_type, :intent_op
@@ -83,11 +88,10 @@
def get_intent options
if options[:get_intents] == true
- request = RestClient.get "http://#{@server}:#{@port}/wm/onos/datagrid/get/intents/json"
+ request = RestClient.get "http://#{@server}:#{@port}/wm/onos/datagrid/get/intents/#{options[:intent_category]}/json"
else
- url = "http://#{@server}:#{@port}/wm/onos/datagrid/get/intent/#{options[:get_intent]}/json"
+ url = "http://#{@server}:#{@port}/wm/onos/datagrid/get/intent/#{options[:intent_category]}/#{options[:get_intent]}/json"
request = RestClient.get url
- #request = RestClient.get "http://#{@server}:#{@port}/wm/onos/datagrid/get/intent/json",{:intent_id => options[:get_intent]}
end
puts request
end