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