3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
10 package org.opendaylight.controller.containermanager.internal;
12 import org.eclipse.osgi.framework.console.CommandProvider;
13 import java.util.Dictionary;
14 import java.util.HashSet;
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;
30 public class Activator extends ComponentActivatorAbstractBase {
31 protected static final Logger logger = LoggerFactory.getLogger(Activator.class);
34 * Function called when the activator starts just after some initializations
35 * are done by the ComponentActivatorAbstractBase.
43 * Function called when the activator stops just before the cleanup done by
44 * ComponentActivatorAbstractBase
48 public void destroy() {
52 * Function that is used to communicate to dependency manager the list of
53 * known implementations for containerd-services
56 * @return An array containing all the CLASS objects that will be
57 * instantiated in order to get an fully working implementation
61 public Object[] getImplementations() {
62 Object[] res = { ContainerImpl.class };
67 * Function that is called when configuration of the dependencies is
71 * dependency manager Component object, used for configuring the
72 * dependencies exported and imported
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
82 public void configureInstance(Component c, Object imp, String containerName) {
83 if (imp.equals(ContainerImpl.class)) {
85 c.setInterface(new String[] { IContainer.class.getName() }, null);
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")
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!
105 * @return The list of implementations the bundle will support, in
106 * non-containerd version
109 protected Object[] getGlobalImplementations() {
110 Object[] res = { ContainerManager.class };
115 * Configure the dependency for a given instance non-containerd
118 * Component assigned for this instance, this will be what will
119 * be used for configuration
121 * implementation to be configured
122 * @param containerName
123 * container on which the configuration happens
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);
133 // export the service
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);
143 c.add(createServiceDependency()
144 .setService(IClusterGlobalServices.class)
145 .setCallbacks("setClusterServices", "unsetClusterServices")
148 // Key kick-starter for container creation in each component
149 c.add(createServiceDependency().setService(IContainerAware.class)
150 .setCallbacks("setIContainerAware", "unsetIContainerAware")
151 .setRequired(false));
153 // Optional interface expected to be exported by the
154 // protocol plugins to setup proper filtering based on
156 c.add(createServiceDependency()
157 .setService(IContainerListener.class)
158 .setCallbacks("setIContainerListener", "unsetIContainerListener")
159 .setRequired(false));