blob: 0d4694f38c42c03732655d6b636c648a10cbece4 [file] [log] [blame]
Madan Jampani35708a92016-07-06 10:48:19 -07001/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
Madan Jampani35708a92016-07-06 10:48:19 -07003 *
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 */
16package org.onosproject.cli.net;
17
18import java.util.Map;
19
20import org.apache.karaf.shell.commands.Command;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.store.service.StorageAdminService;
23import org.onosproject.store.service.WorkQueueStats;
24
25import com.fasterxml.jackson.databind.ObjectMapper;
26import com.fasterxml.jackson.databind.node.ObjectNode;
27
28/**
29 * Command to list stats for all work queues in the system.
30 */
31@Command(scope = "onos", name = "queues",
32 description = "Lists information about work queues in the system")
33public class QueuesListCommand extends AbstractShellCommand {
34
35 private static final String FMT = "name=%s pending=%d inProgress=%d, completed=%d";
36
37 @Override
38 protected void execute() {
39 StorageAdminService storageAdminService = get(StorageAdminService.class);
40 Map<String, WorkQueueStats> queueStats = storageAdminService.getQueueStats();
41 if (outputJson()) {
42 ObjectMapper mapper = new ObjectMapper();
43 ObjectNode jsonQueues = mapper.createObjectNode();
44 queueStats.forEach((k, v) -> {
45 ObjectNode jsonStats = jsonQueues.putObject(k);
46 jsonStats.put("pending", v.totalPending());
47 jsonStats.put("inProgress", v.totalInProgress());
48 jsonStats.put("completed", v.totalCompleted());
49 });
50 print("%s", jsonQueues);
51 } else {
52 queueStats.forEach((name, stats) ->
53 print(FMT, name, stats.totalPending(), stats.totalInProgress(), stats.totalCompleted()));
54 }
55 }
56}