Thomas Vachuska

Adding JSON output for intent list command.

...@@ -19,6 +19,7 @@ import org.onlab.onos.net.intent.PathIntent; ...@@ -19,6 +19,7 @@ import org.onlab.onos.net.intent.PathIntent;
19 import org.onlab.onos.net.intent.PointToPointIntent; 19 import org.onlab.onos.net.intent.PointToPointIntent;
20 import org.onlab.onos.net.intent.SinglePointToMultiPointIntent; 20 import org.onlab.onos.net.intent.SinglePointToMultiPointIntent;
21 21
22 +import java.util.List;
22 import java.util.Set; 23 import java.util.Set;
23 24
24 /** 25 /**
...@@ -39,19 +40,23 @@ public class IntentsListCommand extends AbstractShellCommand { ...@@ -39,19 +40,23 @@ public class IntentsListCommand extends AbstractShellCommand {
39 print("id=%s, state=%s, type=%s, appId=%s", 40 print("id=%s, state=%s, type=%s, appId=%s",
40 intent.id(), state, intent.getClass().getSimpleName(), 41 intent.id(), state, intent.getClass().getSimpleName(),
41 intent.appId().name()); 42 intent.appId().name());
42 - printDetails(intent); 43 + printDetails(service, intent);
43 } 44 }
44 } 45 }
45 } 46 }
46 47
47 - private void printDetails(Intent intent) { 48 + private void printDetails(IntentService service, Intent intent) {
48 if (intent.resources() != null && !intent.resources().isEmpty()) { 49 if (intent.resources() != null && !intent.resources().isEmpty()) {
49 print(" resources=%s", intent.resources()); 50 print(" resources=%s", intent.resources());
50 } 51 }
51 if (intent instanceof ConnectivityIntent) { 52 if (intent instanceof ConnectivityIntent) {
52 ConnectivityIntent ci = (ConnectivityIntent) intent; 53 ConnectivityIntent ci = (ConnectivityIntent) intent;
53 - print(" selector=%s", ci.selector().criteria()); 54 + if (!ci.selector().criteria().isEmpty()) {
54 - print(" treatment=%s", ci.treatment().instructions()); 55 + print(" selector=%s", ci.selector().criteria());
56 + }
57 + if (!ci.treatment().instructions().isEmpty()) {
58 + print(" treatment=%s", ci.treatment().instructions());
59 + }
55 } 60 }
56 61
57 if (intent instanceof PointToPointIntent) { 62 if (intent instanceof PointToPointIntent) {
...@@ -71,6 +76,11 @@ public class IntentsListCommand extends AbstractShellCommand { ...@@ -71,6 +76,11 @@ public class IntentsListCommand extends AbstractShellCommand {
71 print(" links=%s", li.links()); 76 print(" links=%s", li.links());
72 print(" egress=%s", li.egressPoint()); 77 print(" egress=%s", li.egressPoint());
73 } 78 }
79 +
80 + List<Intent> installable = service.getInstallableIntents(intent.id());
81 + if (installable != null && !installable.isEmpty()) {
82 + print(" installable=%s", installable);
83 + }
74 } 84 }
75 85
76 // Produces JSON array of the specified intents. 86 // Produces JSON array of the specified intents.
...@@ -86,10 +96,14 @@ public class IntentsListCommand extends AbstractShellCommand { ...@@ -86,10 +96,14 @@ public class IntentsListCommand extends AbstractShellCommand {
86 private JsonNode json(IntentService service, ObjectMapper mapper, Intent intent) { 96 private JsonNode json(IntentService service, ObjectMapper mapper, Intent intent) {
87 ObjectNode result = mapper.createObjectNode() 97 ObjectNode result = mapper.createObjectNode()
88 .put("id", intent.id().toString()) 98 .put("id", intent.id().toString())
89 - .put("state", service.getIntentState(intent.id()).toString())
90 .put("type", intent.getClass().getSimpleName()) 99 .put("type", intent.getClass().getSimpleName())
91 .put("appId", intent.appId().name()); 100 .put("appId", intent.appId().name());
92 101
102 + IntentState state = service.getIntentState(intent.id());
103 + if (state != null) {
104 + result.put("state", state.toString());
105 + }
106 +
93 if (intent.resources() != null && !intent.resources().isEmpty()) { 107 if (intent.resources() != null && !intent.resources().isEmpty()) {
94 ArrayNode rnode = mapper.createArrayNode(); 108 ArrayNode rnode = mapper.createArrayNode();
95 for (NetworkResource resource : intent.resources()) { 109 for (NetworkResource resource : intent.resources()) {
...@@ -136,6 +150,10 @@ public class IntentsListCommand extends AbstractShellCommand { ...@@ -136,6 +150,10 @@ public class IntentsListCommand extends AbstractShellCommand {
136 result.set("links", LinksListCommand.json(li.links())); 150 result.set("links", LinksListCommand.json(li.links()));
137 } 151 }
138 152
153 + List<Intent> installable = service.getInstallableIntents(intent.id());
154 + if (installable != null && !installable.isEmpty()) {
155 + result.set("installable", json(service, installable));
156 + }
139 return result; 157 return result;
140 } 158 }
141 159
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 3
4 +import java.util.List;
5 +
4 /** 6 /**
5 * Service for application submitting or withdrawing their intents. 7 * Service for application submitting or withdrawing their intents.
6 */ 8 */
...@@ -68,6 +70,15 @@ public interface IntentService { ...@@ -68,6 +70,15 @@ public interface IntentService {
68 IntentState getIntentState(IntentId id); 70 IntentState getIntentState(IntentId id);
69 71
70 /** 72 /**
73 + * Returns the list of the installable events associated with the specified
74 + * top-level intent.
75 + *
76 + * @param intentId top-level intent identifier
77 + * @return compiled installable intents
78 + */
79 + List<Intent> getInstallableIntents(IntentId intentId);
80 +
81 + /**
71 * Adds the specified listener for intent events. 82 * Adds the specified listener for intent events.
72 * 83 *
73 * @param listener listener to be added 84 * @param listener listener to be added
......
...@@ -196,6 +196,11 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -196,6 +196,11 @@ public class FakeIntentManager implements TestableIntentService {
196 } 196 }
197 197
198 @Override 198 @Override
199 + public List<Intent> getInstallableIntents(IntentId intentId) {
200 + return installables.get(intentId);
201 + }
202 +
203 + @Override
199 public void addListener(IntentListener listener) { 204 public void addListener(IntentListener listener) {
200 listeners.add(listener); 205 listeners.add(listener);
201 } 206 }
......
...@@ -153,6 +153,12 @@ public class IntentManager ...@@ -153,6 +153,12 @@ public class IntentManager
153 } 153 }
154 154
155 @Override 155 @Override
156 + public List<Intent> getInstallableIntents(IntentId intentId) {
157 + checkNotNull(intentId, INTENT_ID_NULL);
158 + return store.getInstallableIntents(intentId);
159 + }
160 +
161 + @Override
156 public void addListener(IntentListener listener) { 162 public void addListener(IntentListener listener) {
157 listenerRegistry.addListener(listener); 163 listenerRegistry.addListener(listener);
158 } 164 }
......