Use a String Id for both Node and NodeConnector
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / main / java / org / opendaylight / controller / sal / compatibility / ComponentActivator.xtend
1 package org.opendaylight.controller.sal.compatibility
2
3 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase
4 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey
5 import org.opendaylight.controller.sal.core.Node
6 import org.opendaylight.controller.sal.core.NodeConnector
7 import static org.opendaylight.controller.sal.compatibility.NodeMapping.*
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey
9 import org.apache.felix.dm.Component
10 import java.util.Arrays
11 import org.opendaylight.yangtools.yang.binding.NotificationListener
12 import java.util.Dictionary
13 import java.util.Hashtable
14 import org.opendaylight.controller.sal.utils.GlobalConstants
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker
16 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService
17 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService
18 import org.opendaylight.controller.sal.reader.IPluginInReadService
19 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService
20 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer
21 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService
23 import org.opendaylight.controller.sal.binding.api.NotificationService
24 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService
26 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService
27 import org.osgi.framework.BundleContext
28 import org.opendaylight.controller.sal.reader.IPluginOutReadService
29 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService
30 import org.opendaylight.controller.sal.discovery.IDiscoveryService
31 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.FlowTopologyDiscoveryService
33
34 class ComponentActivator extends ComponentActivatorAbstractBase implements BindingAwareConsumer {
35
36     private BundleContext context;
37
38     @Property
39     FlowProgrammerAdapter flow = new FlowProgrammerAdapter;
40
41     @Property
42     InventoryAndReadAdapter inventory = new InventoryAndReadAdapter;
43
44     @Property
45     DataPacketAdapter dataPacket = new DataPacketAdapter;
46
47     @Property
48     org.opendaylight.controller.sal.utils.INodeFactory nodeFactory = new MDSalNodeFactory
49
50     @Property
51     org.opendaylight.controller.sal.utils.INodeConnectorFactory nodeConnectorFactory = new MDSalNodeConnectorFactory
52
53
54     override protected init() {
55         Node.NodeIDType.registerIDType(MD_SAL_TYPE, String);
56         NodeConnector.NodeConnectorIDType.registerIDType(MD_SAL_TYPE, String, MD_SAL_TYPE);
57     }
58
59     override start(BundleContext context) {
60         super.start(context)
61         this.context = context;
62     }
63
64     def setBroker(BindingAwareBroker broker) {
65         broker.registerConsumer(this, context)
66     }
67
68     override onSessionInitialized(ConsumerContext session) {
69         val subscribe = session.getSALService(NotificationService)
70
71         // Registration of Flow Service
72         flow.delegate = session.getRpcService(SalFlowService)
73         subscribe.registerNotificationListener(flow);
74
75         // Data Packet Service
76         subscribe.registerNotificationListener(inventory);
77
78         // Inventory Service
79         inventory.dataService = session.getSALService(DataBrokerService);
80         inventory.flowStatisticsService = session.getRpcService(OpendaylightFlowStatisticsService);
81         inventory.topologyDiscovery = session.getRpcService(FlowTopologyDiscoveryService);
82
83         subscribe.registerNotificationListener(dataPacket)
84
85     }
86
87     override protected getGlobalImplementations() {
88         return Arrays.asList(this, flow, inventory, dataPacket, nodeFactory, nodeConnectorFactory)
89     }
90
91     override protected configureGlobalInstance(Component c, Object imp) {
92         configure(imp, c);
93     }
94
95     private def dispatch configure(MDSalNodeFactory imp, Component it) {
96         setInterface(org.opendaylight.controller.sal.utils.INodeFactory.name, properties);
97     }
98
99     private def dispatch configure(MDSalNodeConnectorFactory imp, Component it) {
100         setInterface(org.opendaylight.controller.sal.utils.INodeConnectorFactory.name, properties);
101     }
102
103     private def dispatch configure(ComponentActivator imp, Component it) {
104         add(
105             createServiceDependency().setService(BindingAwareBroker) //
106             .setCallbacks("setBroker", "setBroker") //
107             .setRequired(true))
108
109
110     }
111
112     private def dispatch configure(DataPacketAdapter imp, Component it) {
113         add(
114             createServiceDependency() //
115             .setService(IPluginOutDataPacketService) //
116             .setCallbacks("setDataPacketPublisher", "setDataPacketPublisher") //
117             .setRequired(false))
118     }
119
120     private def dispatch configure(FlowProgrammerAdapter imp, Component it) {
121         setInterface(IPluginInFlowProgrammerService.name, properties)
122         add(
123             createServiceDependency() //
124             .setService(IPluginOutFlowProgrammerService) //
125             .setCallbacks("setFlowProgrammerPublisher", "setFlowProgrammerPublisher") //
126             .setRequired(false))
127     }
128
129     private def dispatch configure(InventoryAndReadAdapter imp, Component it) {
130         setInterface(Arrays.asList(IPluginInInventoryService.name, IPluginInReadService.name), properties)
131         add(
132             createServiceDependency() //
133             .setService(IPluginOutReadService) //
134             .setCallbacks("setReadPublisher", "setReadPublisher") //
135             .setRequired(false))
136         add(
137             createServiceDependency() //
138             .setService(IPluginOutInventoryService) //
139             .setCallbacks("setInventoryPublisher", "setInventoryPublisher") //
140             .setRequired(false))
141         add(
142             createServiceDependency() //
143             .setService(IPluginOutTopologyService) //
144             .setCallbacks("setTopologyPublisher", "setTopologyPublisher") //
145             .setRequired(false))
146         add(
147             createServiceDependency() //
148             .setService(IDiscoveryService) //
149             .setCallbacks("setDiscoveryPublisher", "setDiscoveryPublisher") //
150             .setRequired(false))
151         
152     }
153
154     private def Dictionary<String, Object> properties() {
155         val props = new Hashtable<String, Object>();
156         props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString, MD_SAL_TYPE)
157         props.put("protocolName", MD_SAL_TYPE);
158         return props;
159     }
160 }