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.List;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.mdsal.binding.api.DataObjectModification;
13 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
14 import org.opendaylight.mdsal.binding.api.DataTreeModification;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev230728.ServiceInterfacePoints;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev230728.service._interface.points.ServiceEndPoint;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public class TapiListener implements DataTreeChangeListener<ServiceInterfacePoints> {
23 private static final Logger LOG = LoggerFactory.getLogger(TapiListener.class);
24 private static final String SE_JAVA_INTF =
25 "interface org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928"
26 + ".service._interface.points.ServiceEndPoint";
29 public void onDataTreeChanged(@NonNull List<DataTreeModification<ServiceInterfacePoints>> changes) {
30 LOG.info("onDataTreeChanged in TapiListener");
31 for (DataTreeModification<ServiceInterfacePoints> change : changes) {
32 DataObjectModification<ServiceInterfacePoints> rootSIP = change.getRootNode();
33 switch (rootSIP.modificationType()) {
35 LOG.info("onDataTreeChanged in TapiListener : WRITE");
36 MappingUtils.deleteMap();
37 for (ServiceEndPoint sep : rootSIP.dataAfter().getServiceEndPoint().values()) {
38 MappingUtils.addMapSEP(sep);
40 MappingUtils.afficheMap();
42 case SUBTREE_MODIFIED:
43 LOG.info("onDataTreeChanged in TapiListener : SUBTREE_MODIFIED");
44 for (DataObjectModification<? extends DataObject> dom :
45 rootSIP.getModifiedChildren(ServiceEndPoint.class)) {
46 // to delete existing child entry
47 DataObject dataAfter = dom.dataAfter();
48 if (dataAfter == null) {
49 MappingUtils.deleteMapEntry(((ServiceEndPoint) dom.dataBefore()).getUuid());
50 MappingUtils.afficheMap();
53 // to add new child entry
54 if (dom.dataBefore() != null || dom.dataType().toString().compareTo(SE_JAVA_INTF) != 0) {
55 LOG.error("data input type is not a valid 'service-end-point'");
58 MappingUtils.addMapSEP((ServiceEndPoint) dataAfter);
59 MappingUtils.afficheMap();
63 LOG.info("onDataTreeChanged in TapiListener : DELETE");
64 MappingUtils.deleteMap();
67 LOG.error("Error of API REST modification type");