Committed by
Gerrit Code Review
ONOS-4971: Synthetic Link Data -- WIP
- adding CLI commands for dumping Model Cache contents. Change-Id: I28dfe179835de6cd0c5356faf87af46a239eb772
Showing
10 changed files
with
266 additions
and
8 deletions
| ... | @@ -261,6 +261,15 @@ public class UiTopology extends UiElement { | ... | @@ -261,6 +261,15 @@ public class UiTopology extends UiElement { |
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | /** | 263 | /** |
| 264 | + * Returns all links in the model. | ||
| 265 | + * | ||
| 266 | + * @return all links | ||
| 267 | + */ | ||
| 268 | + public Set<UiLink> allLinks() { | ||
| 269 | + return new HashSet<>(linkLookup.values()); | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + /** | ||
| 264 | * Returns the link with the specified identifier, or null if no such | 273 | * Returns the link with the specified identifier, or null if no such |
| 265 | * link exists. | 274 | * link exists. |
| 266 | * | 275 | * |
| ... | @@ -302,6 +311,15 @@ public class UiTopology extends UiElement { | ... | @@ -302,6 +311,15 @@ public class UiTopology extends UiElement { |
| 302 | } | 311 | } |
| 303 | 312 | ||
| 304 | /** | 313 | /** |
| 314 | + * Returns all hosts in the model. | ||
| 315 | + * | ||
| 316 | + * @return all hosts | ||
| 317 | + */ | ||
| 318 | + public Set<UiHost> allHosts() { | ||
| 319 | + return new HashSet<>(hostLookup.values()); | ||
| 320 | + } | ||
| 321 | + | ||
| 322 | + /** | ||
| 305 | * Returns the host with the specified identifier, or null if no such | 323 | * Returns the host with the specified identifier, or null if no such |
| 306 | * host exists. | 324 | * host exists. |
| 307 | * | 325 | * | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 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 | ||
| 7 | + * | ||
| 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. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.ui.impl.topo.cli; | ||
| 18 | + | ||
| 19 | +import org.onosproject.cli.AbstractShellCommand; | ||
| 20 | +import org.onosproject.ui.model.topo.UiElement; | ||
| 21 | + | ||
| 22 | +import java.util.ArrayList; | ||
| 23 | +import java.util.Collections; | ||
| 24 | +import java.util.Comparator; | ||
| 25 | +import java.util.List; | ||
| 26 | +import java.util.Set; | ||
| 27 | + | ||
| 28 | +/** | ||
| 29 | + * Base class for model cache CLI commands. | ||
| 30 | + */ | ||
| 31 | +abstract class AbstractElementCommand extends AbstractShellCommand { | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * Built in comparator for elements. | ||
| 35 | + */ | ||
| 36 | + private static final Comparator<UiElement> ELEMENT_COMPARATOR = | ||
| 37 | + (o1, o2) -> o1.idAsString().compareTo(o2.idAsString()); | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * Returns the given elements in a list, sorted by string representation | ||
| 41 | + * of the identifiers. | ||
| 42 | + * | ||
| 43 | + * @param elements the elements to sort | ||
| 44 | + * @return the sorted elements | ||
| 45 | + */ | ||
| 46 | + protected List<UiElement> sorted(Set<? extends UiElement> elements) { | ||
| 47 | + List<UiElement> list = new ArrayList<>(elements); | ||
| 48 | + Collections.sort(list, ELEMENT_COMPARATOR); | ||
| 49 | + return list; | ||
| 50 | + } | ||
| 51 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 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 | ||
| 7 | + * | ||
| 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. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.ui.impl.topo.cli; | ||
| 18 | + | ||
| 19 | +import org.apache.karaf.shell.commands.Command; | ||
| 20 | +import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * CLI command to list the UiDevices stored in the ModelCache. | ||
| 24 | + */ | ||
| 25 | +@Command(scope = "onos", name = "ui-cache-devices", | ||
| 26 | + description = "Lists UiDevices in the Model Cache") | ||
| 27 | +public class ListDevices extends AbstractElementCommand { | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + protected void execute() { | ||
| 31 | + UiSharedTopologyModel model = get(UiSharedTopologyModel.class); | ||
| 32 | + sorted(model.getDevices()).forEach(d -> print("%s", d)); | ||
| 33 | + } | ||
| 34 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 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 | ||
| 7 | + * | ||
| 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. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.ui.impl.topo.cli; | ||
| 18 | + | ||
| 19 | +import org.apache.karaf.shell.commands.Command; | ||
| 20 | +import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * CLI command to list the UiH0osts stored in the ModelCache. | ||
| 24 | + */ | ||
| 25 | +@Command(scope = "onos", name = "ui-cache-hosts", | ||
| 26 | + description = "Lists UiHosts in the Model Cache") | ||
| 27 | +public class ListHosts extends AbstractElementCommand { | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + protected void execute() { | ||
| 31 | + UiSharedTopologyModel model = get(UiSharedTopologyModel.class); | ||
| 32 | + sorted(model.getHosts()).forEach(h -> print("%s", h)); | ||
| 33 | + } | ||
| 34 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 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 | ||
| 7 | + * | ||
| 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. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.ui.impl.topo.cli; | ||
| 18 | + | ||
| 19 | +import org.apache.karaf.shell.commands.Command; | ||
| 20 | +import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * CLI command to list the UiLinks stored in the ModelCache. | ||
| 24 | + */ | ||
| 25 | +@Command(scope = "onos", name = "ui-cache-links", | ||
| 26 | + description = "Lists UiLinks in the Model Cache") | ||
| 27 | +public class ListLinks extends AbstractElementCommand { | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + protected void execute() { | ||
| 31 | + UiSharedTopologyModel model = get(UiSharedTopologyModel.class); | ||
| 32 | + sorted(model.getLinks()).forEach(l -> print("%s", l)); | ||
| 33 | + } | ||
| 34 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 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 | ||
| 7 | + * | ||
| 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. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.ui.impl.topo.cli; | ||
| 18 | + | ||
| 19 | +import org.apache.karaf.shell.commands.Command; | ||
| 20 | +import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * CLI command to list the UiClusterMembers stored in the ModelCache. | ||
| 24 | + */ | ||
| 25 | +@Command(scope = "onos", name = "ui-cache-members", | ||
| 26 | + description = "Lists UiClusterMembers in the Model Cache") | ||
| 27 | +public class ListMembers extends AbstractElementCommand { | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + protected void execute() { | ||
| 31 | + UiSharedTopologyModel model = get(UiSharedTopologyModel.class); | ||
| 32 | + // note: getClusterMembers() returns an already sorted list... | ||
| 33 | + model.getClusterMembers().forEach(m -> print("%s", m)); | ||
| 34 | + } | ||
| 35 | +} |
| ... | @@ -17,7 +17,6 @@ | ... | @@ -17,7 +17,6 @@ |
| 17 | package org.onosproject.ui.impl.topo.cli; | 17 | package org.onosproject.ui.impl.topo.cli; |
| 18 | 18 | ||
| 19 | import org.apache.karaf.shell.commands.Command; | 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | -import org.onosproject.cli.AbstractShellCommand; | ||
| 21 | import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel; | 20 | import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel; |
| 22 | 21 | ||
| 23 | /** | 22 | /** |
| ... | @@ -25,11 +24,11 @@ import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel; | ... | @@ -25,11 +24,11 @@ import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel; |
| 25 | */ | 24 | */ |
| 26 | @Command(scope = "onos", name = "ui-cache-regions", | 25 | @Command(scope = "onos", name = "ui-cache-regions", |
| 27 | description = "Lists UiRegions in the Model Cache") | 26 | description = "Lists UiRegions in the Model Cache") |
| 28 | -public class ListRegions extends AbstractShellCommand { | 27 | +public class ListRegions extends AbstractElementCommand { |
| 29 | 28 | ||
| 30 | @Override | 29 | @Override |
| 31 | protected void execute() { | 30 | protected void execute() { |
| 32 | UiSharedTopologyModel model = get(UiSharedTopologyModel.class); | 31 | UiSharedTopologyModel model = get(UiSharedTopologyModel.class); |
| 33 | - model.getRegions().forEach(r -> print("%s", r)); | 32 | + sorted(model.getRegions()).forEach(r -> print("%s", r)); |
| 34 | } | 33 | } |
| 35 | } | 34 | } | ... | ... |
| ... | @@ -298,6 +298,10 @@ class ModelCache { | ... | @@ -298,6 +298,10 @@ class ModelCache { |
| 298 | } | 298 | } |
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | + Set<UiDevice> getAllDevices() { | ||
| 302 | + return uiTopology.allDevices(); | ||
| 303 | + } | ||
| 304 | + | ||
| 301 | 305 | ||
| 302 | // === LINKS | 306 | // === LINKS |
| 303 | 307 | ||
| ... | @@ -357,6 +361,9 @@ class ModelCache { | ... | @@ -357,6 +361,9 @@ class ModelCache { |
| 357 | } | 361 | } |
| 358 | } | 362 | } |
| 359 | 363 | ||
| 364 | + Set<UiLink> getAllLinks() { | ||
| 365 | + return uiTopology.allLinks(); | ||
| 366 | + } | ||
| 360 | 367 | ||
| 361 | // === HOSTS | 368 | // === HOSTS |
| 362 | 369 | ||
| ... | @@ -460,6 +467,10 @@ class ModelCache { | ... | @@ -460,6 +467,10 @@ class ModelCache { |
| 460 | } | 467 | } |
| 461 | } | 468 | } |
| 462 | 469 | ||
| 470 | + Set<UiHost> getAllHosts() { | ||
| 471 | + return uiTopology.allHosts(); | ||
| 472 | + } | ||
| 473 | + | ||
| 463 | 474 | ||
| 464 | /** | 475 | /** |
| 465 | * Refreshes the internal state. | 476 | * Refreshes the internal state. | ... | ... |
| ... | @@ -63,6 +63,9 @@ import org.onosproject.net.topology.TopologyService; | ... | @@ -63,6 +63,9 @@ import org.onosproject.net.topology.TopologyService; |
| 63 | import org.onosproject.ui.impl.topo.UiTopoSession; | 63 | import org.onosproject.ui.impl.topo.UiTopoSession; |
| 64 | import org.onosproject.ui.model.ServiceBundle; | 64 | import org.onosproject.ui.model.ServiceBundle; |
| 65 | import org.onosproject.ui.model.topo.UiClusterMember; | 65 | import org.onosproject.ui.model.topo.UiClusterMember; |
| 66 | +import org.onosproject.ui.model.topo.UiDevice; | ||
| 67 | +import org.onosproject.ui.model.topo.UiHost; | ||
| 68 | +import org.onosproject.ui.model.topo.UiLink; | ||
| 66 | import org.onosproject.ui.model.topo.UiRegion; | 69 | import org.onosproject.ui.model.topo.UiRegion; |
| 67 | import org.slf4j.Logger; | 70 | import org.slf4j.Logger; |
| 68 | import org.slf4j.LoggerFactory; | 71 | import org.slf4j.LoggerFactory; |
| ... | @@ -200,7 +203,14 @@ public final class UiSharedTopologyModel | ... | @@ -200,7 +203,14 @@ public final class UiSharedTopologyModel |
| 200 | // Methods for topo session (or CLI) to use to get information from us | 203 | // Methods for topo session (or CLI) to use to get information from us |
| 201 | 204 | ||
| 202 | /** | 205 | /** |
| 203 | - * Returns the list of cluster members stored in our model cache. | 206 | + * Refreshes the cache's internal state. |
| 207 | + */ | ||
| 208 | + public void refresh() { | ||
| 209 | + cache.refresh(); | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + /** | ||
| 213 | + * Returns the list of cluster members stored in the model cache. | ||
| 204 | * | 214 | * |
| 205 | * @return list of cluster members | 215 | * @return list of cluster members |
| 206 | */ | 216 | */ |
| ... | @@ -209,7 +219,7 @@ public final class UiSharedTopologyModel | ... | @@ -209,7 +219,7 @@ public final class UiSharedTopologyModel |
| 209 | } | 219 | } |
| 210 | 220 | ||
| 211 | /** | 221 | /** |
| 212 | - * Returns the set of regions stored in our model cache. | 222 | + * Returns the set of regions stored in the model cache. |
| 213 | * | 223 | * |
| 214 | * @return set of regions | 224 | * @return set of regions |
| 215 | */ | 225 | */ |
| ... | @@ -237,10 +247,30 @@ public final class UiSharedTopologyModel | ... | @@ -237,10 +247,30 @@ public final class UiSharedTopologyModel |
| 237 | } | 247 | } |
| 238 | 248 | ||
| 239 | /** | 249 | /** |
| 240 | - * Refreshes the cache's internal state. | 250 | + * Returns the set of devices stored in the model cache. |
| 251 | + * | ||
| 252 | + * @return set of devices | ||
| 241 | */ | 253 | */ |
| 242 | - public void refresh() { | 254 | + public Set<UiDevice> getDevices() { |
| 243 | - cache.refresh(); | 255 | + return cache.getAllDevices(); |
| 256 | + } | ||
| 257 | + | ||
| 258 | + /** | ||
| 259 | + * Returns the set of hosts stored in the model cache. | ||
| 260 | + * | ||
| 261 | + * @return set of hosts | ||
| 262 | + */ | ||
| 263 | + public Set<UiHost> getHosts() { | ||
| 264 | + return cache.getAllHosts(); | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + /** | ||
| 268 | + * Returns the set of links stored in the model cache. | ||
| 269 | + * | ||
| 270 | + * @return set of links | ||
| 271 | + */ | ||
| 272 | + public Set<UiLink> getLinks() { | ||
| 273 | + return cache.getAllLinks(); | ||
| 244 | } | 274 | } |
| 245 | 275 | ||
| 246 | // ===================================================================== | 276 | // ===================================================================== | ... | ... |
| ... | @@ -18,8 +18,20 @@ | ... | @@ -18,8 +18,20 @@ |
| 18 | 18 | ||
| 19 | <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0"> | 19 | <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0"> |
| 20 | <command> | 20 | <command> |
| 21 | + <action class="org.onosproject.ui.impl.topo.cli.ListMembers"/> | ||
| 22 | + </command> | ||
| 23 | + <command> | ||
| 21 | <action class="org.onosproject.ui.impl.topo.cli.ListRegions"/> | 24 | <action class="org.onosproject.ui.impl.topo.cli.ListRegions"/> |
| 22 | </command> | 25 | </command> |
| 26 | + <command> | ||
| 27 | + <action class="org.onosproject.ui.impl.topo.cli.ListDevices"/> | ||
| 28 | + </command> | ||
| 29 | + <command> | ||
| 30 | + <action class="org.onosproject.ui.impl.topo.cli.ListHosts"/> | ||
| 31 | + </command> | ||
| 32 | + <command> | ||
| 33 | + <action class="org.onosproject.ui.impl.topo.cli.ListLinks"/> | ||
| 34 | + </command> | ||
| 23 | </command-bundle> | 35 | </command-bundle> |
| 24 | 36 | ||
| 25 | <!--<bean id="macIDCompleter" class="org.onosproject.dhcp.cli.MacIdCompleter"/>--> | 37 | <!--<bean id="macIDCompleter" class="org.onosproject.dhcp.cli.MacIdCompleter"/>--> | ... | ... |
-
Please register or login to post a comment