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