Bump versions by x.(y+1).z
[openflowplugin.git] / applications / southbound-cli / src / main / java / org / opendaylight / openflowplugin / applications / southboundcli / cli / ReconciliationCountCommand.java
1 /*
2  * Copyright (c) 2018 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.applications.southboundcli.cli;
10
11 import java.util.Formatter;
12 import org.apache.karaf.shell.api.action.Action;
13 import org.apache.karaf.shell.api.action.Command;
14 import org.apache.karaf.shell.api.action.lifecycle.Reference;
15 import org.apache.karaf.shell.api.action.lifecycle.Service;
16 import org.apache.karaf.shell.api.console.Session;
17 import org.opendaylight.mdsal.binding.api.DataBroker;
18 import org.opendaylight.openflowplugin.applications.southboundcli.util.ShellUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.reconciliation.service.rev180227.reconciliation.counter.ReconcileCounter;
20
21 @Service
22 @Command(scope = "openflow", name = "getReconciliationCount",
23         description = "Displays the number of reconciliation triggered for openflow nodes")
24 public final class ReconciliationCountCommand implements Action {
25     @Reference
26     Session session;
27     @Reference
28     DataBroker dataBroker;
29
30     @Override
31     public Object execute() {
32         if (dataBroker == null) {
33             // not initialized
34             return null;
35         }
36         final var result = ShellUtil.getReconcileCount(dataBroker);
37         if (result.isEmpty()) {
38             session.getConsole().println("Reconciliation count not yet available for openflow nodes.");
39         } else {
40             StringBuilder stringBuilder = new StringBuilder();
41             final Formatter formatter = new Formatter(stringBuilder);
42             session.getConsole().println(getReconcileCountHeaderOutput());
43             session.getConsole().println("-".repeat(100));
44             for (ReconcileCounter reconcile : result) {
45                 session.getConsole().println(formatter.format("%-15s %3s %-15s %9s %-20s %4s %-20s %n",
46                         reconcile.getNodeId(), "", reconcile.getSuccessCount(), "", reconcile.getFailureCount(), "",
47                         reconcile.getLastRequestTime().getValue()));
48                 stringBuilder.setLength(0);
49             }
50             formatter.close();
51         }
52         return null;
53     }
54
55     private static String getReconcileCountHeaderOutput() {
56         final Formatter formatter = new Formatter();
57         String header = formatter.format("%-15s %3s %-15s %3s %-15s %3s %-15s %n", "NodeId", "",
58                 "ReconcileSuccessCount", "", "ReconcileFailureCount", "", "LastReconcileTime").toString();
59         formatter.close();
60         return header;
61     }
62 }