Merge "Fix 'Row cannot be cast to Interface' exceptions"
[ovsdb.git] / plugin / src / main / java / org / opendaylight / ovsdb / plugin / internal / 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.internal;
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.utils.GlobalConstants;
24 import org.opendaylight.controller.sal.utils.INodeConnectorFactory;
25 import org.opendaylight.controller.sal.utils.INodeFactory;
26 import org.opendaylight.ovsdb.lib.OvsdbConnection;
27 import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
28 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
29 import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
30 import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryListener;
31 import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryService;
32 import org.opendaylight.ovsdb.plugin.impl.ConfigurationServiceImpl;
33 import org.opendaylight.ovsdb.plugin.impl.ConnectionServiceImpl;
34 import org.opendaylight.ovsdb.plugin.impl.InventoryServiceImpl;
35 import org.opendaylight.ovsdb.plugin.impl.NodeConnectorFactory;
36 import org.opendaylight.ovsdb.plugin.impl.NodeFactory;
37
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 /**
42  * OVSDB protocol plugin Activator
43  *
44  *
45  */
46 public class Activator extends ComponentActivatorAbstractBase {
47     protected static final Logger logger = LoggerFactory
48             .getLogger(Activator.class);
49
50     /**
51      * Function called when the activator starts just after some initializations
52      * are done by the ComponentActivatorAbstractBase.
53      * Here it registers the node Type
54      *
55      */
56     @Override
57     public void init() {
58         Node.NodeIDType.registerIDType("OVS", String.class);
59         NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class, "OVS");
60     }
61
62     /**
63      * Function called when the activator stops just before the cleanup done by
64      * ComponentActivatorAbstractBase
65      *
66      */
67     @Override
68     public void destroy() {
69         Node.NodeIDType.unRegisterIDType("OVS");
70         NodeConnector.NodeConnectorIDType.unRegisterIDType("OVS");
71     }
72     @Override
73     public Object[] getGlobalImplementations() {
74         Object[] res = { ConnectionServiceImpl.class, ConfigurationServiceImpl.class, NodeFactory.class, NodeConnectorFactory.class, InventoryServiceImpl.class };
75         return res;
76     }
77
78     @Override
79     public void configureGlobalInstance(Component c, Object imp){
80         if (imp.equals(ConfigurationServiceImpl.class)) {
81             // export the service to be used by SAL
82             Dictionary<String, Object> props = new Hashtable<String, Object>();
83             // Set the protocolPluginType property which will be used
84             // by SAL
85             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
86             c.setInterface(new String[] { OvsdbConfigurationService.class.getName()}, props);
87
88             c.add(createServiceDependency()
89                     .setService(OvsdbConnectionService.class)
90                     .setRequired(true));
91             c.add(createServiceDependency()
92                     .setService(OvsdbInventoryService.class)
93                     .setRequired(true));
94             c.add(createServiceDependency()
95                     .setService(IClusterGlobalServices.class)
96                     .setCallbacks("setClusterServices", "unsetClusterServices")
97                     .setRequired(false));
98         }
99
100         if (imp.equals(ConnectionServiceImpl.class)) {
101             // export the service to be used by SAL
102             Dictionary<String, Object> props = new Hashtable<String, Object>();
103             // Set the protocolPluginType property which will be used
104             // by SAL
105             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
106             c.setInterface(
107                     new String[] {IPluginInConnectionService.class.getName(),
108                                   OvsdbConnectionService.class.getName(),
109                                   OvsdbConnectionListener.class.getName()}, props);
110             c.add(createServiceDependency()
111                     .setService(OvsdbInventoryService.class)
112                     .setRequired(true));
113             c.add(createServiceDependency()
114                     .setService(OvsdbConnection.class)
115                     .setRequired(true));
116         }
117
118         if (imp.equals(InventoryServiceImpl.class)) {
119             Dictionary<String, Object> props = new Hashtable<>();
120             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
121             props.put("scope", "Global");
122             c.setInterface(
123                     new String[]{IPluginInInventoryService.class.getName(),
124                                  OvsdbInventoryService.class.getName()}, props);
125             c.add(createServiceDependency()
126                           .setService(IPluginOutInventoryService.class, "(scope=Global)")
127                           .setCallbacks("setPluginOutInventoryServices",
128                                         "unsetPluginOutInventoryServices")
129                           .setRequired(true));
130             c.add(createServiceDependency()
131                     .setService(OvsdbInventoryListener.class)
132                     .setCallbacks("listenerAdded", "listenerRemoved"));
133             c.add(createServiceDependency()
134                     .setService(OvsdbConfigurationService.class)
135                     .setRequired(false));
136         }
137
138         if (imp.equals(NodeFactory.class)) {
139             // export the service to be used by SAL
140             Dictionary<String, Object> props = new Hashtable<String, Object>();
141             // Set the protocolPluginType property which will be used
142             // by SAL
143             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
144             props.put("protocolName", "OVS");
145             c.setInterface(INodeFactory.class.getName(), props);
146         }
147         if (imp.equals(NodeConnectorFactory.class)) {
148             // export the service to be used by SAL
149             Dictionary<String, Object> props = new Hashtable<String, Object>();
150             // Set the protocolPluginType property which will be used
151             // by SAL
152             props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
153             props.put("protocolName", "OVS");
154             c.setInterface(INodeConnectorFactory.class.getName(), props);
155         }
156
157     }
158 }