Fixes to make path redirect affinity work using the new nfchainagent service.
[affinity.git] / affinity / implementation / src / main / java / org / opendaylight / affinity / affinity / internal / Activator.java
1 /*
2  * Copyright (c) 2013 Plexxi, 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.affinity.affinity.internal;
10
11 import java.util.Dictionary;
12 import java.util.HashSet;
13 import java.util.Hashtable;
14 import java.util.Set;
15
16 import org.apache.felix.dm.Component;
17 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
18 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
19 import org.opendaylight.controller.configuration.IConfigurationContainerAware;
20 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
21 import org.opendaylight.affinity.affinity.IAffinityManager;
22 import org.opendaylight.affinity.affinity.IAffinityManagerAware;
23 import org.opendaylight.controller.switchmanager.ISwitchManager;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.opendaylight.controller.hosttracker.IfIptoHost;
27 import org.opendaylight.controller.hosttracker.IfNewHostNotify;
28 import org.opendaylight.affinity.l2agent.IfL2Agent;
29 import org.opendaylight.affinity.nfchainagent.NFchainAgent;
30 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
31
32 /**
33  * AffinityManager Bundle Activator
34  *
35  *
36  */
37 public class Activator extends ComponentActivatorAbstractBase {
38     protected static final Logger logger = LoggerFactory
39             .getLogger(Activator.class);
40
41     /**
42      * Function called when the activator starts just after some
43      * initializations are done by the
44      * ComponentActivatorAbstractBase.
45      *
46      */
47     public void init() {
48
49     }
50
51     /**
52      * Function called when the activator stops just before the
53      * cleanup done by ComponentActivatorAbstractBase
54      *
55      */
56     public void destroy() {
57
58     }
59
60     /**
61      * Function that is used to communicate to dependency manager the
62      * list of known implementations for services inside a container
63      *
64      *
65      * @return An array containing all the CLASS objects that will be
66      * instantiated in order to get an fully working implementation
67      * Object
68      */
69     public Object[] getImplementations() {
70         Object[] res = { AffinityManagerImpl.class };
71         return res;
72     }
73
74     /**
75      * Function that is called when configuration of the dependencies
76      * is required.
77      *
78      * @param c dependency manager Component object, used for
79      * configuring the dependencies exported and imported
80      * @param imp Implementation class that is being configured,
81      * needed as long as the same routine can configure multiple
82      * implementations
83      * @param containerName The containerName being configured, this allow
84      * also optional per-container different behavior if needed, usually
85      * should not be the case though.
86      */
87     public void configureInstance(Component c, Object imp, String containerName) {
88         if (imp.equals(AffinityManagerImpl.class)) {
89             Dictionary<String, Set<String>> props = new Hashtable<String, Set<String>>();
90             Set<String> propSet = new HashSet<String>();
91             propSet.add("affinitymanager.configSaveEvent");
92             props.put("cachenames", propSet);
93             // export the service
94             c.setInterface(new String[] {
95                     IAffinityManager.class.getName(),
96                     ICacheUpdateAware.class.getName(),
97                     IfNewHostNotify.class.getName(),
98                     IConfigurationContainerAware.class.getName() }, props);
99
100             // Now lets add a service dependency to make sure the
101             // provider of service exists
102             /* L2agent dependency causes the service to fail activation. tbd. */
103             c.add(createContainerServiceDependency(containerName)
104                   .setService(IfL2Agent.class)
105                   .setCallbacks("setL2Agent", "unsetL2Agent")
106                   .setRequired(true));
107             c.add(createContainerServiceDependency(containerName).setService(
108                     NFchainAgent.class).setCallbacks(
109                     "setNFchainAgent", "unsetNFchainAgent")
110                     .setRequired(true));
111             c.add(createContainerServiceDependency(containerName)
112                   .setService(IFlowProgrammerService.class)
113                   .setCallbacks("setFlowProgrammerService", "unsetFlowProgrammerService")
114                   .setRequired(true));
115             c.add(createContainerServiceDependency(containerName).setService(
116                     IClusterContainerServices.class).setCallbacks(
117                     "setClusterContainerService",
118                     "unsetClusterContainerService").setRequired(true));
119             c.add(createContainerServiceDependency(containerName).setService(IfIptoHost.class)
120                   .setCallbacks("setHostTracker", "unsetHostTracker").setRequired(true));
121             c.add(createContainerServiceDependency(containerName)
122                     .setService(ISwitchManager.class)
123                     .setCallbacks("setSwitchManager", "unsetSwitchManager")
124                     .setRequired(true));
125             c.add(createContainerServiceDependency(containerName).setService(
126                     IAffinityManagerAware.class).setCallbacks(
127                     "setAffinityManagerAware", "unsetAffinityManagerAware")
128                     .setRequired(false));
129         }
130     }
131 }