Update release in docs/conf.yaml
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / ModelMappingUtils.java
1 /*
2  * Copyright © 2017 AT&T and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.transportpce.renderer;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import java.math.BigDecimal;
13 import java.util.ArrayList;
14 import java.util.HashSet;
15 import java.util.Iterator;
16 import java.util.List;
17 import java.util.Map;
18 import java.util.Set;
19 import java.util.TreeMap;
20 import java.util.stream.Collectors;
21 import org.opendaylight.transportpce.common.NodeIdPair;
22 import org.opendaylight.transportpce.common.StringConstants;
23 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
24 import org.opendaylight.transportpce.common.fixedflex.GridUtils;
25 import org.opendaylight.transportpce.common.mapping.PortMappingUtils;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.Action;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathInput;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathInputBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInput;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInputBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.AEndApiInfo;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.AEndApiInfoBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.ZEndApiInfo;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.ZEndApiInfoBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInputBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutput;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutputBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestInput;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutput;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutputBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommon;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommonBuilder;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyGHz;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.ModulationFormat;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.OpucnTribSlotDef;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteInput;
49 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.PathDescription;
50 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.AToZDirection;
51 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ZToADirection;
52 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZ;
53 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ztoa.direction.ZToA;
54 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.Resource;
55 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.Link;
56 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.TerminationPoint;
57 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.optical.renderer.nodes.Nodes;
58 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.optical.renderer.nodes.NodesBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.optical.renderer.nodes.NodesKey;
60 import org.opendaylight.yangtools.yang.common.Decimal64;
61 import org.opendaylight.yangtools.yang.common.RpcResult;
62 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
63 import org.opendaylight.yangtools.yang.common.Uint32;
64 import org.slf4j.Logger;
65 import org.slf4j.LoggerFactory;
66
67
68 public final class ModelMappingUtils {
69
70     private static final Logger LOG = LoggerFactory.getLogger(ModelMappingUtils.class);
71     private static final String TERMINATION_POINT = "TerminationPoint";
72     private static final String LINK = "Link";
73
74     private ModelMappingUtils() {
75     }
76
77     public static ServicePowerSetupInput createServicePowerSetupInput(List<Nodes> olmList,
78             ServiceImplementationRequestInput input) {
79         ServicePowerSetupInputBuilder olmSetupBldr = new ServicePowerSetupInputBuilder().setNodes(olmList);
80         if (input != null && input.getPathDescription() != null
81                 && input.getPathDescription().getAToZDirection() != null) {
82             AToZDirection atoZDirection = input.getPathDescription().getAToZDirection();
83             olmSetupBldr.setWaveNumber(atoZDirection.getAToZWavelengthNumber());
84             if (atoZDirection.getAToZMinFrequency() != null) {
85                 olmSetupBldr.setLowerSpectralSlotNumber(Uint32
86                     .valueOf(GridUtils
87                         .getLowerSpectralIndexFromFrequency(atoZDirection.getAToZMinFrequency().getValue())));
88             }
89             if (atoZDirection.getAToZMaxFrequency() != null) {
90                 olmSetupBldr.setHigherSpectralSlotNumber(Uint32
91                     .valueOf(GridUtils
92                         .getHigherSpectralIndexFromFrequency(atoZDirection.getAToZMaxFrequency().getValue())));
93             }
94             // Set the MC-width for the OLM
95             olmSetupBldr.setMcWidth(new FrequencyGHz(Decimal64.valueOf(
96                     atoZDirection.getAToZMaxFrequency().getValue().decimalValue()
97                     .subtract(atoZDirection.getAToZMinFrequency().getValue().decimalValue())
98                     .multiply(new BigDecimal(1000)))));
99         }
100         return olmSetupBldr.build();
101     }
102
103     public static ServiceImplementationRequestOutput createServiceImplResponse(String responseCode, String message) {
104         return new ServiceImplementationRequestOutputBuilder()
105                 .setConfigurationResponseCommon(createCommonResponse(responseCode, message))
106                 .build();
107     }
108
109     public static ServiceDeleteOutput createServiceDeleteResponse(String responseCode, String message) {
110         return new ServiceDeleteOutputBuilder()
111                 .setConfigurationResponseCommon(createCommonResponse(responseCode, message))
112                 .build();
113     }
114
115     public static ConfigurationResponseCommon createCommonResponse(String responseCode, String message) {
116         return new ConfigurationResponseCommonBuilder()
117                 .setResponseMessage(message)
118                 .setResponseCode(responseCode)
119                 .build();
120     }
121
122     public static ListenableFuture<RpcResult<ServiceImplementationRequestOutput>>
123             createServiceImplementationRpcResponse(ServiceImplementationRequestOutput payload) {
124         return RpcResultBuilder.success(payload).buildFuture();
125     }
126
127     public static ListenableFuture<RpcResult<ServiceDeleteOutput>>
128             createServiceDeleteRpcResponse(ServiceDeleteOutput payload) {
129         return RpcResultBuilder.success(payload).buildFuture();
130     }
131
132     public static ServicePathInputData rendererCreateServiceInputAToZ(String serviceName,
133             PathDescription pathDescription, Action operation) {
134         int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
135         AToZDirection atoZDirection = pathDescription.getAToZDirection();
136         LOG.info("Building ServicePathInputData for a to z direction {}", atoZDirection);
137         NodeLists nodeLists = getNodesListAToZ(atoZDirection.nonnullAToZ().values().iterator());
138         ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
139             .setServiceName(serviceName)
140             .setOperation(operation)
141             .setNodes(nodeLists.getRendererNodeList())
142             .setNmcWidth(new FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40)))
143             .setMcWidth(new FrequencyGHz(Decimal64.valueOf(
144                     pathDescription.getAToZDirection().getAToZMaxFrequency().getValue().decimalValue()
145                     .subtract(pathDescription.getAToZDirection().getAToZMinFrequency().getValue().decimalValue()))));
146         if (atoZDirection.getAToZWavelengthNumber() != null) {
147             servicePathInputBuilder
148                 .setWaveNumber(atoZDirection.getAToZWavelengthNumber());
149         }
150         if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
151                 .equals(atoZDirection.getAToZWavelengthNumber())) {
152             scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
153         }
154         if (atoZDirection.getAToZMinFrequency() != null) {
155             servicePathInputBuilder.setMinFreq(new FrequencyTHz(atoZDirection.getAToZMinFrequency().getValue()));
156             servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
157                     .valueOf(GridUtils
158                             .getLowerSpectralIndexFromFrequency(atoZDirection.getAToZMinFrequency().getValue())));
159         }
160         if (atoZDirection.getAToZMaxFrequency() != null) {
161             servicePathInputBuilder.setMaxFreq(new FrequencyTHz(atoZDirection.getAToZMaxFrequency().getValue()));
162             servicePathInputBuilder.setHigherSpectralSlotNumber(
163                     Uint32.valueOf(GridUtils
164                             .getHigherSpectralIndexFromFrequency(atoZDirection.getAToZMaxFrequency().getValue())));
165         }
166         if (atoZDirection.getAToZMinFrequency() != null && atoZDirection.getAToZMaxFrequency() != null) {
167             servicePathInputBuilder.setCenterFreq(GridUtils.getCentralFrequencyWithPrecision(
168                     atoZDirection.getAToZMinFrequency().getValue().decimalValue(),
169                     atoZDirection.getAToZMaxFrequency().getValue().decimalValue(),
170                     scale));
171         }
172         if (atoZDirection.getRate() != null && atoZDirection.getModulationFormat() != null) {
173             ModulationFormat modulationFormat = ModulationFormat.forName(atoZDirection.getModulationFormat());
174             if (modulationFormat != null
175                     && GridConstant.FREQUENCY_WIDTH_TABLE
176                     .contains(atoZDirection.getRate(), modulationFormat)) {
177                 servicePathInputBuilder
178                     .setNmcWidth(FrequencyGHz
179                         .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(atoZDirection.getRate(),
180                         modulationFormat)));
181             }
182         }
183         servicePathInputBuilder.setModulationFormat(atoZDirection.getModulationFormat())
184             .setAEndApiInfo(createAendApiInfo(pathDescription, false))
185             .setZEndApiInfo(createZendApiInfo(pathDescription, false));
186         return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
187     }
188
189     public static ServicePathInputData rendererCreateServiceInputZToA(String serviceName,
190             PathDescription pathDescription, Action operation) {
191         int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
192         ZToADirection ztoADirection = pathDescription.getZToADirection();
193         LOG.info("Building ServicePathInputData for z to a direction {}", ztoADirection);
194         NodeLists nodeLists = getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
195         ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
196             .setOperation(operation)
197             .setServiceName(serviceName)
198             .setNodes(nodeLists.getRendererNodeList())
199             .setNmcWidth(new FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40)))
200             .setMcWidth(new FrequencyGHz(Decimal64.valueOf(
201                     pathDescription.getAToZDirection().getAToZMaxFrequency().getValue().decimalValue()
202                     .subtract(pathDescription.getAToZDirection().getAToZMinFrequency().getValue().decimalValue()))));
203         if (ztoADirection.getZToAWavelengthNumber() != null) {
204             servicePathInputBuilder
205                 .setWaveNumber(ztoADirection.getZToAWavelengthNumber());
206         }
207         if (Uint32.valueOf(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER)
208                 .equals(ztoADirection.getZToAWavelengthNumber())) {
209             scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
210         }
211         if (ztoADirection.getZToAMinFrequency() != null) {
212             servicePathInputBuilder.setMinFreq(new FrequencyTHz(ztoADirection.getZToAMinFrequency().getValue()));
213             servicePathInputBuilder.setLowerSpectralSlotNumber(Uint32
214                     .valueOf(GridUtils
215                             .getLowerSpectralIndexFromFrequency(ztoADirection.getZToAMinFrequency().getValue())));
216         }
217         if (ztoADirection.getZToAMaxFrequency() != null) {
218             servicePathInputBuilder.setMaxFreq(new FrequencyTHz(ztoADirection.getZToAMaxFrequency().getValue()));
219             servicePathInputBuilder.setHigherSpectralSlotNumber(
220                     Uint32.valueOf(GridUtils
221                             .getHigherSpectralIndexFromFrequency(ztoADirection.getZToAMaxFrequency().getValue())));
222         }
223         if (ztoADirection.getZToAMinFrequency() != null && ztoADirection.getZToAMaxFrequency() != null) {
224             servicePathInputBuilder.setCenterFreq(GridUtils.getCentralFrequencyWithPrecision(
225                     ztoADirection.getZToAMinFrequency().getValue().decimalValue(),
226                     ztoADirection.getZToAMaxFrequency().getValue().decimalValue(),
227                     scale));
228         }
229         if (ztoADirection.getRate() != null && ztoADirection.getModulationFormat() != null) {
230             ModulationFormat modulationFormat = ModulationFormat.forName(ztoADirection.getModulationFormat());
231             if (modulationFormat != null
232                     && GridConstant.FREQUENCY_WIDTH_TABLE
233                     .contains(ztoADirection.getRate(), modulationFormat)) {
234                 servicePathInputBuilder.setNmcWidth(FrequencyGHz
235                         .getDefaultInstance(GridConstant.FREQUENCY_WIDTH_TABLE.get(ztoADirection.getRate(),
236                                 modulationFormat)));
237             }
238         }
239         servicePathInputBuilder.setModulationFormat(ztoADirection.getModulationFormat())
240             .setAEndApiInfo(createAendApiInfo(pathDescription, false))
241             .setZEndApiInfo(createZendApiInfo(pathDescription, false));
242         return new ServicePathInputData(servicePathInputBuilder.build(), nodeLists);
243     }
244
245     // Adding createOtnServiceInputpath for A-Z and Z-A directions as one method
246     public static OtnServicePathInput rendererCreateOtnServiceInput(String serviceName, Action operation,
247         String serviceFormat, Uint32 serviceRate, PathDescription pathDescription, boolean asideToZside) {
248         // If atoZ is set true use A-to-Z direction otherwise use Z-to-A
249         List<org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.otn.renderer.nodes.Nodes> nodes =
250             new ArrayList<>();
251         NodeLists nodeLists =
252             (asideToZside)
253             ? getNodesListAToZ(pathDescription.getAToZDirection().nonnullAToZ().values().iterator())
254             : getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
255         LOG.info("These are node-lists {}, {}", nodeLists.getRendererNodeList(), nodeLists.getOlmNodeList());
256         for (Nodes node: nodeLists.getRendererNodeList()) {
257             org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.otn.renderer.nodes.NodesBuilder nb
258                 = new org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.otn.renderer.nodes
259                     .NodesBuilder().setNodeId(node.getNodeId()).setNetworkTp(node.getDestTp());
260             if (node.getSrcTp() != null && node.getSrcTp().contains("NETWORK")) {
261                 nb.setNetwork2Tp(node.getSrcTp());
262             } else {
263                 nb.setClientTp(node.getSrcTp());
264             }
265             nodes.add(nb.build());
266         }
267         OtnServicePathInputBuilder otnServicePathInputBuilder = new OtnServicePathInputBuilder()
268             .setServiceName(serviceName)
269             .setOperation(operation)
270             .setServiceFormat(serviceFormat)
271             .setServiceRate(serviceRate)
272             .setNodes(nodes)
273             .setAEndApiInfo(createAendApiInfo(pathDescription, true))
274             .setZEndApiInfo(createZendApiInfo(pathDescription, true));
275
276         // set the trib-slots and trib-ports for the lower oder odu
277         if (serviceRate.intValue() == 1 || (serviceRate.intValue() == 10)) {
278             Short tribPort = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
279                 .split("\\.")[0]);
280             Short minTribSlot = Short.valueOf(pathDescription.getAToZDirection().getMinTribSlot().getValue()
281                 .split("\\.")[1]);
282             otnServicePathInputBuilder
283                 .setTribPortNumber(tribPort)
284                 .setTribSlot(minTribSlot);
285         }
286         if (serviceRate.intValue() == 100 && pathDescription.getAToZDirection().getMinTribSlot() != null
287                 && pathDescription.getAToZDirection().getMaxTribSlot() != null) {
288             Set<OpucnTribSlotDef> opucnTribSlotDefList = new HashSet<>();
289             opucnTribSlotDefList.add(
290                 new OpucnTribSlotDef(pathDescription.getAToZDirection().getMinTribSlot().getValue()));
291             opucnTribSlotDefList.add(
292                 new OpucnTribSlotDef(pathDescription.getAToZDirection().getMaxTribSlot().getValue()));
293             otnServicePathInputBuilder.setOpucnTribSlots(opucnTribSlotDefList);
294         }
295         return otnServicePathInputBuilder.build();
296     }
297
298     public static ServicePathInput rendererDeleteServiceInput(String serviceName,
299             ServiceDeleteInput serviceDeleteInput) {
300         //TODO: finish model-model mapping
301         return new ServicePathInputBuilder().setServiceName(serviceName).build();
302     }
303
304     public static Set<String> getLinksFromServicePathDescription(PathDescription pathDescription) {
305         Set<String> linkidList = new HashSet<>();
306         pathDescription.getAToZDirection().getAToZ().values().stream()
307             .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
308             .forEach(rsc -> {
309                 Link link = (Link) rsc.getResource().getResource();
310                 linkidList.add(link.getLinkId());
311             });
312         pathDescription.getZToADirection().getZToA().values().stream()
313             .filter(lk -> "Link".equals(lk.getResource().getResource().implementedInterface().getSimpleName()))
314             .forEach(rsc -> {
315                 Link link = (Link) rsc.getResource().getResource();
316                 linkidList.add(link.getLinkId());
317             });
318         return linkidList;
319     }
320
321     private static NodeLists getNodesListZtoA(Iterator<ZToA> iterator) {
322         Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
323         List<Nodes> olmList = new ArrayList<>();
324         List<Nodes> list = new ArrayList<>();
325
326         while (iterator.hasNext()) {
327             ZToA pathDesObj = iterator.next();
328             try {
329                 populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "ZtoA");
330             } catch (IllegalArgumentException | SecurityException e) {
331                 //TODO: Auto-generated catch block
332                 LOG.error("Did not find the getResource method", e);
333             }
334         }
335         populateNodeLists(treeMap, list, olmList, false);
336         return new NodeLists(olmList, list);
337     }
338
339     private static NodeLists getNodesListAToZ(Iterator<AToZ> iterator) {
340         Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
341         List<Nodes> list = new ArrayList<>();
342         List<Nodes> olmList = new ArrayList<>();
343
344         while (iterator.hasNext()) {
345             AToZ pathDesObj = iterator.next();
346             try {
347                 populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "AtoZ");
348             } catch (IllegalArgumentException | SecurityException e) {
349                 //TODO: Auto-generated catch block
350                 LOG.error("Did not find the getResource method", e);
351             }
352         }
353         populateNodeLists(treeMap, list, olmList, true);
354         return new NodeLists(olmList, list);
355     }
356
357     private static void populateTreeMap(Map<Integer, NodeIdPair> treeMap, Resource rsrc, String sortId,
358             String direction) {
359         String resourceType = rsrc.implementedInterface().getSimpleName();
360         LOG.info("Inside {} {}", direction, resourceType);
361         switch (resourceType) {
362             case TERMINATION_POINT:
363                 TerminationPoint tp = (TerminationPoint) rsrc;
364                 LOG.info(" TP is {} {}", tp.getTpId(), tp.getTpNodeId());
365                 String tpID = tp.getTpId();
366
367                 //TODO: do not rely on ID to be in certain format
368                 if (tpID.contains("CTP") || tpID.contains("CP")) {
369                     return;
370                 }
371                 String nodeID = "";
372                 if (tpID.contains(StringConstants.TTP_TOKEN)) {
373                     nodeID = tp.getTpNodeId().split("-DEG")[0];
374                 } else if (tpID.contains(StringConstants.PP_TOKEN)) {
375                     nodeID = tp.getTpNodeId().split("-SRG")[0];
376                 } else if (tpID.contains(StringConstants.NETWORK_TOKEN)
377                         || tpID.contains(StringConstants.CLIENT_TOKEN) || tpID.isEmpty()) {
378                     nodeID = tp.getTpNodeId().split("-XPDR")[0];
379                 } else {
380                     return;
381                 }
382                 int id = Integer.parseInt(sortId);
383                 treeMap.put(id, new NodeIdPair(nodeID, tpID));
384                 return;
385             case LINK:
386                 LOG.info("The type is link");
387                 return;
388             default:
389                 LOG.info("The type is not identified: {}", resourceType);
390                 return;
391         }
392     }
393
394     @SuppressFBWarnings(
395         value = {"NP_LOAD_OF_KNOWN_NULL_VALUE","RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"},
396         justification = "loop when value is not always null - "
397                 + "TODO: check if something exists in Java lib")
398     private static void populateNodeLists(Map<Integer, NodeIdPair> treeMap, List<Nodes> list, List<Nodes> olmList,
399             boolean isAToz) {
400         String desID = null;
401         String srcID = null;
402         LOG.info("treeMap values = {}", treeMap.values());
403         for (NodeIdPair values : treeMap.values()) {
404             if (srcID == null) {
405                 srcID = values.getTpID();
406             } else if (desID == null) {
407                 desID = values.getTpID();
408                 NodesBuilder olmNb = new NodesBuilder()
409                     .setNodeId(values.getNodeID())
410                     .setDestTp(desID)
411                     .setSrcTp(srcID);
412                 olmList.add(olmNb.build());
413                 if (srcID.isEmpty()) {
414                     srcID = null;
415                 }
416                 if (desID.isEmpty()) {
417                     desID = new StringBuilder(srcID).toString();
418                     srcID = null;
419                 }
420                 if (isAToz) {
421                     NodesBuilder nb = new NodesBuilder()
422                         .withKey(new NodesKey(values.getNodeID()))
423                         .setDestTp(desID)
424                         .setSrcTp(srcID);
425                     if (srcID != null && desID != null && srcID.contains(StringConstants.NETWORK_TOKEN)) {
426                         nb.setDestTp(srcID).setSrcTp(desID);
427                     }
428                     list.add(nb.build());
429                 } else {
430                     if (srcID != null && desID != null && !srcID.contains(StringConstants.NETWORK_TOKEN)
431                         && !desID.contains(StringConstants.NETWORK_TOKEN)) {
432                         NodesBuilder nb = new NodesBuilder()
433                             .withKey(new NodesKey(values.getNodeID()))
434                             .setDestTp(desID)
435                             .setSrcTp(srcID);
436                         list.add(nb.build());
437                     }
438                 }
439                 srcID = null;
440                 desID = null;
441             } else {
442                 LOG.warn("both, the source and destination id are not null!");
443             }
444         }
445     }
446
447     private static AEndApiInfo createAendApiInfo(PathDescription pathDescription, boolean isForOtn) {
448         String anodeId = null;
449         String sapi = null;
450         String dapi = null;
451         if (isForOtn) {
452             anodeId = extractAendFromPathDescriptionForOtn(pathDescription).get("nodeId");
453             sapi = PortMappingUtils.fnv1size64(
454                 String.join("-", anodeId, extractAendFromPathDescriptionForOtn(pathDescription).get("tpid")));
455             dapi = PortMappingUtils.fnv1size64(
456                 String.join("-", extractZendFromPathDescriptionForOtn(pathDescription).get("nodeId"),
457                     extractZendFromPathDescriptionForOtn(pathDescription).get("tpid")));
458         } else {
459             anodeId = extractAendFromPathDescriptionForOptical(pathDescription).get("nodeId");
460             sapi = PortMappingUtils.fnv1size64(
461                 String.join("-", anodeId, extractAendFromPathDescriptionForOptical(pathDescription).get("tpid")));
462             dapi = PortMappingUtils.fnv1size64(
463                 String.join("-", extractZendFromPathDescriptionForOptical(pathDescription).get("nodeId"),
464                     extractZendFromPathDescriptionForOptical(pathDescription).get("tpid")));
465         }
466         return new AEndApiInfoBuilder()
467             .setSapi(sapi)
468             .setExpectedDapi(sapi)
469             .setDapi(dapi)
470             .setExpectedSapi(dapi)
471             .setNodeId(anodeId)
472             .build();
473     }
474
475     private static ZEndApiInfo createZendApiInfo(PathDescription pathDescription, boolean isForOtn) {
476         String znodeId = null;
477         String sapi = null;
478         String dapi = null;
479         if (isForOtn) {
480             znodeId = extractZendFromPathDescriptionForOtn(pathDescription).get("nodeId");
481             sapi = PortMappingUtils.fnv1size64(
482                 String.join("-", znodeId, extractZendFromPathDescriptionForOtn(pathDescription).get("tpid")));
483             dapi = PortMappingUtils.fnv1size64(
484                 String.join("-", extractAendFromPathDescriptionForOtn(pathDescription).get("nodeId"),
485                     extractAendFromPathDescriptionForOtn(pathDescription).get("tpid")));
486         } else {
487             znodeId = extractZendFromPathDescriptionForOptical(pathDescription).get("nodeId");
488             sapi = PortMappingUtils.fnv1size64(
489                 String.join("-", znodeId, extractZendFromPathDescriptionForOptical(pathDescription).get("tpid")));
490             dapi = PortMappingUtils.fnv1size64(
491                 String.join("-", extractAendFromPathDescriptionForOptical(pathDescription).get("nodeId"),
492                     extractAendFromPathDescriptionForOptical(pathDescription).get("tpid")));
493         }
494         return new ZEndApiInfoBuilder()
495             .setSapi(sapi)
496             .setExpectedDapi(sapi)
497             .setDapi(dapi)
498             .setExpectedSapi(dapi)
499             .setNodeId(znodeId)
500             .build();
501     }
502
503     private static Map<String, String> extractAendFromPathDescriptionForOtn(PathDescription pathDescription) {
504         List<AToZ> tpList = pathDescription.getAToZDirection().getAToZ().values().stream()
505             .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
506             .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
507                 .getSimpleName()))
508             .collect(Collectors.toList());
509         for (AToZ atoZ : tpList) {
510             TerminationPoint tp = (TerminationPoint) atoZ.getResource().getResource();
511             if (!tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
512                 String nodeId = tp.getTpNodeId();
513                 String lcp = tp.getTpId();
514                 return Map.of("nodeId", nodeId, "tpid", lcp);
515             }
516         }
517         return Map.of();
518     }
519
520     private static Map<String, String> extractZendFromPathDescriptionForOtn(PathDescription pathDescription) {
521         List<ZToA> tpList = pathDescription.getZToADirection().getZToA().values().stream()
522             .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
523             .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
524                 .getSimpleName()))
525             .collect(Collectors.toList());
526         for (ZToA ztoA : tpList) {
527             TerminationPoint tp = (TerminationPoint) ztoA.getResource().getResource();
528             if (!tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
529                 String nodeId = tp.getTpNodeId();
530                 String lcp = tp.getTpId();
531                 return Map.of("nodeId", nodeId, "tpid", lcp);
532             }
533         }
534         return Map.of();
535     }
536
537     private static Map<String, String> extractAendFromPathDescriptionForOptical(PathDescription pathDescription) {
538         List<AToZ> tpList = pathDescription.getAToZDirection().getAToZ().values().stream()
539             .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
540             .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
541                 .getSimpleName()))
542             .collect(Collectors.toList());
543         for (AToZ atoZ : tpList) {
544             TerminationPoint tp = (TerminationPoint) atoZ.getResource().getResource();
545             if (!tp.getTpId().contains("CLIENT") && !tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
546 //                String nodeId = tp.getTpNodeId();
547 //                String lcp = tp.getTpId();
548                 return Map.of("nodeId", tp.getTpNodeId(), "tpid", tp.getTpId());
549             }
550         }
551         return Map.of();
552     }
553
554     private static Map<String, String> extractZendFromPathDescriptionForOptical(PathDescription pathDescription) {
555         List<ZToA> tpList = pathDescription.getZToADirection().getZToA().values().stream()
556             .sorted((az1, az2) -> Integer.compare(Integer.parseInt(az1.getId()), Integer.parseInt(az2.getId())))
557             .filter(az -> TERMINATION_POINT.equals(az.getResource().getResource().implementedInterface()
558                 .getSimpleName()))
559             .collect(Collectors.toList());
560         for (ZToA ztoA : tpList) {
561             TerminationPoint tp = (TerminationPoint) ztoA.getResource().getResource();
562             if (!tp.getTpId().contains("CLIENT")  && !tp.getTpId().isEmpty() && !tp.getTpNodeId().isEmpty()) {
563 //                String nodeId = tp.getTpNodeId();
564 //                String lcp = tp.getTpId();
565                 return Map.of("nodeId", tp.getTpNodeId(), "tpid", tp.getTpId());
566             }
567         }
568         return Map.of();
569     }
570 }