From: Tony Tkacik Date: Mon, 14 Oct 2013 12:48:59 +0000 (+0200) Subject: Added composed Activator for MD-SAL to AD-SAL translation X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~625 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=4b69767072a83b7a6e5229a9c3bf38ecc0f49466 Added composed Activator for MD-SAL to AD-SAL translation Activator implements both ComponentBase Activator from AD-SAL and uses Felix DM to retrieve Binding-Aware Broker which then treats Activator as BindingAwareConsumer. Change-Id: I24b414d8b9d0846d12cff55d5a3b54fa6b697c05 Signed-off-by: Tony Tkacik --- diff --git a/opendaylight/md-sal/sal-compability/pom.xml b/opendaylight/md-sal/sal-compability/pom.xml index 525e7a4b01..613033ae51 100644 --- a/opendaylight/md-sal/sal-compability/pom.xml +++ b/opendaylight/md-sal/sal-compability/pom.xml @@ -73,6 +73,7 @@ ${project.name} + org.opendaylight.controller.sal.compability.ComponentActivator org.eclipse.xtend2.lib, org.eclipse.xtend.lib, diff --git a/opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/ComponentActivator.xtend b/opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/ComponentActivator.xtend new file mode 100644 index 0000000000..0ef349ce2c --- /dev/null +++ b/opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/ComponentActivator.xtend @@ -0,0 +1,127 @@ +package org.opendaylight.controller.sal.compability + +import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey +import org.opendaylight.controller.sal.core.Node +import org.opendaylight.controller.sal.core.NodeConnector +import static org.opendaylight.controller.sal.compability.NodeMapping.* +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey +import org.apache.felix.dm.Component +import java.util.Arrays +import org.opendaylight.yangtools.yang.binding.NotificationListener +import java.util.Dictionary +import java.util.Hashtable +import org.opendaylight.controller.sal.utils.GlobalConstants +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker +import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService +import org.opendaylight.controller.sal.inventory.IPluginInInventoryService +import org.opendaylight.controller.sal.reader.IPluginInReadService +import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService +import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService +import org.opendaylight.controller.sal.binding.api.NotificationService +import org.opendaylight.controller.sal.binding.api.data.DataBrokerService +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService +import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService +import org.osgi.framework.BundleContext +import org.opendaylight.controller.sal.reader.IPluginOutReadService +import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService + +class ComponentActivator extends ComponentActivatorAbstractBase implements BindingAwareConsumer { + + private BundleContext context; + + @Property + FlowProgrammerAdapter flow = new FlowProgrammerAdapter; + + @Property + InventoryAndReadAdapter inventory = new InventoryAndReadAdapter; + + @Property + DataPacketAdapter dataPacket = new DataPacketAdapter; + + override protected init() { + Node.NodeIDType.registerIDType(MD_SAL_TYPE, NodeKey); + NodeConnector.NodeConnectorIDType.registerIDType(MD_SAL_TYPE, NodeConnectorKey, MD_SAL_TYPE); + } + + override start(BundleContext context) { + super.start(context) + this.context = context; + } + + def setBroker(BindingAwareBroker broker) { + broker.registerConsumer(this, context) + } + + override onSessionInitialized(ConsumerContext session) { + val subscribe = session.getSALService(NotificationService) + + // Registration of Flow Service + flow.delegate = session.getRpcService(SalFlowService) + subscribe.registerNotificationListener(flow); + + // Data Packet Service + subscribe.registerNotificationListener(inventory); + + // Inventory Service + inventory.dataService = session.getSALService(DataBrokerService); + inventory.flowStatisticsService = session.getRpcService(OpendaylightFlowStatisticsService); + + subscribe.registerNotificationListener(dataPacket) + + } + + override protected getGlobalImplementations() { + return Arrays.asList(this, flow, inventory, dataPacket) + } + + override protected configureGlobalInstance(Component c, Object imp) { + configure(imp, c); + } + + private def dispatch configure(ComponentActivator imp, Component it) { + add( + createServiceDependency().setService(BindingAwareBroker) // + .setCallbacks("setBroker", "setBroker") // + .setRequired(true)) + } + + private def dispatch configure(DataPacketAdapter imp, Component it) { + add( + createServiceDependency() // + .setService(IPluginOutDataPacketService) // + .setCallbacks("setDataPacketPublisher", "setDataPacketPublisher") // + .setRequired(true)) + } + + private def dispatch configure(FlowProgrammerAdapter imp, Component it) { + setInterface(IPluginInFlowProgrammerService.name, properties) + add( + createServiceDependency() // + .setService(IPluginOutFlowProgrammerService) // + .setCallbacks("setFlowProgrammerPublisher", "setFlowProgrammerPublisher") // + .setRequired(true)) + } + + private def dispatch configure(InventoryAndReadAdapter imp, Component it) { + setInterface(Arrays.asList(IPluginInInventoryService.name, IPluginInReadService.name), properties) + add( + createServiceDependency() // + .setService(IPluginOutReadService) // + .setCallbacks("setReadPublisher", "setReadPublisher") // + .setRequired(true)) + add( + createServiceDependency() // + .setService(IPluginOutInventoryService) // + .setCallbacks("setInventoryPublisher", "setInventoryPublisher") // + .setRequired(true)) + } + + private def Dictionary properties() { + val props = new Hashtable(); + props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString, MD_SAL_TYPE) + return props; + } +}