2 * Copyright © 2018 Orange 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
8 package org.opendaylight.transportpce.tapi.utils;
10 import java.util.Iterator;
11 import java.util.List;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.mdsal.binding.api.DataObjectModification;
14 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
15 import org.opendaylight.mdsal.binding.api.DataTreeModification;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev230728.ServiceInterfacePoints;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev230728.service._interface.points.ServiceEndPoint;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public class TapiListener implements DataTreeChangeListener<ServiceInterfacePoints> {
24 private static final Logger LOG = LoggerFactory.getLogger(TapiListener.class);
27 public void onDataTreeChanged(@NonNull List<DataTreeModification<ServiceInterfacePoints>> changes) {
28 LOG.info("onDataTreeChanged in TapiListener");
29 for (DataTreeModification<ServiceInterfacePoints> change : changes) {
30 DataObjectModification<ServiceInterfacePoints> rootSIP = change.getRootNode();
31 switch (rootSIP.modificationType()) {
33 LOG.info("onDataTreeChanged in TapiListener : WRITE");
34 MappingUtils.deleteMap();
35 for (ServiceEndPoint sep : rootSIP.dataAfter().getServiceEndPoint().values()) {
36 MappingUtils.addMapSEP(sep);
38 MappingUtils.afficheMap();
40 case SUBTREE_MODIFIED:
41 LOG.info("onDataTreeChanged in TapiListener : SUBTREE_MODIFIED");
42 Iterator<? extends DataObjectModification<? extends DataObject>> iterator =
43 rootSIP.getModifiedChildren(ServiceEndPoint.class).iterator();
44 if (!iterator.hasNext()) {
47 DataObjectModification<? extends DataObject> dom = iterator.next();
48 // to delete existing child entry
49 DataObject dataAfter = dom.dataAfter();
50 if (dataAfter == null) {
51 MappingUtils.deleteMapEntry(((ServiceEndPoint) dom.dataBefore()).getUuid());
52 MappingUtils.afficheMap();
55 // to add new child entry
56 if (dom.dataBefore() != null || dom.dataType().toString().compareTo(
57 "interface org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928"
58 + ".service._interface.points.ServiceEndPoint") != 0) {
59 LOG.error("data input type is not a valid 'service-end-point'");
62 MappingUtils.addMapSEP((ServiceEndPoint) dataAfter);
63 MappingUtils.afficheMap();
66 LOG.info("onDataTreeChanged in TapiListener : DELETE");
67 MappingUtils.deleteMap();
70 LOG.error("Error of API REST modification type");