Remove uses of BindingAwareProvider/Consumer 04/72804/2
authorTom Pantelis <tompantelis@gmail.com>
Fri, 8 Jun 2018 16:45:34 +0000 (12:45 -0400)
committerTom Pantelis <tompantelis@gmail.com>
Fri, 8 Jun 2018 19:02:24 +0000 (15:02 -0400)
These are legacy and will eventually be deprecated/removed. Most
uses were in sample projects which were converted to blueprint.

Change-Id: I9575f08a4a94a200eb5cce9f7b80ee4d6155e6c5
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
31 files changed:
applications/forwardingrules-sync/src/main/java/org/opendaylight/openflowplugin/applications/frsync/impl/ForwardingRulesSyncProvider.java
applications/forwardingrules-sync/src/main/resources/org/opendaylight/blueprint/forwardingrules-sync.xml
applications/forwardingrules-sync/src/test/java/org/opendaylight/openflowplugin/applications/frsync/impl/ForwardingRulesSyncProviderTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java
samples/learning-switch/pom.xml
samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/Activator.java [deleted file]
samples/learning-switch/src/main/resources/org/opendaylight/blueprint/learning-switch.xml [new file with mode: 0644]
samples/sample-bundles/pom.xml
samples/sample-bundles/src/main/java/org/opendaylight/openflowplugin/samples/sample/bundles/SampleFlowCapableNodeListener.java [moved from samples/sample-bundles/src/main/java/org/opendaylight/openflowplugin/samples/sample/bundles/Activator.java with 92% similarity]
samples/sample-bundles/src/main/resources/org/opendaylight/blueprint/bundle-blueprint.xml [new file with mode: 0644]
samples/sample-consumer/pom.xml
samples/sample-consumer/src/main/java/org/opendaylight/openflowplugin/openflow/samples/consumer/Activator.java [deleted file]
samples/sample-consumer/src/main/java/org/opendaylight/openflowplugin/openflow/samples/consumer/SimpleDropFirewall.java
samples/sample-consumer/src/main/resources/org/opendaylight/blueprint/bundle-blueprint.xml [new file with mode: 0644]
test-provider/pom.xml
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowPluginBulkGroupTransactionProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowPluginBulkTransactionProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginGroupTestCommandProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginGroupTestServiceProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginMeterTestCommandProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginMeterTestServiceProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginStatsTestCommandProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginTableFeaturesTestCommandProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginTableFeaturesTestServiceProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginTestActivator.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginTestCommandProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginTestNodeConnectorNotification.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginTestServiceProvider.java
test-provider/src/main/java/org/opendaylight/openflowplugin/test/OpenflowpluginTestTopologyNotification.java
test-provider/src/main/resources/org/opendaylight/blueprint/test-provider.xml [new file with mode: 0644]

index 71e2ad07337de4bf616ee59b1050a9b5b0ab2f8d..726673a73491e99e31f0cacd701243001233204b 100644 (file)
@@ -18,9 +18,6 @@ import java.util.concurrent.Executors;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
-import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.openflowplugin.applications.frsync.NodeListener;
@@ -47,7 +44,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Top provider of forwarding rules synchronization functionality.
  */
-public class ForwardingRulesSyncProvider implements AutoCloseable, BindingAwareProvider {
+public class ForwardingRulesSyncProvider implements AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(ForwardingRulesSyncProvider.class);
     private static final String FRS_EXECUTOR_PREFIX = "FRS-executor-";
@@ -72,8 +69,7 @@ public class ForwardingRulesSyncProvider implements AutoCloseable, BindingAwareP
 
     private final ListeningExecutorService syncThreadPool;
 
-    public ForwardingRulesSyncProvider(final BindingAwareBroker broker,
-                                       final DataBroker dataBroker,
+    public ForwardingRulesSyncProvider(final DataBroker dataBroker,
                                        final RpcConsumerRegistry rpcRegistry,
                                        final ClusterSingletonServiceProvider clusterSingletonService) {
         Preconditions.checkNotNull(rpcRegistry, "RpcConsumerRegistry can not be null!");
@@ -95,11 +91,9 @@ public class ForwardingRulesSyncProvider implements AutoCloseable, BindingAwareP
                 .setUncaughtExceptionHandler((thread, ex) -> LOG.error("Uncaught exception {}", thread, ex))
                 .build());
         syncThreadPool = MoreExecutors.listeningDecorator(executorService);
-        broker.registerProvider(this);
     }
 
-    @Override
-    public void onSessionInitiated(final ProviderContext providerContext) {
+    public void init() {
         final TableForwarder tableForwarder = new TableForwarder(salTableService);
 
         final SyncPlanPushStrategy syncPlanPushStrategy = new SyncPlanPushStrategyFlatBatchImpl()
index e1f24449239d298a1f222537faa40fbfe5317d58..24b7bacbe611a3218418cb46100647b7c0b47ef4 100644 (file)
            xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
            odl:use-default-for-reference-types="true">
 
-    <reference id="broker" interface="org.opendaylight.controller.sal.binding.api.BindingAwareBroker"/>
     <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker" odl:type="pingpong"/>
     <reference id="rpcRegistry" interface="org.opendaylight.controller.sal.binding.api.RpcProviderRegistry"/>
     <reference id="clusterSingletonService" interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider"/>
 
     <bean id="frSync" class="org.opendaylight.openflowplugin.applications.frsync.impl.ForwardingRulesSyncProvider"
-          destroy-method="close">
-        <argument ref="broker"/>
+          init-method="init" destroy-method="close">
         <argument ref="dataBroker"/>
         <argument ref="rpcRegistry"/>
         <argument ref="clusterSingletonService"/>
     </bean>
 
-</blueprint>
\ No newline at end of file
+</blueprint>
index 514784e5be2cec46516af0a52c4b6ad5b49a99d3..e771a54d2937bd7d6cad8339bb4e1bea4925ce92 100644 (file)
@@ -18,8 +18,6 @@ import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.SalFlatBatchService;
@@ -39,10 +37,6 @@ public class ForwardingRulesSyncProviderTest {
     @Mock
     private RpcConsumerRegistry rpcRegistry;
     @Mock
-    private BindingAwareBroker broker;
-    @Mock
-    private ProviderContext providerContext;
-    @Mock
     private ClusterSingletonServiceProvider clusterSingletonService;
 
     @Before
@@ -54,15 +48,14 @@ public class ForwardingRulesSyncProviderTest {
                     return Mockito.mock(serviceType);
                 });
 
-        provider = new ForwardingRulesSyncProvider(broker, dataBroker, rpcRegistry, clusterSingletonService);
+        provider = new ForwardingRulesSyncProvider(dataBroker, rpcRegistry, clusterSingletonService);
         Mockito.verify(rpcRegistry).getRpcService(SalTableService.class);
         Mockito.verify(rpcRegistry).getRpcService(SalFlatBatchService.class);
-        Mockito.verify(broker).registerProvider(provider);
     }
 
     @Test
-    public void testOnSessionInitiated() throws Exception {
-        provider.onSessionInitiated(providerContext);
+    public void testInit() throws Exception {
+        provider.init();
 
         Mockito.verify(dataBroker, Mockito.times(2)).registerDataTreeChangeListener(
                 Matchers.<DataTreeIdentifier<FlowCapableNode>>any(),
index 5bd6e67630b668474968bda950b7507f954f4aaa..202cadd98d7baf17de3c25f947523b7312a8a891 100644 (file)
@@ -21,6 +21,7 @@ import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
@@ -46,7 +47,7 @@ public class RpcContextImplTest {
 
 
     @Mock
-    private BindingAwareBroker.ProviderContext rpcProviderRegistry;
+    private RpcProviderRegistry rpcProviderRegistry;
     @Mock
     private DeviceState deviceState;
     @Mock
index 65e57b6ef5511a567fffcb2846d81509e8fbca0b..3fa77d09d0ec2b3cb9367dde0a3ae064c7d50891 100644 (file)
@@ -21,7 +21,7 @@ import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
@@ -49,7 +49,7 @@ public class RpcManagerImplTest {
     private RpcManagerImpl rpcManager;
 
     @Mock
-    private ProviderContext rpcProviderRegistry;
+    private RpcProviderRegistry rpcProviderRegistry;
     @Mock
     private DeviceContext deviceContext;
     @Mock
@@ -75,7 +75,7 @@ public class RpcManagerImplTest {
     @Mock
     private KeyedInstanceIdentifier<Node, NodeKey> nodePath;
 
-    private NodeId nodeId = new NodeId("openflow-junit:1");
+    private final NodeId nodeId = new NodeId("openflow-junit:1");
 
     @Before
     public void setUp() {
index 60f33ad0c2a1d50ad06eb4c939c9b47830e9160d..02bff9ffb4498ba83374df1d55a7d5fdc8f4ce5e 100644 (file)
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
                 <extensions>true</extensions>
-                <configuration>
-                    <instructions>
-                        <Embed-Transitive>
-                            false
-                        </Embed-Transitive>
-                        <Bundle-Activator>
-                            org.opendaylight.openflowplugin.learningswitch.Activator
-                        </Bundle-Activator>
-                    </instructions>
-                    <manifestLocation>${project.build.directory}/META-INF</manifestLocation>
-                </configuration>
             </plugin>
         </plugins>
     </build>
             <artifactId>infrautils-util</artifactId>
             <version>${infrautils.version}</version>
         </dependency>
-        <dependency>
-          <groupId>org.osgi</groupId>
-          <artifactId>org.osgi.core</artifactId>
-        </dependency>
-
-
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 </project>
 
diff --git a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/Activator.java b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/Activator.java
deleted file mode 100644 (file)
index 7201fdd..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.openflowplugin.learningswitch;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareConsumer;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
-import org.opendaylight.controller.sal.binding.api.NotificationService;
-import org.opendaylight.openflowplugin.learningswitch.multi.LearningSwitchManagerMultiImpl;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
-import org.osgi.framework.BundleContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Learning switch activator
- * Activator is derived from AbstractBindingAwareConsumer, which takes care
- * of looking up MD-SAL in Service Registry and registering consumer
- * when MD-SAL is present.
- */
-public class Activator extends AbstractBindingAwareConsumer implements AutoCloseable {
-
-    private static final Logger LOG = LoggerFactory.getLogger(Activator.class);
-    private LearningSwitchManager learningSwitch;
-
-    @Override
-    protected void startImpl(BundleContext context) {
-        LOG.info("startImpl() passing");
-    }
-
-    /**
-     * Invoked when consumer is registered to the MD-SAL.
-     */
-    @Override
-    public void onSessionInitialized(ConsumerContext session) {
-        LOG.info("inSessionInitialized() passing");
-        /**
-         * We create instance of our LearningSwitchManager
-         * and set all required dependencies,
-         *
-         * which are
-         *   Data Broker (data storage service) - for configuring flows and reading stored switch state
-         *   PacketProcessingService - for sending out packets
-         *   NotificationService - for receiving notifications such as packet in.
-         */
-        learningSwitch = new LearningSwitchManagerMultiImpl();
-        learningSwitch.setDataBroker(session.getSALService(DataBroker.class));
-        learningSwitch.setPacketProcessingService(session.getRpcService(PacketProcessingService.class));
-        learningSwitch.setNotificationService(session.getSALService(NotificationService.class));
-        learningSwitch.start();
-    }
-
-    @Override
-    public void close() {
-        LOG.info("close() passing");
-        if (learningSwitch != null) {
-            learningSwitch.stop();
-        }
-    }
-
-    @Override
-    protected void stopImpl(BundleContext context) {
-        close();
-        super.stopImpl(context);
-    }
-}
diff --git a/samples/learning-switch/src/main/resources/org/opendaylight/blueprint/learning-switch.xml b/samples/learning-switch/src/main/resources/org/opendaylight/blueprint/learning-switch.xml
new file mode 100644 (file)
index 0000000..c969ef9
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+    odl:use-default-for-reference-types="true">
+
+  <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
+  <reference id="notificationService" interface="org.opendaylight.controller.sal.binding.api.NotificationService"/>
+
+  <odl:rpc-service id="packetProcessingService" interface="org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService"/>
+
+  <bean id="learningSwitch" class="org.opendaylight.openflowplugin.learningswitch.multi.LearningSwitchManagerMultiImpl"
+      init-method="start" destroy-method="stop">
+    <property name="dataBroker" ref="dataBroker"/>
+    <property name="notificationService" ref="notificationService"/>
+    <property name="packetProcessingService" ref="packetProcessingService"/>
+  </bean>
+
+</blueprint>
index 613bc18655e85b56bd43c84f079bb801c4461910..97d810f711df76e3dcd4088cdaa8ebbc5bcde605 100644 (file)
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
                 <extensions>true</extensions>
-                <configuration>
-                    <instructions>
-                        <Embed-Transitive>
-                            false
-                        </Embed-Transitive>
-                        <Bundle-Activator>
-                            org.opendaylight.openflowplugin.samples.sample.bundles.Activator
-                        </Bundle-Activator>
-                    </instructions>
-                    <manifestLocation>${project.build.directory}/META-INF</manifestLocation>
-                </configuration>
             </plugin>
         </plugins>
     </build>
@@ -23,10 +23,6 @@ import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.Mod
 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.sal.binding.api.AbstractBrokerAwareActivator;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
-import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
@@ -84,49 +80,54 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.on
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleControlType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleFlags;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleId;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Sample bundles activator.
+ * Sample DataTreeChangeListener.
  */
-public class Activator extends AbstractBrokerAwareActivator implements BindingAwareConsumer,
-        ClusteredDataTreeChangeListener<FlowCapableNode>, AutoCloseable {
+public class SampleFlowCapableNodeListener implements ClusteredDataTreeChangeListener<FlowCapableNode>, AutoCloseable {
 
-    private static final Logger LOG = LoggerFactory.getLogger(Activator.class);
+    private static final Logger LOG = LoggerFactory.getLogger(SampleFlowCapableNodeListener.class);
 
     private static final BundleId BUNDLE_ID = new BundleId(1L);
     private static final BundleFlags BUNDLE_FLAGS = new BundleFlags(true, true);
     private static final ExecutorService EXECUTOR = Executors.newSingleThreadExecutor();
 
-    private DataBroker dataBroker;
-    private SalBundleService bundleService;
+    private final DataBroker dataBroker;
+    private final SalBundleService bundleService;
+    private ListenerRegistration<?> listenerReg;
+
+    public SampleFlowCapableNodeListener(DataBroker dataBroker, SalBundleService bundleService) {
+        this.dataBroker = dataBroker;
+        this.bundleService = bundleService;
+    }
 
     @Override
-    public void close() throws Exception {
+    public void close() {
         LOG.debug("close() passing");
+        if (listenerReg != null) {
+            listenerReg.close();
+        }
     }
 
-    @Override
-    public void onSessionInitialized(ConsumerContext consumerContext) {
+    public void init() {
         LOG.debug("inSessionInitialized() passing");
-        dataBroker = consumerContext.getSALService(DataBroker.class);
 
         final InstanceIdentifier<FlowCapableNode> path = InstanceIdentifier.create(Nodes.class).child(Node.class)
                 .augmentation(FlowCapableNode.class);
         final DataTreeIdentifier<FlowCapableNode> identifier =
                 new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, path);
 
-        dataBroker.registerDataTreeChangeListener(identifier, Activator.this);
-        bundleService = consumerContext.getRpcService(SalBundleService.class);
+        listenerReg = dataBroker.registerDataTreeChangeListener(identifier, SampleFlowCapableNodeListener.this);
     }
 
     @Override
     public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<FlowCapableNode>> modifications) {
-        for (DataTreeModification modification : modifications) {
+        for (DataTreeModification<FlowCapableNode> modification : modifications) {
             if (modification.getRootNode().getModificationType() == ModificationType.WRITE) {
                 LOG.info("Node connected:  {}",
                         modification.getRootPath().getRootIdentifier().firstIdentifierOf(Node.class));
@@ -192,12 +193,6 @@ public class Activator extends AbstractBrokerAwareActivator implements BindingAw
         }, EXECUTOR);
     }
 
-    @Override
-    protected void onBrokerAvailable(BindingAwareBroker bindingAwareBroker, BundleContext bundleContext) {
-        LOG.debug("onBrokerAvailable() passing");
-        bindingAwareBroker.registerConsumer(this);
-    }
-
     private static List<Message> createMessages(NodeRef nodeRef) {
         List<Message> messages  = new ArrayList<>();
 
diff --git a/samples/sample-bundles/src/main/resources/org/opendaylight/blueprint/bundle-blueprint.xml b/samples/sample-bundles/src/main/resources/org/opendaylight/blueprint/bundle-blueprint.xml
new file mode 100644 (file)
index 0000000..9412061
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+    odl:use-default-for-reference-types="true">
+
+  <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
+
+  <odl:rpc-service id="salBundleService" interface="org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.SalBundleService"/>
+
+  <bean id="sampleListener" class="org.opendaylight.openflowplugin.samples.sample.bundles.SampleFlowCapableNodeListener"
+          init-method="init" destroy-method="close">
+    <argument ref="dataBroker"/>
+    <argument ref="salBundleService"/>
+  </bean>
+
+</blueprint>
index f0af1c2a592e01a3f333d8aacf5cf3094d433370..7a041706a73882604ccc38989d8ec17cf4e3df59 100644 (file)
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
                 <extensions>true</extensions>
-                <configuration>
-                    <instructions>
-                        <Embed-Transitive>
-                            false
-                        </Embed-Transitive>
-                        <Bundle-Activator>
-                            org.opendaylight.openflowplugin.openflow.samples.consumer.Activator
-                        </Bundle-Activator>
-                    </instructions>
-                    <manifestLocation>${project.build.directory}/META-INF</manifestLocation>
-                </configuration>
             </plugin>
         </plugins>
     </build>
             <groupId>org.opendaylight.mdsal</groupId>
             <artifactId>yang-binding</artifactId>
         </dependency>
-        <dependency>
-          <groupId>org.osgi</groupId>
-          <artifactId>org.osgi.core</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>sal-common-util</artifactId>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 </project>
 
diff --git a/samples/sample-consumer/src/main/java/org/opendaylight/openflowplugin/openflow/samples/consumer/Activator.java b/samples/sample-consumer/src/main/java/org/opendaylight/openflowplugin/openflow/samples/consumer/Activator.java
deleted file mode 100644 (file)
index 4ef79f6..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.openflowplugin.openflow.samples.consumer;
-
-import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareConsumer;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
-
-public class Activator extends AbstractBindingAwareConsumer {
-
-    @Override
-    public void onSessionInitialized(ConsumerContext session) {
-        SalFlowService flowService = session.getRpcService(SalFlowService.class);
-        new SimpleDropFirewall(flowService).start();
-    }
-}
index 1ae2478c7a50f2cee581d76996acc1c542dbdb2e..5932c0d7510f8f2033a066c44a1059df40d613cd 100644 (file)
@@ -24,9 +24,6 @@ public class SimpleDropFirewall {
         this.flowService = flowService;
     }
 
-    public void start() {
-    }
-
     public boolean addFlow(AddFlowInput flow) throws InterruptedException,
             ExecutionException, TimeoutException {
         Future<RpcResult<AddFlowOutput>> result = flowService.addFlow(flow);
diff --git a/samples/sample-consumer/src/main/resources/org/opendaylight/blueprint/bundle-blueprint.xml b/samples/sample-consumer/src/main/resources/org/opendaylight/blueprint/bundle-blueprint.xml
new file mode 100644 (file)
index 0000000..9e74362
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+    odl:use-default-for-reference-types="true">
+
+  <odl:rpc-service id="salFlowService" interface="org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService"/>
+
+  <bean id="simpleDropFirewall" class="org.opendaylight.openflowplugin.openflow.samples.consumer.SimpleDropFirewall">
+    <argument ref="salFlowService"/>
+  </bean>
+
+</blueprint>
index bff5d332b43c5ada296460ed94769e941d528465..4eaa0aa661a099505235a8361e59f9d4ecd5e986 100644 (file)
@@ -24,7 +24,7 @@
         <dependency>
             <groupId>org.opendaylight.openflowplugin.model</groupId>
             <artifactId>model-flow-service</artifactId>
-        </dependency>    
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.openflowplugin.model</groupId>
             <artifactId>model-flow-base</artifactId>
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
-                <version>${maven.bundle.version}</version>
                 <extensions>true</extensions>
-                <configuration>
-                    <instructions>
-                        <Bundle-Activator>org.opendaylight.openflowplugin.test.OpenflowpluginTestActivator</Bundle-Activator>
-                        <Embed-Dependency>commons-lang</Embed-Dependency>
-                        <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
-                    </instructions>
-                </configuration>
             </plugin>
         </plugins>
     </build>
index 101801a5bb01554eabc72d4b1aa329ea6b60b1d8..0f45855999447286502a89075c0e77f50aacb149 100644 (file)
@@ -20,7 +20,6 @@ import org.eclipse.osgi.framework.console.CommandProvider;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.NotificationService;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
@@ -107,22 +106,23 @@ import org.slf4j.LoggerFactory;
 @SuppressWarnings("checkstyle:MethodName")
 public class OpenflowPluginBulkGroupTransactionProvider implements CommandProvider {
     private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginBulkGroupTransactionProvider.class);
-    private DataBroker dataBroker;
+    private final DataBroker dataBroker;
     private final BundleContext ctx;
     private final String originalFlowName = "Foo";
     private final NodeErrorListener nodeErrorListener = new NodeErrorListenerLoggingImpl();
     private Node testNode12;
     private final String originalGroupName = "Foo";
-    private NotificationService notificationService;
+    private final NotificationService notificationService;
 
-    public OpenflowPluginBulkGroupTransactionProvider(BundleContext ctx) {
+    public OpenflowPluginBulkGroupTransactionProvider(DataBroker dataBroker, NotificationService notificationService,
+            BundleContext ctx) {
+        this.dataBroker = dataBroker;
+        this.notificationService = notificationService;
         this.ctx = ctx;
     }
 
-    public void onSessionInitiated(ProviderContext session) {
-        notificationService = session.getSALService(NotificationService.class);
+    public void init() {
         notificationService.registerNotificationListener(nodeErrorListener);
-        dataBroker = session.getSALService(DataBroker.class);
         ctx.registerService(CommandProvider.class.getName(), this, null);
         createTestFlow(createTestNode(null), null, null);
     }
index 65d33d106d4ef6ecbe1e83686a05f8dd2cb6dcaf..58637d97be4f9f19d842a15f6b1de8e4376aaf33 100644 (file)
@@ -20,7 +20,6 @@ import org.eclipse.osgi.framework.console.CommandProvider;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.NotificationService;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel;
@@ -117,20 +116,21 @@ import org.slf4j.LoggerFactory;
 public class OpenflowPluginBulkTransactionProvider implements CommandProvider {
 
     private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginBulkTransactionProvider.class);
-    private DataBroker dataBroker;
+    private final DataBroker dataBroker;
     private final BundleContext ctx;
     private final String originalFlowName = "Foo";
     private final NodeErrorListener nodeErrorListener = new NodeErrorListenerLoggingImpl();
-    private NotificationService notificationService;
+    private final NotificationService notificationService;
 
-    public OpenflowPluginBulkTransactionProvider(BundleContext ctx) {
+    public OpenflowPluginBulkTransactionProvider(DataBroker dataBroker, NotificationService notificationService,
+            BundleContext ctx) {
+        this.dataBroker = dataBroker;
+        this.notificationService = notificationService;
         this.ctx = ctx;
     }
 
-    public void onSessionInitiated(ProviderContext session) {
-        notificationService = session.getSALService(NotificationService.class);
+    public void init() {
         notificationService.registerNotificationListener(nodeErrorListener);
-        dataBroker = session.getSALService(DataBroker.class);
         ctx.registerService(CommandProvider.class.getName(), this, null);
         createTestFlow(createTestNode(null), null, null);
     }
index 7b4ab775d1ed06fda69eae82d42cca4d86fcacd8..743711ac7593f0d598dd157dd2962283638c14de 100644 (file)
@@ -20,7 +20,6 @@ import org.eclipse.osgi.framework.console.CommandProvider;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder;
@@ -79,17 +78,17 @@ import org.osgi.framework.BundleContext;
 public class OpenflowpluginGroupTestCommandProvider implements CommandProvider {
     private static final String ORIGINAL_GROUP_NAME = "Foo";
 
-    private DataBroker dataBroker;
+    private final DataBroker dataBroker;
     private final BundleContext ctx;
     private Group testGroup;
     private Node testNode;
 
-    public OpenflowpluginGroupTestCommandProvider(BundleContext ctx) {
+    public OpenflowpluginGroupTestCommandProvider(DataBroker dataBroker, BundleContext ctx) {
+        this.dataBroker = dataBroker;
         this.ctx = ctx;
     }
 
-    public void onSessionInitiated(ProviderContext session) {
-        dataBroker = session.getSALService(DataBroker.class);
+    public void init() {
         ctx.registerService(CommandProvider.class.getName(), this, null);
         createTestNode();
     }
index 112659e2d42a3d926a2415313435e6dae44321b8..0c30639811a8db32247fff27b46dcd98cc2fbf65 100644 (file)
@@ -9,9 +9,9 @@
 package org.opendaylight.openflowplugin.test;
 
 import com.google.common.util.concurrent.ListenableFuture;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
@@ -142,9 +142,8 @@ public class OpenflowpluginGroupTestServiceProvider implements AutoCloseable,
     }
 
     public ObjectRegistration<OpenflowpluginGroupTestServiceProvider> register(
-            final ProviderContext ctx) {
-        RoutedRpcRegistration<SalGroupService> addRoutedRpcImplementation = ctx
-                .<SalGroupService>addRoutedRpcImplementation(
+            final RpcProviderRegistry rpcRegistry) {
+        RoutedRpcRegistration<SalGroupService> addRoutedRpcImplementation = rpcRegistry.addRoutedRpcImplementation(
                         SalGroupService.class, this);
         setGroupRegistration(addRoutedRpcImplementation);
 
index 8218c9d4586ca8c221788a12aa40aaca495b91f8..9ca3d4fdae88474657192ed113bb224fc5e03f5f 100644 (file)
@@ -19,7 +19,6 @@ import org.eclipse.osgi.framework.console.CommandProvider;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.NotificationService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
@@ -53,7 +52,7 @@ import org.slf4j.LoggerFactory;
 public class OpenflowpluginMeterTestCommandProvider implements CommandProvider {
 
     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginMeterTestCommandProvider.class);
-    private DataBroker dataBroker;
+    private final DataBroker dataBroker;
     private final BundleContext ctx;
     private Meter testMeter;
     private Meter testMeter1;
@@ -62,17 +61,18 @@ public class OpenflowpluginMeterTestCommandProvider implements CommandProvider {
     private final String originalMeterName = "Foo";
     private final String updatedMeterName = "Bar";
     private final MeterEventListener meterEventListener = new MeterEventListener();
-    private NotificationService notificationService;
+    private final NotificationService notificationService;
     private Registration listener1Reg;
 
-    public OpenflowpluginMeterTestCommandProvider(BundleContext ctx) {
+    public OpenflowpluginMeterTestCommandProvider(DataBroker dataBroker, NotificationService notificationService,
+            BundleContext ctx) {
+        this.dataBroker = dataBroker;
+        this.notificationService = notificationService;
         this.ctx = ctx;
     }
 
-    public void onSessionInitiated(ProviderContext session) {
-        dataBroker = session.getSALService(DataBroker.class);
+    public void init() {
         ctx.registerService(CommandProvider.class.getName(), this, null);
-        notificationService = session.getSALService(NotificationService.class);
         // For switch events
         listener1Reg = notificationService.registerNotificationListener(meterEventListener);
 
index bd55a4e53355e3563063f8719be0428056cd32da..98cfe835e242c2a13d3656dcfa3c6f5914dd20c8 100644 (file)
@@ -10,9 +10,9 @@ package org.opendaylight.openflowplugin.test;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
@@ -159,10 +159,9 @@ public class OpenflowpluginMeterTestServiceProvider implements AutoCloseable,
     }
 
     public ObjectRegistration<OpenflowpluginMeterTestServiceProvider> register(
-            final ProviderContext ctx) {
+            final RpcProviderRegistry rpcRegistry) {
 
-        RoutedRpcRegistration<SalMeterService> addRoutedRpcImplementation = ctx
-                .<SalMeterService>addRoutedRpcImplementation(
+        RoutedRpcRegistration<SalMeterService> addRoutedRpcImplementation = rpcRegistry.addRoutedRpcImplementation(
                         SalMeterService.class, this);
 
         setMeterRegistration(addRoutedRpcImplementation);
index 264736000bd438404d88313f922ce43be0d3227b..0a0a8e74c0c190b5d3dee05e1962b843917e317c 100644 (file)
@@ -13,7 +13,6 @@ import org.eclipse.osgi.framework.console.CommandInterpreter;
 import org.eclipse.osgi.framework.console.CommandProvider;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
@@ -46,15 +45,15 @@ import org.slf4j.LoggerFactory;
 public class OpenflowpluginStatsTestCommandProvider implements CommandProvider {
 
     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginStatsTestCommandProvider.class);
-    private DataBroker dataProviderService;
+    private final DataBroker dataProviderService;
     private final BundleContext ctx;
 
-    public OpenflowpluginStatsTestCommandProvider(BundleContext ctx) {
+    public OpenflowpluginStatsTestCommandProvider(DataBroker dataProviderService, BundleContext ctx) {
+        this.dataProviderService = dataProviderService;
         this.ctx = ctx;
     }
 
-    public void onSessionInitiated(ProviderContext session) {
-        dataProviderService = session.getSALService(DataBroker.class);
+    public void init() {
         ctx.registerService(CommandProvider.class.getName(), this, null);
 
     }
index 751eb532d89be6f88aabf1f149baea4015039f0c..33cb8e3b10b04fc31e2184b216d8d595fb32f7c2 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder;
@@ -77,16 +76,16 @@ import org.osgi.framework.BundleContext;
 @SuppressWarnings("checkstyle:MethodName")
 public class OpenflowpluginTableFeaturesTestCommandProvider implements CommandProvider {
 
-    private DataBroker dataBroker;
+    private final DataBroker dataBroker;
     private final BundleContext ctx;
     private Node testNode;
 
-    public OpenflowpluginTableFeaturesTestCommandProvider(BundleContext ctx) {
+    public OpenflowpluginTableFeaturesTestCommandProvider(DataBroker dataBroker, BundleContext ctx) {
+        this.dataBroker = dataBroker;
         this.ctx = ctx;
     }
 
-    public void onSessionInitiated(ProviderContext session) {
-        dataBroker = session.getSALService(DataBroker.class);
+    public void init() {
         ctx.registerService(CommandProvider.class.getName(), this, null);
         // createTestNode();
         // createTestTableFeatures();
index ce978684cdc568683b97d814446b25eb12b0b324..ea49777c0fa1b1fb17a5e37a83fdb936c01ad1c0 100644 (file)
@@ -9,9 +9,9 @@
 package org.opendaylight.openflowplugin.test;
 
 import com.google.common.util.concurrent.ListenableFuture;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
@@ -105,9 +105,8 @@ public class OpenflowpluginTableFeaturesTestServiceProvider implements
     }
 
     public ObjectRegistration<OpenflowpluginTableFeaturesTestServiceProvider> register(
-            final ProviderContext ctx) {
-        RoutedRpcRegistration<SalTableService> addRoutedRpcImplementation = ctx
-                .<SalTableService>addRoutedRpcImplementation(
+            final RpcProviderRegistry rpcRegistry) {
+        RoutedRpcRegistration<SalTableService> addRoutedRpcImplementation = rpcRegistry.addRoutedRpcImplementation(
                         SalTableService.class, this);
 
         setTableRegistration(addRoutedRpcImplementation);
index d565f5fa6407a189ecc4cd096e627cb3aaf796d3..732bca02404af63056e8a9b932bb6ab25cd44409 100644 (file)
 package org.opendaylight.openflowplugin.test;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class OpenflowpluginTestActivator extends AbstractBindingAwareProvider {
+public class OpenflowpluginTestActivator implements AutoCloseable {
     private static final Logger LOG = LoggerFactory
             .getLogger(OpenflowpluginTestActivator.class);
 
-    private static OpenflowpluginTestServiceProvider provider = new OpenflowpluginTestServiceProvider();
-    private static OpenflowpluginGroupTestServiceProvider groupProvider = new OpenflowpluginGroupTestServiceProvider();
-    private static OpenflowpluginMeterTestServiceProvider meterProvider = new OpenflowpluginMeterTestServiceProvider();
-    private static OpenflowpluginTableFeaturesTestServiceProvider tableProvider =
+    private DataBroker dataBroker;
+    private NotificationProviderService notificationService;
+    private RpcProviderRegistry rpcRegistry;
+    private final OpenflowpluginTestServiceProvider provider;
+    private final OpenflowpluginGroupTestServiceProvider groupProvider = new OpenflowpluginGroupTestServiceProvider();
+    private final OpenflowpluginMeterTestServiceProvider meterProvider = new OpenflowpluginMeterTestServiceProvider();
+    private final OpenflowpluginTableFeaturesTestServiceProvider tableProvider =
             new OpenflowpluginTableFeaturesTestServiceProvider();
 
-    private OpenflowpluginTestCommandProvider cmdProvider;
+    private final OpenflowpluginTestCommandProvider cmdProvider;
 
-    private OpenflowpluginGroupTestCommandProvider cmdGroupProvider;
+    private final OpenflowpluginGroupTestCommandProvider cmdGroupProvider;
 
-    private OpenflowpluginMeterTestCommandProvider cmdMeterProvider;
+    private final OpenflowpluginMeterTestCommandProvider cmdMeterProvider;
 
-    private OpenflowpluginTableFeaturesTestCommandProvider cmdTableProvider;
+    private final OpenflowpluginTableFeaturesTestCommandProvider cmdTableProvider;
 
-    private OpenflowpluginStatsTestCommandProvider cmdStatsProvider;
+    private final OpenflowpluginStatsTestCommandProvider cmdStatsProvider;
 
-    private OpenflowpluginTestNodeConnectorNotification cmdNodeConnectorNotification;
+    private final OpenflowpluginTestNodeConnectorNotification cmdNodeConnectorNotification;
 
-    private OpenflowpluginTestTopologyNotification cmdTopologyNotification;
+    private final OpenflowpluginTestTopologyNotification cmdTopologyNotification;
 
-    private OpenflowPluginBulkTransactionProvider bulkCmdProvider;
+    private final OpenflowPluginBulkTransactionProvider bulkCmdProvider;
 
-    private OpenflowPluginBulkGroupTransactionProvider groupCmdProvider;
+    private final OpenflowPluginBulkGroupTransactionProvider groupCmdProvider;
 
     public static final String NODE_ID = "foo:node:1";
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.opendaylight.controller.sal.binding.api.BindingAwareProvider#
-     * onSessionInitiated
-     * (org.opendaylight.controller.sal.binding.api.BindingAwareBroker
-     * .ProviderContext)
-     */
-    @Override
-    public void onSessionInitiated(ProviderContext session) {
-        DataBroker salService = session
-                .<DataBroker>getSALService(DataBroker.class);
-        OpenflowpluginTestActivator.provider.setDataService(salService);
-
-        NotificationProviderService salService1 = session
-                .<NotificationProviderService>getSALService(NotificationProviderService.class);
-
-        OpenflowpluginTestActivator.provider
-                .setNotificationService(salService1);
-        OpenflowpluginTestActivator.provider.start();
-        OpenflowpluginTestActivator.provider.register(session);
-
-        OpenflowpluginTestActivator.groupProvider.register(session);
-        OpenflowpluginTestActivator.meterProvider.register(session);
-        OpenflowpluginTestActivator.tableProvider.register(session);
-
-        this.cmdProvider.onSessionInitiated(session);
-        this.cmdGroupProvider.onSessionInitiated(session);
-        this.cmdMeterProvider.onSessionInitiated(session);
-        this.cmdTableProvider.onSessionInitiated(session);
-        this.cmdStatsProvider.onSessionInitiated(session);
-        this.cmdNodeConnectorNotification.onSessionInitiated(session);
-        this.cmdTopologyNotification.onSessionInitiated(session);
-        this.bulkCmdProvider.onSessionInitiated(session);
-        this.groupCmdProvider.onSessionInitiated(session);
-    }
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.controller.sal.binding.api.AbstractBrokerAwareActivator
-     * #startImpl(org.osgi.framework.BundleContext)
-     */
-    @Override
-    public void startImpl(final BundleContext ctx) {
-        super.startImpl(ctx);
-
+    public OpenflowpluginTestActivator(DataBroker dataBroker, NotificationProviderService notificationService,
+            BundleContext ctx) {
+        provider = new OpenflowpluginTestServiceProvider(dataBroker, notificationService);
         OpenflowpluginTestCommandProvider openflowpluginTestCommandProvider = new OpenflowpluginTestCommandProvider(
-                ctx);
+                dataBroker, notificationService, ctx);
         this.cmdProvider = openflowpluginTestCommandProvider;
         OpenflowpluginGroupTestCommandProvider openflowpluginGroupTestCommandProvider =
-                new OpenflowpluginGroupTestCommandProvider(ctx);
+                new OpenflowpluginGroupTestCommandProvider(dataBroker, ctx);
         this.cmdGroupProvider = openflowpluginGroupTestCommandProvider;
         OpenflowpluginMeterTestCommandProvider openflowpluginMeterTestCommandProvider =
-                new OpenflowpluginMeterTestCommandProvider(ctx);
+                new OpenflowpluginMeterTestCommandProvider(dataBroker, notificationService, ctx);
         this.cmdMeterProvider = openflowpluginMeterTestCommandProvider;
         OpenflowpluginTableFeaturesTestCommandProvider openflowpluginTableFeaturesTestCommandProvider =
-                new OpenflowpluginTableFeaturesTestCommandProvider(ctx);
+                new OpenflowpluginTableFeaturesTestCommandProvider(dataBroker, ctx);
         this.cmdTableProvider = openflowpluginTableFeaturesTestCommandProvider;
         OpenflowpluginStatsTestCommandProvider openflowpluginStatsTestCommandProvider =
-                new OpenflowpluginStatsTestCommandProvider(ctx);
+                new OpenflowpluginStatsTestCommandProvider(dataBroker, ctx);
         this.cmdStatsProvider = openflowpluginStatsTestCommandProvider;
         OpenflowpluginTestNodeConnectorNotification openflowpluginTestNodeConnectorNotification =
-                new OpenflowpluginTestNodeConnectorNotification(ctx);
+                new OpenflowpluginTestNodeConnectorNotification(notificationService);
         this.cmdNodeConnectorNotification = openflowpluginTestNodeConnectorNotification;
         OpenflowpluginTestTopologyNotification openflowpluginTestTopologyNotification =
-                new OpenflowpluginTestTopologyNotification(ctx);
+                new OpenflowpluginTestTopologyNotification(notificationService);
         this.cmdTopologyNotification = openflowpluginTestTopologyNotification;
         OpenflowPluginBulkTransactionProvider openflowPluginBulkTransactionProvider =
-                new OpenflowPluginBulkTransactionProvider(ctx);
+                new OpenflowPluginBulkTransactionProvider(dataBroker, notificationService, ctx);
         this.bulkCmdProvider = openflowPluginBulkTransactionProvider;
         OpenflowPluginBulkGroupTransactionProvider openflowPluginBulkGroupTransactionProvider =
-                new OpenflowPluginBulkGroupTransactionProvider(ctx);
+                new OpenflowPluginBulkGroupTransactionProvider(dataBroker, notificationService, ctx);
         this.groupCmdProvider = openflowPluginBulkGroupTransactionProvider;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.controller.sal.binding.api.AbstractBrokerAwareActivator
-     * #stopImpl(org.osgi.framework.BundleContext)
-     */
+    public void init() {
+        provider.register(rpcRegistry);
+
+        groupProvider.register(rpcRegistry);
+        meterProvider.register(rpcRegistry);
+        tableProvider.register(rpcRegistry);
+
+        this.cmdProvider.init();
+        this.cmdGroupProvider.init();
+        this.cmdMeterProvider.init();
+        this.cmdTableProvider.init();
+        this.cmdStatsProvider.init();
+        this.cmdNodeConnectorNotification.init();
+        this.cmdTopologyNotification.init();
+        this.bulkCmdProvider.init();
+        this.groupCmdProvider.init();
+    }
+
     @Override
     @SuppressWarnings("checkstyle:IllegalCatch")
-    protected void stopImpl(final BundleContext context) {
-
+    public void close() {
         try {
-            OpenflowpluginTestActivator.provider.close();
+            provider.close();
         } catch (Exception e) {
             // TODO Auto-generated catch block
             LOG.error("Stopping bundle OpenflowpluginTestActivator failed.", e);
index da2077be716913984b37ff80a381bef35cc64b98..01cac59d94b2d19bc9785905b99fc07258470248 100644 (file)
@@ -23,7 +23,6 @@ import org.eclipse.osgi.framework.console.CommandProvider;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.NotificationService;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
@@ -182,7 +181,7 @@ public class OpenflowpluginTestCommandProvider implements CommandProvider {
 
     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestCommandProvider.class);
 
-    private DataBroker dataBroker;
+    private final DataBroker dataBroker;
     private final BundleContext ctx;
     private static final String ORIGINAL_FLOW_NAME = "Foo";
     private static final String UPDATED_FLOW_NAME = "Bar";
@@ -191,18 +190,19 @@ public class OpenflowpluginTestCommandProvider implements CommandProvider {
     private static final String SRC_MAC_ADDRESS = "00:00:00:00:23:ae";
     private final SalFlowListener flowEventListener = new FlowEventListenerLoggingImpl();
     private final NodeErrorListener nodeErrorListener = new NodeErrorListenerLoggingImpl();
-    private NotificationService notificationService;
+    private final NotificationService notificationService;
 
-    public OpenflowpluginTestCommandProvider(final BundleContext ctx) {
+    public OpenflowpluginTestCommandProvider(final DataBroker dataBroker, final NotificationService notificationService,
+            final BundleContext ctx) {
+        this.dataBroker = dataBroker;
+        this.notificationService = notificationService;
         this.ctx = ctx;
     }
 
-    public void onSessionInitiated(final ProviderContext session) {
-        notificationService = session.getSALService(NotificationService.class);
+    public void init() {
         // For switch events
         notificationService.registerNotificationListener(flowEventListener);
         notificationService.registerNotificationListener(nodeErrorListener);
-        dataBroker = session.getSALService(DataBroker.class);
         ctx.registerService(CommandProvider.class.getName(), this, null);
         createTestFlow(createTestNode(null), null, null);
     }
index a53b09dbefeb5727bfd80b25d6dd584aeba1c5b5..9eb918fadc3f8d2d712ca41323af3f4458ace8ac 100644 (file)
@@ -9,14 +9,12 @@ package org.opendaylight.openflowplugin.test;
 
 import java.util.ArrayList;
 import java.util.List;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.NotificationService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.OpendaylightInventoryListener;
-import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -25,13 +23,13 @@ public class OpenflowpluginTestNodeConnectorNotification {
     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestNodeConnectorNotification.class);
 
     private final PortEventListener portEventListener = new PortEventListener();
-    private NotificationService notificationService;
+    private final NotificationService notificationService;
 
-    public OpenflowpluginTestNodeConnectorNotification(BundleContext ctx) {
+    public OpenflowpluginTestNodeConnectorNotification(NotificationService notificationService) {
+        this.notificationService = notificationService;
     }
 
-    public void onSessionInitiated(ProviderContext session) {
-        notificationService = session.getSALService(NotificationService.class);
+    public void init() {
         // For switch events
         notificationService.registerNotificationListener(portEventListener);
     }
index a5d5740641736fcba9e17b37cfabd10d8074c240..10ee6a4d0dd0ceafdc4286e98c2feec3d2b28240 100644 (file)
@@ -10,9 +10,9 @@ package org.opendaylight.openflowplugin.test;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
@@ -39,9 +39,15 @@ public class OpenflowpluginTestServiceProvider implements AutoCloseable,
     private static final Logger LOG = LoggerFactory
             .getLogger(OpenflowpluginTestServiceProvider.class);
 
-    private DataBroker dataService;
+    private final DataBroker dataService;
     private RoutedRpcRegistration<SalFlowService> flowRegistration;
-    private NotificationProviderService notificationProviderService;
+    private final NotificationProviderService notificationProviderService;
+
+    public OpenflowpluginTestServiceProvider(DataBroker dataService,
+            NotificationProviderService notificationProviderService) {
+        this.dataService = dataService;
+        this.notificationProviderService = notificationProviderService;
+    }
 
     /**
      * Get data service.
@@ -52,13 +58,6 @@ public class OpenflowpluginTestServiceProvider implements AutoCloseable,
         return dataService;
     }
 
-    /**
-     * Set {@link #dataService}.
-     */
-    public void setDataService(final DataBroker dataService) {
-        this.dataService = dataService;
-    }
-
     /**
      * Get flow registration.
      *
@@ -85,18 +84,6 @@ public class OpenflowpluginTestServiceProvider implements AutoCloseable,
         return notificationProviderService;
     }
 
-    /**
-     * Set {@link #notificationProviderService}.
-     */
-    public void setNotificationService(final NotificationProviderService service) {
-        this.notificationProviderService = service;
-    }
-
-    public void start() {
-        OpenflowpluginTestServiceProvider.LOG
-                .info("SalFlowServiceProvider Started.");
-    }
-
     /*
      * (non-Javadoc)
      *
@@ -157,11 +144,9 @@ public class OpenflowpluginTestServiceProvider implements AutoCloseable,
         return null;
     }
 
-    public ObjectRegistration<OpenflowpluginTestServiceProvider> register(
-            final ProviderContext ctx) {
-        RoutedRpcRegistration<SalFlowService> addRoutedRpcImplementation = ctx
-                .<SalFlowService>addRoutedRpcImplementation(
-                        SalFlowService.class, this);
+    public ObjectRegistration<OpenflowpluginTestServiceProvider> register(RpcProviderRegistry rpcRegistry) {
+        RoutedRpcRegistration<SalFlowService> addRoutedRpcImplementation =
+                rpcRegistry.addRoutedRpcImplementation(SalFlowService.class, this);
 
         setFlowRegistration(addRoutedRpcImplementation);
 
index 9f48ebcc776035d3bdf429b2e8ae46c3e0f19bd9..45f80b485357bd1af363cddc09f3a0dec009e6bb 100644 (file)
@@ -7,14 +7,12 @@
  */
 package org.opendaylight.openflowplugin.test;
 
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.NotificationService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.FlowTopologyDiscoveryListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkDiscovered;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkOverutilized;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkUtilizationNormal;
-import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -23,13 +21,13 @@ public class OpenflowpluginTestTopologyNotification {
     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestTopologyNotification.class);
 
     private final TopologyEventListener topologyEventListener = new TopologyEventListener();
-    private NotificationService notificationService;
+    private final NotificationService notificationService;
 
-    public OpenflowpluginTestTopologyNotification(BundleContext ctx) {
+    public OpenflowpluginTestTopologyNotification(NotificationService notificationService) {
+        this.notificationService = notificationService;
     }
 
-    public void onSessionInitiated(ProviderContext session) {
-        notificationService = session.getSALService(NotificationService.class);
+    public void init() {
         // For switch events
         notificationService.registerNotificationListener(topologyEventListener);
     }
diff --git a/test-provider/src/main/resources/org/opendaylight/blueprint/test-provider.xml b/test-provider/src/main/resources/org/opendaylight/blueprint/test-provider.xml
new file mode 100644 (file)
index 0000000..d88f434
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+    odl:use-default-for-reference-types="true">
+
+  <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
+  <reference id="notificationService" interface="org.opendaylight.controller.sal.binding.api.NotificationProviderService"/>
+
+  <bean id="activator" class="org.opendaylight.openflowplugin.test.OpenflowpluginTestActivator"
+          init-method="init" destroy-method="close">
+    <argument ref="dataBroker"/>
+    <argument ref="notificationService"/>
+    <argument ref="blueprintBundleContext"/>
+  </bean>
+</blueprint>