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