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