Refactor reconciliation wiring 99/110199/8
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 9 Feb 2024 02:49:57 +0000 (03:49 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 9 Feb 2024 14:13:15 +0000 (15:13 +0100)
Current wiring is a bit buggy in that it confuses local (e.g. OSGi SR)
and global (e.g. RPC) access and uses the latter for OSGi service
injection.

Remove the confusion by removing the OSGi SR registration, and instead:
- expose the interface for ForwardingRulesManager
- move the RPC implementation to its sole registrant, where it is a
  simple wrapper around

We have only a single RPC to register, which is now wired through OSGi.

JIRA: OPNFLWPLUG-1112
JIRA: OPNFLWPLUG-1125
Change-Id: I1fa7cb5a94380a8761aba843f8caadaf108fd7dc
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/FlowNodeReconciliation.java
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/ForwardingRulesManager.java
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastership.java
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastershipManager.java
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FlowNodeReconciliationImpl.java
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/ForwardingRulesManagerImpl.java
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FrmReconciliationServiceImpl.java [deleted file]
applications/forwardingrules-manager/src/main/resources/OSGI-INF/blueprint/forwardingrules-manager.xml
applications/forwardingrules-manager/src/test/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastershipManagerTest.java
applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/ReconciliationServiceImpl.java
applications/southbound-cli/src/main/resources/OSGI-INF/blueprint/southbound-cli.xml

index 92d4c7895b8ccae11300cc0bc6f84b9aa3485af9..7a0fbc249335d70a328c5d2901ad2ce8f799907a 100644 (file)
@@ -22,6 +22,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
  */
 public interface FlowNodeReconciliation extends ReconciliationNotificationListener, AutoCloseable {
+
     ListenableFuture<Boolean> reconcileConfiguration(InstanceIdentifier<FlowCapableNode> connectedNode);
 
     void flowNodeDisconnected(InstanceIdentifier<FlowCapableNode> disconnectedNode);
index abb2697b822dbe58e9a7e3e7844a7e6557844e99..f63d3440e5b088becb77d4b2a5878ae968333521 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.openflowplugin.applications.frm;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.api.ReadTransaction;
 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationListener;
 import org.opendaylight.openflowplugin.applications.frm.impl.DevicesGroupRegistry;
@@ -199,6 +200,13 @@ public interface ForwardingRulesManager extends ConfigurationListener {
      */
     NodeConfigurator getNodeConfigurator();
 
+    /**
+     * Return the {@link FlowNodeReconciliation} associated with this manager.
+     *
+     * @return the FlowNodeReconciliation
+     */
+    @NonNull FlowNodeReconciliation getFlowNodeReconciliation();
+
     /**
      * Method for register RecoverableListener.
      *
index 4f3a52674fa5842d9868183112e515efbb17ad14..6aa463b3ad11ba4a6684dc36425b66d972ca3376 100644 (file)
@@ -11,7 +11,6 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.concurrent.atomic.AtomicBoolean;
-import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
@@ -20,8 +19,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 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.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.FrmReconciliationService;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.ReconcileNode;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.slf4j.Logger;
@@ -39,11 +38,11 @@ public class DeviceMastership implements ClusterSingletonService, AutoCloseable
     private final InstanceIdentifier<FlowCapableNode> fcnIID;
     private final KeyedInstanceIdentifier<Node, NodeKey> path;
 
-    private ObjectRegistration<@NonNull FrmReconciliationService> reg;
+    private Registration reg;
 
     public DeviceMastership(final NodeId nodeId) {
         this.nodeId = nodeId;
-        this.identifier = ServiceGroupIdentifier.create(nodeId.getValue());
+        identifier = ServiceGroupIdentifier.create(nodeId.getValue());
         fcnIID = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId))
                 .augmentation(FlowCapableNode.class);
         path = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
@@ -83,18 +82,16 @@ public class DeviceMastership implements ClusterSingletonService, AutoCloseable
         deviceMastered.set(true);
     }
 
-    public void registerReconciliationRpc(final RpcProviderService rpcProviderService,
-            final FrmReconciliationService reconcliationService) {
+    public void registerReconcileNode(final RpcProviderService rpcProviderService, final ReconcileNode reconcileNode) {
         if (reg == null) {
             LOG.debug("The path is registered : {}", path);
-            reg = rpcProviderService.registerRpcImplementation(FrmReconciliationService.class, reconcliationService,
-                ImmutableSet.of(path));
+            reg = rpcProviderService.registerRpcImplementation(reconcileNode, ImmutableSet.of(path));
         } else {
             LOG.debug("The path is already registered : {}", path);
         }
     }
 
-    public void deregisterReconciliationRpc() {
+    public void deregisterReconcileNode() {
         if (reg != null) {
             reg.close();
             reg = null;
index ee063c52c00c03d8b3b0c00470479396b90df58a..3299043337915f4fc01993e54a7e39605ce9e319 100644 (file)
@@ -9,6 +9,11 @@ package org.opendaylight.openflowplugin.applications.frm.impl;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Iterables;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
+import com.google.common.util.concurrent.SettableFuture;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Collection;
 import java.util.Set;
@@ -23,7 +28,6 @@ import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 import org.opendaylight.mdsal.binding.api.DataTreeModification;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeRegistration;
 import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeService;
@@ -33,10 +37,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.Fl
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.FrmReconciliationService;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.ReconcileNodeInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.ReconcileNodeOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.ReconcileNodeOutputBuilder;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.ErrorType;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,28 +59,22 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener<
     private static final InstanceIdentifier<FlowCapableNode> II_TO_FLOW_CAPABLE_NODE = InstanceIdentifier
             .builder(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class).build();
 
-    private final ClusterSingletonServiceProvider clusterSingletonService;
-    private final FlowNodeReconciliation reconcliationAgent;
     private final ConcurrentHashMap<NodeId, DeviceMastership> deviceMasterships = new ConcurrentHashMap<>();
     private final Set<InstanceIdentifier<FlowCapableNode>> activeNodes = ConcurrentHashMap.newKeySet();
     private final ReentrantLock lock = new ReentrantLock();
+    private final FlowNodeReconciliation reconcliationAgent;
     private final RpcProviderService rpcProviderService;
-    private final FrmReconciliationService reconcliationService;
 
-    private ListenerRegistration<DeviceMastershipManager> listenerRegistration;
+    private Registration listenerRegistration;
     private MastershipChangeRegistration mastershipChangeServiceRegistration;
 
     @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "Non-final for mocking")
-    public DeviceMastershipManager(final ClusterSingletonServiceProvider clusterSingletonService,
-                                   final FlowNodeReconciliation reconcliationAgent,
+    public DeviceMastershipManager(final FlowNodeReconciliation reconcliationAgent,
                                    final DataBroker dataBroker,
                                    final MastershipChangeServiceManager mastershipChangeServiceManager,
-                                   final RpcProviderService rpcProviderService,
-                                   final FrmReconciliationService reconciliationService) {
-        this.clusterSingletonService = clusterSingletonService;
+                                   final RpcProviderService rpcProviderService) {
         this.reconcliationAgent = reconcliationAgent;
         this.rpcProviderService = rpcProviderService;
-        reconcliationService = reconciliationService;
         listenerRegistration = dataBroker.registerDataTreeChangeListener(
             DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
                 InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)), this);
@@ -193,14 +197,45 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener<
         final var membership = deviceMasterships.computeIfAbsent(deviceInfo.getNodeId(),
             device -> new DeviceMastership(deviceInfo.getNodeId()));
         membership.reconcile();
-        membership.registerReconciliationRpc(rpcProviderService, reconcliationService);
+        membership.registerReconcileNode(rpcProviderService, this::reconcileNode);
+    }
+
+    private ListenableFuture<RpcResult<ReconcileNodeOutput>> reconcileNode(final ReconcileNodeInput input) {
+        final var nodeId = input.requireNodeId();
+        LOG.debug("Triggering reconciliation for node: {}", nodeId);
+
+        final var nodeDpn = new NodeBuilder().setId(new NodeId("openflow:" + nodeId)).build();
+        final var connectedNode = InstanceIdentifier.builder(Nodes.class)
+                .child(Node.class, nodeDpn.key()).augmentation(FlowCapableNode.class)
+                .build();
+        final var rpcResult = SettableFuture.<RpcResult<ReconcileNodeOutput>>create();
+        Futures.addCallback(reconcliationAgent.reconcileConfiguration(connectedNode), new FutureCallback<>() {
+            @Override
+            public void onSuccess(final Boolean result) {
+                rpcResult.set(result
+                    ? RpcResultBuilder.success(new ReconcileNodeOutputBuilder().setResult(result).build()).build()
+                        : RpcResultBuilder.<ReconcileNodeOutput>failed()
+                            .withError(ErrorType.APPLICATION, "Error while triggering reconciliation")
+                            .build());
+            }
+
+            @Override
+            public void onFailure(final Throwable error) {
+                LOG.error("initReconciliation failed", error);
+                rpcResult.set(RpcResultBuilder.<ReconcileNodeOutput>failed()
+                        .withError(ErrorType.RPC, "Error while calling RPC").build());
+            }
+        }, MoreExecutors.directExecutor());
+
+        LOG.debug("Completing reconciliation for node: {}", nodeId);
+        return rpcResult;
     }
 
     @Override
     public void onLoseOwnership(@NonNull final DeviceInfo deviceInfo) {
         final var mastership = deviceMasterships.remove(deviceInfo.getNodeId());
         if (mastership != null) {
-            mastership.deregisterReconciliationRpc();
+            mastership.deregisterReconcileNode();
             mastership.close();
             LOG.debug("Unregistered deviceMastership for device : {}", deviceInfo.getNodeId());
         }
index ded654f3e7a062c9aab1f1056e79b51187790ec4..300072ccf5d95a55d870579f76da5e11127bbdc3 100644 (file)
@@ -108,7 +108,6 @@ import org.slf4j.LoggerFactory;
  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
  */
 public class FlowNodeReconciliationImpl implements FlowNodeReconciliation {
-
     private static final Logger LOG = LoggerFactory.getLogger(FlowNodeReconciliationImpl.class);
     private static final Logger OF_EVENT_LOG = LoggerFactory.getLogger("OfEventLog");
 
index b4e7bd4886aa86ff75a54c3b9ebda8b4862b606f..02e7a2a4069be38c00530cff98e687673c5b337f 100644 (file)
@@ -94,7 +94,7 @@ public final class ForwardingRulesManagerImpl implements ForwardingRulesManager,
     private ForwardingRulesCommiter<Group> groupListener;
     private ForwardingRulesCommiter<Meter> meterListener;
     private ForwardingRulesCommiter<TableFeatures> tableListener;
-    private FlowNodeReconciliation nodeListener;
+    private FlowNodeReconciliationImpl flowNodeReconciliation;
     private NotificationRegistration reconciliationNotificationRegistration;
     private DeviceMastershipManager deviceMastershipManager;
     private boolean disableReconciliation;
@@ -141,17 +141,16 @@ public final class ForwardingRulesManagerImpl implements ForwardingRulesManager,
                 requireNonNull(rpcRegistry.getRpcService(ArbitratorReconcileService.class),
                         "ArbitratorReconciliationManager can not be null!");
 
-        nodeListener = new FlowNodeReconciliationImpl(this, dataService, SERVICE_NAME, FRM_RECONCILIATION_PRIORITY,
-                ResultState.DONOTHING, flowGroupCacheManager);
+        flowNodeReconciliation = new FlowNodeReconciliationImpl(this, dataService, SERVICE_NAME,
+                FRM_RECONCILIATION_PRIORITY, ResultState.DONOTHING, flowGroupCacheManager);
         if (isReconciliationDisabled()) {
             LOG.debug("Reconciliation is disabled by user");
         } else {
-            reconciliationNotificationRegistration = reconciliationManager.registerService(nodeListener);
+            reconciliationNotificationRegistration = reconciliationManager.registerService(flowNodeReconciliation);
             LOG.debug("Reconciliation is enabled by user and successfully registered to the reconciliation framework");
         }
-        deviceMastershipManager = new DeviceMastershipManager(clusterSingletonServiceProvider, nodeListener,
-                dataService, mastershipChangeServiceManager, rpcProviderService,
-                new FrmReconciliationServiceImpl(this));
+        deviceMastershipManager = new DeviceMastershipManager(flowNodeReconciliation, dataService,
+            mastershipChangeServiceManager, rpcProviderService);
         flowNodeConnectorInventoryTranslatorImpl = new FlowNodeConnectorInventoryTranslatorImpl(dataService);
 
         bundleFlowListener = new BundleFlowForwarder(this);
@@ -184,9 +183,9 @@ public final class ForwardingRulesManagerImpl implements ForwardingRulesManager,
             tableListener.close();
             tableListener = null;
         }
-        if (nodeListener != null) {
-            nodeListener.close();
-            nodeListener = null;
+        if (flowNodeReconciliation != null) {
+            flowNodeReconciliation.close();
+            flowNodeReconciliation = null;
         }
         if (deviceMastershipManager != null) {
             deviceMastershipManager.close();
@@ -328,8 +327,9 @@ public final class ForwardingRulesManagerImpl implements ForwardingRulesManager,
         return nodeConfigurator;
     }
 
-    public FlowNodeReconciliation getNodeListener() {
-        return nodeListener;
+    @Override
+    public FlowNodeReconciliation getFlowNodeReconciliation() {
+        return flowNodeReconciliation;
     }
 
     @Override
diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FrmReconciliationServiceImpl.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FrmReconciliationServiceImpl.java
deleted file mode 100644 (file)
index 9e43568..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (c) 2018 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
- *
- * 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.applications.frm.impl;
-
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.MoreExecutors;
-import com.google.common.util.concurrent.SettableFuture;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.FrmReconciliationService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.ReconcileNodeInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.ReconcileNodeOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.ReconcileNodeOutputBuilder;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.ErrorType;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Singleton
-public class FrmReconciliationServiceImpl implements FrmReconciliationService {
-
-    private static final Logger LOG = LoggerFactory.getLogger(FrmReconciliationServiceImpl.class);
-
-    private final ForwardingRulesManagerImpl forwardingRulesManagerImpl;
-
-    @Inject
-    public FrmReconciliationServiceImpl(ForwardingRulesManagerImpl forwardingRulesManagerImpl) {
-        this.forwardingRulesManagerImpl = forwardingRulesManagerImpl;
-    }
-
-    private static Node buildNode(long nodeIid) {
-        NodeId nodeId = new NodeId("openflow:" + nodeIid);
-        Node nodeDpn = new NodeBuilder().setId(nodeId).withKey(new NodeKey(nodeId)).build();
-        return nodeDpn;
-    }
-
-    @Override
-    public ListenableFuture<RpcResult<ReconcileNodeOutput>> reconcileNode(ReconcileNodeInput input) {
-        LOG.debug("Triggering reconciliation for node: {}", input.getNodeId());
-        Node nodeDpn = buildNode(input.getNodeId().longValue());
-        InstanceIdentifier<FlowCapableNode> connectedNode = InstanceIdentifier.builder(Nodes.class)
-                .child(Node.class, nodeDpn.key()).augmentation(FlowCapableNode.class).build();
-        SettableFuture<RpcResult<ReconcileNodeOutput>> rpcResult = SettableFuture.create();
-        ListenableFuture<Boolean> futureResult = forwardingRulesManagerImpl
-                .getNodeListener().reconcileConfiguration(connectedNode);
-        Futures.addCallback(futureResult, new ResultCallBack(futureResult, rpcResult),
-                MoreExecutors.directExecutor());
-        LOG.debug("Completing reconciliation for node: {}", input.getNodeId());
-        return rpcResult;
-    }
-
-    private static class ResultCallBack implements FutureCallback<Boolean> {
-        private final SettableFuture<RpcResult<ReconcileNodeOutput>> futureResult;
-
-        ResultCallBack(ListenableFuture<Boolean> rpcResult,
-                       SettableFuture<RpcResult<ReconcileNodeOutput>> futureResult) {
-            this.futureResult = futureResult;
-        }
-
-        @Override
-        public void onSuccess(Boolean result) {
-            if (result) {
-                ReconcileNodeOutput output = new ReconcileNodeOutputBuilder().setResult(result).build();
-                futureResult.set(RpcResultBuilder.success(output).build());
-            } else {
-                futureResult.set(RpcResultBuilder.<ReconcileNodeOutput>failed()
-                        .withError(ErrorType.APPLICATION, "Error while triggering reconciliation").build());
-            }
-
-        }
-
-        @Override
-        public void onFailure(Throwable error) {
-            LOG.error("initReconciliation failed", error);
-            futureResult.set(RpcResultBuilder.<ReconcileNodeOutput>failed()
-                    .withError(ErrorType.RPC, "Error while calling RPC").build());
-        }
-    }
-}
index 46e483c58291399a2a0e87e01b48dbe5365ebc92..cced482159d3827ef183835e9b67c7df3dae7282 100644 (file)
@@ -1,34 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
         odl:use-default-for-reference-types="true">
-  <bean id="frmReconciliationServiceImpl"
-        class="org.opendaylight.openflowplugin.applications.frm.impl.FrmReconciliationServiceImpl">
-    <argument ref="forwardingRulesManagerImpl"/>
-  </bean>
-  <service ref="frmReconciliationServiceImpl"
-           interface="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.FrmReconciliationService"/>
-
-  <bean id="forwardingRulesManagerImpl"
-        class="org.opendaylight.openflowplugin.applications.frm.impl.ForwardingRulesManagerImpl"
-        destroy-method="close">
-    <argument ref="dataBroker"/>
-    <argument ref="rpcConsumerRegistry"/>
-    <argument ref="rpcProviderService"/>
-    <argument ref="forwardingRulesManagerConfig"/>
-    <argument ref="mastershipChangeServiceManager"/>
-    <argument ref="clusterSingletonServiceProvider"/>
-    <argument ref="configurationService"/>
-    <argument ref="reconciliationManager"/>
-    <argument ref="openflowServiceRecoveryHandler"/>
-    <argument ref="serviceRecoveryRegistry"/>
-    <argument ref="flowGroupCacheManager"/>
-    <argument ref="listenerRegistrationHelper"/>
-  </bean>
-
-  <odl:clustered-app-config id="forwardingRulesManagerConfig"
-                            binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.forwardingrules.manager.config.rev160511.ForwardingRulesManagerConfig"/>
-
   <reference id="flowGroupCacheManager"
              interface="org.opendaylight.openflowplugin.api.openflow.FlowGroupCacheManager"/>
   <reference id="dataBroker"
              interface="org.opendaylight.openflowplugin.applications.frm.impl.ListenerRegistrationHelper"/>
   <reference id="openflowServiceRecoveryHandler"
              interface="org.opendaylight.openflowplugin.applications.frm.recovery.OpenflowServiceRecoveryHandler"/>
+
+  <odl:clustered-app-config id="forwardingRulesManagerConfig"
+                            binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.forwardingrules.manager.config.rev160511.ForwardingRulesManagerConfig"/>
+
+  <bean id="forwardingRulesManagerImpl"
+        class="org.opendaylight.openflowplugin.applications.frm.impl.ForwardingRulesManagerImpl"
+        destroy-method="close">
+    <argument ref="dataBroker"/>
+    <argument ref="rpcConsumerRegistry"/>
+    <argument ref="rpcProviderService"/>
+    <argument ref="forwardingRulesManagerConfig"/>
+    <argument ref="mastershipChangeServiceManager"/>
+    <argument ref="clusterSingletonServiceProvider"/>
+    <argument ref="configurationService"/>
+    <argument ref="reconciliationManager"/>
+    <argument ref="openflowServiceRecoveryHandler"/>
+    <argument ref="serviceRecoveryRegistry"/>
+    <argument ref="flowGroupCacheManager"/>
+    <argument ref="listenerRegistrationHelper"/>
+  </bean>
+
+  <service ref="forwardingRulesManagerImpl"
+           interface="org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager"/>
 </blueprint>
index 92a0d65c15f43170014f03d32a9f8a28334daaf5..aefeff030d83fdd7a345a2499c2ae05aaa2c02bf 100644 (file)
@@ -23,7 +23,6 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager;
 import org.opendaylight.openflowplugin.applications.frm.FlowNodeReconciliation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.FrmReconciliationService;
 
 /**
  * Test for {@link DeviceMastershipManager}.
@@ -47,13 +46,11 @@ public class DeviceMastershipManagerTest {
     private NodeId nodeId;
     @Mock
     private RpcProviderService rpcProviderService;
-    @Mock
-    private FrmReconciliationService reconciliationService;
 
     @Before
     public void setUp() {
-        deviceMastershipManager = new DeviceMastershipManager(clusterSingletonService, reconciliationAgent, dataBroker,
-                mastershipChangeServiceManager, rpcProviderService, reconciliationService);
+        deviceMastershipManager = new DeviceMastershipManager(reconciliationAgent, dataBroker,
+                mastershipChangeServiceManager, rpcProviderService);
         Mockito.lenient().when(clusterSingletonService
                 .registerClusterSingletonService(ArgumentMatchers.any()))
                 .thenReturn(registration);
index 6a9118eb6a23c43d39df2686fb315364bbb8d2fd..f09f748fd90dea53ce32c44808716e442c0b414d 100644 (file)
@@ -25,26 +25,23 @@ import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
 import java.util.stream.Collectors;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.api.openflow.FlowGroupCacheManager;
 import org.opendaylight.openflowplugin.api.openflow.ReconciliationState;
+import org.opendaylight.openflowplugin.applications.frm.FlowNodeReconciliation;
+import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager;
 import org.opendaylight.openflowplugin.applications.southboundcli.alarm.AlarmAgent;
 import org.opendaylight.openflowplugin.applications.southboundcli.util.OFNode;
 import org.opendaylight.openflowplugin.applications.southboundcli.util.ShellUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 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.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.FrmReconciliationService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.ReconcileNodeInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.ReconcileNodeInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.ReconcileNodeOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.reconciliation.service.rev180227.ReconcileInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.reconciliation.service.rev180227.ReconcileOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.reconciliation.service.rev180227.ReconcileOutputBuilder;
@@ -67,20 +64,20 @@ public class ReconciliationServiceImpl implements ReconciliationService, AutoClo
     private static final Logger LOG = LoggerFactory.getLogger(ReconciliationServiceImpl.class);
 
     private final DataBroker broker;
-    private final FrmReconciliationService frmReconciliationService;
+    private final FlowNodeReconciliation flowNodeReconciliation;
     private final AlarmAgent alarmAgent;
     private final NodeListener nodeListener;
     private final Map<String, ReconciliationState> reconciliationStates;
 
     private ExecutorService executor = Executors.newWorkStealingPool(10);
 
-    public ReconciliationServiceImpl(final DataBroker broker, final FrmReconciliationService frmReconciliationService,
-                                     final AlarmAgent alarmAgent, final NodeListener nodeListener,
-                                     final FlowGroupCacheManager flowGroupCacheManager) {
-        this.broker = broker;
-        this.frmReconciliationService = frmReconciliationService;
-        this.alarmAgent = alarmAgent;
-        this.nodeListener = requireNonNull(nodeListener, "NodeListener cannot be null!");
+    public ReconciliationServiceImpl(final DataBroker broker, final ForwardingRulesManager frm,
+            final AlarmAgent alarmAgent, final NodeListener nodeListener,
+            final FlowGroupCacheManager flowGroupCacheManager) {
+        this.broker = requireNonNull(broker);
+        flowNodeReconciliation = frm.getFlowNodeReconciliation();
+        this.alarmAgent = requireNonNull(alarmAgent);
+        this.nodeListener = requireNonNull(nodeListener);
         reconciliationStates = flowGroupCacheManager.getReconciliationStates();
     }
 
@@ -170,22 +167,20 @@ public class ReconciliationServiceImpl implements ReconciliationService, AutoClo
 
         @Override
         public void run() {
-            ReconcileNodeInput reconInput = new ReconcileNodeInputBuilder()
-                    .setNodeId(nodeId).setNode(new NodeRef(InstanceIdentifier.builder(Nodes.class)
-                            .child(Node.class, nodeKey).build())).build();
             updateReconciliationState(STARTED);
-            Future<RpcResult<ReconcileNodeOutput>> reconOutput = frmReconciliationService
-                    .reconcileNode(reconInput);
+            final var reconOutput = flowNodeReconciliation.reconcileConfiguration(
+                InstanceIdentifier.create(Nodes.class)
+                    .child(Node.class, nodeKey)
+                    .augmentation(FlowCapableNode.class));
             try {
-                RpcResult<ReconcileNodeOutput> rpcResult = reconOutput.get();
-                if (rpcResult.isSuccessful()) {
-                    increaseReconcileCount(true);
+                final boolean rpcResult = reconOutput.get();
+                increaseReconcileCount(rpcResult);
+                if (rpcResult) {
                     updateReconciliationState(COMPLETED);
                     LOG.info("Reconciliation successfully completed for node {}", nodeId);
                 } else {
-                    increaseReconcileCount(false);
                     updateReconciliationState(FAILED);
-                    LOG.error("Reconciliation failed for node {} with error {}", nodeId, rpcResult.getErrors());
+                    LOG.error("Reconciliation failed for node {}", nodeId);
                 }
             } catch (ExecutionException | InterruptedException e) {
                 increaseReconcileCount(false);
index 1c9d8d851a649d27b4b21af31f4137d42f9c96aa..2745a6b5daa9a4f5ef25e0882a5fc88030044df4 100644 (file)
@@ -6,10 +6,11 @@
 
     <reference id="dataBroker"
                interface="org.opendaylight.mdsal.binding.api.DataBroker"/>
-    <reference id="flowCacheManager" interface="org.opendaylight.openflowplugin.api.openflow.FlowGroupCacheManager"/>
+    <reference id="flowCacheManager"
+               interface="org.opendaylight.openflowplugin.api.openflow.FlowGroupCacheManager"/>
+    <reference id="frm"
+               interface="org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager"/>
 
-    <odl:rpc-service id="frmReconciliationService"
-             interface="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.frm.reconciliation.service.rev180227.FrmReconciliationService"/>
     <bean id="alarmAgent"
           class="org.opendaylight.openflowplugin.applications.southboundcli.alarm.AlarmAgent" init-method="start">
     </bean>
@@ -23,7 +24,7 @@
           class="org.opendaylight.openflowplugin.applications.southboundcli.ReconciliationServiceImpl"
           destroy-method="close">
         <argument ref="dataBroker"/>
-        <argument ref="frmReconciliationService"/>
+        <argument ref="frm"/>
         <argument ref="alarmAgent"/>
         <argument ref="nodeListener"/>
         <argument ref="flowCacheManager"/>