5df971af70ef8174182293d688c8c44abf22e4f3
[ovsdb.git] / ovsdb / src / main / java / org / opendaylight / ovsdb / plugin / Activator.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
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  * Authors : Madhu Venugopal, Brent Salisbury
9  */
10 package org.opendaylight.ovsdb.plugin;
11
12 import java.util.Dictionary;
13 import java.util.Hashtable;
14
15 import org.apache.felix.dm.Component;
16 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
17 import org.opendaylight.controller.sal.connection.IPluginInConnectionService;
18 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
19 import org.opendaylight.controller.sal.core.Node;
20 import org.opendaylight.controller.sal.core.NodeConnector;
21 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
22 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
23 import org.opendaylight.controller.sal.networkconfig.bridgedomain.IPluginInBridgeDomainConfigService;
24 import org.opendaylight.controller.sal.utils.GlobalConstants;
25 import org.opendaylight.controller.sal.utils.INodeConnectorFactory;
26 import org.opendaylight.controller.sal.utils.INodeFactory;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * OVSDB protocol plugin 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 initializations
41      * are done by the ComponentActivatorAbstractBase.
42      * Here it registers the node Type
43      *
44      */
45     @Override
46     public void init() {
47         Node.NodeIDType.registerIDType("OVS", String.class);
48         NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class, "OVS");
49     }
50
51     /**
52      * Function called when the activator stops just before the cleanup done by
53      * ComponentActivatorAbstractBase
54      *
55      */
56     @Override
57     public void destroy() {
58         Node.NodeIDType.unRegisterIDType("OVS");
59         NodeConnector.NodeConnectorIDType.unRegisterIDType("OVS");
60     }
61     @Override
62     public Object[] getGlobalImplementations() {
63         Object[] res = { ConnectionService.class, ConfigurationService.class, NodeFactory.class, NodeConnectorFactory.class, InventoryService.class };
64         return res;
65     }
66
67     @Override
68     public void configureGlobalInstance(Component c, Object imp){
69         if (imp.equals(ConfigurationService.class)) {
70             // export the service to be used by SAL
71             Dictionary<String, Object> props = new Hashtable<String, Object>();
72             // Set the protocolPluginType property which will be used
73             // by SAL
74             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
75             c.setInterface(new String[] { IPluginInBridgeDomainConfigService.class.getName(),
76                                           OVSDBConfigService.class.getName()}, props);
77
78             c.add(createServiceDependency()
79                     .setService(IConnectionServiceInternal.class)
80                     .setCallbacks("setConnectionServiceInternal", "unsetConnectionServiceInternal")
81                     .setRequired(true));
82             c.add(createServiceDependency()
83                     .setService(InventoryServiceInternal.class)
84                     .setCallbacks("setInventoryServiceInternal", "unsetInventoryServiceInternal")
85                     .setRequired(true));
86         }
87
88         if (imp.equals(ConnectionService.class)) {
89             // export the service to be used by SAL
90             Dictionary<String, Object> props = new Hashtable<String, Object>();
91             // Set the protocolPluginType property which will be used
92             // by SAL
93             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
94             c.setInterface(
95                     new String[] {IPluginInConnectionService.class.getName(),
96                                   IConnectionServiceInternal.class.getName()}, props);
97             c.add(createServiceDependency()
98                     .setService(InventoryServiceInternal.class)
99                     .setCallbacks("setInventoryServiceInternal", "unsetInventoryServiceInternal")
100                     .setRequired(true));
101             c.add(createServiceDependency()
102                     .setService(IClusterGlobalServices.class)
103                     .setCallbacks("setClusterServices", "unsetClusterServices")
104                     .setRequired(false));
105         }
106
107         if (imp.equals(InventoryService.class)) {
108             Dictionary<String, Object> props = new Hashtable<String, Object>();
109             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
110             c.setInterface(
111                     new String[] {IPluginInInventoryService.class.getName(),
112                             InventoryServiceInternal.class.getName()}, props);
113             c.add(createServiceDependency()
114                     .setService(IPluginOutInventoryService.class, "(scope=Global)")
115                     .setCallbacks("setPluginOutInventoryServices",
116                             "unsetPluginOutInventoryServices")
117                     .setRequired(true));
118         }
119
120         if (imp.equals(NodeFactory.class)) {
121             // export the service to be used by SAL
122             Dictionary<String, Object> props = new Hashtable<String, Object>();
123             // Set the protocolPluginType property which will be used
124             // by SAL
125             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
126             props.put("protocolName", "OVS");
127             c.setInterface(INodeFactory.class.getName(), props);
128         }
129         if (imp.equals(NodeConnectorFactory.class)) {
130             // export the service to be used by SAL
131             Dictionary<String, Object> props = new Hashtable<String, Object>();
132             // Set the protocolPluginType property which will be used
133             // by SAL
134             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
135             props.put("protocolName", "OVS");
136             c.setInterface(INodeConnectorFactory.class.getName(), props);
137         }
138
139     }
140 }