blob: 612fb9e53db898fc95cf63885475f7467095a770 [file] [log] [blame]
Madan Jampani35708a92016-07-06 10:48:19 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
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
Ray Milkeyd84f89b2018-08-17 14:54:17 -070020import org.apache.karaf.shell.api.action.Command;
21import org.apache.karaf.shell.api.action.lifecycle.Service;
Madan Jampani35708a92016-07-06 10:48:19 -070022import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.store.service.StorageAdminService;
24import org.onosproject.store.service.WorkQueueStats;
25
26import com.fasterxml.jackson.databind.ObjectMapper;
27import com.fasterxml.jackson.databind.node.ObjectNode;
28
29/**
30 * Command to list stats for all work queues in the system.
31 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070032@Service
Madan Jampani35708a92016-07-06 10:48:19 -070033@Command(scope = "onos", name = "queues",
34 description = "Lists information about work queues in the system")
35public class QueuesListCommand extends AbstractShellCommand {
36
37 private static final String FMT = "name=%s pending=%d inProgress=%d, completed=%d";
38
39 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070040 protected void doExecute() {
Madan Jampani35708a92016-07-06 10:48:19 -070041 StorageAdminService storageAdminService = get(StorageAdminService.class);
42 Map<String, WorkQueueStats> queueStats = storageAdminService.getQueueStats();
43 if (outputJson()) {
44 ObjectMapper mapper = new ObjectMapper();
45 ObjectNode jsonQueues = mapper.createObjectNode();
46 queueStats.forEach((k, v) -> {
47 ObjectNode jsonStats = jsonQueues.putObject(k);
48 jsonStats.put("pending", v.totalPending());
49 jsonStats.put("inProgress", v.totalInProgress());
50 jsonStats.put("completed", v.totalCompleted());
51 });
52 print("%s", jsonQueues);
53 } else {
54 queueStats.forEach((name, stats) ->
55 print(FMT, name, stats.totalPending(), stats.totalInProgress(), stats.totalCompleted()));
56 }
57 }
58}