Revert "WIP: Bump upstreams"
[openflowplugin.git] / applications / reconciliation-framework / src / main / java / org / opendaylight / openflowplugin / applications / reconciliation / cli / GetRegisteredServices.java
1 /*
2  * Copyright (c) 2017 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.reconciliation.cli;
9
10 import static java.util.Objects.requireNonNull;
11
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.openflowplugin.applications.reconciliation.ReconciliationManager;
16 import org.opendaylight.openflowplugin.applications.reconciliation.ReconciliationNotificationListener;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 @Command(scope = "reconciliation", name = "getRegisteredServices", description = "displaying services registered to "
21         + "Reconciliation Framework")
22 /*
23  * CLI to display the service priority, service name and service status TODO
24  * service status
25  */
26 public class GetRegisteredServices extends OsgiCommandSupport {
27     private static final Logger LOG = LoggerFactory.getLogger(GetRegisteredServices.class);
28     private static final String CLI_FORMAT = "%d %-20s ";
29
30     private ReconciliationManager reconciliationManager;
31
32     public void setReconciliationManager(final ReconciliationManager reconciliationManager) {
33         this.reconciliationManager = requireNonNull(reconciliationManager, "ReconciliationManager can not be null!");
34     }
35
36     @Override
37     protected Object doExecute() {
38         LOG.debug("Executing getRegisteredServices to Reconciliation Framework command");
39         if (reconciliationManager.getRegisteredServices().isEmpty()) {
40             session.getConsole().println("No Services have registered to Reconciliation Framework");
41         } else {
42             for (List<ReconciliationNotificationListener> services : reconciliationManager.getRegisteredServices()
43                     .values()) {
44                 for (ReconciliationNotificationListener service : services) {
45                     session.getConsole().println(String.format(CLI_FORMAT, service.getPriority(), service.getName()));
46                 }
47             }
48         }
49
50         return null;
51     }
52 }