2 * Copyright © 2018 Orange, Inc. 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.HashMap;
12 import java.util.Map.Entry;
14 import org.opendaylight.transportpce.tapi.connectivity.ConnectivityUtils;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.create.input.ServiceAEnd;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.create.input.ServiceZEnd;
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.EndPointType;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.service._interface.points.ServiceEndPoint;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public final class MappingUtils {
25 private static final Logger LOG = LoggerFactory.getLogger(MappingUtils.class);
27 private static Map<Uuid, GenericServiceEndpoint> map = new HashMap<>();
29 private MappingUtils() {
32 private static GenericServiceEndpoint createMapEntry(ServiceEndPoint sep) {
33 if (sep.getEndPoint().getServiceEndPointType().equals(EndPointType.Aend)) {
34 ServiceAEnd sepG = ConnectivityUtils.buildServiceAEnd(sep.getEndPoint().getNodeId().getValue(),
35 sep.getEndPoint().getClli(),
36 sep.getEndPoint().getTxDirection().values().stream().findFirst().orElseThrow().getPort()
38 sep.getEndPoint().getTxDirection().values().stream().findFirst().orElseThrow().getPort()
40 sep.getEndPoint().getRxDirection().values().stream().findFirst().orElseThrow().getPort()
42 sep.getEndPoint().getRxDirection().values().stream().findFirst().orElseThrow().getPort()
44 return new GenericServiceEndpoint(sepG, ServiceEndpointType.SERVICEAEND);
46 ServiceZEnd sepG = ConnectivityUtils.buildServiceZEnd(sep.getEndPoint().getNodeId().getValue(),
47 sep.getEndPoint().getClli(),
48 sep.getEndPoint().getTxDirection().values().stream().findFirst().orElseThrow().getPort()
50 sep.getEndPoint().getTxDirection().values().stream().findFirst().orElseThrow().getPort()
52 sep.getEndPoint().getRxDirection().values().stream().findFirst().orElseThrow().getPort()
54 sep.getEndPoint().getRxDirection().values().stream().findFirst().orElseThrow().getPort()
56 return new GenericServiceEndpoint(sepG, ServiceEndpointType.SERVICEZEND);
60 public static void addMapSEP(ServiceEndPoint sep) {
61 Uuid uuid = sep.getUuid();
62 if (!map.containsKey(uuid)) {
63 LOG.info("adding new entry {} into static map", uuid);
64 map.put(uuid, MappingUtils.createMapEntry(sep));
66 LOG.error("service-end-point entry already exist. Please DELETE it before PUT it...");
70 public static void deleteMapEntry(Uuid uuid) {
71 if (map.containsKey(uuid)) {
72 LOG.info("map size = {}", Integer.toString(map.size()));
74 LOG.info("map size = {}", Integer.toString(map.size()));
76 LOG.info("No existing entry with uuid {}", uuid);
80 public static void afficheMap() {
82 Set<Entry<Uuid, GenericServiceEndpoint>> entries = map.entrySet();
83 LOG.info("Displaying the static map...");
84 for (Entry<Uuid, GenericServiceEndpoint> entry : entries) {
85 LOG.info("uuid = {} \t service end point = {}", entry.getKey(), entry.getValue().getValue());
88 LOG.info("Static map is empty - Nothing to display");
93 public static void deleteMap() {
97 LOG.info("Static map is already empty - Nothing to delete");
101 public static Map<Uuid, GenericServiceEndpoint> getMap() {