FRM code cleanup. 07/88907/12
authorShweta Chaturvedi <shweta.chaturvedi@ericsson.com>
Fri, 7 Dec 2018 11:42:39 +0000 (17:12 +0530)
committerDheenadayalan.b <dhinua@gmail.com>
Wed, 12 Aug 2020 09:50:34 +0000 (15:20 +0530)
Change-Id: I35697d2544464d6cdc4ee88d13978eaabcf33353
Signed-off-by: Shweta Chaturvedi <shweta.chaturvedi@ericsson.com>
14 files changed:
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/AbstractListeningCommiter.java
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FlowForwarder.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/GroupForwarder.java
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/ListenerRegistrationHelper.java [new file with mode: 0644]
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/MeterForwarder.java
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/TableForwarder.java
applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/util/FrmUtil.java
applications/forwardingrules-manager/src/test/java/test/mock/FlowListenerTest.java
applications/forwardingrules-manager/src/test/java/test/mock/GroupListenerTest.java
applications/forwardingrules-manager/src/test/java/test/mock/MeterListenerTest.java
applications/forwardingrules-manager/src/test/java/test/mock/NodeListenerTest.java
applications/forwardingrules-manager/src/test/java/test/mock/TableFeaturesListenerTest.java
applications/forwardingrules-manager/src/test/java/test/mock/util/FRMTest.java

index c45e90c2d133aa28d781c97325039945e4d8bfa3..77390a7cc34342da7a7b65c8b7db99556374e7e7 100644 (file)
@@ -8,15 +8,22 @@
 package org.opendaylight.openflowplugin.applications.frm.impl;
 
 import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
 import java.util.Collection;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesCommiter;
 import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager;
 import org.opendaylight.openflowplugin.applications.frm.NodeConfigurator;
 import org.opendaylight.serviceutils.srm.RecoverableListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
@@ -26,24 +33,28 @@ import org.slf4j.LoggerFactory;
  * AbstractChangeListner implemented basic {@link org.opendaylight.mdsal.binding.api.DataTreeModification}
  * processing for flow node subDataObject (flows, groups and meters).
  */
-public abstract class AbstractListeningCommiter<T extends DataObject> implements ForwardingRulesCommiter<T>,
-        RecoverableListener {
+public abstract class AbstractListeningCommiter<T extends DataObject>
+        implements ForwardingRulesCommiter<T>, RecoverableListener {
 
     private static final Logger LOG = LoggerFactory.getLogger(AbstractListeningCommiter.class);
-
     final ForwardingRulesManager provider;
     NodeConfigurator nodeConfigurator;
     protected final DataBroker dataBroker;
+    protected final ListenerRegistrationHelper registrationHelper;
+    protected ListenerRegistration<AbstractListeningCommiter> listenerRegistration;
 
-    public AbstractListeningCommiter(final ForwardingRulesManager provider, final DataBroker dataBroker) {
+    public AbstractListeningCommiter(final ForwardingRulesManager provider, final DataBroker dataBroker,
+                                     final ListenerRegistrationHelper registrationHelper) {
         this.provider = Preconditions.checkNotNull(provider, "ForwardingRulesManager can not be null!");
         this.nodeConfigurator = Preconditions.checkNotNull(provider.getNodeConfigurator(),
                 "NodeConfigurator can not be null!");
         this.dataBroker = Preconditions.checkNotNull(dataBroker, "DataBroker can not be null!");
+        this.registrationHelper = Preconditions.checkNotNull(registrationHelper, "registrationHelper can not be null!");
         registerListener();
         provider.addRecoverableListener(this);
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     public void onDataTreeChanged(Collection<DataTreeModification<T>> changes) {
         Preconditions.checkNotNull(changes, "Changes may not be null!");
@@ -54,46 +65,73 @@ public abstract class AbstractListeningCommiter<T extends DataObject> implements
             final DataObjectModification<T> mod = change.getRootNode();
             final InstanceIdentifier<FlowCapableNode> nodeIdent =
                     key.firstIdentifierOf(FlowCapableNode.class);
-            if (preConfigurationCheck(nodeIdent)) {
-                switch (mod.getModificationType()) {
-                    case DELETE:
-                        remove(key, mod.getDataBefore(), nodeIdent);
-                        break;
-                    case SUBTREE_MODIFIED:
-                        update(key, mod.getDataBefore(), mod.getDataAfter(), nodeIdent);
-                        break;
-                    case WRITE:
-                        if (mod.getDataBefore() == null) {
-                            add(key, mod.getDataAfter(), nodeIdent);
-                        } else {
-                            update(key, mod.getDataBefore(), mod.getDataAfter(), nodeIdent);
-                        }
-                        break;
-                    default:
-                        throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
-                }
-            } else {
-                if (provider.isStaleMarkingEnabled()) {
-                    LOG.info("Stale-Marking ENABLED and switch {} is NOT connected, storing stale entities",
-                            nodeIdent.toString());
-                    // Switch is NOT connected
+            try {
+                if (preConfigurationCheck(nodeIdent)) {
                     switch (mod.getModificationType()) {
                         case DELETE:
-                            createStaleMarkEntity(key, mod.getDataBefore(), nodeIdent);
+                            remove(key, mod.getDataBefore(), nodeIdent);
                             break;
                         case SUBTREE_MODIFIED:
+                            update(key, mod.getDataBefore(), mod.getDataAfter(), nodeIdent);
                             break;
                         case WRITE:
+                            if (mod.getDataBefore() == null) {
+                                add(key, mod.getDataAfter(), nodeIdent);
+                            } else {
+                                update(key, mod.getDataBefore(), mod.getDataAfter(), nodeIdent);
+                            }
                             break;
                         default:
                             throw new
-                            IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
+                                    IllegalArgumentException("Unhandled modification type "
+                                    + mod.getModificationType());
+                    }
+                } else {
+                    if (provider.isStaleMarkingEnabled()) {
+                        LOG.info("Stale-Marking ENABLED and switch {} is NOT connected, storing stale entities",
+                                nodeIdent.toString());
+                        // Switch is NOT connected
+                        switch (mod.getModificationType()) {
+                            case DELETE:
+                                createStaleMarkEntity(key, mod.getDataBefore(), nodeIdent);
+                                break;
+                            case SUBTREE_MODIFIED:
+                                break;
+                            case WRITE:
+                                break;
+                            default:
+                                throw new
+                                        IllegalArgumentException("Unhandled modification type "
+                                        + mod.getModificationType());
+                        }
                     }
                 }
+            } catch (RuntimeException e) {
+                LOG.error("Failed to handle event {} key {} due to error ", mod.getModificationType(), key, e);
             }
         }
     }
 
+    @Override
+    public void registerListener() {
+        final DataTreeIdentifier<T> treeId =
+                DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, getWildCardPath());
+        Futures.addCallback(registrationHelper.checkedRegisterListener(treeId, this),
+                new FutureCallback<ListenerRegistration<AbstractListeningCommiter>>() {
+                    @Override
+                    public void onSuccess(
+                            @Nullable ListenerRegistration<AbstractListeningCommiter> flowListenerRegistration) {
+                        LOG.info("{} registered successfully", flowListenerRegistration.getInstance());
+                        listenerRegistration = flowListenerRegistration;
+                    }
+
+                    @Override
+                    public void onFailure(Throwable throwable) {
+                        LOG.error("Registration failed ", throwable);
+                    }
+                }, MoreExecutors.directExecutor());
+    }
+
     /**
      * Method return wildCardPath for Listener registration
      * and for identify the correct KeyInstanceIdentifier from data.
@@ -113,5 +151,4 @@ public abstract class AbstractListeningCommiter<T extends DataObject> implements
         // trigger the event of new node connected.
         return provider.isNodeOwner(nodeIdent);
     }
-}
-
+}
\ No newline at end of file
index 5c9600f34ce706d9505393cbe63a4157b0d02638..99935e4f1213bf28db965f7f18290a6a7c386ae3 100644 (file)
@@ -26,7 +26,6 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
 import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 import org.opendaylight.mdsal.binding.api.ReadTransaction;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
@@ -85,25 +84,14 @@ public class FlowForwarder extends AbstractListeningCommiter<Flow> {
 
     private ListenerRegistration<FlowForwarder> listenerRegistration;
 
-    public FlowForwarder(final ForwardingRulesManager manager, final DataBroker db) {
-        super(manager, db);
-    }
+    private final BundleFlowForwarder bundleFlowForwarder;
 
-    @Override
-    @SuppressWarnings("IllegalCatch")
-    public void registerListener() {
-        final DataTreeIdentifier<Flow> treeId = DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
-                getWildCardPath());
-        try {
-            listenerRegistration = dataBroker.registerDataTreeChangeListener(treeId, FlowForwarder.this);
-        } catch (final Exception e) {
-            LOG.warn("FRM Flow DataTreeChange listener registration fail!");
-            LOG.debug("FRM Flow DataTreeChange listener registration fail ..", e);
-            throw new IllegalStateException("FlowForwarder startup fail! System needs restart.", e);
-        }
+    public FlowForwarder(final ForwardingRulesManager manager, final DataBroker db,
+                         final ListenerRegistrationHelper registrationHelper) {
+        super(manager, db, registrationHelper);
+        bundleFlowForwarder = new BundleFlowForwarder(manager);
     }
 
-
     @Override
     public  void deregisterListener() {
         close();
@@ -466,4 +454,4 @@ public class FlowForwarder extends AbstractListeningCommiter<Flow> {
             resultFuture.setException(throwable);
         }
     }
-}
+}
\ No newline at end of file
index 30ea3e27d3d89524104b841eccecd4964b7bb2a2..4b45c0f3571881180fff0c690cf8c8f8dedd4507 100644 (file)
@@ -107,6 +107,7 @@ public class ForwardingRulesManagerImpl implements ForwardingRulesManager {
     private final OpenflowServiceRecoveryHandler openflowServiceRecoveryHandler;
     private final ServiceRecoveryRegistry serviceRecoveryRegistry;
     private final FlowGroupCacheManager flowGroupCacheManager;
+    private final ListenerRegistrationHelper registrationHelper;
 
     @Inject
     public ForwardingRulesManagerImpl(@Reference final DataBroker dataBroker,
@@ -119,12 +120,14 @@ public class ForwardingRulesManagerImpl implements ForwardingRulesManager {
                                       @Reference final ReconciliationManager reconciliationManager,
                                       final OpenflowServiceRecoveryHandler openflowServiceRecoveryHandler,
                                       @Reference final ServiceRecoveryRegistry serviceRecoveryRegistry,
-                                      @Reference final FlowGroupCacheManager flowGroupCacheManager) {
+                                      @Reference final FlowGroupCacheManager flowGroupCacheManager,
+                                      final ListenerRegistrationHelper registrationHelper) {
         disableReconciliation = config.isDisableReconciliation();
         staleMarkingEnabled = config.isStaleMarkingEnabled();
         reconciliationRetryCount = config.getReconciliationRetryCount().toJava();
         isBundleBasedReconciliationEnabled = config.isBundleBasedReconciliationEnabled();
         this.configurationServiceRegistration = configurationService.registerListener(this);
+        this.registrationHelper = Preconditions.checkNotNull(registrationHelper, "RegistrationHelper cannot be null");
         this.dataService = Preconditions.checkNotNull(dataBroker, "DataBroker can not be null!");
         this.clusterSingletonServiceProvider = Preconditions.checkNotNull(clusterSingletonService,
                 "ClusterSingletonService provider can not be null");
@@ -174,10 +177,10 @@ public class ForwardingRulesManagerImpl implements ForwardingRulesManager {
 
         this.bundleFlowListener = new BundleFlowForwarder(this);
         this.bundleGroupListener = new BundleGroupForwarder(this);
-        this.flowListener = new FlowForwarder(this, dataService);
-        this.groupListener = new GroupForwarder(this, dataService);
-        this.meterListener = new MeterForwarder(this, dataService);
-        this.tableListener = new TableForwarder(this, dataService);
+        this.flowListener = new FlowForwarder(this, dataService, registrationHelper);
+        this.groupListener = new GroupForwarder(this, dataService, registrationHelper);
+        this.meterListener = new MeterForwarder(this, dataService, registrationHelper);
+        this.tableListener = new TableForwarder(this, dataService, registrationHelper);
         LOG.info("ForwardingRulesManager has started successfully.");
     }
 
index eae69f575297e68fbf261574be5312bd9f7e8968..9b65c0374ba471d13623aad372380d95399f5bd0 100644 (file)
@@ -18,7 +18,6 @@ import com.google.common.util.concurrent.MoreExecutors;
 import java.util.concurrent.Future;
 import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
 import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager;
@@ -64,23 +63,12 @@ public class GroupForwarder extends AbstractListeningCommiter<Group> {
     private static final Logger LOG = LoggerFactory.getLogger(GroupForwarder.class);
     private ListenerRegistration<GroupForwarder> listenerRegistration;
 
-    public GroupForwarder(final ForwardingRulesManager manager, final DataBroker db) {
-        super(manager, db);
-    }
+    private final BundleGroupForwarder bundleGroupForwarder;
 
-    @SuppressWarnings("IllegalCatch")
-    @Override
-    public void registerListener() {
-        final DataTreeIdentifier<Group> treeId = DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
-                getWildCardPath());
-
-        try {
-            listenerRegistration = dataBroker.registerDataTreeChangeListener(treeId, GroupForwarder.this);
-        } catch (final Exception e) {
-            LOG.warn("FRM Group DataTreeChange listener registration fail!");
-            LOG.debug("FRM Group DataTreeChange listener registration fail ..", e);
-            throw new IllegalStateException("GroupForwarder startup fail! System needs restart.", e);
-        }
+    public GroupForwarder(final ForwardingRulesManager manager, final DataBroker db,
+                          final ListenerRegistrationHelper registrationHelper) {
+        super(manager, db, registrationHelper);
+        this.bundleGroupForwarder = new BundleGroupForwarder(manager);
     }
 
     @Override
diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/ListenerRegistrationHelper.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/ListenerRegistrationHelper.java
new file mode 100644 (file)
index 0000000..842560c
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2020 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 static org.opendaylight.openflowplugin.applications.frm.util.FrmUtil.getInventoryConfigDataStoreStatus;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.apache.aries.blueprint.annotation.service.Reference;
+import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
+import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@Singleton
+public class ListenerRegistrationHelper {
+    private static final Logger LOG = LoggerFactory.getLogger(ListenerRegistrationHelper.class);
+    private final long inventoryCheckTimer = 1;
+    private final String operational = "OPERATIONAL";
+    private final ListeningExecutorService listeningExecutorService;
+    private final DataBroker dataBroker;
+
+    @Inject
+    public ListenerRegistrationHelper(@Reference final DataBroker dataBroker) {
+        this.dataBroker = dataBroker;
+        listeningExecutorService = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor(
+                 new ThreadFactoryBuilder()
+                .setNameFormat("frm-listener" + "%d")
+                .setDaemon(false)
+                .setUncaughtExceptionHandler((thread, ex) -> LOG.error("Uncaught exception {}", thread, ex))
+                .build()));
+    }
+
+    public <T extends DataObject, L extends ClusteredDataTreeChangeListener<T>>
+        ListenableFuture<ListenerRegistration<L>>
+        checkedRegisterListener(DataTreeIdentifier<T> treeId, L listener) {
+        return listeningExecutorService.submit(() -> {
+            while (! getInventoryConfigDataStoreStatus().equals(operational)) {
+                try {
+                    LOG.debug("Retrying for datastore to become operational for listener {}", listener);
+                    Thread.sleep(inventoryCheckTimer * 1000);
+                } catch (InterruptedException e) {
+                    LOG.info("registerDataTreeChangeListener thread is interrupted");
+                    Thread.currentThread().interrupt();
+                }
+            }
+            SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK,
+                    ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES);
+            return looper.loopUntilNoException(() -> dataBroker.registerDataTreeChangeListener(treeId, listener));
+        });
+    }
+
+    public void close() throws Exception {
+        MoreExecutors.shutdownAndAwaitTermination(listeningExecutorService, 5, TimeUnit.SECONDS);
+    }
+}
\ No newline at end of file
index 210bb1eb6f48e5b7cf3e24fadd2080a42605c5cd..ecf18514a3dffe0e706f3c583ef49c8921a80109 100644 (file)
@@ -13,7 +13,6 @@ import com.google.common.util.concurrent.MoreExecutors;
 import java.util.concurrent.Future;
 import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
 import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager;
@@ -35,7 +34,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.met
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeterBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterRef;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
@@ -52,29 +50,14 @@ import org.slf4j.LoggerFactory;
 public class MeterForwarder extends AbstractListeningCommiter<Meter> {
 
     private static final Logger LOG = LoggerFactory.getLogger(MeterForwarder.class);
-    private ListenerRegistration<MeterForwarder> listenerRegistration;
 
-    public MeterForwarder(final ForwardingRulesManager manager, final DataBroker db) {
-        super(manager, db);
+    public MeterForwarder(final ForwardingRulesManager manager, final DataBroker db,
+                          final ListenerRegistrationHelper listenerRegistrationHelper) {
+        super(manager, db, listenerRegistrationHelper);
     }
 
-    @SuppressWarnings("IllegalCatch")
     @Override
-    public void registerListener() {
-        final DataTreeIdentifier<Meter> treeId = DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
-                getWildCardPath());
-
-        try {
-            listenerRegistration = dataBroker.registerDataTreeChangeListener(treeId, MeterForwarder.this);
-        } catch (final Exception e) {
-            LOG.warn("FRM Meter DataTreeChange listener registration fail!");
-            LOG.debug("FRM Meter DataTreeChange listener registration fail ..", e);
-            throw new IllegalStateException("MeterForwarder startup fail! System needs restart.", e);
-        }
-    }
-
-    @Override
-    public  void deregisterListener() {
+    public void deregisterListener() {
         close();
     }
 
index 10b5d1dd0eadc1527ab47a7406274e3ad0e173ba..f130593af1792a0425542014a681dfa65794dd8c 100644 (file)
@@ -12,8 +12,6 @@ import java.util.Collections;
 import java.util.concurrent.Future;
 import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
 import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
@@ -25,7 +23,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.tab
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
@@ -34,25 +31,10 @@ import org.slf4j.LoggerFactory;
 public class TableForwarder extends AbstractListeningCommiter<TableFeatures> {
 
     private static final Logger LOG = LoggerFactory.getLogger(TableForwarder.class);
-    private ListenerRegistration<TableForwarder> listenerRegistration;
 
-    public TableForwarder(final ForwardingRulesManager manager, final DataBroker db) {
-        super(manager, db);
-    }
-
-    @SuppressWarnings("IllegalCatch")
-    @Override
-    public void registerListener() {
-        final DataTreeIdentifier<TableFeatures> treeId = DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
-                getWildCardPath());
-
-        try {
-            listenerRegistration = dataBroker.registerDataTreeChangeListener(treeId, TableForwarder.this);
-        } catch (final Exception e) {
-            LOG.warn("FRM Table DataTreeChangeListener registration fail!");
-            LOG.debug("FRM Table DataTreeChangeListener registration fail ..", e);
-            throw new IllegalStateException("TableForwarder startup fail! System needs restart.", e);
-        }
+    public TableForwarder(final ForwardingRulesManager manager, final DataBroker db,
+                          final ListenerRegistrationHelper registrationHelper) {
+        super(manager, db, registrationHelper);
     }
 
     @Override
index c7f4cbba019c340f301d4922dcff41876e6df7a4..05ee7206e8e9d40c9246b25a016fa89d14a606e5 100644 (file)
@@ -8,12 +8,21 @@
 
 package org.opendaylight.openflowplugin.applications.frm.util;
 
+import java.lang.management.ManagementFactory;
 import java.math.BigInteger;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
 import org.opendaylight.openflowplugin.applications.frm.ActionType;
 import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
@@ -44,11 +53,16 @@ import org.opendaylight.yangtools.yang.common.Uint8;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@SuppressWarnings("IllegalCatch")
 public final class FrmUtil {
     private static final Logger LOG = LoggerFactory.getLogger(FrmUtil.class);
     private static final String SEPARATOR = ":";
     private static final long RPC_RESULT_TIMEOUT = 2500;
 
+    private static final String JMX_OBJ_NAME_LIST_OF_SHRDS = "org.opendaylight.controller:type="
+            + "DistributedConfigDatastore,Category=ShardManager,name=shard-manager-config";
+    private static String JMX_OBJECT_SHARD_STATUS = "";
+
     private FrmUtil() {
         throw new IllegalStateException("This class should not be instantiated.");
     }
@@ -146,4 +160,70 @@ public final class FrmUtil {
         String nodeId = getNodeIdValueFromNodeIdentifier(nodeIdent);
         return provider.getDevicesGroupRegistry().isGroupPresent(nodeId, groupId);
     }
-}
+
+    public static String getInventoryConfigDataStoreStatus() {
+        boolean statusResult = true;
+        try {
+            ArrayList listOfShards = getAttributeJMXCommand(JMX_OBJ_NAME_LIST_OF_SHRDS, "LocalShards");
+            if (listOfShards != null) {
+                for (Object listOfShard : listOfShards) {
+                    LOG.info("Listofshard is  {} ",listOfShard);
+                    if (listOfShard.toString().contains("inventory")) {
+                        JMX_OBJECT_SHARD_STATUS =
+                                "org.opendaylight.controller:Category=Shards,name=" + listOfShard
+                                        + ",type=DistributedConfigDatastore";
+                        LOG.info("JMX object shard status is {} ",JMX_OBJECT_SHARD_STATUS);
+                        String leader = getLeaderJMX(JMX_OBJECT_SHARD_STATUS, "Leader");
+                        if (leader != null && leader.length() > 1) {
+                            LOG.info("{} ::Inventory Shard has the Leader as:: {}", listOfShard, leader);
+                        } else {
+                            statusResult = false;
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("ERROR ::", e);
+        }
+        if (statusResult) {
+            return "OPERATIONAL";
+        } else {
+            return "ERROR";
+        }
+    }
+
+    private static ArrayList getAttributeJMXCommand(String objectName, String attributeName) {
+        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+        ArrayList listOfShards = new ArrayList();
+        if (mbs != null) {
+            try {
+                listOfShards = (ArrayList) mbs.getAttribute(new ObjectName(objectName), attributeName);
+            } catch (MBeanException | AttributeNotFoundException | InstanceNotFoundException
+                    | MalformedObjectNameException | ReflectionException e) {
+                LOG.error("Exception while reading list of shards ", e);
+            }
+        }
+        return listOfShards;
+    }
+
+    private static String getLeaderJMX(String objectName, String atrName) {
+        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+        String leader = "";
+        if (mbs != null) {
+            try {
+                leader  = (String) mbs.getAttribute(new ObjectName(objectName), atrName);
+            } catch (MalformedObjectNameException monEx) {
+                LOG.error("CRITICAL EXCEPTION : Malformed Object Name Exception");
+            } catch (MBeanException mbEx) {
+                LOG.error("CRITICAL EXCEPTION : MBean Exception");
+            } catch (InstanceNotFoundException infEx) {
+                LOG.error("CRITICAL EXCEPTION : Instance Not Found Exception");
+            } catch (ReflectionException rEx) {
+                LOG.error("CRITICAL EXCEPTION : Reflection Exception");
+            } catch (Exception e) {
+                LOG.error("Attribute not found");
+            }
+        }
+        return leader;
+    }
+}
\ No newline at end of file
index 1e49669077f1a025a3186b22c23b0f42478f5f48..9d5d503f8d2d60d02573555db81a29a79321fcc7 100644 (file)
@@ -7,8 +7,8 @@
  */
 package test.mock;
 
+import static java.util.concurrent.TimeUnit.SECONDS;
 import static org.awaitility.Awaitility.await;
-import static org.hamcrest.Matchers.equalTo;
 import static org.junit.Assert.assertEquals;
 
 import java.util.Collections;
@@ -85,7 +85,7 @@ public class FlowListenerTest extends FRMTest {
         forwardingRulesManager = new ForwardingRulesManagerImpl(getDataBroker(), rpcProviderRegistryMock,
                 rpcProviderRegistryMock, getConfig(), mastershipChangeServiceManager, clusterSingletonService,
                 getConfigurationService(), reconciliationManager, openflowServiceRecoveryHandler,
-                serviceRecoveryRegistry, flowGroupCacheManager);
+                serviceRecoveryRegistry, flowGroupCacheManager, getRegistrationHelper());
         forwardingRulesManager.start();
         // TODO consider tests rewrite (added because of complicated access)
         forwardingRulesManager.setDeviceMastershipManager(deviceMastershipManager);
@@ -109,7 +109,7 @@ public class FlowListenerTest extends FRMTest {
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
         assertCommit(writeTx.commit());
         SalFlowServiceMock salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
-        await().until(listSize(salFlowService.getAddFlowCalls()), equalTo(1));
+        await().atMost(10, SECONDS).until(() -> salFlowService.getAddFlowCalls().size() == 1);
         List<AddFlowInput> addFlowCalls = salFlowService.getAddFlowCalls();
         assertEquals(1, addFlowCalls.size());
         assertEquals("DOM-0", addFlowCalls.get(0).getTransactionUri().getValue());
@@ -120,9 +120,9 @@ public class FlowListenerTest extends FRMTest {
         flow = new FlowBuilder().withKey(flowKey).setTableId((short) 2).build();
         writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
+
         assertCommit(writeTx.commit());
-        salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
-        await().until(listSize(salFlowService.getAddFlowCalls()), equalTo(2));
+        await().atMost(10, SECONDS).until(() -> salFlowService.getAddFlowCalls().size() == 2);
         addFlowCalls = salFlowService.getAddFlowCalls();
         assertEquals(2, addFlowCalls.size());
         assertEquals("DOM-1", addFlowCalls.get(1).getTransactionUri().getValue());
@@ -146,8 +146,8 @@ public class FlowListenerTest extends FRMTest {
         writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table);
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
         assertCommit(writeTx.commit());
-        SalFlowServiceMock salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
-        await().until(listSize(salFlowService.getAddFlowCalls()), equalTo(1));
+        final SalFlowServiceMock salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
+        await().atMost(10, SECONDS).until(() -> salFlowService.getAddFlowCalls().size() == 1);
 
         List<AddFlowInput> addFlowCalls = salFlowService.getAddFlowCalls();
         assertEquals(1, addFlowCalls.size());
@@ -160,8 +160,7 @@ public class FlowListenerTest extends FRMTest {
         writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
         assertCommit(writeTx.commit());
-        salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
-        await().until(listSize(salFlowService.getUpdateFlowCalls()), equalTo(1));
+        await().atMost(10, SECONDS).until(() -> salFlowService.getUpdateFlowCalls().size() == 1);
         List<UpdateFlowInput> updateFlowCalls = salFlowService.getUpdateFlowCalls();
         assertEquals(1, updateFlowCalls.size());
         assertEquals("DOM-1", updateFlowCalls.get(0).getTransactionUri().getValue());
@@ -188,8 +187,8 @@ public class FlowListenerTest extends FRMTest {
         writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table);
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
         assertCommit(writeTx.commit());
-        SalFlowServiceMock salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
-        await().until(listSize(salFlowService.getAddFlowCalls()), equalTo(1));
+        final SalFlowServiceMock salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
+        await().atMost(10, SECONDS).until(() -> salFlowService.getAddFlowCalls().size() == 1);
         List<AddFlowInput> addFlowCalls = salFlowService.getAddFlowCalls();
         assertEquals(1, addFlowCalls.size());
         assertEquals("DOM-0", addFlowCalls.get(0).getTransactionUri().getValue());
@@ -203,8 +202,7 @@ public class FlowListenerTest extends FRMTest {
         writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
         assertCommit(writeTx.commit());
-        salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
-        await().until(listSize(salFlowService.getUpdateFlowCalls()), equalTo(1));
+        await().atMost(10, SECONDS).until(() -> salFlowService.getUpdateFlowCalls().size() == 1);
         List<UpdateFlowInput> updateFlowCalls = salFlowService.getUpdateFlowCalls();
         assertEquals(1, updateFlowCalls.size());
         assertEquals("DOM-1", updateFlowCalls.get(0).getTransactionUri().getValue());
@@ -228,8 +226,8 @@ public class FlowListenerTest extends FRMTest {
         writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table);
         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
         assertCommit(writeTx.commit());
-        SalFlowServiceMock salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
-        await().until(listSize(salFlowService.getAddFlowCalls()), equalTo(1));
+        final SalFlowServiceMock salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
+        await().atMost(10, SECONDS).until(() -> salFlowService.getAddFlowCalls().size() == 1);
         List<AddFlowInput> addFlowCalls = salFlowService.getAddFlowCalls();
         assertEquals(1, addFlowCalls.size());
         assertEquals("DOM-0", addFlowCalls.get(0).getTransactionUri().getValue());
@@ -237,8 +235,7 @@ public class FlowListenerTest extends FRMTest {
         writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.delete(LogicalDatastoreType.CONFIGURATION, flowII);
         assertCommit(writeTx.commit());
-        salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
-        await().until(listSize(salFlowService.getRemoveFlowCalls()), equalTo(1));
+        await().atMost(10, SECONDS).until(() -> salFlowService.getRemoveFlowCalls().size() == 1);
         List<RemoveFlowInput> removeFlowCalls = salFlowService.getRemoveFlowCalls();
         assertEquals(1, removeFlowCalls.size());
         assertEquals("DOM-1", removeFlowCalls.get(0).getTransactionUri().getValue());
@@ -247,8 +244,7 @@ public class FlowListenerTest extends FRMTest {
     }
 
     @Test
-    public void staleMarkedFlowCreationTest() {
-
+    public void staleMarkedFlowCreationTest() throws Exception {
         addFlowCapableNode(NODE_KEY);
 
         StaleFlowKey flowKey = new StaleFlowKey(new FlowId("stale_Flow"));
index f7614879dcbdeef2a846fe294870a7ee1bb459d2..8e51d5920d39c94953227a29236b8d321684a750 100644 (file)
@@ -7,8 +7,8 @@
  */
 package test.mock;
 
+import static java.util.concurrent.TimeUnit.SECONDS;
 import static org.awaitility.Awaitility.await;
-import static org.hamcrest.Matchers.equalTo;
 import static org.junit.Assert.assertEquals;
 
 import java.util.List;
@@ -84,7 +84,9 @@ public class GroupListenerTest extends FRMTest {
                 reconciliationManager,
                 openflowServiceRecoveryHandler,
                 serviceRecoveryRegistry,
-                flowGroupCacheManager);
+                flowGroupCacheManager,
+                getRegistrationHelper()
+                );
 
         forwardingRulesManager.start();
         // TODO consider tests rewrite (added because of complicated access)
@@ -104,8 +106,8 @@ public class GroupListenerTest extends FRMTest {
         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
         assertCommit(writeTx.commit());
-        SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
-        await().until(listSize(salGroupService.getAddGroupCalls()), equalTo(1));
+        final SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
+        await().atMost(10, SECONDS).until(() -> salGroupService.getAddGroupCalls().size() == 1);
         List<AddGroupInput> addGroupCalls = salGroupService.getAddGroupCalls();
         assertEquals(1, addGroupCalls.size());
         assertEquals("DOM-0", addGroupCalls.get(0).getTransactionUri().getValue());
@@ -117,8 +119,7 @@ public class GroupListenerTest extends FRMTest {
         writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
         assertCommit(writeTx.commit());
-        salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
-        await().until(listSize(salGroupService.getAddGroupCalls()), equalTo(2));
+        await().atMost(10, SECONDS).until(() -> salGroupService.getAddGroupCalls().size() == 2);
         addGroupCalls = salGroupService.getAddGroupCalls();
         assertEquals(2, addGroupCalls.size());
         assertEquals("DOM-1", addGroupCalls.get(1).getTransactionUri().getValue());
@@ -136,8 +137,8 @@ public class GroupListenerTest extends FRMTest {
         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
         assertCommit(writeTx.commit());
-        SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
-        await().until(listSize(salGroupService.getAddGroupCalls()), equalTo(1));
+        final SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
+        await().atMost(10, SECONDS).until(() -> salGroupService.getAddGroupCalls().size() == 1);
         List<AddGroupInput> addGroupCalls = salGroupService.getAddGroupCalls();
         assertEquals(1, addGroupCalls.size());
         assertEquals("DOM-0", addGroupCalls.get(0).getTransactionUri().getValue());
@@ -146,8 +147,7 @@ public class GroupListenerTest extends FRMTest {
         writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
         assertCommit(writeTx.commit());
-        salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
-        await().until(listSize(salGroupService.getUpdateGroupCalls()), equalTo(1));
+        await().atMost(10, SECONDS).until(() -> salGroupService.getUpdateGroupCalls().size() == 1);
         List<UpdateGroupInput> updateGroupCalls = salGroupService.getUpdateGroupCalls();
         assertEquals(1, updateGroupCalls.size());
         assertEquals("DOM-1", updateGroupCalls.get(0).getTransactionUri().getValue());
@@ -166,7 +166,7 @@ public class GroupListenerTest extends FRMTest {
         writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
         assertCommit(writeTx.commit());
         SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
-        await().until(listSize(salGroupService.getAddGroupCalls()), equalTo(1));
+        await().atMost(10, SECONDS).until(() -> salGroupService.getAddGroupCalls().size() == 1);
         List<AddGroupInput> addGroupCalls = salGroupService.getAddGroupCalls();
         assertEquals(1, addGroupCalls.size());
         assertEquals("DOM-0", addGroupCalls.get(0).getTransactionUri().getValue());
@@ -174,8 +174,7 @@ public class GroupListenerTest extends FRMTest {
         writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.delete(LogicalDatastoreType.CONFIGURATION, groupII);
         assertCommit(writeTx.commit());
-        salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
-        await().until(listSize(salGroupService.getRemoveGroupCalls()), equalTo(1));
+        await().atMost(10, SECONDS).until(() -> salGroupService.getRemoveGroupCalls().size() == 1);
         List<RemoveGroupInput> removeGroupCalls = salGroupService.getRemoveGroupCalls();
         assertEquals(1, removeGroupCalls.size());
         assertEquals("DOM-1", removeGroupCalls.get(0).getTransactionUri().getValue());
index 1fade0fdfbc722feab5bb9129d1e53f3433035e4..b21b74e465a36f886e98fa2bbc8df1c1aa60625e 100644 (file)
@@ -7,6 +7,8 @@
  */
 package test.mock;
 
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.awaitility.Awaitility.await;
 import static org.junit.Assert.assertEquals;
 
 import java.util.List;
@@ -82,7 +84,9 @@ public class MeterListenerTest extends FRMTest {
                 reconciliationManager,
                 openflowServiceRecoveryHandler,
                 serviceRecoveryRegistry,
-                flowGroupCacheManager);
+                flowGroupCacheManager,
+                getRegistrationHelper()
+                );
 
         forwardingRulesManager.start();
         // TODO consider tests rewrite (added because of complicated access)
@@ -103,6 +107,7 @@ public class MeterListenerTest extends FRMTest {
         writeTx.put(LogicalDatastoreType.CONFIGURATION, meterII, meter);
         assertCommit(writeTx.commit());
         SalMeterServiceMock salMeterService = (SalMeterServiceMock) forwardingRulesManager.getSalMeterService();
+        await().atMost(10, SECONDS).until(() -> salMeterService.getAddMeterCalls().size() == 1);
         List<AddMeterInput> addMeterCalls = salMeterService.getAddMeterCalls();
         assertEquals(1, addMeterCalls.size());
         assertEquals("DOM-0", addMeterCalls.get(0).getTransactionUri().getValue());
@@ -114,7 +119,7 @@ public class MeterListenerTest extends FRMTest {
         writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, meterII, meter);
         assertCommit(writeTx.commit());
-        salMeterService = (SalMeterServiceMock) forwardingRulesManager.getSalMeterService();
+        await().atMost(10, SECONDS).until(() -> salMeterService.getAddMeterCalls().size() == 2);
         addMeterCalls = salMeterService.getAddMeterCalls();
         assertEquals(2, addMeterCalls.size());
         assertEquals("DOM-1", addMeterCalls.get(1).getTransactionUri().getValue());
@@ -134,6 +139,7 @@ public class MeterListenerTest extends FRMTest {
         writeTx.put(LogicalDatastoreType.CONFIGURATION, meterII, meter);
         assertCommit(writeTx.commit());
         SalMeterServiceMock salMeterService = (SalMeterServiceMock) forwardingRulesManager.getSalMeterService();
+        await().atMost(10, SECONDS).until(() -> salMeterService.getAddMeterCalls().size() == 1);
         List<AddMeterInput> addMeterCalls = salMeterService.getAddMeterCalls();
         assertEquals(1, addMeterCalls.size());
         assertEquals("DOM-0", addMeterCalls.get(0).getTransactionUri().getValue());
@@ -142,7 +148,7 @@ public class MeterListenerTest extends FRMTest {
         writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.CONFIGURATION, meterII, meter);
         assertCommit(writeTx.commit());
-        salMeterService = (SalMeterServiceMock) forwardingRulesManager.getSalMeterService();
+        await().atMost(10, SECONDS).until(() -> salMeterService.getUpdateMeterCalls().size() == 1);
         List<UpdateMeterInput> updateMeterCalls = salMeterService.getUpdateMeterCalls();
         assertEquals(1, updateMeterCalls.size());
         assertEquals("DOM-1", updateMeterCalls.get(0).getTransactionUri().getValue());
@@ -162,6 +168,7 @@ public class MeterListenerTest extends FRMTest {
         writeTx.put(LogicalDatastoreType.CONFIGURATION, meterII, meter);
         assertCommit(writeTx.commit());
         SalMeterServiceMock salMeterService = (SalMeterServiceMock) forwardingRulesManager.getSalMeterService();
+        await().atMost(10, SECONDS).until(() -> salMeterService.getAddMeterCalls().size() == 1);
         List<AddMeterInput> addMeterCalls = salMeterService.getAddMeterCalls();
         assertEquals(1, addMeterCalls.size());
         assertEquals("DOM-0", addMeterCalls.get(0).getTransactionUri().getValue());
@@ -169,7 +176,7 @@ public class MeterListenerTest extends FRMTest {
         writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.delete(LogicalDatastoreType.CONFIGURATION, meterII);
         assertCommit(writeTx.commit());
-        salMeterService = (SalMeterServiceMock) forwardingRulesManager.getSalMeterService();
+        await().atMost(10, SECONDS).until(() -> salMeterService.getRemoveMeterCalls().size() == 1);
         List<RemoveMeterInput> removeMeterCalls = salMeterService.getRemoveMeterCalls();
         assertEquals(1, removeMeterCalls.size());
         assertEquals("DOM-1", removeMeterCalls.get(0).getTransactionUri().getValue());
index 516bed903fd28ea69eaa57007439bb90864c7382..5e904151c00099f079c99a9cff1a839889722285 100644 (file)
@@ -64,7 +64,9 @@ public class NodeListenerTest extends FRMTest {
                 reconciliationManager,
                 openflowServiceRecoveryHandler,
                 serviceRecoveryRegistry,
-                flowGroupCacheManager);
+                flowGroupCacheManager,
+                getRegistrationHelper());
+
         forwardingRulesManager.start();
     }
 
index bb30caec52d521f40157bd88a850a83a6a7c3273..9d8c13cd18cb0ab951da71c2ddac2784829bf329 100644 (file)
@@ -7,6 +7,8 @@
  */
 package test.mock;
 
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.awaitility.Awaitility.await;
 import static org.junit.Assert.assertEquals;
 
 import java.util.List;
@@ -68,7 +70,9 @@ public class TableFeaturesListenerTest extends FRMTest {
         forwardingRulesManager = new ForwardingRulesManagerImpl(getDataBroker(), rpcProviderRegistryMock,
                 rpcProviderRegistryMock, getConfig(), mastershipChangeServiceManager, clusterSingletonService,
                 getConfigurationService(), reconciliationManager, openflowServiceRecoveryHandler,
-                serviceRecoveryRegistry, flowGroupCacheManager);
+                serviceRecoveryRegistry, flowGroupCacheManager, getRegistrationHelper());
+
+
         forwardingRulesManager.start();
         // TODO consider tests rewrite (added because of complicated access)
         forwardingRulesManager.setDeviceMastershipManager(deviceMastershipManager);
@@ -96,6 +100,7 @@ public class TableFeaturesListenerTest extends FRMTest {
         assertCommit(writeTx.commit());
 
         SalTableServiceMock salTableServiceMock = (SalTableServiceMock) forwardingRulesManager.getSalTableService();
+        await().atMost(10, SECONDS).until(() -> salTableServiceMock.getUpdateTableInput().size() == 1);
         List<UpdateTableInput> updateTableInputs = salTableServiceMock.getUpdateTableInput();
         assertEquals(1, updateTableInputs.size());
         assertEquals("DOM-0", updateTableInputs.get(0).getTransactionUri().getValue());
index 58f00b1fcf515453304793286516fae7ef7ac4a8..ddaf83e5db1aaf46d1ac566818a72cab28669494 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTest;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService;
+import org.opendaylight.openflowplugin.applications.frm.impl.ListenerRegistrationHelper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
@@ -108,4 +109,9 @@ public abstract class FRMTest extends AbstractDataBrokerTest {
         // The condition supplier part
         return list::size;
     }
+
+    public ListenerRegistrationHelper getRegistrationHelper() {
+        ListenerRegistrationHelper registrationHelper = new ListenerRegistrationHelper(getDataBroker());
+        return registrationHelper;
+    }
 }