Make methods static
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / SouthboundProviderConfigurator.java
1 /*
2  * Copyright (c) 2019 Red Hat, Inc. 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.ovsdb.southbound;
9
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.Map;
13 import java.util.StringTokenizer;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 /**
18  * Helper to let Blueprint XML configure {@link SouthboundProvider}.
19  *
20  * @author Michael Vorburger.ch
21  */
22 public class SouthboundProviderConfigurator {
23
24     private static final Logger LOG = LoggerFactory.getLogger(SouthboundProviderConfigurator.class);
25
26     private static final String SKIP_MONITORING_MANAGER_STATUS_PARAM = "skip-monitoring-manager-status";
27     private static final String BRIDGES_RECONCILIATION_INCLUSION_LIST_PARAM = "bridges-reconciliation-inclusion-list";
28     private static final String BRIDGES_RECONCILIATION_EXCLUSION_LIST_PARAM = "bridges-reconciliation-exclusion-list";
29
30     private final SouthboundProvider southboundProvider;
31
32     public SouthboundProviderConfigurator(SouthboundProvider southboundProvider) {
33         this.southboundProvider = southboundProvider;
34     }
35
36     public void setSkipMonitoringManagerStatus(boolean flag) {
37         southboundProvider.setSkipMonitoringManagerStatus(flag);
38     }
39
40     public void setBridgesReconciliationInclusionList(String bridgeListStr) {
41         if (bridgeListStr != null && !bridgeListStr.equals("")) {
42             SouthboundProvider.setBridgesReconciliationInclusionList(getBridgesList(bridgeListStr));
43         }
44     }
45
46     public void setBridgesReconciliationExclusionList(String bridgeListStr) {
47         if (bridgeListStr != null && !bridgeListStr.equals("")) {
48             SouthboundProvider.setBridgesReconciliationExclusionList(getBridgesList(bridgeListStr));
49         }
50     }
51
52     private static List<String> getBridgesList(final String bridgeListStr) {
53         List<String> bridgeList = new ArrayList<>();
54         StringTokenizer tokenizer = new StringTokenizer(bridgeListStr, ",");
55         while (tokenizer.hasMoreTokens()) {
56             bridgeList.add(tokenizer.nextToken());
57         }
58         return bridgeList;
59
60     }
61
62     public void updateConfigParameter(Map<String, Object> configParameters) {
63         if (configParameters != null && !configParameters.isEmpty()) {
64             LOG.debug("Config parameters received : {}", configParameters.entrySet());
65             for (Map.Entry<String, Object> paramEntry : configParameters.entrySet()) {
66                 if (paramEntry.getKey().equalsIgnoreCase(SKIP_MONITORING_MANAGER_STATUS_PARAM)) {
67                     southboundProvider
68                             .setSkipMonitoringManagerStatus(Boolean.parseBoolean((String) paramEntry.getValue()));
69                 } else if (paramEntry.getKey().equalsIgnoreCase(BRIDGES_RECONCILIATION_INCLUSION_LIST_PARAM)) {
70                     String bridgeListStr = (String)paramEntry.getValue();
71                     if (bridgeListStr != null && !bridgeListStr.equals("")) {
72                         SouthboundProvider.setBridgesReconciliationInclusionList(getBridgesList(bridgeListStr));
73                     }
74                 } else if (paramEntry.getKey().equalsIgnoreCase(BRIDGES_RECONCILIATION_EXCLUSION_LIST_PARAM)) {
75                     String bridgeListStr = (String)paramEntry.getValue();
76                     if (bridgeListStr != null && !bridgeListStr.equals("")) {
77                         SouthboundProvider.setBridgesReconciliationExclusionList(getBridgesList(bridgeListStr));
78                     }
79                 }
80             }
81         }
82     }
83 }