import com.google.common.collect.Maps;
import java.util.Map;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.Hostconfigs;
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.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class NeutronHostConfigChangeListener extends AbstractDataChangeListener<Node> implements AutoCloseable {
+public class NeutronHostConfigChangeListener extends AsyncDataTreeChangeListenerBase<Node,
+ NeutronHostConfigChangeListener> implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(NeutronHostConfigChangeListener.class);
- private ListenerRegistration<DataChangeListener>listenerRegistration;
private final DataBroker dataBroker;
private final SouthboundUtils southboundUtils;
private final MdsalUtils mdsalUtils;
DELETE
}
- public NeutronHostConfigChangeListener(final DataBroker dataBroker){
- super(Node.class);
+ public NeutronHostConfigChangeListener(final DataBroker dataBroker) {
+ super(Node.class,NeutronHostConfigChangeListener.class);
this.dataBroker = dataBroker;
this.mdsalUtils = new MdsalUtils(dataBroker);
this.southboundUtils = new SouthboundUtils(mdsalUtils);
public void start() {
LOG.info("{} start", getClass().getSimpleName());
- listenerRegistration = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
- getWildCardPath(), this, AsyncDataBroker.DataChangeScope.SUBTREE);
+ registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
}
- private InstanceIdentifier<Node> getWildCardPath(){
+ @Override
+ protected InstanceIdentifier<Node> getWildCardPath() {
return InstanceIdentifier
.create(NetworkTopology.class)
.child(Topology.class,new TopologyKey(SouthboundUtils.OVSDB_TOPOLOGY_ID))
}
@Override
- public void close() throws Exception {
- if (listenerRegistration != null) {
- listenerRegistration.close();
- listenerRegistration = null;
- }
- LOG.info("{} close", getClass().getSimpleName());
+ protected NeutronHostConfigChangeListener getDataTreeChangeListener() {
+ return NeutronHostConfigChangeListener.this;
}
+
@Override
- protected void remove(InstanceIdentifier<Node>identifier, Node del){
- LOG.trace("NeutronHostConfigChangeListener.remove {}",del);
+ protected void remove(InstanceIdentifier<Node> identifier, Node del) {
updateHostConfig(del, Action.DELETE);
}
@Override
- protected void update(InstanceIdentifier<Node>identifier, Node original, Node update){
- LOG.trace("NeutronHostConfigChangeListener.update {}",update);
+ protected void update(InstanceIdentifier<Node> identifier, Node original, Node update) {
updateHostConfig(update, Action.UPDATE);
}
@Override
- protected void add(InstanceIdentifier<Node>identifier, Node add){
- LOG.trace("NeutronHostConfigChangeListener.add {}",add);
+ protected void add(InstanceIdentifier<Node> identifier, Node add) {
updateHostConfig(add, Action.ADD);
}
private void updateHostConfig(Node node, Action action) {
String hostId = getExternalId(node, OS_HOST_CONFIG_HOST_ID_KEY);
- if (hostId == null){
+ if (hostId == null) {
return;
}
- for(Map.Entry<String,String> entry : extractHostConfig(node).entrySet()) {
+ for (Map.Entry<String,String> entry : extractHostConfig(node).entrySet()) {
updateMdsal(buildHostConfigInfo(hostId, entry.getKey(), entry.getValue()), action);
}
}
hostType = hostType.substring(0, HOST_TYPE_STR_LEN);
}
hostType = "ODL " + hostType.toUpperCase();
- if (null != openvswitchExternalIds.getExternalIdValue())
+ if (null != openvswitchExternalIds.getExternalIdValue()) {
config.put(hostType, openvswitchExternalIds.getExternalIdValue());
+ }
}
}
}
result = mdsalUtils.delete(LogicalDatastoreType.OPERATIONAL, hostConfigId);
LOG.trace("Delete Node: result: {}", result);
break;
+ default:
+ LOG.warn("Invalid action: %s", action);
+ break;
}
}
return null;
}
- private OvsdbNodeAugmentation getOvsdbNodeAugmentation(Node node)
- {
+ private OvsdbNodeAugmentation getOvsdbNodeAugmentation(Node node) {
OvsdbNodeAugmentation ovsdbNode = southboundUtils.extractOvsdbNode(node);
if (ovsdbNode == null) {
Node nodeFromReadOvsdbNode = southboundUtils.readOvsdbNode(node);