package org.opendaylight.ovsdb.southbound;
+import java.net.ConnectException;
import java.net.UnknownHostException;
import java.util.Collection;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-
import javax.annotation.Nonnull;
-
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.DataObjectModification;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.Augmentation;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/** The data broker. */
private final DataBroker db;
+ /** The instance identifier codec. */
+ private final InstanceIdentifierCodec instanceIdentifierCodec;
+
/** Logger. */
private static final Logger LOG = LoggerFactory.getLogger(OvsdbDataTreeChangeListener.class);
* @param db The data broker.
* @param cm The connection manager.
*/
- OvsdbDataTreeChangeListener(DataBroker db, OvsdbConnectionManager cm) {
+ OvsdbDataTreeChangeListener(DataBroker db, OvsdbConnectionManager cm,
+ InstanceIdentifierCodec instanceIdentifierCodec) {
this.cm = cm;
this.db = db;
+ this.instanceIdentifierCodec = instanceIdentifierCodec;
InstanceIdentifier<Node> path = InstanceIdentifier
.create(NetworkTopology.class)
.child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID))
InstanceIdentifier<Node> instanceIdentifier = change.getRootPath().getRootIdentifier();
cm.connect(instanceIdentifier, ovsdbNode);
LOG.info("OVSDB node has been connected: {}",ovsdbNode);
- } catch (UnknownHostException e) {
+ } catch (UnknownHostException | ConnectException e) {
LOG.warn("Failed to connect to ovsdbNode", e);
}
}
cm.disconnect(ovsdbNodeModification.getDataBefore());
cm.connect(change.getRootPath().getRootIdentifier(), ovsdbNodeModification
.getDataAfter());
- } catch (UnknownHostException e) {
+ } catch (UnknownHostException | ConnectException e) {
LOG.warn("Error disconnecting from or connecting to ovsdbNode", e);
}
}
connectionInstancesFromChanges(changes).entrySet()) {
OvsdbConnectionInstance connectionInstance = connectionInstanceEntry.getValue();
connectionInstance.transact(new TransactCommandAggregator(),
- new BridgeOperationalState(db, changes), changes);
+ new BridgeOperationalState(db, changes), changes, instanceIdentifierCodec);
}
}
new HashMap<>();
for (DataTreeModification<Node> change : changes) {
OvsdbConnectionInstance client = null;
- Node node = change.getRootNode().getDataAfter() != null?
- change.getRootNode().getDataAfter() : change.getRootNode().getDataBefore();
+ Node node = change.getRootNode().getDataAfter() != null
+ ? change.getRootNode().getDataAfter() : change.getRootNode().getDataBefore();
if (node != null) {
InstanceIdentifier<Node> nodeIid;
- Augmentation nodeAug = node.getAugmentation(OvsdbNodeAugmentation.class) !=null?
- node.getAugmentation(OvsdbNodeAugmentation.class):node.getAugmentation(OvsdbBridgeAugmentation.class);
+ Augmentation nodeAug = node.getAugmentation(OvsdbNodeAugmentation.class) != null
+ ? node.getAugmentation(OvsdbNodeAugmentation.class)
+ : node.getAugmentation(OvsdbBridgeAugmentation.class);
- if(nodeAug instanceof OvsdbNodeAugmentation) {
+ if (nodeAug instanceof OvsdbNodeAugmentation) {
OvsdbNodeAugmentation ovsdbNode = (OvsdbNodeAugmentation) nodeAug;
- if(ovsdbNode.getConnectionInfo() != null) {
+ if (ovsdbNode.getConnectionInfo() != null) {
client = cm.getConnectionInstance(ovsdbNode.getConnectionInfo());
- }else {
+ } else {
client = cm.getConnectionInstance(SouthboundMapper.createInstanceIdentifier(node.getNodeId()));
}
}
- if(nodeAug instanceof OvsdbBridgeAugmentation) {
+ if (nodeAug instanceof OvsdbBridgeAugmentation) {
OvsdbBridgeAugmentation bridgeAugmentation = (OvsdbBridgeAugmentation)nodeAug;
- if(bridgeAugmentation.getManagedBy() != null) {
+ if (bridgeAugmentation.getManagedBy() != null) {
nodeIid = (InstanceIdentifier<Node>) bridgeAugmentation.getManagedBy().getValue();
client = cm.getConnectionInstance(nodeIid);
}
}
+ if (client == null) {
+ //Try getting from change root identifier
+ client = cm.getConnectionInstance(change.getRootPath().getRootIdentifier());
+ }
} else {
LOG.warn("Following change don't have after/before data {}", change);
}