Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.cli.net; |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 17 | |
Ray Milkey | 3078fc0 | 2015-05-06 16:14:14 -0700 | [diff] [blame] | 18 | import java.util.List; |
| 19 | |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.commands.Command; |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.commands.Option; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.cli.AbstractShellCommand; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import org.onosproject.net.intent.ConnectivityIntent; |
Pavlin Radoslavov | aab51a3 | 2014-12-08 11:07:38 -0800 | [diff] [blame] | 24 | import org.onosproject.net.intent.HostToHostIntent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.net.intent.Intent; |
| 26 | import org.onosproject.net.intent.IntentService; |
| 27 | import org.onosproject.net.intent.IntentState; |
| 28 | import org.onosproject.net.intent.LinkCollectionIntent; |
| 29 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
| 30 | import org.onosproject.net.intent.PathIntent; |
| 31 | import org.onosproject.net.intent.PointToPointIntent; |
| 32 | import org.onosproject.net.intent.SinglePointToMultiPointIntent; |
Thomas Vachuska | 6ce7304 | 2014-10-21 10:01:49 -0700 | [diff] [blame] | 33 | |
Ray Milkey | 3078fc0 | 2015-05-06 16:14:14 -0700 | [diff] [blame] | 34 | import com.fasterxml.jackson.databind.JsonNode; |
| 35 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 36 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 37 | import com.fasterxml.jackson.databind.node.ObjectNode; |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Lists the inventory of intents and their states. |
| 41 | */ |
| 42 | @Command(scope = "onos", name = "intents", |
| 43 | description = "Lists the inventory of intents and their states") |
| 44 | public class IntentsListCommand extends AbstractShellCommand { |
| 45 | |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 46 | @Option(name = "-i", aliases = "--installable", |
| 47 | description = "Output Installable Intents", |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 48 | required = false, multiValued = false) |
| 49 | private boolean showInstallable = false; |
| 50 | |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 51 | @Option(name = "-s", aliases = "--summary", |
| 52 | description = "Intents summary", |
| 53 | required = false, multiValued = false) |
| 54 | private boolean intentsSummary = false; |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 55 | |
Jonathan Hart | 34f1e38 | 2015-02-24 16:52:23 -0800 | [diff] [blame] | 56 | @Option(name = "-p", aliases = "--pending", |
| 57 | description = "Show inforamtion about pending intents", |
| 58 | required = false, multiValued = false) |
| 59 | private boolean pending = false; |
| 60 | |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 61 | @Override |
| 62 | protected void execute() { |
| 63 | IntentService service = get(IntentService.class); |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 64 | |
| 65 | if (intentsSummary) { |
| 66 | IntentSummaries intentSummaries = new IntentSummaries(); |
| 67 | intentSummaries.collectIntentSummary(service, |
| 68 | service.getIntents()); |
| 69 | if (outputJson()) { |
| 70 | print("%s", intentSummaries.json()); |
| 71 | } else { |
| 72 | intentSummaries.printSummary(); |
| 73 | } |
| 74 | return; |
Jonathan Hart | 34f1e38 | 2015-02-24 16:52:23 -0800 | [diff] [blame] | 75 | } else if (pending) { |
Ray Milkey | 740c8a3 | 2015-03-17 13:41:03 -0700 | [diff] [blame] | 76 | if (outputJson()) { |
| 77 | print("%s", json(service, service.getPending())); |
| 78 | } else { |
| 79 | service.getPending().forEach(intent -> |
| 80 | print("id=%s, key=%s, type=%s, appId=%s", |
| 81 | intent.id(), intent.key(), |
| 82 | intent.getClass().getSimpleName(), |
| 83 | intent.appId().name()) |
| 84 | ); |
| 85 | } |
Jonathan Hart | 34f1e38 | 2015-02-24 16:52:23 -0800 | [diff] [blame] | 86 | return; |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 87 | } |
| 88 | |
Thomas Vachuska | 6ce7304 | 2014-10-21 10:01:49 -0700 | [diff] [blame] | 89 | if (outputJson()) { |
| 90 | print("%s", json(service, service.getIntents())); |
| 91 | } else { |
| 92 | for (Intent intent : service.getIntents()) { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 93 | IntentState state = service.getIntentState(intent.key()); |
Thomas Vachuska | 3ea690b | 2014-11-29 12:39:03 -0800 | [diff] [blame] | 94 | if (state != null) { |
Jonathan Hart | 189f9bf | 2015-02-11 19:24:28 -0800 | [diff] [blame] | 95 | print("id=%s, state=%s, key=%s, type=%s, appId=%s", |
| 96 | intent.id(), state, intent.key(), |
| 97 | intent.getClass().getSimpleName(), |
Thomas Vachuska | 3ea690b | 2014-11-29 12:39:03 -0800 | [diff] [blame] | 98 | intent.appId().name()); |
| 99 | printDetails(service, intent); |
| 100 | } |
Thomas Vachuska | 6ce7304 | 2014-10-21 10:01:49 -0700 | [diff] [blame] | 101 | } |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 105 | /** |
| 106 | * Internal local class to keep track of all intent summaries. |
| 107 | */ |
| 108 | private class IntentSummaries { |
| 109 | private IntentSummary summaryAll; |
| 110 | private IntentSummary summaryConnectivity; |
Pavlin Radoslavov | aab51a3 | 2014-12-08 11:07:38 -0800 | [diff] [blame] | 111 | private IntentSummary summaryHostToHost; |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 112 | private IntentSummary summaryPointToPoint; |
| 113 | private IntentSummary summaryMultiPointToSinglePoint; |
| 114 | private IntentSummary summarySinglePointToMultiPoint; |
| 115 | private IntentSummary summaryPath; |
| 116 | private IntentSummary summaryLinkCollection; |
| 117 | private IntentSummary summaryUnknownType; |
| 118 | |
| 119 | /** |
| 120 | * Initializes the internal state. |
| 121 | */ |
| 122 | private void init() { |
| 123 | summaryAll = new IntentSummary("All"); |
| 124 | summaryConnectivity = new IntentSummary("Connectivity"); |
Pavlin Radoslavov | aab51a3 | 2014-12-08 11:07:38 -0800 | [diff] [blame] | 125 | summaryHostToHost = new IntentSummary("HostToHost"); |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 126 | summaryPointToPoint = new IntentSummary("PointToPoint"); |
| 127 | summaryMultiPointToSinglePoint = |
| 128 | new IntentSummary("MultiPointToSinglePoint"); |
| 129 | summarySinglePointToMultiPoint = |
| 130 | new IntentSummary("SinglePointToMultiPoint"); |
| 131 | summaryPath = new IntentSummary("Path"); |
| 132 | summaryLinkCollection = new IntentSummary("LinkCollection"); |
| 133 | summaryUnknownType = new IntentSummary("UnknownType"); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Collects summary of all intents. |
| 138 | * |
| 139 | * @param service the Intent Service to use |
| 140 | * @param intents the intents |
| 141 | */ |
| 142 | private void collectIntentSummary(IntentService service, |
| 143 | Iterable<Intent> intents) { |
| 144 | init(); |
| 145 | |
| 146 | // Collect the summary for each intent type intents |
| 147 | for (Intent intent : intents) { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 148 | IntentState intentState = service.getIntentState(intent.key()); |
Pavlin Radoslavov | deb8a10 | 2014-11-26 13:31:36 -0800 | [diff] [blame] | 149 | if (intentState == null) { |
| 150 | continue; |
| 151 | } |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 152 | |
| 153 | // Update the summary for all Intents |
| 154 | summaryAll.update(intentState); |
| 155 | |
| 156 | if (intent instanceof ConnectivityIntent) { |
| 157 | summaryConnectivity.update(intentState); |
| 158 | // NOTE: ConnectivityIntent is a base type Intent |
| 159 | // continue; |
| 160 | } |
Pavlin Radoslavov | aab51a3 | 2014-12-08 11:07:38 -0800 | [diff] [blame] | 161 | if (intent instanceof HostToHostIntent) { |
| 162 | summaryHostToHost.update(intentState); |
| 163 | continue; |
| 164 | } |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 165 | if (intent instanceof PointToPointIntent) { |
| 166 | summaryPointToPoint.update(intentState); |
| 167 | continue; |
| 168 | } |
| 169 | if (intent instanceof MultiPointToSinglePointIntent) { |
| 170 | summaryMultiPointToSinglePoint.update(intentState); |
| 171 | continue; |
| 172 | } |
| 173 | if (intent instanceof SinglePointToMultiPointIntent) { |
| 174 | summarySinglePointToMultiPoint.update(intentState); |
| 175 | continue; |
| 176 | } |
| 177 | if (intent instanceof PathIntent) { |
| 178 | summaryPath.update(intentState); |
| 179 | continue; |
| 180 | } |
| 181 | if (intent instanceof LinkCollectionIntent) { |
| 182 | summaryLinkCollection.update(intentState); |
| 183 | continue; |
| 184 | } |
| 185 | |
| 186 | summaryUnknownType.update(intentState); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Gets JSON representation of all Intents summary. |
| 192 | * |
| 193 | * @return JSON representation of all Intents summary |
| 194 | */ |
| 195 | ObjectNode json() { |
| 196 | ObjectMapper mapper = new ObjectMapper(); |
| 197 | ObjectNode result = mapper.createObjectNode(); |
Ray Milkey | 9d810f6 | 2015-02-13 11:20:58 -0800 | [diff] [blame] | 198 | result.set("connectivity", summaryConnectivity.json(mapper)); |
| 199 | result.set("hostToHost", summaryHostToHost.json(mapper)); |
| 200 | result.set("pointToPoint", summaryPointToPoint.json(mapper)); |
| 201 | result.set("multiPointToSinglePoint", |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 202 | summaryMultiPointToSinglePoint.json(mapper)); |
Ray Milkey | 9d810f6 | 2015-02-13 11:20:58 -0800 | [diff] [blame] | 203 | result.set("singlePointToMultiPoint", |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 204 | summarySinglePointToMultiPoint.json(mapper)); |
Ray Milkey | 9d810f6 | 2015-02-13 11:20:58 -0800 | [diff] [blame] | 205 | result.set("path", summaryPath.json(mapper)); |
| 206 | result.set("linkCollection", summaryLinkCollection.json(mapper)); |
| 207 | result.set("unknownType", summaryUnknownType.json(mapper)); |
| 208 | result.set("all", summaryAll.json(mapper)); |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 209 | return result; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Prints summary of the intents. |
| 214 | */ |
| 215 | private void printSummary() { |
| 216 | summaryConnectivity.printState(); |
Pavlin Radoslavov | aab51a3 | 2014-12-08 11:07:38 -0800 | [diff] [blame] | 217 | summaryHostToHost.printState(); |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 218 | summaryPointToPoint.printState(); |
| 219 | summaryMultiPointToSinglePoint.printState(); |
| 220 | summarySinglePointToMultiPoint.printState(); |
| 221 | summaryPath.printState(); |
| 222 | summaryLinkCollection.printState(); |
| 223 | summaryUnknownType.printState(); |
| 224 | summaryAll.printState(); |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Internal local class to keep track of a single type Intent summary. |
| 229 | */ |
| 230 | private class IntentSummary { |
| 231 | private final String intentType; |
| 232 | private int total = 0; |
Pavlin Radoslavov | 67c0514 | 2014-12-02 13:04:08 -0800 | [diff] [blame] | 233 | private int installReq = 0; |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 234 | private int compiling = 0; |
| 235 | private int installing = 0; |
| 236 | private int installed = 0; |
| 237 | private int recompiling = 0; |
Pavlin Radoslavov | 67c0514 | 2014-12-02 13:04:08 -0800 | [diff] [blame] | 238 | private int withdrawReq = 0; |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 239 | private int withdrawing = 0; |
| 240 | private int withdrawn = 0; |
| 241 | private int failed = 0; |
| 242 | private int unknownState = 0; |
| 243 | |
| 244 | private static final String FORMAT_SUMMARY_LINE1 = |
| 245 | "%-23s total= %7d installed= %7d"; |
| 246 | private static final String FORMAT_SUMMARY_LINE2 = |
| 247 | "%-23s withdrawn= %7d failed= %7d"; |
| 248 | private static final String FORMAT_SUMMARY_LINE3 = |
Pavlin Radoslavov | 67c0514 | 2014-12-02 13:04:08 -0800 | [diff] [blame] | 249 | "%-23s installReq= %7d compiling= %7d"; |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 250 | private static final String FORMAT_SUMMARY_LINE4 = |
| 251 | "%-23s installing= %7d recompiling= %7d"; |
| 252 | private static final String FORMAT_SUMMARY_LINE5 = |
Pavlin Radoslavov | 67c0514 | 2014-12-02 13:04:08 -0800 | [diff] [blame] | 253 | "%-23s withdrawReq= %7d withdrawing= %7d"; |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 254 | private static final String FORMAT_SUMMARY_LINE6 = |
| 255 | "%-23s unknownState= %7d"; |
| 256 | |
| 257 | /** |
| 258 | * Constructor. |
| 259 | * |
| 260 | * @param intentType the scring describing the Intent type |
| 261 | */ |
| 262 | IntentSummary(String intentType) { |
| 263 | this.intentType = intentType; |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Updates the Intent Summary. |
| 268 | * |
| 269 | * @param intentState the state of the Intent |
| 270 | */ |
| 271 | void update(IntentState intentState) { |
| 272 | total++; |
| 273 | switch (intentState) { |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 274 | case INSTALL_REQ: |
Pavlin Radoslavov | 67c0514 | 2014-12-02 13:04:08 -0800 | [diff] [blame] | 275 | installReq++; |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 276 | break; |
| 277 | case COMPILING: |
| 278 | compiling++; |
| 279 | break; |
| 280 | case INSTALLING: |
| 281 | installing++; |
| 282 | break; |
| 283 | case INSTALLED: |
| 284 | installed++; |
| 285 | break; |
| 286 | case RECOMPILING: |
| 287 | recompiling++; |
| 288 | break; |
Pavlin Radoslavov | 67c0514 | 2014-12-02 13:04:08 -0800 | [diff] [blame] | 289 | case WITHDRAW_REQ: |
| 290 | withdrawReq++; |
| 291 | break; |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 292 | case WITHDRAWING: |
| 293 | withdrawing++; |
| 294 | break; |
| 295 | case WITHDRAWN: |
| 296 | withdrawn++; |
| 297 | break; |
| 298 | case FAILED: |
| 299 | failed++; |
| 300 | break; |
| 301 | default: |
| 302 | unknownState++; |
| 303 | break; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Prints the Intent Summary. |
| 309 | */ |
| 310 | void printState() { |
| 311 | print(FORMAT_SUMMARY_LINE1, intentType, total, installed); |
| 312 | print(FORMAT_SUMMARY_LINE2, intentType, withdrawn, failed); |
Pavlin Radoslavov | 67c0514 | 2014-12-02 13:04:08 -0800 | [diff] [blame] | 313 | print(FORMAT_SUMMARY_LINE3, intentType, installReq, compiling); |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 314 | print(FORMAT_SUMMARY_LINE4, intentType, installing, recompiling); |
Pavlin Radoslavov | 67c0514 | 2014-12-02 13:04:08 -0800 | [diff] [blame] | 315 | print(FORMAT_SUMMARY_LINE5, intentType, withdrawReq, withdrawing); |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 316 | if (unknownState != 0) { |
| 317 | print(FORMAT_SUMMARY_LINE6, intentType, unknownState); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Gets the JSON representation of the Intent Summary. |
| 323 | * |
| 324 | * @return the JSON representation of the Intent Summary |
| 325 | */ |
| 326 | JsonNode json(ObjectMapper mapper) { |
| 327 | ObjectNode result = mapper.createObjectNode() |
| 328 | .put("total", total) |
| 329 | .put("installed", installed) |
| 330 | .put("failed", failed) |
Pavlin Radoslavov | 67c0514 | 2014-12-02 13:04:08 -0800 | [diff] [blame] | 331 | .put("installReq", installReq) |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 332 | .put("compiling", compiling) |
| 333 | .put("installing", installing) |
| 334 | .put("recompiling", recompiling) |
Pavlin Radoslavov | 67c0514 | 2014-12-02 13:04:08 -0800 | [diff] [blame] | 335 | .put("withdrawReq", withdrawReq) |
Pavlin Radoslavov | 708e820 | 2014-11-14 17:18:37 -0800 | [diff] [blame] | 336 | .put("withdrawing", withdrawing) |
| 337 | .put("withdrawn", withdrawn) |
| 338 | .put("unknownState", unknownState); |
| 339 | |
| 340 | return result; |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
Thomas Vachuska | 10d4abc | 2014-10-21 12:47:26 -0700 | [diff] [blame] | 345 | private void printDetails(IntentService service, Intent intent) { |
Sho SHIMIZU | d7d1800 | 2015-01-21 14:37:14 -0800 | [diff] [blame] | 346 | if (!intent.resources().isEmpty()) { |
Thomas Vachuska | 6ce7304 | 2014-10-21 10:01:49 -0700 | [diff] [blame] | 347 | print(" resources=%s", intent.resources()); |
| 348 | } |
| 349 | if (intent instanceof ConnectivityIntent) { |
| 350 | ConnectivityIntent ci = (ConnectivityIntent) intent; |
Thomas Vachuska | 10d4abc | 2014-10-21 12:47:26 -0700 | [diff] [blame] | 351 | if (!ci.selector().criteria().isEmpty()) { |
| 352 | print(" selector=%s", ci.selector().criteria()); |
| 353 | } |
Ray Milkey | 4250735 | 2015-03-20 15:16:10 -0700 | [diff] [blame] | 354 | if (!ci.treatment().allInstructions().isEmpty()) { |
| 355 | print(" treatment=%s", ci.treatment().allInstructions()); |
Thomas Vachuska | 10d4abc | 2014-10-21 12:47:26 -0700 | [diff] [blame] | 356 | } |
Thomas Vachuska | edc944c | 2014-11-04 15:42:25 -0800 | [diff] [blame] | 357 | if (ci.constraints() != null && !ci.constraints().isEmpty()) { |
| 358 | print(" constraints=%s", ci.constraints()); |
| 359 | } |
Thomas Vachuska | 6ce7304 | 2014-10-21 10:01:49 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Pavlin Radoslavov | aab51a3 | 2014-12-08 11:07:38 -0800 | [diff] [blame] | 362 | if (intent instanceof HostToHostIntent) { |
| 363 | HostToHostIntent pi = (HostToHostIntent) intent; |
| 364 | print(" host1=%s, host2=%s", pi.one(), pi.two()); |
| 365 | } else if (intent instanceof PointToPointIntent) { |
Thomas Vachuska | 6ce7304 | 2014-10-21 10:01:49 -0700 | [diff] [blame] | 366 | PointToPointIntent pi = (PointToPointIntent) intent; |
| 367 | print(" ingress=%s, egress=%s", pi.ingressPoint(), pi.egressPoint()); |
| 368 | } else if (intent instanceof MultiPointToSinglePointIntent) { |
| 369 | MultiPointToSinglePointIntent pi = (MultiPointToSinglePointIntent) intent; |
| 370 | print(" ingress=%s, egress=%s", pi.ingressPoints(), pi.egressPoint()); |
| 371 | } else if (intent instanceof SinglePointToMultiPointIntent) { |
| 372 | SinglePointToMultiPointIntent pi = (SinglePointToMultiPointIntent) intent; |
| 373 | print(" ingress=%s, egress=%s", pi.ingressPoint(), pi.egressPoints()); |
| 374 | } else if (intent instanceof PathIntent) { |
| 375 | PathIntent pi = (PathIntent) intent; |
| 376 | print(" path=%s, cost=%d", pi.path().links(), pi.path().cost()); |
| 377 | } else if (intent instanceof LinkCollectionIntent) { |
| 378 | LinkCollectionIntent li = (LinkCollectionIntent) intent; |
| 379 | print(" links=%s", li.links()); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 380 | print(" egress=%s", li.egressPoints()); |
Thomas Vachuska | 6ce7304 | 2014-10-21 10:01:49 -0700 | [diff] [blame] | 381 | } |
Thomas Vachuska | 10d4abc | 2014-10-21 12:47:26 -0700 | [diff] [blame] | 382 | |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 383 | List<Intent> installable = service.getInstallableIntents(intent.key()); |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 384 | if (showInstallable && installable != null && !installable.isEmpty()) { |
Thomas Vachuska | 10d4abc | 2014-10-21 12:47:26 -0700 | [diff] [blame] | 385 | print(" installable=%s", installable); |
| 386 | } |
Thomas Vachuska | 6ce7304 | 2014-10-21 10:01:49 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | // Produces JSON array of the specified intents. |
| 390 | private JsonNode json(IntentService service, Iterable<Intent> intents) { |
| 391 | ObjectMapper mapper = new ObjectMapper(); |
| 392 | ArrayNode result = mapper.createArrayNode(); |
Ray Milkey | 3078fc0 | 2015-05-06 16:14:14 -0700 | [diff] [blame] | 393 | |
| 394 | intents.forEach(intent -> result.add(jsonForEntity(intent, Intent.class))); |
Thomas Vachuska | 6ce7304 | 2014-10-21 10:01:49 -0700 | [diff] [blame] | 395 | return result; |
| 396 | } |
| 397 | |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 398 | } |