- final UpdateFlowInputBuilder builder = new UpdateFlowInputBuilder();
-
- builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
- builder.setFlowRef(new FlowRef(identifier));
- builder.setTransactionUri(new Uri(provider.getNewTransactionId()));
-
- // This method is called only when a given flow object in datastore
- // has been updated. So FRM always needs to set strict flag into
- // update-flow input so that only a flow entry associated with
- // a given flow object is updated.
- builder.setUpdatedFlow((new UpdatedFlowBuilder(update)).setStrict(Boolean.TRUE).build());
- builder.setOriginalFlow((new OriginalFlowBuilder(original)).setStrict(Boolean.TRUE).build());
-
- provider.getSalFlowService().updateFlow(builder.build());
+ BundleId bundleId = getActiveBundle(nodeIdent, provider);
+ if (bundleId != null) {
+ provider.getBundleFlowListener().update(identifier, original, update, nodeIdent, bundleId);
+ } else {
+ final String nodeId = getNodeIdValueFromNodeIdentifier(nodeIdent);
+ nodeConfigurator.enqueueJob(nodeId, () -> {
+ final UpdateFlowInputBuilder builder = new UpdateFlowInputBuilder();
+ builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
+ builder.setFlowRef(new FlowRef(identifier));
+ builder.setTransactionUri(new Uri(provider.getNewTransactionId()));
+
+ // This method is called only when a given flow object in datastore
+ // has been updated. So FRM always needs to set strict flag into
+ // update-flow input so that only a flow entry associated with
+ // a given flow object is updated.
+ builder.setUpdatedFlow(new UpdatedFlowBuilder(update).setStrict(Boolean.TRUE).build());
+ builder.setOriginalFlow(new OriginalFlowBuilder(original).setStrict(Boolean.TRUE).build());
+
+ Uint32 groupId = isFlowDependentOnGroup(update);
+ if (groupId != null) {
+ LOG.trace("The flow {} is dependent on group {}. Checking if the group is already present",
+ getFlowId(identifier), groupId);
+ if (isGroupExistsOnDevice(nodeIdent, groupId, provider)) {
+ LOG.trace("The dependent group {} is already programmed. Updating the flow {}", groupId,
+ getFlowId(identifier));
+ return provider.getSalFlowService().updateFlow(builder.build());
+ } else {
+ LOG.trace("The dependent group {} isn't programmed yet. Pushing the group", groupId);
+ ListenableFuture<RpcResult<AddGroupOutput>> groupFuture = pushDependentGroup(nodeIdent,
+ groupId);
+ SettableFuture<RpcResult<UpdateFlowOutput>> resultFuture = SettableFuture.create();
+ Futures.addCallback(groupFuture,
+ new UpdateFlowCallBack(builder.build(), nodeId, resultFuture, groupId),
+ MoreExecutors.directExecutor());
+ return resultFuture;
+ }
+ }
+
+ LOG.trace("The flow {} is not dependent on any group. Updating the flow",
+ getFlowId(identifier));
+ return provider.getSalFlowService().updateFlow(builder.build());
+ });
+ }