2 * Copyright (c) 2018 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.applications.southboundcli.cli;
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.mdsal.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;
19 @Command(scope = "openflow", name = "getReconciliationCount",
20 description = "Displays the number of reconciliation triggered for openflow nodes")
21 public class ReconciliationCount extends OsgiCommandSupport {
23 private DataBroker dataBroker;
25 public void setDataBroker(final DataBroker dataBroker) {
26 this.dataBroker = dataBroker;
29 @SuppressWarnings("checkstyle:RegexpSinglelineJava")
31 protected Object doExecute() {
32 List<ReconcileCounter> result = ShellUtil.getReconcileCount(dataBroker);
33 if (result.isEmpty()) {
34 System.out.println("Reconciliation count not yet available for openflow nodes.");
36 StringBuilder stringBuilder = new StringBuilder();
37 final Formatter formatter = new Formatter(stringBuilder);
38 System.out.println(getReconcileCountHeaderOutput());
39 System.out.println("--------------------------------------------------------------------------"
40 + "---------------------------");
41 for (ReconcileCounter reconcile : result) {
42 System.out.println(formatter.format("%-15s %3s %-15s %9s %-20s %4s %-20s %n",
43 reconcile.getNodeId(), "", reconcile.getSuccessCount(), "", reconcile.getFailureCount(), "",
44 reconcile.getLastRequestTime().getValue()).toString());
45 stringBuilder.setLength(0);
52 private String getReconcileCountHeaderOutput() {
53 final Formatter formatter = new Formatter();
54 String header = formatter.format("%-15s %3s %-15s %3s %-15s %3s %-15s %n", "NodeId", "",
55 "ReconcileSuccessCount", "", "ReconcileFailureCount", "", "LastReconcileTime").toString();