Update MRI projects for Aluminium
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginMeterTestCommandProvider.java
index 8218c9d4586ca8c221788a12aa40aaca495b91f8..f385405a12c64487223db3cd487ea91ba9b8230e 100644 (file)
@@ -5,22 +5,18 @@
  * 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.test;
 
 import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.util.ArrayList;
 import java.util.List;
 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.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.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 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;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
@@ -53,7 +49,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 +58,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);
 
@@ -102,23 +99,20 @@ public class OpenflowpluginMeterTestCommandProvider implements CommandProvider {
 
         @Override
         public void onMeterAdded(MeterAdded notification) {
-            LOG.info("Meter to be added.........................." + notification.toString());
-            LOG.info("Meter  Xid........................." + notification.getTransactionId().getValue());
-            LOG.info("-----------------------------------------------------------------------------------");
+            LOG.info("Meter to be added {}", notification.toString());
+            LOG.info("Meter  Xid {}", notification.getTransactionId().getValue());
         }
 
         @Override
         public void onMeterRemoved(MeterRemoved notification) {
-            LOG.info("Meter to be removed.........................." + notification.toString());
-            LOG.info("Meter  Xid........................." + notification.getTransactionId().getValue());
-            LOG.info("-----------------------------------------------------------------------------------");
+            LOG.info("Meter to be removed {}", notification.toString());
+            LOG.info("Meter  Xid {}", notification.getTransactionId().getValue());
         }
 
         @Override
         public void onMeterUpdated(MeterUpdated notification) {
-            LOG.info("Meter to be updated.........................." + notification.toString());
-            LOG.info("Meter  Xid........................." + notification.getTransactionId().getValue());
-            LOG.info("-----------------------------------------------------------------------------------");
+            LOG.info("Meter to be updated {}", notification.toString());
+            LOG.info("Meter  Xid {}", notification.getTransactionId().getValue());
         }
 
     }
@@ -232,10 +226,9 @@ public class OpenflowpluginMeterTestCommandProvider implements CommandProvider {
         InstanceIdentifier<Meter> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.key())
                 .augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(testMeter.getMeterId()));
         modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
-        ListenableFuture<Void> commitFuture = modification.submit();
-        Futures.addCallback(commitFuture, new FutureCallback<Void>() {
+        modification.commit().addCallback(new FutureCallback<Object>() {
             @Override
-            public void onSuccess(Void notUsed) {
+            public void onSuccess(Object notUsed) {
                 ci.println("Status of Group Data Loaded Transaction: success.");
             }
 
@@ -314,10 +307,9 @@ public class OpenflowpluginMeterTestCommandProvider implements CommandProvider {
                 break;
         }
 
-        ListenableFuture<Void> commitFuture = modification.submit();
-        Futures.addCallback(commitFuture, new FutureCallback<Void>() {
+        modification.commit().addCallback(new FutureCallback<Object>() {
             @Override
-            public void onSuccess(Void notUsed) {
+            public void onSuccess(Object notUsed) {
                 ci.println("Status of Group Data Loaded Transaction: success.");
             }
 
@@ -385,12 +377,12 @@ public class OpenflowpluginMeterTestCommandProvider implements CommandProvider {
         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
         InstanceIdentifier<Meter> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.key())
                 .augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(meter.getMeterId()));
-        modification.merge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode, true);
-        modification.merge(LogicalDatastoreType.CONFIGURATION, path1, meter, true);
-        ListenableFuture<Void> commitFuture = modification.submit();
-        Futures.addCallback(commitFuture, new FutureCallback<Void>() {
+        modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode),
+                testNode);
+        modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path1, meter);
+        modification.commit().addCallback(new FutureCallback<Object>() {
             @Override
-            public void onSuccess(Void notUsed) {
+            public void onSuccess(Object notUsed) {
                 ci.println("Status of Group Data Loaded Transaction: success.");
             }
 
@@ -405,17 +397,18 @@ public class OpenflowpluginMeterTestCommandProvider implements CommandProvider {
         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
         InstanceIdentifier<Meter> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.key())
                 .augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(meter.getMeterId()));
-        modification.merge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode, true);
-        modification.merge(LogicalDatastoreType.CONFIGURATION, path1, meter, true);
+        modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode),
+                testNode);
+        modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path1, meter);
         InstanceIdentifier<Meter> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.key())
                 .augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(meter1.getMeterId()));
-        modification.merge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode, true);
-        modification.merge(LogicalDatastoreType.CONFIGURATION, path2, meter1, true);
+        modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode),
+                testNode);
+        modification.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, path2, meter1);
 
-        ListenableFuture<Void> commitFuture = modification.submit();
-        Futures.addCallback(commitFuture, new FutureCallback<Void>() {
+        modification.commit().addCallback(new FutureCallback<Object>() {
             @Override
-            public void onSuccess(Void notUsed) {
+            public void onSuccess(Object notUsed) {
                 ci.println("Status of Group Data Loaded Transaction: success.");
             }