Reconciliation Failure Count is not increased in failure scenarios.
[openflowplugin.git] / applications / southbound-cli / src / main / java / org / opendaylight / openflowplugin / applications / southboundcli / cli / ReconciliationCount.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 java.util.List;
13 import org.apache.karaf.shell.commands.Command;
14 import org.apache.karaf.shell.console.OsgiCommandSupport;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.openflowplugin.applications.southboundcli.util.ShellUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.reconciliation.service.rev180227.reconciliation.counter.ReconcileCounter;
18
19 @Command(scope = "openflow", name = "getReconciliationCount",
20         description = "Displays the number of reconciliation triggered for openflow nodes")
21 public class ReconciliationCount extends OsgiCommandSupport {
22
23     private DataBroker dataBroker;
24
25     public void setDataBroker(final DataBroker dataBroker) {
26         this.dataBroker = dataBroker;
27     }
28
29     @Override
30     protected Object doExecute() throws Exception {
31         List<ReconcileCounter> result = ShellUtil.getReconcileCount(dataBroker);
32         if (result.isEmpty()) {
33             session.getConsole().println("Reconciliation is not yet completed or connected device not found.");
34         } else {
35             StringBuilder stringBuilder = new StringBuilder();
36             final Formatter formatter = new Formatter(stringBuilder);
37             session.getConsole().println(getReconcileCountHeaderOutput());
38             session.getConsole().println("--------------------------------------------------------------------------"
39                     + "----------------------");
40             for (ReconcileCounter reconcile : result) {
41                 session.getConsole().println(formatter.format("%-15s %3s %-15s %9s %-20s %4s %-20s %n",
42                         reconcile.getNodeId(), "", reconcile.getSuccessCount(), "", reconcile.getFailureCount(), "",
43                         reconcile.getLastRequestTime()).toString());
44                 stringBuilder.setLength(0);
45             }
46             formatter.close();
47         }
48         return null;
49     }
50
51     private String getReconcileCountHeaderOutput() {
52         final Formatter formatter = new Formatter();
53         String header = formatter.format("%-15s %3s %-15s %3s %-15s %3s %-15s %n", "NodeId", "",
54                 "ReconcileSuccessCount", "", "ReconcileFailureCount", "", "LastReconcileTime").toString();
55         formatter.close();
56         return header;
57     }
58 }