Merge "SONAR TD - Remove unused fields, fix naming" into stable/boron
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / SalMeterServiceImpl.java
index 946669043a64676799b0c3ad28689bd403c3d086..d96e2190120bf5812059096991907e7e8f8683a1 100644 (file)
@@ -7,20 +7,20 @@
  */
 package org.opendaylight.openflowplugin.impl.services;
 
-import java.util.Collection;
-import java.util.concurrent.Future;
-
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import java.util.Collection;
+import java.util.concurrent.Future;
+import javax.annotation.Nullable;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
 import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
@@ -38,8 +38,6 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.annotation.Nullable;
-
 public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource {
     private static final Logger LOG = LoggerFactory.getLogger(SalMeterServiceImpl.class);
     private final MeterService<AddMeterInput, AddMeterOutput> addMeter;
@@ -48,11 +46,11 @@ public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource
     private ItemLifecycleListener itemLifecycleListener;
     private final DeviceContext deviceContext;
 
-    public SalMeterServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+    public SalMeterServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor) {
         this.deviceContext = deviceContext;
-        addMeter = new MeterService<>(requestContextStack, deviceContext, AddMeterOutput.class);
-        updateMeter = new MeterService<>(requestContextStack, deviceContext, UpdateMeterOutput.class);
-        removeMeter = new MeterService<>(requestContextStack, deviceContext, RemoveMeterOutput.class);
+        addMeter = new MeterService<>(requestContextStack, deviceContext, AddMeterOutput.class, convertorExecutor);
+        updateMeter = new MeterService<>(requestContextStack, deviceContext, UpdateMeterOutput.class, convertorExecutor);
+        removeMeter = new MeterService<>(requestContextStack, deviceContext, RemoveMeterOutput.class, convertorExecutor);
     }
 
     @Override
@@ -62,19 +60,18 @@ public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource
 
     @Override
     public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
-        addMeter.getDeviceContext().getDeviceMeterRegistry().store(input.getMeterId());
 
         final ListenableFuture<RpcResult<AddMeterOutput>> resultFuture = addMeter.handleServiceCall(input);
         Futures.addCallback(resultFuture, new FutureCallback<RpcResult<AddMeterOutput>>() {
-
             @Override
             public void onSuccess(@Nullable RpcResult<AddMeterOutput> result) {
                 if (result.isSuccessful()) {
-                    if(LOG.isDebugEnabled()) {
+                   if(LOG.isDebugEnabled()) {
                         LOG.debug("Meter add finished without error, id={}", input.getMeterId());
                     }
+                    deviceContext.getDeviceMeterRegistry().store(input.getMeterId());
                     addIfNecessaryToDS(input.getMeterId(),input);
-                }else{
+                } else {
                     LOG.error("Meter add with id {} failed with error {}", input.getMeterId(),
                             errorsToString(result.getErrors()));
                 }
@@ -82,7 +79,7 @@ public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource
 
             @Override
             public void onFailure(Throwable t) {
-                LOG.error("Meter add failed for id={}. Exception {}", input.getMeterId(), t);
+                 LOG.error("Meter add failed for id={}. Exception {}", input.getMeterId(), t);
             }
         });
 
@@ -92,7 +89,6 @@ public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource
     @Override
     public Future<RpcResult<UpdateMeterOutput>> updateMeter(final UpdateMeterInput input) {
         final ListenableFuture<RpcResult<UpdateMeterOutput>> resultFuture = updateMeter.handleServiceCall(input.getUpdatedMeter());
-
         Futures.addCallback(resultFuture, new FutureCallback<RpcResult<UpdateMeterOutput>>() {
 
             @Override
@@ -122,7 +118,7 @@ public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource
 
     @Override
     public Future<RpcResult<RemoveMeterOutput>> removeMeter(final RemoveMeterInput input) {
-        removeMeter.getDeviceContext().getDeviceMeterRegistry().markToBeremoved(input.getMeterId());
+        removeMeter.getDeviceRegistry().getDeviceMeterRegistry().markToBeremoved(input.getMeterId());
         final ListenableFuture<RpcResult<RemoveMeterOutput>> resultFuture = removeMeter.handleServiceCall(input);
         Futures.addCallback(resultFuture, new FutureCallback<RpcResult<RemoveMeterOutput>>() {
 
@@ -152,7 +148,7 @@ public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource
         if (itemLifecycleListener != null) {
             KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter, MeterKey> meterPath
                     = createMeterPath(meterId,
-                    deviceContext.getDeviceState().getNodeInstanceIdentifier());
+                    deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
             itemLifecycleListener.onRemoved(meterPath);
         }
     }
@@ -161,7 +157,7 @@ public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource
         if (itemLifecycleListener != null) {
             KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter, MeterKey> groupPath
                     = createMeterPath(meterId,
-                    deviceContext.getDeviceState().getNodeInstanceIdentifier());
+                    deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
             itemLifecycleListener.onAdded(groupPath, new MeterBuilder(data).build());
         }
     }
@@ -179,4 +175,4 @@ public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource
         }
         return errors.toString();
     }
-}
+}
\ No newline at end of file