Merge "Fix minor bug in FRM proactive flow code path"
[controller.git] / opendaylight / sal / networkconfiguration / implementation / src / main / java / org / opendaylight / controller / sal / networkconfig / bridgedomain / internal / BridgeDomainConfigService.java
1 package org.opendaylight.controller.sal.networkconfig.bridgedomain.internal;
2
3 import java.util.List;
4 import java.util.Map;
5 import java.util.concurrent.ConcurrentHashMap;
6 import java.util.concurrent.ConcurrentMap;
7
8 import org.opendaylight.controller.sal.core.Node;
9 import org.opendaylight.controller.sal.core.NodeConnector;
10 import org.opendaylight.controller.sal.networkconfig.bridgedomain.ConfigConstants;
11 import org.opendaylight.controller.sal.networkconfig.bridgedomain.IBridgeDomainConfigService;
12 import org.opendaylight.controller.sal.networkconfig.bridgedomain.IPluginInBridgeDomainConfigService;
13 import org.opendaylight.controller.sal.utils.GlobalConstants;
14 import org.opendaylight.controller.sal.utils.Status;
15 import org.opendaylight.controller.sal.utils.StatusCode;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class BridgeDomainConfigService implements IBridgeDomainConfigService {
20     protected static final Logger logger = LoggerFactory
21             .getLogger(BridgeDomainConfigService.class);
22     private ConcurrentMap<String, IPluginInBridgeDomainConfigService> pluginService =
23             new ConcurrentHashMap<String, IPluginInBridgeDomainConfigService>();
24
25     void setPluginInService (Map props, IPluginInBridgeDomainConfigService s) {
26         String type = null;
27         Object value = props.get(GlobalConstants.PROTOCOLPLUGINTYPE.toString());
28         if (value instanceof String) {
29             type = (String) value;
30         }
31         if (type == null) {
32             logger.error("Received a PluginInConnectionService without any "
33                     + "protocolPluginType provided");
34         } else {
35             this.pluginService.put(type, s);
36         }
37     }
38
39     void unsetPluginInService(Map props, IPluginInBridgeDomainConfigService s) {
40         String type = null;
41
42         Object value = props.get(GlobalConstants.PROTOCOLPLUGINTYPE.toString());
43         if (value instanceof String) {
44             type = (String) value;
45         }
46         if (type == null) {
47             logger.error("Received a PluginInConnectionService without any "
48                     + "protocolPluginType provided");
49         } else if (this.pluginService.get(type).equals(s)) {
50             this.pluginService.remove(type);
51         }
52     }
53
54     /**
55      * Function called by the dependency manager when all the required
56      * dependencies are satisfied
57      *
58      */
59     void init() {
60     }
61
62     /**
63      * Function called by the dependency manager when at least one dependency
64      * become unsatisfied or when the component is shutting down because for
65      * example bundle is being stopped.
66      *
67      */
68     void destroy() {
69         if (this.pluginService != null) {
70             this.pluginService.clear();
71         }
72     }
73
74     @Override
75     public Status createBridgeDomain(Node node, String bridgeIdentifier, Map<ConfigConstants, Object> params)
76             throws Throwable {
77         if (pluginService != null) {
78             IPluginInBridgeDomainConfigService plugin = this.pluginService.get(node.getType());
79             if (plugin != null) {
80                 return plugin.createBridgeDomain(node, bridgeIdentifier, params);
81             }
82         }
83         return new Status(StatusCode.NOSERVICE, "Requested Plugin Service Not available");
84     }
85
86     @Override
87     public Status deleteBridgeDomain(Node node, String bridgeIdentifier) {
88         if (pluginService != null) {
89             IPluginInBridgeDomainConfigService plugin = this.pluginService.get(node.getType());
90             if (plugin != null) {
91                 return plugin.deleteBridgeDomain(node, bridgeIdentifier);
92             }
93         }
94         return new Status(StatusCode.NOSERVICE, "Requested Plugin Service Not available");
95     }
96
97     @Override
98     public List<String> getBridgeDomains(Node node) {
99         if (pluginService != null) {
100             IPluginInBridgeDomainConfigService plugin = this.pluginService.get(node.getType());
101             if (plugin != null) {
102                 return plugin.getBridgeDomains(node);
103             }
104         }
105         return null;
106     }
107
108     @Override
109     public Status addBridgeDomainConfig(Node node, String bridgeIdentifier, Map<ConfigConstants, Object> params) {
110         if (pluginService != null) {
111             IPluginInBridgeDomainConfigService plugin = this.pluginService.get(node.getType());
112             if (plugin != null) {
113                 return plugin.addBridgeDomainConfig(node, bridgeIdentifier, params);
114             }
115         }
116         return new Status(StatusCode.NOSERVICE, "Requested Plugin Service Not available");
117     }
118
119     @Override
120     public Status removeBridgeDomainConfig(Node node, String bridgeIdentifier, Map<ConfigConstants, Object> params) {
121         if (pluginService != null) {
122             IPluginInBridgeDomainConfigService plugin = this.pluginService.get(node.getType());
123             if (plugin != null) {
124                 return plugin.removeBridgeDomainConfig(node, bridgeIdentifier, params);
125             }
126         }
127         return new Status(StatusCode.NOSERVICE, "Requested Plugin Service Not available");
128     }
129
130     @Override
131     public Map<ConfigConstants, Object> getBridgeDomainConfigs(Node node, String bridgeIdentifier) {
132         if (pluginService != null) {
133             IPluginInBridgeDomainConfigService plugin = this.pluginService.get(node.getType());
134             if (plugin != null) {
135                 return plugin.getBridgeDomainConfigs(node, bridgeIdentifier);
136             }
137         }
138         return null;
139     }
140
141     @Override
142     public Node getBridgeDomainNode(Node configNode, String bridgeIdentifier) {
143         if (pluginService != null) {
144             IPluginInBridgeDomainConfigService plugin = this.pluginService.get(configNode.getType());
145             if (plugin != null) {
146                 return plugin.getBridgeDomainNode(configNode, bridgeIdentifier);
147             }
148         }
149         return null;
150     }
151
152     @Override
153     public Status addPort(Node node, String bridgeIdentifier, String portIdentifier, Map<ConfigConstants, Object> params) {
154         if (pluginService != null) {
155             IPluginInBridgeDomainConfigService plugin = this.pluginService.get(node.getType());
156             if (plugin != null) {
157                 return plugin.addPort(node, bridgeIdentifier, portIdentifier, params);
158             }
159         }
160         return new Status(StatusCode.NOSERVICE, "Requested Plugin Service Not available");
161     }
162
163     @Override
164     public Status deletePort(Node node, String bridgeIdentifier, String portIdentifier) {
165         if (pluginService != null) {
166             IPluginInBridgeDomainConfigService plugin = this.pluginService.get(node.getType());
167             if (plugin != null) {
168                 return plugin.deletePort(node, bridgeIdentifier, portIdentifier);
169             }
170         }
171         return new Status(StatusCode.NOSERVICE, "Requested Plugin Service Not available");
172     }
173
174     @Override
175     public Status addPortConfig(Node node, String bridgeIdentifier, String portIdentifier,
176             Map<ConfigConstants, Object> params) {
177         if (pluginService != null) {
178             IPluginInBridgeDomainConfigService plugin = this.pluginService.get(node.getType());
179             if (plugin != null) {
180                 return plugin.addPortConfig(node, bridgeIdentifier, portIdentifier, params);
181             }
182         }
183         return new Status(StatusCode.NOSERVICE, "Requested Plugin Service Not available");
184     }
185
186     @Override
187     public Status removePortConfig(Node node, String bridgeIdentifier, String portIdentifier,
188             Map<ConfigConstants, Object> params) {
189         if (pluginService != null) {
190             IPluginInBridgeDomainConfigService plugin = this.pluginService.get(node.getType());
191             if (plugin != null) {
192                 return plugin.removePortConfig(node, bridgeIdentifier, portIdentifier, params);
193             }
194         }
195         return new Status(StatusCode.NOSERVICE, "Requested Plugin Service Not available");
196     }
197
198     @Override
199     public Map<ConfigConstants, Object> getPortConfigs(Node node, String bridgeIdentifier, String portIdentifier) {
200         if (pluginService != null) {
201             IPluginInBridgeDomainConfigService plugin = this.pluginService.get(node.getType());
202             if (plugin != null) {
203                 return plugin.getPortConfigs(node, bridgeIdentifier, portIdentifier);
204             }
205         }
206         return null;
207     }
208
209     @Override
210     public NodeConnector getNodeConnector(Node configNode, String bridgeIdentifier, String portIdentifier) {
211         if (pluginService != null) {
212             IPluginInBridgeDomainConfigService plugin = this.pluginService.get(configNode.getType());
213             if (plugin != null) {
214                 return plugin.getNodeConnector(configNode, bridgeIdentifier, portIdentifier);
215             }
216         }
217         return null;
218     }
219 }