Search in sources :

Example 1 with WorkQueueStats

use of org.onosproject.store.service.WorkQueueStats in project onos by opennetworkinglab.

the class WorkQueueTestCommand method doExecute.

@Override
protected void doExecute() {
    StorageService storageService = get(StorageService.class);
    Serializer serializer = Serializer.using(KryoNamespaces.BASIC);
    queue = storageService.getWorkQueue(name, serializer);
    if ("add".equals(operation)) {
        if (value1 == null) {
            print("Usage: add <value1>");
        } else {
            get(queue.addOne(value1));
            print("Done");
        }
    } else if ("addMultiple".equals(operation)) {
        if (value1 == null || value2 == null) {
            print("Usage: addMultiple <value1> <value2>");
        } else {
            get(queue.addMultiple(Arrays.asList(value1, value2)));
            print("Done");
        }
    } else if ("takeAndComplete".equals(operation)) {
        int maxItems = value1 != null ? Integer.parseInt(value1) : 1;
        Collection<Task<String>> tasks = get(queue.take(maxItems));
        tasks.forEach(task -> get(queue.complete(task.taskId())));
        print("Done");
    } else if ("totalPending".equals(operation)) {
        WorkQueueStats stats = get(queue.stats());
        print("%d", stats.totalPending());
    } else if ("totalInProgress".equals(operation)) {
        WorkQueueStats stats = get(queue.stats());
        print("%d", stats.totalInProgress());
    } else if ("totalCompleted".equals(operation)) {
        WorkQueueStats stats = get(queue.stats());
        print("%d", stats.totalCompleted());
    } else if ("destroy".equals(operation)) {
        get(queue.destroy());
    } else {
        print("Invalid operation name. Valid operations names are:" + " [add, addMultiple takeAndComplete, totalPending, totalInProgress, totalCompleted, destroy]");
    }
}
Also used : Task(org.onosproject.store.service.Task) WorkQueueStats(org.onosproject.store.service.WorkQueueStats) StorageService(org.onosproject.store.service.StorageService) Serializer(org.onosproject.store.service.Serializer)

Example 2 with WorkQueueStats

use of org.onosproject.store.service.WorkQueueStats in project onos by opennetworkinglab.

the class QueuesListCommand method doExecute.

@Override
protected void doExecute() {
    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()));
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) WorkQueueStats(org.onosproject.store.service.WorkQueueStats) StorageAdminService(org.onosproject.store.service.StorageAdminService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

WorkQueueStats (org.onosproject.store.service.WorkQueueStats)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Serializer (org.onosproject.store.service.Serializer)1 StorageAdminService (org.onosproject.store.service.StorageAdminService)1 StorageService (org.onosproject.store.service.StorageService)1 Task (org.onosproject.store.service.Task)1