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