7e5b093c072f20aa093014a56b873871977f9bd6
[controller.git] / opendaylight / networkconfiguration / neutron / implementation / src / main / java / org / opendaylight / controller / networkconfig / neutron / implementation / Activator.java
1 /*\r
2  * Copyright IBM Corporation, 2013.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.controller.networkconfig.neutron.implementation;\r
10 \r
11 import java.util.Hashtable;\r
12 import java.util.Dictionary;\r
13 import org.apache.felix.dm.Component;\r
14 import org.slf4j.Logger;\r
15 import org.slf4j.LoggerFactory;\r
16 \r
17 import org.opendaylight.controller.clustering.services.IClusterContainerServices;\r
18 import org.opendaylight.controller.networkconfig.neutron.INeutronFloatingIPCRUD;\r
19 import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;\r
20 import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;\r
21 import org.opendaylight.controller.networkconfig.neutron.INeutronRouterCRUD;\r
22 import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;\r
23 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;\r
24 \r
25 public class Activator extends ComponentActivatorAbstractBase {\r
26     protected static final Logger logger = LoggerFactory\r
27     .getLogger(Activator.class);\r
28 \r
29     /**\r
30      * Function called when the activator starts just after some\r
31      * initializations are done by the\r
32      * ComponentActivatorAbstractBase.\r
33      *\r
34      */\r
35     public void init() {\r
36 \r
37     }\r
38 \r
39     /**\r
40      * Function called when the activator stops just before the\r
41      * cleanup done by ComponentActivatorAbstractBase\r
42      *\r
43      */\r
44     public void destroy() {\r
45 \r
46     }\r
47 \r
48     /**\r
49      * Function that is used to communicate to dependency manager the\r
50      * list of known implementations for services inside a container\r
51      *\r
52      *\r
53      * @return An array containing all the CLASS objects that will be\r
54      * instantiated in order to get an fully working implementation\r
55      * Object\r
56      */\r
57     public Object[] getImplementations() {\r
58         Object[] res = { NeutronFloatingIPInterface.class,\r
59                 NeutronRouterInterface.class,\r
60                 NeutronPortInterface.class,\r
61                 NeutronSubnetInterface.class,\r
62                 NeutronNetworkInterface.class };\r
63         return res;\r
64     }\r
65 \r
66     /**\r
67      * Function that is called when configuration of the dependencies\r
68      * is required.\r
69      *\r
70      * @param c dependency manager Component object, used for\r
71      * configuring the dependencies exported and imported\r
72      * @param imp Implementation class that is being configured,\r
73      * needed as long as the same routine can configure multiple\r
74      * implementations\r
75      * @param containerName The containerName being configured, this allow\r
76      * also optional per-container different behavior if needed, usually\r
77      * should not be the case though.\r
78      */\r
79     public void configureInstance(Component c, Object imp, String containerName) {\r
80         if (imp.equals(NeutronFloatingIPInterface.class)) {\r
81             // export the service\r
82             c.setInterface(\r
83                     new String[] { INeutronFloatingIPCRUD.class.getName() }, null);\r
84             Dictionary<String, String> props = new Hashtable<String, String>();\r
85             props.put("salListenerName", "neutron");\r
86             c.add(createContainerServiceDependency(containerName)\r
87                     .setService(IClusterContainerServices.class)\r
88                     .setCallbacks("setClusterContainerService",\r
89                     "unsetClusterContainerService").setRequired(true));\r
90         }\r
91         if (imp.equals(NeutronRouterInterface.class)) {\r
92             // export the service\r
93             c.setInterface(\r
94                     new String[] { INeutronRouterCRUD.class.getName() }, null);\r
95             Dictionary<String, String> props = new Hashtable<String, String>();\r
96             props.put("salListenerName", "neutron");\r
97             c.add(createContainerServiceDependency(containerName)\r
98                     .setService(IClusterContainerServices.class)\r
99                     .setCallbacks("setClusterContainerService",\r
100                     "unsetClusterContainerService").setRequired(true));\r
101         }\r
102         if (imp.equals(NeutronPortInterface.class)) {\r
103             // export the service\r
104             c.setInterface(\r
105                     new String[] { INeutronPortCRUD.class.getName() }, null);\r
106             Dictionary<String, String> props = new Hashtable<String, String>();\r
107             props.put("salListenerName", "neutron");\r
108             c.add(createContainerServiceDependency(containerName)\r
109                     .setService(IClusterContainerServices.class)\r
110                     .setCallbacks("setClusterContainerService",\r
111                     "unsetClusterContainerService").setRequired(true));\r
112         }\r
113         if (imp.equals(NeutronSubnetInterface.class)) {\r
114             // export the service\r
115             c.setInterface(\r
116                     new String[] { INeutronSubnetCRUD.class.getName() }, null);\r
117             Dictionary<String, String> props = new Hashtable<String, String>();\r
118             props.put("salListenerName", "neutron");\r
119             c.add(createContainerServiceDependency(containerName)\r
120                     .setService(IClusterContainerServices.class)\r
121                     .setCallbacks("setClusterContainerService",\r
122                     "unsetClusterContainerService").setRequired(true));\r
123         }\r
124         if (imp.equals(NeutronNetworkInterface.class)) {\r
125             // export the service\r
126             c.setInterface(\r
127                     new String[] { INeutronNetworkCRUD.class.getName() }, null);\r
128             Dictionary<String, String> props = new Hashtable<String, String>();\r
129             props.put("salListenerName", "neutron");\r
130             c.add(createContainerServiceDependency(containerName)\r
131                     .setService(IClusterContainerServices.class)\r
132                     .setCallbacks("setClusterContainerService",\r
133                     "unsetClusterContainerService").setRequired(true));\r
134         }\r
135     }\r
136 }\r