import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
-
import java.util.Collection;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
-
import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener;
import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration;
import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipState;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
private static final Logger LOG = LoggerFactory.getLogger(HwvtepSouthboundProvider.class);
private static final String ENTITY_TYPE = "ovsdb-hwvtepsouthbound-provider";
- public static DataBroker getDb() {
- return db;
- }
-
- private static DataBroker db;
+ private final DataBroker dataBroker;
private final EntityOwnershipService entityOwnershipService;
private final OvsdbConnection ovsdbConnection;
private HwvtepsbPluginInstanceEntityOwnershipListener providerOwnershipChangeListener;
private HwvtepDataChangeListener hwvtepDTListener;
private HwvtepReconciliationManager hwvtepReconciliationManager;
- private AtomicBoolean registered = new AtomicBoolean(false);
+ private final AtomicBoolean registered = new AtomicBoolean(false);
private ListenerRegistration<HwvtepSouthboundProvider> operTopologyRegistration;
public HwvtepSouthboundProvider(final DataBroker dataBroker,
final OvsdbConnection ovsdbConnection,
final DOMSchemaService schemaService,
final BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer) {
- this.db = dataBroker;
+ this.dataBroker = dataBroker;
this.entityOwnershipService = entityOwnershipServiceDependency;
registration = null;
this.ovsdbConnection = ovsdbConnection;
*/
public void init() {
LOG.info("HwvtepSouthboundProvider Session Initiated");
- txInvoker = new TransactionInvokerImpl(db);
- cm = new HwvtepConnectionManager(db, txInvoker, entityOwnershipService);
- hwvtepDTListener = new HwvtepDataChangeListener(db, cm);
- hwvtepReconciliationManager = new HwvtepReconciliationManager(db, cm);
+ txInvoker = new TransactionInvokerImpl(dataBroker);
+ cm = new HwvtepConnectionManager(dataBroker, txInvoker, entityOwnershipService);
+ hwvtepDTListener = new HwvtepDataChangeListener(dataBroker, cm);
+ hwvtepReconciliationManager = new HwvtepReconciliationManager(dataBroker, cm);
//Register listener for entityOnwership changes
providerOwnershipChangeListener =
new HwvtepsbPluginInstanceEntityOwnershipListener(this,this.entityOwnershipService);
//register instance entity to get the ownership of the provider
Entity instanceEntity = new Entity(ENTITY_TYPE, ENTITY_TYPE);
try {
- Optional<EntityOwnershipState> ownershipStateOpt = entityOwnershipService.getOwnershipState(instanceEntity);
registration = entityOwnershipService.registerCandidate(instanceEntity);
} catch (CandidateAlreadyRegisteredException e) {
LOG.warn("HWVTEP Southbound Provider instance entity {} was already "
.create(NetworkTopology.class)
.child(Topology.class, new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID));
DataTreeIdentifier<Topology> treeId =
- new DataTreeIdentifier<Topology>(LogicalDatastoreType.OPERATIONAL, path);
+ new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, path);
LOG.trace("Registering listener for path {}", treeId);
- operTopologyRegistration = db.registerDataTreeChangeListener(treeId, this);
+ operTopologyRegistration = dataBroker.registerDataTreeChangeListener(treeId, this);
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
public void close() throws Exception {
LOG.info("HwvtepSouthboundProvider Closed");
if (txInvoker != null) {
LOG.error("HWVTEP Southbound Provider failed to close TransactionInvoker", e);
}
}
- if(cm != null){
+ if (cm != null) {
cm.close();
cm = null;
}
- if(registration != null) {
+ if (registration != null) {
registration.close();
registration = null;
}
- if(providerOwnershipChangeListener != null) {
+ if (providerOwnershipChangeListener != null) {
providerOwnershipChangeListener.close();
providerOwnershipChangeListener = null;
}
- if(hwvtepDTListener != null) {
+ if (hwvtepDTListener != null) {
hwvtepDTListener.close();
hwvtepDTListener = null;
}
InstanceIdentifier<Topology> path = InstanceIdentifier
.create(NetworkTopology.class)
.child(Topology.class, new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID));
- ReadWriteTransaction transaction = db.newReadWriteTransaction();
+ ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
CheckedFuture<Optional<Topology>, ReadFailedException> hwvtepTp = transaction.read(type, path);
try {
if (!hwvtepTp.get().isPresent()) {
} else {
transaction.cancel();
}
- } catch (Exception e) {
+ } catch (InterruptedException | ExecutionException e) {
LOG.error("Error initializing hwvtep topology", e);
}
}
public void handleOwnershipChange(EntityOwnershipChange ownershipChange) {
if (ownershipChange.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"
- ,HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID);
+ LOG.info("Initialize HWVTEP topology {} in operational and config data store if not already present",
+ HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID);
initializeHwvtepTopology(LogicalDatastoreType.OPERATIONAL);
initializeHwvtepTopology(LogicalDatastoreType.CONFIGURATION);
} else {
}).start();
}
- private class HwvtepsbPluginInstanceEntityOwnershipListener implements EntityOwnershipListener {
- private HwvtepSouthboundProvider hsp;
- private EntityOwnershipListenerRegistration listenerRegistration;
+ private static class HwvtepsbPluginInstanceEntityOwnershipListener implements EntityOwnershipListener {
+ private final HwvtepSouthboundProvider hsp;
+ private final EntityOwnershipListenerRegistration listenerRegistration;
HwvtepsbPluginInstanceEntityOwnershipListener(HwvtepSouthboundProvider hsp,
EntityOwnershipService entityOwnershipService) {
public void close() {
this.listenerRegistration.close();
}
+
@Override
public void ownershipChanged(EntityOwnershipChange ownershipChange) {
hsp.handleOwnershipChange(ownershipChange);