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