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;
* 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!");
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.
// trigger the event of new node connected.
return provider.isNodeOwner(nodeIdent);
}
-}
-
+}
\ No newline at end of file
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;
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();
resultFuture.setException(throwable);
}
}
-}
+}
\ No newline at end of file
private final OpenflowServiceRecoveryHandler openflowServiceRecoveryHandler;
private final ServiceRecoveryRegistry serviceRecoveryRegistry;
private final FlowGroupCacheManager flowGroupCacheManager;
+ private final ListenerRegistrationHelper registrationHelper;
@Inject
public ForwardingRulesManagerImpl(@Reference final DataBroker dataBroker,
@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");
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.");
}
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;
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
--- /dev/null
+/*
+ * 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
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;
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;
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();
}
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;
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;
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
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;
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.");
}
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
*/
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;
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);
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());
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());
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());
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());
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());
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());
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());
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());
}
@Test
- public void staleMarkedFlowCreationTest() {
-
+ public void staleMarkedFlowCreationTest() throws Exception {
addFlowCapableNode(NODE_KEY);
StaleFlowKey flowKey = new StaleFlowKey(new FlowId("stale_Flow"));
*/
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;
reconciliationManager,
openflowServiceRecoveryHandler,
serviceRecoveryRegistry,
- flowGroupCacheManager);
+ flowGroupCacheManager,
+ getRegistrationHelper()
+ );
forwardingRulesManager.start();
// TODO consider tests rewrite (added because of complicated access)
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());
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());
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());
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());
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());
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());
*/
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;
reconciliationManager,
openflowServiceRecoveryHandler,
serviceRecoveryRegistry,
- flowGroupCacheManager);
+ flowGroupCacheManager,
+ getRegistrationHelper()
+ );
forwardingRulesManager.start();
// TODO consider tests rewrite (added because of complicated access)
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());
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());
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());
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());
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());
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());
reconciliationManager,
openflowServiceRecoveryHandler,
serviceRecoveryRegistry,
- flowGroupCacheManager);
+ flowGroupCacheManager,
+ getRegistrationHelper());
+
forwardingRulesManager.start();
}
*/
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;
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);
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());
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;
// The condition supplier part
return list::size;
}
+
+ public ListenerRegistrationHelper getRegistrationHelper() {
+ ListenerRegistrationHelper registrationHelper = new ListenerRegistrationHelper(getDataBroker());
+ return registrationHelper;
+ }
}