Controller inventory service doesn't come up
[controller.git] / opendaylight / sal / implementation / src / main / java / org / opendaylight / controller / sal / implementation / internal / Activator.java
1 /*
2  * Copyright (c) 2013 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
9 package org.opendaylight.controller.sal.implementation.internal;
10
11 import java.util.Dictionary;
12 import java.util.Hashtable;
13
14 import org.apache.felix.dm.Component;
15 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
16 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
17 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
18 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
19 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
20 import org.opendaylight.controller.sal.inventory.IInventoryService;
21 import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
22 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
23 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
24 import org.opendaylight.controller.sal.packet.IDataPacketService;
25 import org.opendaylight.controller.sal.packet.IListenDataPacket;
26 import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
27 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
28 import org.opendaylight.controller.sal.reader.IPluginInReadService;
29 import org.opendaylight.controller.sal.reader.IPluginOutReadService;
30 import org.opendaylight.controller.sal.reader.IReadService;
31 import org.opendaylight.controller.sal.reader.IReadServiceListener;
32 import org.opendaylight.controller.sal.topology.IListenTopoUpdates;
33 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
34 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
35 import org.opendaylight.controller.sal.topology.ITopologyService;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 public class Activator extends ComponentActivatorAbstractBase {
40     protected static final Logger logger = LoggerFactory
41             .getLogger(Activator.class);
42
43     /**
44      * Function called when the activator starts just after some initializations
45      * are done by the ComponentActivatorAbstractBase.
46      *
47      */
48     @Override
49     public void init() {
50
51     }
52
53     /**
54      * Function called when the activator stops just before the cleanup done by
55      * ComponentActivatorAbstractBase
56      *
57      */
58     @Override
59     public void destroy() {
60
61     }
62
63     /**
64      * Function that is used to communicate to dependency manager the list of
65      * known Global implementations
66      *
67      *
68      * @return An array containing all the CLASS objects that will be
69      *         instantiated in order to get an fully working implementation
70      *         Object
71      */
72     public Object[] getGlobalImplementations() {
73         Object[] res = { Inventory.class };
74         return res;
75     }
76
77     /**
78      * Function that is called when configuration of the dependencies is required.
79      *
80      * @param c
81      *            dependency manager Component object, used for configuring the
82      *            dependencies exported and imported
83      * @param imp
84      *            Implementation class that is being configured, needed as long
85      *            as the same routine can configure multiple implementations
86      */
87     public void configureGlobalInstance(Component c, Object imp) {
88         if (imp.equals(Inventory.class)) {
89             Dictionary<String, Object> props = new Hashtable<String, Object>();
90             props.put("scope", "Global");
91             // export the service
92             c.setInterface(
93                     new String[] { IPluginOutInventoryService.class.getName(),
94                             IInventoryService.class.getName() }, props);
95
96             // Now lets add a service dependency to make sure the
97             // provider of service exists
98             c.add(createServiceDependency()
99                     .setService(IListenInventoryUpdates.class, "(scope=Global)")
100                     .setCallbacks("setUpdateService", "unsetUpdateService")
101                     .setRequired(false));
102             c.add(createServiceDependency()
103                     .setService(IPluginInInventoryService.class, "(scope=Global)")
104                     .setCallbacks("setPluginService", "unsetPluginService")
105                     .setRequired(false));
106         }
107     }
108
109     /**
110      * Function that is used to communicate to dependency manager the list of
111      * known implementations for services inside a container
112      *
113      *
114      * @return An array containing all the CLASS objects that will be
115      *         instantiated in order to get an fully working implementation
116      *         Object
117      */
118     @Override
119     public Object[] getImplementations() {
120         Object[] res = { Topology.class, Inventory.class,
121                 FlowProgrammerService.class, ReadService.class,
122                 DataPacketService.class };
123         return res;
124     }
125
126     /**
127      * Function that is called when configuration of the dependencies is
128      * required.
129      *
130      * @param c
131      *            dependency manager Component object, used for configuring the
132      *            dependencies exported and imported
133      * @param imp
134      *            Implementation class that is being configured, needed as long
135      *            as the same routine can configure multiple implementations
136      * @param containerName
137      *            The containerName being configured, this allow also optional
138      *            per-container different behavior if needed, usually should not
139      *            be the case though.
140      */
141     @Override
142     public void configureInstance(Component c, Object imp, String containerName) {
143         if (imp.equals(Topology.class)) {
144             // export the service for Apps and Plugins
145             c.setInterface(
146                     new String[] { IPluginOutTopologyService.class.getName(),
147                             ITopologyService.class.getName() }, null);
148
149             // There can be multiple Topology listeners or there could
150             // be none, hence the dependency is optional
151             c.add(createContainerServiceDependency(containerName)
152                     .setService(IListenTopoUpdates.class)
153                     .setCallbacks("setUpdateService", "unsetUpdateService")
154                     .setRequired(false));
155
156             // There can be multiple southbound plugins or there could
157             // be none, the dependency is optional
158             c.add(createContainerServiceDependency(containerName)
159                     .setService(IPluginInTopologyService.class)
160                     .setCallbacks("setPluginService", "unsetPluginService")
161                     .setRequired(false));
162         }
163
164         if (imp.equals(Inventory.class)) {
165             // export the service
166             c.setInterface(
167                     new String[] { IPluginOutInventoryService.class.getName(),
168                             IInventoryService.class.getName() }, null);
169
170             // Now lets add a service dependency to make sure the
171             // provider of service exists
172             c.add(createContainerServiceDependency(containerName)
173                     .setService(IListenInventoryUpdates.class)
174                     .setCallbacks("setUpdateService", "unsetUpdateService")
175                     .setRequired(false));
176             c.add(createContainerServiceDependency(containerName)
177                     .setService(IPluginInInventoryService.class)
178                     .setCallbacks("setPluginService", "unsetPluginService")
179                     .setRequired(false));
180         }
181
182         if (imp.equals(FlowProgrammerService.class)) {
183             c.setInterface(
184                     new String[] { IFlowProgrammerService.class.getName(),
185                             IPluginOutFlowProgrammerService.class.getName() },
186                     null);
187
188             c.add(createServiceDependency()
189                     .setService(IPluginInFlowProgrammerService.class)
190                     .setCallbacks("setService", "unsetService")
191                     .setRequired(false));
192             c.add(createContainerServiceDependency(containerName)
193                     .setService(IFlowProgrammerListener.class)
194                     .setCallbacks("setListener", "unsetListener")
195                     .setRequired(false));
196         }
197
198         if (imp.equals(ReadService.class)) {
199             // export services
200             c.setInterface(new String[] {
201                     IReadService.class.getName(),IPluginOutReadService.class.getName()}, null);
202
203             // It is also the consumer of IPluginInReadService
204             c.add(createContainerServiceDependency(containerName)
205                     .setService(IPluginInReadService.class)
206                     .setCallbacks("setService", "unsetService")
207                     .setRequired(false));
208
209             //consumes plugins' reader updates
210             c.add(createContainerServiceDependency(containerName)
211                     .setService(IReadServiceListener.class)
212                     .setCallbacks("setReaderListener", "unsetReaderListener")
213                     .setRequired(false));
214
215         }
216
217         /************************/
218         /* DATA PACKET SERVICES */
219         /************************/
220         if (imp.equals(DataPacketService.class)) {
221             c.setInterface(
222                     new String[] { IPluginOutDataPacketService.class.getName(),
223                             IDataPacketService.class.getName() }, null);
224
225             // Optionally use PluginInDataService if any southbound
226             // protocol plugin exists
227             c.add(createContainerServiceDependency(containerName)
228                     .setService(IPluginInDataPacketService.class)
229                     .setCallbacks("setPluginInDataService",
230                             "unsetPluginInDataService").setRequired(false));
231
232             // Optionally listed to IListenDataPacket services
233             c.add(createContainerServiceDependency(containerName)
234                     .setService(IListenDataPacket.class)
235                     .setCallbacks("setListenDataPacket",
236                             "unsetListenDataPacket").setRequired(false));
237         }
238     }
239 }