Bump versions by x.(y+1).z
[openflowplugin.git] / applications / southbound-cli / src / main / java / org / opendaylight / openflowplugin / applications / southboundcli / cli / GetReconciliationStateProvider.java
1 /*
2  * Copyright (c) 2020 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 package org.opendaylight.openflowplugin.applications.southboundcli.cli;
9
10 import java.util.ArrayList;
11 import org.apache.karaf.shell.commands.Command;
12 import org.apache.karaf.shell.console.OsgiCommandSupport;
13 import org.opendaylight.openflowplugin.applications.frm.ReconciliationJMXServiceMBean;
14
15 @Command(scope = "openflow", name = "getreconciliationstate",
16         description = "Print reconciliation state for all devices")
17 public class GetReconciliationStateProvider extends OsgiCommandSupport {
18     private final ReconciliationJMXServiceMBean reconciliationJMXServiceMBean;
19
20     public GetReconciliationStateProvider(final ReconciliationJMXServiceMBean reconciliationJMXServiceMBean) {
21         this.reconciliationJMXServiceMBean = reconciliationJMXServiceMBean;
22     }
23
24     @Override
25     protected Object doExecute() {
26         final var reconciliationStates  = reconciliationJMXServiceMBean.acquireReconciliationStates();
27         if (!reconciliationStates.isEmpty()) {
28             final var result = new ArrayList<String>();
29             reconciliationStates.forEach((datapathId, reconciliationState) -> {
30                 String status = String.format("%-17s %-50s", datapathId, reconciliationState);
31                 result.add(status);
32             });
33             session.getConsole().println(getHeaderOutput());
34             session.getConsole().println(getLineSeparator());
35             result.stream().forEach(p -> session.getConsole().println(p));
36         } else {
37             session.getConsole().println("Reconciliation data not available");
38         }
39         return null;
40     }
41
42     private static String getHeaderOutput() {
43         return String.format("%-17s %-25s %-25s", "DatapathId", "Reconciliation Status", "Reconciliation Time");
44     }
45
46     private static String getLineSeparator() {
47         return "-------------------------------------------------------------------";
48     }
49 }