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.Collection;
11 import java.util.Iterator;
12 import java.util.List;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.mdsal.binding.api.DataObjectModification;
15 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
16 import org.opendaylight.mdsal.binding.api.DataTreeModification;
17 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.ServiceInterfacePoints;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.service._interface.points.ServiceEndPoint;
20 import org.opendaylight.yangtools.yang.binding.DataObject;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public class TapiListener implements DataTreeChangeListener<ServiceInterfacePoints> {
26 private static final Logger LOG = LoggerFactory.getLogger(TapiListener.class);
29 public void onDataTreeChanged(@NonNull Collection<DataTreeModification<ServiceInterfacePoints>> changes) {
30 LOG.info("onDataTreeChanged in TapiListener");
31 for (DataTreeModification<ServiceInterfacePoints> change : changes) {
32 DataObjectModification<ServiceInterfacePoints> rootSIP = change.getRootNode();
33 switch (rootSIP.getModificationType()) {
35 LOG.info("onDataTreeChanged in TapiListener : WRITE");
36 ServiceInterfacePoints data = rootSIP.getDataAfter();
37 List<ServiceEndPoint> listSEP = data.getServiceEndPoint();
38 MappingUtils.deleteMap();
39 for (ServiceEndPoint sep : listSEP) {
40 MappingUtils.addMapSEP(sep);
42 MappingUtils.afficheMap();
44 case SUBTREE_MODIFIED:
45 LOG.info("onDataTreeChanged in TapiListener : SUBTREE_MODIFIED");
46 Iterator<? extends DataObjectModification<? extends DataObject>> iterator = rootSIP
47 .getModifiedChildren().iterator();
48 while (iterator.hasNext()) {
49 DataObjectModification<? extends DataObject> dom = iterator.next();
50 // to delete existing child entry
51 if (dom.getDataAfter() == null) {
52 DataObject dataObject = dom.getDataBefore();
53 ServiceEndPoint sep = null;
54 sep = (ServiceEndPoint) dataObject;
55 Uuid uuid = sep.getUuid();
56 MappingUtils.deleteMapEntry(uuid);
57 MappingUtils.afficheMap();
61 // to add new child entry
62 if (dom.getDataType().toString().compareTo("interface org.opendaylight.yang.gen.v1.urn.opendayl"
63 + "ight.params.xml.ns.yang.tapi.rev180928.service._interface.points.ServiceEndPoint") == 0
64 && dom.getDataBefore() == null) {
65 DataObject dataObject = dom.getDataAfter();
66 ServiceEndPoint sep = null;
67 sep = (ServiceEndPoint) dataObject;
68 MappingUtils.addMapSEP(sep);
69 MappingUtils.afficheMap();
71 LOG.error("data input type is not a valid 'service-end-point'");
77 LOG.info("onDataTreeChanged in TapiListener : DELETE");
78 MappingUtils.deleteMap();
81 LOG.error("Error of API REST modification type");