Madan Jampani | 35708a9 | 2016-07-06 10:48:19 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0a4e674 | 2016-09-15 23:03:10 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Madan Jampani | 35708a9 | 2016-07-06 10:48:19 -0700 | [diff] [blame] | 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 | package org.onosproject.cli.net; |
| 17 | |
| 18 | import java.util.Map; |
| 19 | |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.store.service.StorageAdminService; |
| 23 | import org.onosproject.store.service.WorkQueueStats; |
| 24 | |
| 25 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 26 | import 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") |
| 33 | public 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 | } |