Distributed work queue primitive

Change-Id: Ia8e531e6611ec502399edec376ccc00522e47994
diff --git a/cli/src/main/java/org/onosproject/cli/net/QueuesListCommand.java b/cli/src/main/java/org/onosproject/cli/net/QueuesListCommand.java
new file mode 100644
index 0000000..a60cc6c
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/net/QueuesListCommand.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2015-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.cli.net;
+
+import java.util.Map;
+
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.store.service.StorageAdminService;
+import org.onosproject.store.service.WorkQueueStats;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+/**
+ * Command to list stats for all work queues in the system.
+ */
+@Command(scope = "onos", name = "queues",
+        description = "Lists information about work queues in the system")
+public class QueuesListCommand extends AbstractShellCommand {
+
+    private static final String FMT = "name=%s pending=%d inProgress=%d, completed=%d";
+
+    @Override
+    protected void execute() {
+        StorageAdminService storageAdminService = get(StorageAdminService.class);
+        Map<String, WorkQueueStats> queueStats = storageAdminService.getQueueStats();
+        if (outputJson()) {
+            ObjectMapper mapper = new ObjectMapper();
+            ObjectNode jsonQueues = mapper.createObjectNode();
+            queueStats.forEach((k, v) -> {
+                ObjectNode jsonStats = jsonQueues.putObject(k);
+                jsonStats.put("pending", v.totalPending());
+                jsonStats.put("inProgress", v.totalInProgress());
+                jsonStats.put("completed", v.totalCompleted());
+            });
+            print("%s", jsonQueues);
+        } else {
+            queueStats.forEach((name, stats) ->
+            print(FMT, name, stats.totalPending(), stats.totalInProgress(), stats.totalCompleted()));
+        }
+    }
+}
diff --git a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 6ea9077..c767289 100644
--- a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -400,6 +400,9 @@
             <action class="org.onosproject.cli.net.CountersListCommand"/>
         </command>
         <command>
+            <action class="org.onosproject.cli.net.QueuesListCommand"/>
+        </command>
+        <command>
             <action class="org.onosproject.cli.net.TransactionsCommand"/>
         </command>
         <command>