Madan Jampani | 35708a9 | 2016-07-06 10:48:19 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
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 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.Command; |
| 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Madan Jampani | 35708a9 | 2016-07-06 10:48:19 -0700 | [diff] [blame] | 22 | import org.onosproject.cli.AbstractShellCommand; |
| 23 | import org.onosproject.store.service.StorageAdminService; |
| 24 | import org.onosproject.store.service.WorkQueueStats; |
| 25 | |
| 26 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 27 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 28 | |
| 29 | /** |
| 30 | * Command to list stats for all work queues in the system. |
| 31 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 32 | @Service |
Madan Jampani | 35708a9 | 2016-07-06 10:48:19 -0700 | [diff] [blame] | 33 | @Command(scope = "onos", name = "queues", |
| 34 | description = "Lists information about work queues in the system") |
| 35 | public class QueuesListCommand extends AbstractShellCommand { |
| 36 | |
| 37 | private static final String FMT = "name=%s pending=%d inProgress=%d, completed=%d"; |
| 38 | |
| 39 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 40 | protected void doExecute() { |
Madan Jampani | 35708a9 | 2016-07-06 10:48:19 -0700 | [diff] [blame] | 41 | 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 | } |