Merge "Declare a property for commons-lang version in poms and use it."
[controller.git] / opendaylight / containermanager / implementation / src / main / java / org / opendaylight / controller / containermanager / internal / Activator.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.containermanager.internal;
11
12 import org.eclipse.osgi.framework.console.CommandProvider;
13 import java.util.Dictionary;
14 import java.util.HashSet;
15 import java.util.Set;
16 import java.util.Hashtable;
17 import org.opendaylight.controller.containermanager.IContainerManager;
18 import org.apache.felix.dm.Component;
19 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
20 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
21 import org.opendaylight.controller.configuration.IConfigurationAware;
22 import org.opendaylight.controller.containermanager.IContainerAuthorization;
23 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
24 import org.opendaylight.controller.sal.core.IContainer;
25 import org.opendaylight.controller.sal.core.IContainerAware;
26 import org.opendaylight.controller.sal.core.IContainerListener;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 public class Activator extends ComponentActivatorAbstractBase {
31     protected static final Logger logger = LoggerFactory.getLogger(Activator.class);
32
33     /**
34      * Function called when the activator starts just after some initializations
35      * are done by the ComponentActivatorAbstractBase.
36      *
37      */
38     @Override
39     public void init() {
40     }
41
42     /**
43      * Function called when the activator stops just before the cleanup done by
44      * ComponentActivatorAbstractBase
45      *
46      */
47     @Override
48     public void destroy() {
49     }
50
51     /**
52      * Function that is used to communicate to dependency manager the list of
53      * known implementations for containerd-services
54      *
55      *
56      * @return An array containing all the CLASS objects that will be
57      *         instantiated in order to get an fully working implementation
58      *         Object
59      */
60     @Override
61     public Object[] getImplementations() {
62         Object[] res = { ContainerImpl.class };
63         return res;
64     }
65
66     /**
67      * Function that is called when configuration of the dependencies is
68      * required.
69      *
70      * @param c
71      *            dependency manager Component object, used for configuring the
72      *            dependencies exported and imported
73      * @param imp
74      *            Implementation class that is being configured, needed as long
75      *            as the same routine can configure multiple implementations
76      * @param containerName
77      *            The containername being configured, this allow also optional
78      *            per-container different behavior if needed, usually should not be
79      *            the case though.
80      */
81     @Override
82     public void configureInstance(Component c, Object imp, String containerName) {
83         if (imp.equals(ContainerImpl.class)) {
84             // export the service
85             c.setInterface(new String[] { IContainer.class.getName() }, null);
86
87             // private interface exported by ContainerManager to retrieve
88             // internal data, this is mandatory to implement the
89             // IContainer functionality
90             c.add(createServiceDependency().setService(IContainerInternal.class)
91                     .setCallbacks("setIContainerInternal", "unsetIContainerInternal")
92                     .setRequired(true));
93         }
94     }
95
96     /**
97      * Method which tells how many NON-containerd implementations are supported by
98      * the bundle. This way we can tune the number of components created. This
99      * components will be created ONLY at the time of bundle startup and will be
100      * destroyed only at time of bundle destruction, this is the major
101      * difference with the implementation retrieved via getImplementations where
102      * all of them are assumed to be containerd!
103      *
104      *
105      * @return The list of implementations the bundle will support, in
106      *         non-containerd version
107      */
108     @Override
109     protected Object[] getGlobalImplementations() {
110         Object[] res = { ContainerManager.class };
111         return res;
112     }
113
114     /**
115      * Configure the dependency for a given instance non-containerd
116      *
117      * @param c
118      *            Component assigned for this instance, this will be what will
119      *            be used for configuration
120      * @param imp
121      *            implementation to be configured
122      * @param containerName
123      *            container on which the configuration happens
124      */
125     @Override
126     protected void configureGlobalInstance(Component c, Object imp) {
127         if (imp.equals(ContainerManager.class)) {
128             Dictionary<String, Set<String>> props = new Hashtable<String, Set<String>>();
129             Set<String> propSet = new HashSet<String>();
130             propSet.add("containermgr.event.containerChange");
131             props.put("cachenames", propSet);
132
133             // export the service
134             c.setInterface(
135                     new String[] { IContainerManager.class.getName(),
136                             IContainerManager.class.getName(),
137                             IConfigurationAware.class.getName(),
138                             CommandProvider.class.getName(),
139                             IContainerInternal.class.getName(),
140                             IContainerAuthorization.class.getName(),
141                             ICacheUpdateAware.class.getName()}, props);
142
143             c.add(createServiceDependency()
144                     .setService(IClusterGlobalServices.class)
145                     .setCallbacks("setClusterServices", "unsetClusterServices")
146                     .setRequired(true));
147
148             // Key kick-starter for container creation in each component
149             c.add(createServiceDependency().setService(IContainerAware.class)
150                     .setCallbacks("setIContainerAware", "unsetIContainerAware")
151                     .setRequired(false));
152
153             // Optional interface expected to be exported by the
154             // protocol plugins to setup proper filtering based on
155             // slicing events
156             c.add(createServiceDependency()
157                     .setService(IContainerListener.class)
158                     .setCallbacks("setIContainerListener", "unsetIContainerListener")
159                     .setRequired(false));
160         }
161     }
162 }