2 * Copyright (c) 2016 CableLabs and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.unimgr.impl;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
13 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.unimgr.api.UnimgrDataTreeChangeListener;
16 import org.opendaylight.unimgr.command.UniAddCommand;
17 import org.opendaylight.unimgr.command.UniRemoveCommand;
18 import org.opendaylight.unimgr.command.UniUpdateCommand;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
23 import org.opendaylight.yangtools.concepts.ListenerRegistration;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class UniDataTreeChangeListener extends UnimgrDataTreeChangeListener<Node> {
30 private static final Logger LOG = LoggerFactory.getLogger(UniDataTreeChangeListener.class);
31 private final ListenerRegistration<UniDataTreeChangeListener> listener;
34 public UniDataTreeChangeListener(final DataBroker dataBroker) {
36 final InstanceIdentifier<Node> uniPath = getUniTopologyPath();
37 final DataTreeIdentifier<Node> dataTreeIid = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, uniPath);
38 listener = dataBroker.registerDataTreeChangeListener(dataTreeIid, this);
39 LOG.info("UniDataTreeChangeListener created and registered");
43 public void add(final DataTreeModification<Node> newDataObject) {
44 if (newDataObject.getRootPath() != null && newDataObject.getRootNode() != null) {
45 LOG.info("uni node {} created", newDataObject.getRootNode().getIdentifier());
46 final UniAddCommand uniAddCmd = new UniAddCommand(dataBroker, newDataObject);
52 public void close() throws Exception {
56 private InstanceIdentifier<Node> getUniTopologyPath() {
57 final InstanceIdentifier<Node> nodePath = InstanceIdentifier
58 .create(NetworkTopology.class)
59 .child(Topology.class,
60 new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
66 public void remove(final DataTreeModification<Node> removedDataObject) {
67 if (removedDataObject.getRootPath() != null && removedDataObject.getRootNode() != null) {
68 LOG.info("uni node {} deleted", removedDataObject.getRootNode().getIdentifier());
69 final UniRemoveCommand uniRemoveCmd = new UniRemoveCommand(dataBroker, removedDataObject);
70 uniRemoveCmd.execute();
75 public void update(final DataTreeModification<Node> modifiedDataObject) {
76 if (modifiedDataObject.getRootPath() != null && modifiedDataObject.getRootNode() != null) {
77 LOG.info("uni node {} created", modifiedDataObject.getRootNode().getIdentifier());
78 final UniUpdateCommand uniUpdateCmd = new UniUpdateCommand(dataBroker, modifiedDataObject);
79 uniUpdateCmd.execute();