DeviceState changes
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / SalFlowServiceImpl.java
index 4c16bf01c37ddbb8e9e8151346681c64527b2e6c..cf2a160998321f1077b310cbbf79b142acebecb7 100644 (file)
@@ -82,31 +82,34 @@ 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());
+                                deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
                         final FlowBuilder flowBuilder = new FlowBuilder(input).setId(flowDescriptor.getFlowId());
                         itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
                     }
                 } else {
-                    LOG.debug("flow add failed with error, id={}", flowId.getValue());
-                }
+                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,44 +120,50 @@ 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());
+                                    deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
                             itemLifecycleListener.onRemoved(flowPath);
                         }
                     }
                 } else {
-                    if (LOG.isTraceEnabled()) {
-                        StringBuilder errors = new StringBuilder();
-                        Collection<RpcError> rpcErrors = result.getErrors();
-                        if (null != rpcErrors && rpcErrors.size() > 0) {
-                            for (RpcError rpcError : rpcErrors) {
-                                errors.append(rpcError.getMessage());
-                            }
-                        }
-                        LOG.trace("Flow modification failed. Errors : {}", errors.toString());
-                    }
+                    LOG.error("Flow remove failed with errors : {}",errorsToString(result.getErrors()));
                 }
             }
 
             @Override
             public void onFailure(final Throwable throwable) {
-                LOG.trace("Flow modification failed..", throwable);
+                LOG.error("Service call for removing flow with id {} failed ,reason {}",input.getFlowRef().getValue(), throwable);
             }
         });
 
         return future;
     }
 
+    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();
+    }
+
     @Override
     public Future<RpcResult<UpdateFlowOutput>> updateFlow(final UpdateFlowInput input) {
         final UpdateFlowInput in = input;
@@ -194,7 +203,7 @@ public class SalFlowServiceImpl implements SalFlowService, ItemLifeCycleSource {
                     final FlowDescriptor flowDescriptor = deviceContext.getDeviceFlowRegistry().retrieveIdForFlow(flowRegistryKey);
                     if (flowDescriptor != null) {
                         KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
-                                deviceContext.getDeviceState().getNodeInstanceIdentifier());
+                                deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
                         itemLifecycleListener.onRemoved(flowPath);
                     }
                 }
@@ -206,7 +215,7 @@ public class SalFlowServiceImpl implements SalFlowService, ItemLifeCycleSource {
 
                     if (itemLifecycleListener != null) {
                         KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
-                                deviceContext.getDeviceState().getNodeInstanceIdentifier());
+                                deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
                         final FlowBuilder flowBuilder = new FlowBuilder(input.getUpdatedFlow()).setId(flowDescriptor.getFlowId());
                         itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
                     }
@@ -215,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;