Merge "Add test for generated code checking list of dependencies."
[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 java.util.Arrays
4 import java.util.Dictionary
5 import java.util.Hashtable
6 import org.apache.felix.dm.Component
7 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker
8 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext
9 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer
10 import org.opendaylight.controller.sal.binding.api.NotificationService
11 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService
12 import org.opendaylight.controller.sal.binding.api.data.DataProviderService
13 import org.opendaylight.controller.sal.compatibility.topology.TopologyAdapter
14 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase
15 import org.opendaylight.controller.sal.core.Node
16 import org.opendaylight.controller.sal.core.NodeConnector
17 import org.opendaylight.controller.sal.discovery.IDiscoveryService
18 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService
19 import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService
20 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService
21 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService
22 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService
23 import org.opendaylight.controller.sal.reader.IPluginInReadService
24 import org.opendaylight.controller.sal.reader.IPluginOutReadService
25 import org.opendaylight.controller.sal.topology.IPluginInTopologyService
26 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService
27 import org.opendaylight.controller.sal.utils.GlobalConstants
28 import org.opendaylight.controller.sal.utils.INodeConnectorFactory
29 import org.opendaylight.controller.sal.utils.INodeFactory
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.FlowTopologyDiscoveryService
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService
35 import org.osgi.framework.BundleContext
36
37 import static org.opendaylight.controller.sal.compatibility.NodeMapping.*
38 import org.opendaylight.controller.sal.compatibility.topology.TopologyProvider
39
40 class ComponentActivator extends ComponentActivatorAbstractBase implements BindingAwareConsumer {
41
42     private BundleContext context;
43
44     @Property
45     FlowProgrammerAdapter flow = new FlowProgrammerAdapter;
46
47     @Property
48     InventoryAndReadAdapter inventory = new InventoryAndReadAdapter;
49
50     @Property
51     DataPacketAdapter dataPacket = new DataPacketAdapter;
52
53     @Property
54     INodeFactory nodeFactory = new MDSalNodeFactory
55
56     @Property
57     INodeConnectorFactory nodeConnectorFactory = new MDSalNodeConnectorFactory
58     
59     @Property
60     TopologyAdapter topology = new TopologyAdapter
61     
62     @Property
63     TopologyProvider tpProvider = new TopologyProvider()
64
65
66     override protected init() {
67         Node.NodeIDType.registerIDType(MD_SAL_TYPE, String);
68         NodeConnector.NodeConnectorIDType.registerIDType(MD_SAL_TYPE, String, MD_SAL_TYPE);
69     }
70
71     override start(BundleContext context) {
72         super.start(context)
73         this.context = context;
74     }
75
76     def setBroker(BindingAwareBroker broker) {
77         broker.registerConsumer(this, context)
78     }
79
80     override onSessionInitialized(ConsumerContext session) {
81         val subscribe = session.getSALService(NotificationService)
82
83         // Registration of Flow Service
84         flow.delegate = session.getRpcService(SalFlowService)
85         flow.dataBrokerService = session.getSALService(DataBrokerService);
86         subscribe.registerNotificationListener(flow);
87
88         // Data Packet Service
89         subscribe.registerNotificationListener(inventory);
90
91         // Inventory Service
92         inventory.dataService = session.getSALService(DataBrokerService);
93         inventory.flowStatisticsService = session.getRpcService(OpendaylightFlowStatisticsService);
94         inventory.flowTableStatisticsService = session.getRpcService(OpendaylightFlowTableStatisticsService);
95         inventory.nodeConnectorStatisticsService = session.getRpcService(OpendaylightPortStatisticsService);
96         inventory.topologyDiscovery = session.getRpcService(FlowTopologyDiscoveryService);
97                 inventory.dataProviderService = session.getSALService(DataProviderService)
98                 topology.dataService = session.getSALService(DataProviderService)
99                 tpProvider.dataService = session.getSALService(DataProviderService)
100                 tpProvider.start();
101
102         subscribe.registerNotificationListener(dataPacket)
103
104     }
105
106     override protected getGlobalImplementations() {
107         return Arrays.asList(this, flow, inventory, dataPacket, nodeFactory, nodeConnectorFactory,topology,tpProvider)
108     }
109
110     override protected configureGlobalInstance(Component c, Object imp) {
111         configure(imp, c);
112     }
113
114     private def dispatch configure(MDSalNodeFactory imp, Component it) {
115         setInterface(INodeFactory.name, properties);
116     }
117
118     private def dispatch configure(MDSalNodeConnectorFactory imp, Component it) {
119         setInterface(INodeConnectorFactory.name, properties);
120     }
121
122     private def dispatch configure(ComponentActivator imp, Component it) {
123         add(
124             createServiceDependency().setService(BindingAwareBroker) //
125             .setCallbacks("setBroker", "setBroker") //
126             .setRequired(true))
127
128
129     }
130
131     private def dispatch configure(DataPacketAdapter imp, Component it) {
132         add(
133             createServiceDependency() //
134             .setService(IPluginOutDataPacketService) //
135             .setCallbacks("setDataPacketPublisher", "setDataPacketPublisher") //
136             .setRequired(false))
137     }
138
139     private def dispatch configure(FlowProgrammerAdapter imp, Component it) {
140         setInterface(IPluginInFlowProgrammerService.name, properties)
141         add(
142             createServiceDependency() //
143             .setService(IPluginOutFlowProgrammerService) //
144             .setCallbacks("setFlowProgrammerPublisher", "setFlowProgrammerPublisher") //
145             .setRequired(false))
146     }
147
148     private def dispatch configure(InventoryAndReadAdapter imp, Component it) {
149         setInterface(Arrays.asList(IPluginInInventoryService.name, IPluginInReadService.name), properties)
150         add(
151             createServiceDependency() //
152             .setService(IPluginOutReadService) //
153             .setCallbacks("setReadPublisher", "unsetReadPublisher") //
154             .setRequired(false))
155         add(
156             createServiceDependency() //
157             .setService(IPluginOutInventoryService) //
158             .setCallbacks("setInventoryPublisher", "setInventoryPublisher") //
159             .setRequired(false))
160         add(
161             createServiceDependency() //
162             .setService(IDiscoveryService) //
163             .setCallbacks("setDiscoveryPublisher", "setDiscoveryPublisher") //
164             .setRequired(false))
165         
166     }
167     
168     private def dispatch configure (TopologyAdapter imp, Component it) {
169         setInterface(Arrays.asList(IPluginInTopologyService.name), properties)
170         add(
171             createServiceDependency() //
172             .setService(IPluginOutTopologyService) //
173             .setCallbacks("setTopologyPublisher", "setTopologyPublisher") //
174             .setRequired(false))
175     }
176     
177     private def dispatch configure (TopologyProvider imp, Component it) {
178         add(
179             createServiceDependency() //
180             .setService(IPluginOutTopologyService) //
181             .setCallbacks("setTopologyPublisher", "setTopologyPublisher") //
182             .setRequired(false))
183     }
184
185     private def Dictionary<String, Object> properties() {
186         val props = new Hashtable<String, Object>();
187         props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString, MD_SAL_TYPE)
188         props.put("protocolName", MD_SAL_TYPE);
189         return props;
190     }
191 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.