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.EvcAddCommand;
17 import org.opendaylight.unimgr.command.EvcRemoveCommand;
18 import org.opendaylight.unimgr.command.EvcUpdateCommand;
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.Link;
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 EvcDataTreeChangeListener extends UnimgrDataTreeChangeListener<Link> {
30 private static final Logger LOG = LoggerFactory.getLogger(EvcDataTreeChangeListener.class);
31 private final ListenerRegistration<EvcDataTreeChangeListener> listener;
33 public EvcDataTreeChangeListener(final DataBroker dataBroker) {
35 final DataTreeIdentifier<Link> dataTreeIid = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getEvcTopologyPath());
36 listener = dataBroker.registerDataTreeChangeListener(dataTreeIid, this);
37 LOG.info("EvcDataTreeChangeListener created and registered");
41 public void add(final DataTreeModification<Link> newDataObject) {
42 if(newDataObject.getRootPath() != null && newDataObject.getRootNode() != null) {
43 LOG.info("evc link {} created", newDataObject.getRootNode().getIdentifier());
44 final EvcAddCommand evcAddCmd = new EvcAddCommand(dataBroker, newDataObject);
50 public void close() throws Exception {
54 private InstanceIdentifier<Link> getEvcTopologyPath() {
55 final InstanceIdentifier<Link> evcPath = InstanceIdentifier
56 .create(NetworkTopology.class)
57 .child(Topology.class, new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
63 public void remove(final DataTreeModification<Link> removedDataObject) {
64 if(removedDataObject.getRootPath() != null && removedDataObject.getRootNode() != null) {
65 LOG.info("evc link {} deleted", removedDataObject.getRootNode().getIdentifier());
66 final EvcRemoveCommand evcRemovedCmd = new EvcRemoveCommand(dataBroker, removedDataObject);
67 evcRemovedCmd.execute();
72 public void update(final DataTreeModification<Link> modifiedDataObject) {
73 if(modifiedDataObject.getRootPath() != null && modifiedDataObject.getRootNode() != null) {
74 LOG.info("evc link {} updated", modifiedDataObject.getRootNode().getIdentifier());
75 final EvcUpdateCommand evcUpdateCmd = new EvcUpdateCommand(dataBroker, modifiedDataObject);
76 evcUpdateCmd.execute();