X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=inline;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fservices%2FSalMeterServiceImpl.java;h=02f72dc6ab8195da6c55f43f32682d7580ca5960;hb=1537fd31483e3c9f5ec62e882d54acf9e508e556;hp=9bc608eae0df8d53db131a57551a3302d283e616;hpb=39125bccef7edfbca3ac2a13b73e08d8c6401411;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalMeterServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalMeterServiceImpl.java index 9bc608eae0..02f72dc6ab 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalMeterServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalMeterServiceImpl.java @@ -7,19 +7,20 @@ */ package org.opendaylight.openflowplugin.impl.services; -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.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.impl.util.ErrorUtil; +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; @@ -36,8 +37,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 addMeter; @@ -46,11 +45,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 @@ -60,48 +59,59 @@ public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource @Override public Future> addMeter(final AddMeterInput input) { - addMeter.getDeviceContext().getDeviceMeterRegistry().store(input.getMeterId()); - final ListenableFuture> resultFuture = addMeter.handleServiceCall(input); Futures.addCallback(resultFuture, new FutureCallback>() { - @Override public void onSuccess(@Nullable RpcResult result) { if (result.isSuccessful()) { - LOG.debug("Meter add finished without error, id={}", input.getMeterId()); + if (LOG.isDebugEnabled()) { + LOG.debug("Meter add with id={} finished without error", input.getMeterId()); + } + deviceContext.getDeviceMeterRegistry().store(input.getMeterId()); addIfNecessaryToDS(input.getMeterId(),input); + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("Meter add with id={} failed, errors={}", input.getMeterId(), + ErrorUtil.errorsToString(result.getErrors())); + } } } @Override public void onFailure(Throwable t) { - LOG.error("Meter add failed for id={}. Exception {}", input.getMeterId(), t); + LOG.warn("Service call for adding meter={} failed, reason: {}", input.getMeterId(), t); } }); - return resultFuture; } @Override public Future> updateMeter(final UpdateMeterInput input) { final ListenableFuture> resultFuture = updateMeter.handleServiceCall(input.getUpdatedMeter()); - Futures.addCallback(resultFuture, new FutureCallback>() { @Override public void onSuccess(@Nullable RpcResult result) { if (result.isSuccessful()) { - LOG.debug("Meter update finished without error, id={}", input.getOriginalMeter().getMeterId()); + if (LOG.isDebugEnabled()) { + LOG.debug("Meter update with id={} finished without error", input.getOriginalMeter().getMeterId()); + } if (itemLifecycleListener != null) { removeIfNecessaryFromDS(input.getOriginalMeter().getMeterId()); addIfNecessaryToDS(input.getUpdatedMeter().getMeterId(),input.getUpdatedMeter()); } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("Meter update with id={} failed, errors={}", input.getOriginalMeter().getMeterId(), + ErrorUtil.errorsToString(result.getErrors())); + } } } @Override public void onFailure(Throwable t) { - LOG.error("Meter update failed. for id={}. Exception {}.",input.getOriginalMeter().getMeterId(),t); + LOG.warn("Service call for updating meter={} failed, reason: {}", + input.getOriginalMeter().getMeterId(),t); } }); return resultFuture; @@ -109,32 +119,36 @@ public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource @Override public Future> removeMeter(final RemoveMeterInput input) { - removeMeter.getDeviceContext().getDeviceMeterRegistry().markToBeremoved(input.getMeterId()); + removeMeter.getDeviceRegistry().getDeviceMeterRegistry().markToBeremoved(input.getMeterId()); final ListenableFuture> resultFuture = removeMeter.handleServiceCall(input); Futures.addCallback(resultFuture, new FutureCallback>() { - @Override public void onSuccess(@Nullable RpcResult result) { if (result.isSuccessful()) { - LOG.debug("Meter remove finished without error, id={}", input.getMeterId()); + if (LOG.isDebugEnabled()) { + LOG.debug("Meter remove with id={} finished without error", input.getMeterId()); + } removeIfNecessaryFromDS(input.getMeterId()); + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("Meter remove with id={} failed, errors={}", input.getMeterId(), + ErrorUtil.errorsToString(result.getErrors())); + } } } @Override public void onFailure(Throwable t) { - LOG.error("Meter remove failed for id={}. Exception {}",input.getMeterId(),t); + LOG.warn("Service call for removing meter={} failed, reason: {}",input.getMeterId(),t); } }); - return resultFuture; } private void removeIfNecessaryFromDS(final MeterId meterId) { if (itemLifecycleListener != null) { KeyedInstanceIdentifier meterPath - = createMeterPath(meterId, - deviceContext.getDeviceState().getNodeInstanceIdentifier()); + = createMeterPath(meterId, deviceContext.getDeviceInfo().getNodeInstanceIdentifier()); itemLifecycleListener.onRemoved(meterPath); } } @@ -142,14 +156,12 @@ public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource private void addIfNecessaryToDS(final MeterId meterId, final Meter data) { if (itemLifecycleListener != null) { KeyedInstanceIdentifier groupPath - = createMeterPath(meterId, - deviceContext.getDeviceState().getNodeInstanceIdentifier()); + = createMeterPath(meterId, deviceContext.getDeviceInfo().getNodeInstanceIdentifier()); itemLifecycleListener.onAdded(groupPath, new MeterBuilder(data).build()); } } - static KeyedInstanceIdentifier createMeterPath(final MeterId meterId, final KeyedInstanceIdentifier nodePath) { + private static KeyedInstanceIdentifier createMeterPath(final MeterId meterId, final KeyedInstanceIdentifier nodePath) { return nodePath.augmentation(FlowCapableNode.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter.class, new MeterKey(meterId)); } - -} +} \ No newline at end of file