BUG-4148: Improving the logging in flow/group/meter to provide more contextual 54/38254/4
authorShuva Kar <shuva.jyoti.kar@ericsson.com>
Mon, 2 May 2016 08:17:23 +0000 (13:47 +0530)
committerShuva Jyoti Kar <shuva.jyoti.kar@ericsson.com>
Wed, 4 May 2016 05:22:14 +0000 (05:22 +0000)
information as to the success/failure of the operation

Change-Id: Ica94dbca7559f0afff1f8dfe5695ed8d0bf6376e
Signed-off-by: Shuva Kar <shuva.jyoti.kar@ericsson.com>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalGroupServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalMeterServiceImpl.java

index c8735bc13b725c3f9c6946aa24db28576c7a038c..d89b59781cb53b3e4f6d9655182541062618d11e 100644 (file)
@@ -82,16 +82,19 @@ public class SalFlowServiceImpl implements SalFlowService, ItemLifeCycleSource {
         } else {
             flowId = FlowUtil.createAlienFlowId(input.getTableId());
         }
-
+        LOG.trace("Calling add flow for flow with ID ={}.", flowId);
         final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
         final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
         deviceContext.getDeviceFlowRegistry().store(flowRegistryKey, flowDescriptor);
-        final ListenableFuture<RpcResult<AddFlowOutput>> future = flowAdd.processFlowModInputBuilders(flowAdd.toFlowModInputs(input));
+        final ListenableFuture<RpcResult<AddFlowOutput>> future =
+                flowAdd.processFlowModInputBuilders(flowAdd.toFlowModInputs(input));
         Futures.addCallback(future, new FutureCallback<RpcResult<AddFlowOutput>>() {
             @Override
             public void onSuccess(final RpcResult<AddFlowOutput> rpcResult) {
                 if (rpcResult.isSuccessful()) {
-                    LOG.debug("flow add finished without error, id={}", flowId.getValue());
+                    if(LOG.isDebugEnabled()) {
+                        LOG.debug("flow add with id={},finished without error,", flowId.getValue());
+                    }
                     if (itemLifecycleListener != null) {
                         KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
                                 deviceContext.getDeviceState().getNodeInstanceIdentifier());
@@ -99,14 +102,14 @@ public class SalFlowServiceImpl implements SalFlowService, ItemLifeCycleSource {
                         itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
                     }
                 } else {
-                    LOG.error("flow add failed with id={}, errors={}", flowId.getValue(), errorsToString(rpcResult.getErrors()));
-                }
+                LOG.error("flow add failed for id={}, errors={}", flowId.getValue(), errorsToString(rpcResult.getErrors()));
+            }
             }
 
             @Override
             public void onFailure(final Throwable throwable) {
                 deviceContext.getDeviceFlowRegistry().markToBeremoved(flowRegistryKey);
-                LOG.trace("Service call for adding flows failed, id={}.", flowId.getValue(), throwable);
+                LOG.error("Service call for adding flow with  id={} failed, reason {} .", flowId.getValue(), throwable);
             }
         });
 
@@ -117,15 +120,20 @@ public class SalFlowServiceImpl implements SalFlowService, ItemLifeCycleSource {
     public Future<RpcResult<RemoveFlowOutput>> removeFlow(final RemoveFlowInput input) {
         LOG.trace("Calling remove flow for flow with ID ={}.", input.getFlowRef());
 
-        final ListenableFuture<RpcResult<RemoveFlowOutput>> future = flowRemove.processFlowModInputBuilders(flowRemove.toFlowModInputs(input));
+        final ListenableFuture<RpcResult<RemoveFlowOutput>> future =
+                flowRemove.processFlowModInputBuilders(flowRemove.toFlowModInputs(input));
         Futures.addCallback(future, new FutureCallback<RpcResult<RemoveFlowOutput>>() {
             @Override
             public void onSuccess(final RpcResult<RemoveFlowOutput> result) {
                 if (result.isSuccessful()) {
+                    if(LOG.isDebugEnabled()) {
+                        LOG.debug("flow removed finished without error,");
+                    }
                     FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
                     deviceContext.getDeviceFlowRegistry().markToBeremoved(flowRegistryKey);
                     if (itemLifecycleListener != null) {
-                        final FlowDescriptor flowDescriptor = deviceContext.getDeviceFlowRegistry().retrieveIdForFlow(flowRegistryKey);
+                        final FlowDescriptor flowDescriptor =
+                                deviceContext.getDeviceFlowRegistry().retrieveIdForFlow(flowRegistryKey);
                         if (flowDescriptor != null) {
                             KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
                                     deviceContext.getDeviceState().getNodeInstanceIdentifier());
@@ -133,13 +141,13 @@ public class SalFlowServiceImpl implements SalFlowService, ItemLifeCycleSource {
                         }
                     }
                 } else {
-                    LOG.error("Flow remove failed with errors : {}", errorsToString(result.getErrors()));
+                    LOG.error("Flow remove failed with errors : {}",errorsToString(result.getErrors()));
                 }
             }
 
             @Override
             public void onFailure(final Throwable throwable) {
-                LOG.trace("Flow remove failed..", throwable);
+                LOG.error("Service call for removing flow with id {} failed ,reason {}",input.getFlowRef().getValue(), throwable);
             }
         });
 
@@ -216,7 +224,7 @@ public class SalFlowServiceImpl implements SalFlowService, ItemLifeCycleSource {
 
             @Override
             public void onFailure(final Throwable throwable) {
-                LOG.debug("Flow update failed", throwable);
+                LOG.error("Service call for updating flow failed, reason{}", throwable);
             }
         });
         return future;
index 1e0dcd7e52c01c87982cf0125da9d5aed8a6f324..0179f8e3f09112ebe945144dab64893f2b3b78f7 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.openflowplugin.impl.services;
 
+import java.util.Collection;
 import java.util.concurrent.Future;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -38,6 +39,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group
 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.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -72,14 +74,20 @@ public class SalGroupServiceImpl implements SalGroupService, ItemLifeCycleSource
             @Override
             public void onSuccess(RpcResult<AddGroupOutput> result) {
                 if (result.isSuccessful()) {
-                    LOG.debug("group add finished without error, id={}", input.getGroupId().getValue());
+                    if(LOG.isDebugEnabled()) {
+                        LOG.debug("group add with id={} finished without error", input.getGroupId().getValue());
+                    }
                     addIfNecessaryToDS(input.getGroupId(), input);
-                }
+                } else {
+                LOG.error("group add with id={} failed, errors={}", input.getGroupId().getValue(),
+                        errorsToString(result.getErrors()));
+                 }
             }
 
             @Override
             public void onFailure(Throwable t) {
-                LOG.error("group add failed for id={}. Exception: {}", input.getGroupId().getValue(), t);
+                LOG.error("Service call for group add failed for id={}. Exception: {}",
+                        input.getGroupId().getValue(), t);
             }
         });
 
@@ -94,15 +102,21 @@ public class SalGroupServiceImpl implements SalGroupService, ItemLifeCycleSource
             @Override
             public void onSuccess(@Nullable RpcResult<UpdateGroupOutput> result) {
                 if (result.isSuccessful()) {
-                    LOG.debug("Group update succeded");
+                    if(LOG.isDebugEnabled()) {
+                        LOG.debug("Group update for original id {} succeded", input.getOriginalGroup().getGroupId().getValue());
+                    }
                     removeIfNecessaryFromDS(input.getOriginalGroup().getGroupId());
                     addIfNecessaryToDS(input.getUpdatedGroup().getGroupId(), input.getUpdatedGroup());
+                }else{
+                    LOG.error("group update failed with id={}, errors={}", input.getOriginalGroup().getGroupId(),
+                            errorsToString(result.getErrors()));
                 }
             }
 
             @Override
             public void onFailure(Throwable t) {
-                LOG.debug("Group update failed for id={}. Exception: {}", input.getOriginalGroup().getGroupId(), t);
+                LOG.error("Service call for group  update failed for id={}. Exception: {}",
+                        input.getOriginalGroup().getGroupId(), t);
             }
         });
         return resultFuture;
@@ -116,14 +130,20 @@ public class SalGroupServiceImpl implements SalGroupService, ItemLifeCycleSource
             @Override
             public void onSuccess(@Nullable RpcResult<RemoveGroupOutput> result) {
                 if (result.isSuccessful()) {
-                    LOG.debug("Group remove succeded");
+                    if(LOG.isDebugEnabled()) {
+                        LOG.debug("Group remove for id {} succeded", input.getGroupId().getValue());
+                    }
                     removeIfNecessaryFromDS(input.getGroupId());
+                }else{
+                    LOG.error("group remove failed with id={}, errors={}", input.getGroupId().getValue(),
+                            errorsToString(result.getErrors()));
                 }
             }
 
             @Override
             public void onFailure(Throwable t) {
-                LOG.error("Group remove failed for id={}. Exception: {}", input.getGroupId(), t);
+                LOG.error("Service call for group remove failed for id={}. Exception: {}",
+                        input.getGroupId().getValue(), t);
             }
         });
         return resultFuture;
@@ -147,7 +167,19 @@ public class SalGroupServiceImpl implements SalGroupService, ItemLifeCycleSource
         }
     }
 
-    static KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group, GroupKey> createGroupPath(final GroupId groupId, final KeyedInstanceIdentifier<Node, NodeKey> nodePath) {
-        return nodePath.augmentation(FlowCapableNode.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group.class, new GroupKey(groupId));
+    static KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group, GroupKey>
+    createGroupPath(final GroupId groupId, final KeyedInstanceIdentifier<Node, NodeKey> nodePath) {
+        return nodePath.augmentation(FlowCapableNode.class).
+                child(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group.class, new GroupKey(groupId));
+    }
+
+    private final String errorsToString(final Collection<RpcError> rpcErrors) {
+        final StringBuilder errors = new StringBuilder();
+        if ((null != rpcErrors) && (rpcErrors.size() > 0)) {
+            for (final RpcError rpcError : rpcErrors) {
+                errors.append(rpcError.getMessage());
+            }
+        }
+        return errors.toString();
     }
 }
index 9bc608eae0df8d53db131a57551a3302d283e616..946669043a64676799b0c3ad28689bd403c3d086 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.openflowplugin.impl.services;
 
+import java.util.Collection;
 import java.util.concurrent.Future;
 
 import com.google.common.util.concurrent.FutureCallback;
@@ -32,6 +33,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.Upd
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -68,8 +70,13 @@ public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource
             @Override
             public void onSuccess(@Nullable RpcResult<AddMeterOutput> result) {
                 if (result.isSuccessful()) {
-                    LOG.debug("Meter add finished without error, id={}", input.getMeterId());
+                    if(LOG.isDebugEnabled()) {
+                        LOG.debug("Meter add finished without error, id={}", input.getMeterId());
+                    }
                     addIfNecessaryToDS(input.getMeterId(),input);
+                }else{
+                    LOG.error("Meter add with id {} failed with error {}", input.getMeterId(),
+                            errorsToString(result.getErrors()));
                 }
             }
 
@@ -91,17 +98,23 @@ public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource
             @Override
             public void onSuccess(@Nullable RpcResult<UpdateMeterOutput> result) {
                 if (result.isSuccessful()) {
-                    LOG.debug("Meter update finished without error, id={}", input.getOriginalMeter().getMeterId());
+                    if(LOG.isDebugEnabled()) {
+                        LOG.debug("Meter update finished without error, id={}", input.getOriginalMeter().getMeterId());
+                    }
                     if (itemLifecycleListener != null) {
                         removeIfNecessaryFromDS(input.getOriginalMeter().getMeterId());
                         addIfNecessaryToDS(input.getUpdatedMeter().getMeterId(),input.getUpdatedMeter());
                     }
+                }else{
+                    LOG.error("Meter update with id {} failed with error {}", input.getOriginalMeter().getMeterId(),
+                            errorsToString(result.getErrors()));
                 }
             }
 
             @Override
             public void onFailure(Throwable t) {
-                LOG.error("Meter update failed. for id={}. Exception {}.",input.getOriginalMeter().getMeterId(),t);
+                LOG.error("Service call for meter update failed. for id={}. Exception {}.",
+                        input.getOriginalMeter().getMeterId(),t);
             }
         });
         return resultFuture;
@@ -116,14 +129,19 @@ public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource
             @Override
             public void onSuccess(@Nullable RpcResult<RemoveMeterOutput> result) {
                 if (result.isSuccessful()) {
-                    LOG.debug("Meter remove finished without error, id={}", input.getMeterId());
+                    if(LOG.isDebugEnabled()) {
+                        LOG.debug("Meter remove finished without error, id={}", input.getMeterId());
+                    }
                     removeIfNecessaryFromDS(input.getMeterId());
+                }else{
+                    LOG.error("Meter remove with id {} failed with error {}", input.getMeterId(),
+                            errorsToString(result.getErrors()));
                 }
             }
 
             @Override
             public void onFailure(Throwable t) {
-                LOG.error("Meter remove failed for id={}. Exception {}",input.getMeterId(),t);
+                LOG.error("Service call for meter remove failed for id={}. Exception {}",input.getMeterId(),t);
             }
         });
 
@@ -152,4 +170,13 @@ public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource
         return nodePath.augmentation(FlowCapableNode.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter.class, new MeterKey(meterId));
     }
 
+    private final String errorsToString(final Collection<RpcError> rpcErrors) {
+        final StringBuilder errors = new StringBuilder();
+        if ((null != rpcErrors) && (rpcErrors.size() > 0)) {
+            for (final RpcError rpcError : rpcErrors) {
+                errors.append(rpcError.getMessage());
+            }
+        }
+        return errors.toString();
+    }
 }