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 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;
22 @Command(scope = "openflow", name = "getReconciliationCount",
23 description = "Displays the number of reconciliation triggered for openflow nodes")
24 public final class ReconciliationCountCommand implements Action {
28 DataBroker dataBroker;
31 public Object execute() {
32 if (dataBroker == null) {
36 final var result = ShellUtil.getReconcileCount(dataBroker);
37 if (result.isEmpty()) {
38 session.getConsole().println("Reconciliation count not yet available for openflow nodes.");
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);
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();