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 | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 17 | |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 19 | import com.google.common.collect.Lists; |
| 20 | import org.apache.karaf.shell.commands.Argument; |
| 21 | import org.apache.karaf.shell.commands.Command; |
Ray Milkey | c747729 | 2016-03-11 10:53:43 -0800 | [diff] [blame] | 22 | import org.onosproject.utils.Comparators; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.topology.TopologyCluster; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 25 | |
| 26 | import java.util.Collections; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 27 | import java.util.List; |
| 28 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 29 | import static org.onosproject.cli.MastersListCommand.json; |
| 30 | import static org.onosproject.net.topology.ClusterId.clusterId; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Lists devices of the specified topology cluster in the current topology. |
| 34 | */ |
| 35 | @Command(scope = "onos", name = "cluster-devices", |
| 36 | description = "Lists devices of the specified topology cluster in the current topology") |
| 37 | public class ClusterDevicesCommand extends ClustersListCommand { |
| 38 | |
| 39 | @Argument(index = 0, name = "id", description = "Cluster ID", |
Jon Hall | 8f31b7b | 2015-02-09 11:17:39 -0800 | [diff] [blame] | 40 | required = true, multiValued = false) |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 41 | String id = null; |
| 42 | |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 43 | @Override |
tom | 0872a17 | 2014-09-23 11:24:26 -0700 | [diff] [blame] | 44 | protected void execute() { |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 45 | int cid = Integer.parseInt(id); |
| 46 | init(); |
| 47 | TopologyCluster cluster = service.getCluster(topology, clusterId(cid)); |
tom | 9eb57fb | 2014-09-11 19:42:38 -0700 | [diff] [blame] | 48 | if (cluster == null) { |
| 49 | error("No such cluster %s", cid); |
| 50 | } else { |
| 51 | List<DeviceId> ids = Lists.newArrayList(service.getClusterDevices(topology, cluster)); |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 52 | Collections.sort(ids, Comparators.ELEMENT_ID_COMPARATOR); |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame] | 53 | if (outputJson()) { |
| 54 | print("%s", json(new ObjectMapper(), ids)); |
| 55 | } else { |
| 56 | for (DeviceId deviceId : ids) { |
| 57 | print("%s", deviceId); |
| 58 | } |
tom | 9eb57fb | 2014-09-11 19:42:38 -0700 | [diff] [blame] | 59 | } |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 60 | } |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 61 | } |
| 62 | |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 63 | } |