DeviceState changes
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / SalFlowServiceImpl.java
index a0cda7447461f90916f04090f340e14f48ee1527..cf2a160998321f1077b310cbbf79b142acebecb7 100644 (file)
@@ -1,38 +1,37 @@
 /**
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- * <p/>
+ *
  * This program and the accompanying materials are made available under the
  * 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.impl.services;
 
-import com.google.common.base.Function;
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.SettableFuture;
-import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
+import javax.annotation.Nullable;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
-import org.opendaylight.openflowplugin.api.openflow.device.Xid;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
-import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
+import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
+import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
 import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory;
-import org.opendaylight.openflowplugin.impl.registry.flow.FlowHashFactory;
+import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
 import org.opendaylight.openflowplugin.impl.util.FlowUtil;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
@@ -45,47 +44,34 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.Upda
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
+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.openflow.protocol.rev130731.FlowModInputBuilder;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-public class SalFlowServiceImpl extends CommonService implements SalFlowService {
-
-    private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalFlowServiceImpl.class);
+public class SalFlowServiceImpl implements SalFlowService, ItemLifeCycleSource {
+    private static final Logger LOG = LoggerFactory.getLogger(SalFlowServiceImpl.class);
+    private final FlowService<UpdateFlowOutput> flowUpdate;
+    private final FlowService<AddFlowOutput> flowAdd;
+    private final FlowService<RemoveFlowOutput> flowRemove;
+    private final DeviceContext deviceContext;
+    private ItemLifecycleListener itemLifecycleListener;
 
     public SalFlowServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
-        super(requestContextStack, deviceContext);
+        this.deviceContext = deviceContext;
+        flowRemove = new FlowService(requestContextStack, deviceContext, RemoveFlowOutput.class);
+        flowAdd = new FlowService<>(requestContextStack, deviceContext, AddFlowOutput.class);
+        flowUpdate = new FlowService<>(requestContextStack, deviceContext, UpdateFlowOutput.class);
     }
 
-    <T, F> ListenableFuture<RpcResult<T>> handleServiceCall(final BigInteger connectionID,
-                                                            final FlowModInputBuilder flowModInputBuilder, final Function<DataCrate<T>, ListenableFuture<RpcResult<F>>> function) {
-        LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
-
-        final RequestContext<T> requestContext = requestContextStack.createRequestContext();
-        final SettableFuture<RpcResult<T>> result = requestContextStack.storeOrFail(requestContext);
-
-        if (!result.isDone()) {
-
-            final DataCrate<T> dataCrate = DataCrateBuilder.<T>builder().setiDConnection(connectionID)
-                    .setRequestContext(requestContext).setFlowModInputBuilder(flowModInputBuilder).build();
-
-            requestContext.setXid(deviceContext.getNextXid());
-
-            LOG.trace("Hooking xid {} to device context - precaution.", requestContext.getXid().getValue());
-            deviceContext.hookRequestCtx(requestContext.getXid(), requestContext);
-
-            final ListenableFuture<RpcResult<F>> resultFromOFLib = function.apply(dataCrate);
-
-            final OFJResult2RequestCtxFuture<T> OFJResult2RequestCtxFuture = new OFJResult2RequestCtxFuture<>(requestContext, deviceContext);
-            OFJResult2RequestCtxFuture.processResultFromOfJava(resultFromOFLib);
-
-        } else {
-            RequestContextUtil.closeRequstContext(requestContext);
-        }
-        return result;
+    @Override
+    public void setItemLifecycleListener(@Nullable ItemLifecycleListener itemLifecycleListener) {
+        this.itemLifecycleListener = itemLifecycleListener;
     }
 
     @Override
@@ -96,25 +82,34 @@ public class SalFlowServiceImpl extends CommonService implements SalFlowService
         } else {
             flowId = FlowUtil.createAlienFlowId(input.getTableId());
         }
-
-
-        final FlowHash flowHash = FlowHashFactory.create(input);
+        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(flowHash, flowDescriptor);
-
-        final List<FlowModInputBuilder> ofFlowModInputs = FlowConvertor.toFlowModInputs(input, version, datapathId);
-        final ListenableFuture future = processFlowModInputBuilders(ofFlowModInputs);
-
-        Futures.addCallback(future, new FutureCallback() {
+        deviceContext.getDeviceFlowRegistry().store(flowRegistryKey, flowDescriptor);
+        final ListenableFuture<RpcResult<AddFlowOutput>> future =
+                flowAdd.processFlowModInputBuilders(flowAdd.toFlowModInputs(input));
+        Futures.addCallback(future, new FutureCallback<RpcResult<AddFlowOutput>>() {
             @Override
-            public void onSuccess(final Object o) {
-                LOG.debug("flow add finished without error, id={}", flowId.getValue());
+            public void onSuccess(final RpcResult<AddFlowOutput> rpcResult) {
+                if (rpcResult.isSuccessful()) {
+                    if(LOG.isDebugEnabled()) {
+                        LOG.debug("flow add with id={},finished without error,", flowId.getValue());
+                    }
+                    if (itemLifecycleListener != null) {
+                        KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
+                                deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
+                        final FlowBuilder flowBuilder = new FlowBuilder(input).setId(flowDescriptor.getFlowId());
+                        itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
+                    }
+                } else {
+                LOG.error("flow add failed for id={}, errors={}", flowId.getValue(), errorsToString(rpcResult.getErrors()));
+            }
             }
 
             @Override
             public void onFailure(final Throwable throwable) {
-                deviceContext.getDeviceFlowRegistry().markToBeremoved(flowHash);
-                LOG.trace("Service call for adding flows failed, id={}.", flowId.getValue(), throwable);
+                deviceContext.getDeviceFlowRegistry().markToBeremoved(flowRegistryKey);
+                LOG.error("Service call for adding flow with  id={} failed, reason {} .", flowId.getValue(), throwable);
             }
         });
 
@@ -124,40 +119,49 @@ public class SalFlowServiceImpl extends CommonService implements SalFlowService
     @Override
     public Future<RpcResult<RemoveFlowOutput>> removeFlow(final RemoveFlowInput input) {
         LOG.trace("Calling remove flow for flow with ID ={}.", input.getFlowRef());
-        return this.<RemoveFlowOutput, Void>handleServiceCall(PRIMARY_CONNECTION,
-                new Function<DataCrate<RemoveFlowOutput>, ListenableFuture<RpcResult<Void>>>() {
-                    @Override
-                    public ListenableFuture<RpcResult<Void>> apply(final DataCrate<RemoveFlowOutput> data) {
-                        final FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(input, version,
-                                datapathId);
-                        final ListenableFuture<RpcResult<Void>> future = createResultForFlowMod(data, ofFlowModInput);
-                        Futures.addCallback(future, new FutureCallback() {
-                            @Override
-                            public void onSuccess(final Object o) {
-                                FlowHash flowHash = FlowHashFactory.create(input);
-                                deviceContext.getDeviceFlowRegistry().markToBeremoved(flowHash);
-                            }
 
-                            @Override
-                            public void onFailure(final Throwable throwable) {
-                                StringBuffer errors = new StringBuffer();
-                                try {
-                                    RpcResult<Void> result = future.get();
-                                    Collection<RpcError> rpcErrors = result.getErrors();
-                                    if (null != rpcErrors && rpcErrors.size() > 0) {
-                                        for (RpcError rpcError : rpcErrors) {
-                                            errors.append(rpcError.getMessage());
-                                        }
-                                    }
-                                } catch (InterruptedException | ExecutionException e) {
-                                    LOG.trace("Flow modification failed. Can't read errors from RpcResult.");
-                                }
-                                LOG.trace("Flow modification failed. Errors : {}", errors.toString());
-                            }
-                        });
-                        return future;
+        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);
+                        if (flowDescriptor != null) {
+                            KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
+                                    deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
+                            itemLifecycleListener.onRemoved(flowPath);
+                        }
                     }
-                });
+                } else {
+                    LOG.error("Flow remove failed with errors : {}",errorsToString(result.getErrors()));
+                }
+            }
+
+            @Override
+            public void onFailure(final Throwable 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
@@ -167,157 +171,70 @@ public class SalFlowServiceImpl extends CommonService implements SalFlowService
         final OriginalFlow original = in.getOriginalFlow();
 
         final List<FlowModInputBuilder> allFlowMods = new ArrayList<>();
-        List<FlowModInputBuilder> ofFlowModInputs;
+        final List<FlowModInputBuilder> ofFlowModInputs;
 
-        if (!FlowCreatorUtil.canModifyFlow(original, updated, version)) {
+        if (!FlowCreatorUtil.canModifyFlow(original, updated, flowUpdate.getVersion())) {
             // We would need to remove original and add updated.
 
             // remove flow
             final RemoveFlowInputBuilder removeflow = new RemoveFlowInputBuilder(original);
-            final List<FlowModInputBuilder> ofFlowRemoveInput = FlowConvertor.toFlowModInputs(removeflow.build(),
-                    version, datapathId);
+            final List<FlowModInputBuilder> ofFlowRemoveInput = flowUpdate.toFlowModInputs(removeflow.build());
             // remove flow should be the first
             allFlowMods.addAll(ofFlowRemoveInput);
             final AddFlowInputBuilder addFlowInputBuilder = new AddFlowInputBuilder(updated);
-            ofFlowModInputs = FlowConvertor.toFlowModInputs(addFlowInputBuilder.build(), version, datapathId);
+            ofFlowModInputs = flowUpdate.toFlowModInputs(addFlowInputBuilder.build());
         } else {
-            ofFlowModInputs = FlowConvertor.toFlowModInputs(updated, version, datapathId);
+            ofFlowModInputs = flowUpdate.toFlowModInputs(updated);
         }
 
         allFlowMods.addAll(ofFlowModInputs);
-        ListenableFuture future = processFlowModInputBuilders(allFlowMods);
-        Futures.addCallback(future, new FutureCallback() {
-            @Override
-            public void onSuccess(final Object o) {
-                FlowHash flowHash = FlowHashFactory.create(original);
-                deviceContext.getDeviceFlowRegistry().markToBeremoved(flowHash);
-
-                flowHash = FlowHashFactory.create(updated);
-                FlowId flowId = input.getFlowRef().getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
-                FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(updated.getTableId(), flowId);
-                deviceContext.getDeviceFlowRegistry().store(flowHash, flowDescriptor);
-
-            }
-
-            @Override
-            public void onFailure(final Throwable throwable) {
-
-            }
-        });
-        return future;
-    }
-
-    private <T> ListenableFuture<RpcResult<T>> processFlowModInputBuilders(
-            final List<FlowModInputBuilder> ofFlowModInputs) {
-        final List<ListenableFuture<RpcResult<T>>> partialFutures = new ArrayList<>();
-        for (FlowModInputBuilder flowModInputBuilder : ofFlowModInputs) {
-            ListenableFuture<RpcResult<T>> partialFuture = handleServiceCall(PRIMARY_CONNECTION, flowModInputBuilder,
-                    new Function<DataCrate<T>, ListenableFuture<RpcResult<Void>>>() {
-                        @Override
-                        public ListenableFuture<RpcResult<Void>> apply(final DataCrate<T> data) {
-                            return createResultForFlowMod(data);
-                        }
-                    });
-            partialFutures.add(partialFuture);
-        }
-
-        final ListenableFuture<List<RpcResult<T>>> allFutures = Futures.allAsList(partialFutures);
-        final SettableFuture<RpcResult<T>> finalFuture = SettableFuture.create();
-        Futures.addCallback(allFutures, new FutureCallback<List<RpcResult<T>>>() {
+        ListenableFuture<RpcResult<UpdateFlowOutput>> future = flowUpdate.processFlowModInputBuilders(allFlowMods);
+        Futures.addCallback(future, new FutureCallback<RpcResult<UpdateFlowOutput>>() {
             @Override
-            public void onSuccess(List<RpcResult<T>> results) {
-                Iterator<FlowModInputBuilder> flowModInputBldIterator = ofFlowModInputs.iterator();
-                List<RpcError> rpcErrorLot = new ArrayList<>();
-                for (RpcResult<T> rpcResult : results) {
-                    FlowModInputBuilder flowModInputBld = flowModInputBldIterator.next();
-                    if (rpcResult.isSuccessful()) {
-                        Long xid = flowModInputBld.getXid();
-                        LOG.warn("Positive confirmation of flow push is not supported by OF-spec");
-                        LOG.warn("flow future result was successful [{}] = this should have never happen",
-                                xid);
-                        rpcErrorLot.add(RpcResultBuilder.newError(ErrorType.APPLICATION, "",
-                                "flow future result was successful ["+xid+"] = this should have never happen"));
-                    } else {
-                        rpcErrorLot.addAll(rpcResult.getErrors());
+            public void onSuccess(final RpcResult<UpdateFlowOutput> o) {
+                FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(original);
+
+                FlowRegistryKey updatedflowRegistryKey = FlowRegistryKeyFactory.create(updated);
+                final FlowRef flowRef = input.getFlowRef();
+                final DeviceFlowRegistry deviceFlowRegistry = deviceContext.getDeviceFlowRegistry();
+                deviceFlowRegistry.markToBeremoved(flowRegistryKey);
+
+                if (itemLifecycleListener != null) {
+                    final FlowDescriptor flowDescriptor = deviceContext.getDeviceFlowRegistry().retrieveIdForFlow(flowRegistryKey);
+                    if (flowDescriptor != null) {
+                        KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
+                                deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
+                        itemLifecycleListener.onRemoved(flowPath);
                     }
                 }
-                finalFuture.set(RpcResultBuilder.<T>failed().withRpcErrors(rpcErrorLot).build());
-            }
-
-            @Override
-            public void onFailure(Throwable t) {
-                LOG.trace("Flow mods chained future failed.");
-                RpcResultBuilder<T> resultBuilder;
-                if (allFutures.isCancelled()) {
-                    if (LOG.isTraceEnabled()) {
-                        for (FlowModInputBuilder ofFlowModInput : ofFlowModInputs) {
-                            LOG.trace("flow future result was cancelled [{}] = barrier passed it without error",
-                                    ofFlowModInput.getXid());
-                        }
+                //if provided, store flow id to flow registry
+                if (flowRef != null) {
+                    final FlowId flowId = flowRef.getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
+                    final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(updated.getTableId(), flowId);
+                    deviceFlowRegistry.store(updatedflowRegistryKey, flowDescriptor);
+
+                    if (itemLifecycleListener != null) {
+                        KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
+                                deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
+                        final FlowBuilder flowBuilder = new FlowBuilder(input.getUpdatedFlow()).setId(flowDescriptor.getFlowId());
+                        itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
                     }
-                    resultBuilder = RpcResultBuilder.<T>success();
-                } else {
-                    resultBuilder = RpcResultBuilder.<T>failed().withError(ErrorType.APPLICATION, "", t.getMessage());
                 }
-                finalFuture.set(resultBuilder.build());
-            }
-        });
-
-        return finalFuture;
-    }
-
-    protected <T> ListenableFuture<RpcResult<Void>> createResultForFlowMod(final DataCrate<T> data) {
-        return createResultForFlowMod(data, data.getFlowModInputBuilder());
-    }
-
-    protected <T> ListenableFuture<RpcResult<Void>> createResultForFlowMod(final DataCrate<T> data, final FlowModInputBuilder flowModInput) {
-        final Xid xid = data.getRequestContext().getXid();
-        flowModInput.setXid(xid.getValue());
-        Future<RpcResult<Void>> flowModResult = provideConnectionAdapter(data.getiDConnection()).flowMod(
-                flowModInput.build());
-
-        final ListenableFuture<RpcResult<Void>> result = JdkFutureAdapters.listenInPoolThread(flowModResult);
-        final RequestContext requestContext = data.getRequestContext();
-
-        Futures.addCallback(result, new FutureCallback<RpcResult<Void>>() {
-            @Override
-            public void onSuccess(final RpcResult<Void> voidRpcResult) {
-                if (!voidRpcResult.isSuccessful()) {
-                    // remove current request from request cache in deviceContext
-                    deviceContext.getRequests().remove(requestContext.getXid().getValue());
-                    // handle requestContext failure
-                    StringBuilder rpcErrors = new StringBuilder();
-                    if (null != voidRpcResult.getErrors() && voidRpcResult.getErrors().size() > 0) {
-                        for (RpcError error : voidRpcResult.getErrors()) {
-                            rpcErrors.append(error.getMessage());
-                        }
-                    }
-                    LOG.trace("OF Java result for XID {} was not successful. Errors : {}", requestContext.getXid().getValue(), rpcErrors.toString());
-                    requestContext.getFuture().set(
-                            RpcResultBuilder.<T>failed().withRpcErrors(voidRpcResult.getErrors()).build());
-                    RequestContextUtil.closeRequstContext(requestContext);
-                }
-
             }
 
             @Override
             public void onFailure(final Throwable throwable) {
-                if (result.isCancelled()) {
-                    LOG.trace("Asymmetric message - no response from OF Java expected for XID {}. Closing as successful.", requestContext.getXid().getValue());
-                    requestContext.getFuture().set(RpcResultBuilder.<T>success().build());
-                } else {
-                    LOG.trace("Exception occured while processing OF Java response for XID {}.", requestContext.getXid().getValue(), throwable);
-                    requestContext.getFuture().set(
-                            RpcResultBuilder.<T>failed()
-                                    .withError(RpcError.ErrorType.APPLICATION, "", "Flow translation to OF JAVA failed.")
-                                    .build());
-                }
-
-                RequestContextUtil.closeRequstContext(requestContext);
-
+                LOG.error("Service call for updating flow failed, reason{}", throwable);
             }
         });
-        return result;
+        return future;
     }
 
+    @VisibleForTesting
+    static KeyedInstanceIdentifier<Flow, FlowKey> createFlowPath(FlowDescriptor flowDescriptor,
+                                                                 KeyedInstanceIdentifier<Node, NodeKey> nodePath) {
+        return nodePath.augmentation(FlowCapableNode.class)
+                .child(Table.class, flowDescriptor.getTableKey())
+                .child(Flow.class, new FlowKey(flowDescriptor.getFlowId()));
+    }
 }