kdarapu | 97843dc | 2018-05-10 12:46:32 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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.nodemetrics.cli; |
| 18 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.Argument; |
| 20 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame^] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
kdarapu | 97843dc | 2018-05-10 12:46:32 +0530 | [diff] [blame] | 22 | import org.onosproject.cli.AbstractShellCommand; |
| 23 | import org.onosproject.cluster.NodeId; |
| 24 | import org.onosproject.nodemetrics.NodeDiskUsage; |
| 25 | import org.onosproject.nodemetrics.NodeMetricsService; |
| 26 | |
| 27 | import java.util.Collection; |
| 28 | import java.util.Objects; |
| 29 | |
| 30 | /** |
| 31 | * Lists disk usage across nodes. |
| 32 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame^] | 33 | @Service |
kdarapu | 97843dc | 2018-05-10 12:46:32 +0530 | [diff] [blame] | 34 | @Command(scope = "onos", name = "node-disk", |
| 35 | description = "Lists all node disk utilization") |
| 36 | public class ShowNodeDiskUsageCommand extends AbstractShellCommand { |
| 37 | |
| 38 | @Argument(index = 0, name = "nodeId", description = "Node identity", |
| 39 | required = false, multiValued = false) |
| 40 | String nodeId = null; |
| 41 | private NodeMetricsService nodeService = AbstractShellCommand |
| 42 | .get(NodeMetricsService.class); |
| 43 | |
| 44 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 45 | protected void doExecute() { |
kdarapu | 97843dc | 2018-05-10 12:46:32 +0530 | [diff] [blame] | 46 | if (nodeId != null) { |
| 47 | NodeDiskUsage disk = nodeService.disk(NodeId.nodeId(nodeId)); |
| 48 | if (Objects.nonNull(disk)) { |
| 49 | print("Disk usage : %s", disk); |
| 50 | } else { |
| 51 | print("Node %s doesn't exists", nodeId); |
| 52 | } |
| 53 | |
| 54 | } else { |
| 55 | Collection<NodeDiskUsage> disk = nodeService.disk().values(); |
| 56 | printDiskUsage(disk); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | private void printDiskUsage(Collection<NodeDiskUsage> diskList) { |
| 61 | diskList.forEach(disk -> print("%s", disk)); |
| 62 | } |
| 63 | } |