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