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