blob: 7c9f4b876b678056dd62a3ac96aa2cd284c4e9ad [file] [log] [blame]
kdarapu97843dc2018-05-10 12:46:32 +05301/*
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
17package org.onosproject.nodemetrics.cli;
18
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
kdarapu97843dc2018-05-10 12:46:32 +053022import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.cluster.NodeId;
24import org.onosproject.nodemetrics.NodeDiskUsage;
25import org.onosproject.nodemetrics.NodeMetricsService;
26
27import java.util.Collection;
28import java.util.Objects;
29
30/**
31 * Lists disk usage across nodes.
32 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070033@Service
kdarapu97843dc2018-05-10 12:46:32 +053034@Command(scope = "onos", name = "node-disk",
35 description = "Lists all node disk utilization")
36public 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 Milkey86ad7bb2018-09-27 12:32:28 -070045 protected void doExecute() {
kdarapu97843dc2018-05-10 12:46:32 +053046 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}