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