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