}
}
- private void initializeHwvtepTopology(LogicalDatastoreType type) {
+ private void initializeHwvtepTopology(final LogicalDatastoreType type) {
InstanceIdentifier<Topology> path = InstanceIdentifier
.create(NetworkTopology.class)
.child(Topology.class, new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID));
}
}
- public void handleOwnershipChange(EntityOwnershipChange ownershipChange) {
+ public void handleOwnershipChange(final EntityOwnershipChange ownershipChange) {
if (ownershipChange.getState().isOwner()) {
LOG.info("*This* instance of HWVTEP southbound provider is set as a MASTER instance");
LOG.info("Initialize HWVTEP topology {} in operational and config data store if not already present",
@Override
- public void onDataTreeChanged(Collection<DataTreeModification<Topology>> collection) {
+ public void onDataTreeChanged(final Collection<DataTreeModification<Topology>> collection) {
if (!registered.getAndSet(true)) {
LOG.info("Starting the ovsdb port");
ovsdbConnection.registerConnectionListener(cm);
ovsdbConnection.startOvsdbManager();
}
- //mdsal registration/deregistration in mdsal update callback should be avoided
- new Thread(() -> {
- if (operTopologyRegistration != null) {
- operTopologyRegistration.close();
- operTopologyRegistration = null;
- }
- }).start();
+
+ if (operTopologyRegistration != null) {
+ operTopologyRegistration.close();
+ operTopologyRegistration = null;
+ }
}
private static class HwvtepsbPluginInstanceEntityOwnershipListener implements EntityOwnershipListener {
private final HwvtepSouthboundProvider hsp;
private final EntityOwnershipListenerRegistration listenerRegistration;
- HwvtepsbPluginInstanceEntityOwnershipListener(HwvtepSouthboundProvider hsp,
- EntityOwnershipService entityOwnershipService) {
+ HwvtepsbPluginInstanceEntityOwnershipListener(final HwvtepSouthboundProvider hsp,
+ final EntityOwnershipService entityOwnershipService) {
this.hsp = hsp;
listenerRegistration = entityOwnershipService.registerListener(ENTITY_TYPE, this);
}
}
@Override
- public void ownershipChanged(EntityOwnershipChange ownershipChange) {
+ public void ownershipChanged(final EntityOwnershipChange ownershipChange) {
hsp.handleOwnershipChange(ownershipChange);
}
}
*/
package org.opendaylight.ovsdb.southbound;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@Reference final BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer,
@Reference final SystemReadyMonitor systemReadyMonitor,
@Reference final DiagStatusService diagStatusService) {
- this.db = dataBroker;
+ SouthboundProvider.db = dataBroker;
this.entityOwnershipService = entityOwnershipServiceDependency;
registration = null;
this.ovsdbConnection = ovsdbConnection;
ovsdbStatusProvider.reportStatus(ServiceState.UNREGISTERED, "OVSDB Service stopped");
}
- private void initializeOvsdbTopology(LogicalDatastoreType type) {
+ private void initializeOvsdbTopology(final LogicalDatastoreType type) {
InstanceIdentifier<Topology> path = InstanceIdentifier
.create(NetworkTopology.class)
.child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID));
}
}
- public void handleOwnershipChange(EntityOwnershipChange ownershipChange) {
+ public void handleOwnershipChange(final EntityOwnershipChange ownershipChange) {
if (ownershipChange.getState().isOwner()) {
LOG.info("*This* instance of OVSDB southbound provider is set as a MASTER instance");
LOG.info("Initialize OVSDB topology {} in operational and config data store if not already present",
}
@Override
- public void onDataTreeChanged(Collection<DataTreeModification<Topology>> collection) {
+ public void onDataTreeChanged(final Collection<DataTreeModification<Topology>> collection) {
if (!registered.getAndSet(true)) {
LOG.info("Starting the ovsdb port");
ovsdbConnection.registerConnectionListener(cm);
ovsdbConnection.startOvsdbManager();
LOG.info("Started OVSDB Manager (in system ready listener)");
});
- //mdsal registration/deregistration in mdsal update callback should be avoided
- new Thread(() -> {
- if (operTopologyRegistration != null) {
- operTopologyRegistration.close();
- operTopologyRegistration = null;
- }
- }).start();
+
+ if (operTopologyRegistration != null) {
+ operTopologyRegistration.close();
+ operTopologyRegistration = null;
+ }
ovsdbStatusProvider.reportStatus(ServiceState.OPERATIONAL, "OVSDB initialization complete");
}
}
private final SouthboundProvider sp;
private final EntityOwnershipListenerRegistration listenerRegistration;
- SouthboundPluginInstanceEntityOwnershipListener(SouthboundProvider sp,
- EntityOwnershipService entityOwnershipService) {
+ SouthboundPluginInstanceEntityOwnershipListener(final SouthboundProvider sp,
+ final EntityOwnershipService entityOwnershipService) {
this.sp = sp;
listenerRegistration = entityOwnershipService.registerListener(ENTITY_TYPE, this);
}
}
@Override
- public void ownershipChanged(EntityOwnershipChange ownershipChange) {
+ public void ownershipChanged(final EntityOwnershipChange ownershipChange) {
sp.handleOwnershipChange(ownershipChange);
}
}
- public void setSkipMonitoringManagerStatus(boolean flag) {
+ public void setSkipMonitoringManagerStatus(final boolean flag) {
LOG.debug("skipManagerStatus set to {}", flag);
if (flag) {
SouthboundConstants.SKIP_COLUMN_FROM_TABLE.get("Manager").add("status");
SouthboundConstants.SKIP_COLUMN_FROM_TABLE.get("Manager").remove("status");
}
}
+
+ @VisibleForTesting
+ boolean isRegistered() {
+ return registered.get();
+ }
}
* 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.ovsdb.southbound;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import static org.opendaylight.infrautils.ready.testutils.TestSystemReadyMonitor.Behaviour.IMMEDIATE;
+import com.google.common.base.Stopwatch;
+import com.google.common.util.concurrent.Uninterruptibles;
+import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.infrautils.diagstatus.DiagStatusService;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-public class SouthboundProviderTest extends AbstractDataBrokerTest {
+public class SouthboundProviderTest extends AbstractConcurrentDataBrokerTest {
private EntityOwnershipService entityOwnershipService;
+ public SouthboundProviderTest() {
+ super(true);
+ }
+
@Before
public void setUp() throws CandidateAlreadyRegisteredException {
entityOwnershipService = mock(EntityOwnershipService.class);
southboundProvider.handleOwnershipChange(new EntityOwnershipChange(entity,
EntityOwnershipChangeState.from(false, true, true)));
+ // Up to 3 seconds for DTCL to settle
+ final Stopwatch sw = Stopwatch.createStarted();
+ while (!southboundProvider.isRegistered() && sw.elapsed(TimeUnit.SECONDS) < 3) {
+ Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
+ }
+ assertTrue(southboundProvider.isRegistered());
+
// Now the OVSDB topology must be present in both trees
assertTrue(getDataBroker().newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION,
topologyIid).checkedGet().isPresent());