2 * Copyright © 2017 AT&T 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.renderer.provisiondevice;
10 import com.google.common.collect.Sets;
11 import com.google.common.util.concurrent.FluentFuture;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.LinkedList;
15 import java.util.List;
17 import java.util.Optional;
19 import java.util.concurrent.ConcurrentHashMap;
20 import java.util.concurrent.ConcurrentLinkedQueue;
21 import java.util.concurrent.CopyOnWriteArrayList;
22 import java.util.concurrent.ExecutionException;
23 import java.util.concurrent.ForkJoinPool;
24 import java.util.concurrent.ForkJoinTask;
25 import java.util.concurrent.Future;
26 import java.util.concurrent.TimeUnit;
27 import java.util.concurrent.TimeoutException;
28 import java.util.concurrent.atomic.AtomicBoolean;
29 import org.eclipse.jdt.annotation.NonNull;
30 import org.opendaylight.mdsal.binding.api.DataBroker;
31 import org.opendaylight.mdsal.binding.api.ReadTransaction;
32 import org.opendaylight.mdsal.binding.api.WriteTransaction;
33 import org.opendaylight.mdsal.common.api.CommitInfo;
34 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
35 import org.opendaylight.transportpce.common.StringConstants;
36 import org.opendaylight.transportpce.common.Timeouts;
37 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
38 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
39 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
40 import org.opendaylight.transportpce.common.fixedflex.GridUtils;
41 import org.opendaylight.transportpce.common.fixedflex.SpectrumInformation;
42 import org.opendaylight.transportpce.common.mapping.PortMapping;
43 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
44 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
45 import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
46 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
47 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServiceListTopology;
48 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServicePathDirection;
49 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.ServiceNodelist;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service.nodelist.NodelistBuilder;
51 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service.nodelist.NodelistKey;
52 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.CreateOtsOmsInput;
53 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.CreateOtsOmsOutput;
54 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.CreateOtsOmsOutputBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.RendererRollbackInput;
56 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.RendererRollbackOutput;
57 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.RendererRollbackOutputBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.ServicePathInput;
59 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.ServicePathOutput;
60 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.ServicePathOutputBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.renderer.rollback.output.FailedToRollback;
62 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.renderer.rollback.output.FailedToRollbackBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.renderer.rollback.output.FailedToRollbackKey;
64 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.OpenroadmNodeVersion;
65 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.Mapping;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.Topology;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceList;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesBuilder;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesKey;
71 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.node.interfaces.NodeInterface;
72 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.node.interfaces.NodeInterfaceBuilder;
73 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.node.interfaces.NodeInterfaceKey;
74 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.optical.renderer.nodes.Nodes;
75 import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev210511.OtnLinkType;
76 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
77 import org.slf4j.Logger;
78 import org.slf4j.LoggerFactory;
81 public class DeviceRendererServiceImpl implements DeviceRendererService {
82 private static final String IS_NOT_MOUNTED_ON_THE_CONTROLLER = " is not mounted on the controller";
83 private static final String ODU4 = "-ODU4";
84 private static final Logger LOG = LoggerFactory.getLogger(DeviceRendererServiceImpl.class);
85 private final DataBroker dataBroker;
86 private final DeviceTransactionManager deviceTransactionManager;
87 private final OpenRoadmInterfaceFactory openRoadmInterfaceFactory;
88 private final OpenRoadmInterfaces openRoadmInterfaces;
89 private final CrossConnect crossConnect;
90 private final PortMapping portMapping;
91 private final NetworkModelService networkModelService;
93 public DeviceRendererServiceImpl(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
94 OpenRoadmInterfaceFactory openRoadmInterfaceFactory, OpenRoadmInterfaces openRoadmInterfaces,
95 CrossConnect crossConnect, PortMapping portMapping, NetworkModelService networkModelService) {
96 this.dataBroker = dataBroker;
97 this.deviceTransactionManager = deviceTransactionManager;
98 this.openRoadmInterfaceFactory = openRoadmInterfaceFactory;
99 this.openRoadmInterfaces = openRoadmInterfaces;
100 this.crossConnect = crossConnect;
101 this.portMapping = portMapping;
102 this.networkModelService = networkModelService;
106 public ServicePathOutput setupServicePath(ServicePathInput input, ServicePathDirection direction) {
107 LOG.info("setup service path for input {} and direction {}", input, direction);
108 List<Nodes> nodes = new ArrayList<>();
109 if (input.getNodes() != null) {
110 nodes.addAll(input.getNodes());
112 SpectrumInformation spectrumInformation = GridUtils.initSpectrumInformationFromServicePathInput(input);
113 // Register node for suppressing alarms
114 if (!alarmSuppressionNodeRegistration(input)) {
115 LOG.warn("Alarm suppresion node registration failed!!!!");
117 ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<>();
118 Map<NodeInterfaceKey,NodeInterface> nodeInterfaces = new ConcurrentHashMap<>();
119 Set<String> nodesProvisioned = Sets.newConcurrentHashSet();
120 CopyOnWriteArrayList<Nodes> otnNodesProvisioned = new CopyOnWriteArrayList<>();
121 ServiceListTopology topology = new ServiceListTopology();
122 AtomicBoolean success = new AtomicBoolean(true);
123 ForkJoinPool forkJoinPool = new ForkJoinPool();
124 ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
125 String nodeId = node.getNodeId();
126 // take the index of the node
127 int nodeIndex = nodes.indexOf(node);
128 LOG.info("Starting provisioning for node : {}", nodeId);
129 List<String> createdEthInterfaces = new ArrayList<>();
130 List<String> createdOtuInterfaces = new ArrayList<>();
131 List<String> createdOduInterfaces = new ArrayList<>();
132 List<String> createdOchInterfaces = new ArrayList<>();
133 List<String> createdConnections = new ArrayList<>();
134 int crossConnectFlag = 0;
136 // if the node is currently mounted then proceed
137 if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
138 String srcTp = node.getSrcTp();
139 String destTp = node.getDestTp();
140 if ((destTp != null) && destTp.contains(StringConstants.NETWORK_TOKEN)) {
141 LOG.info("Adding supporting OCH interface for node {}, dest tp {}, spectrumInformation {}",
142 nodeId, destTp, spectrumInformation);
144 String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
145 nodeId, destTp, spectrumInformation);
146 createdOchInterfaces.add(supportingOchInterface);
147 // Here we pass logical connection-point of z-end to set SAPI and DAPI
148 Nodes tgtNode = null;
149 if (nodeIndex + 1 == nodes.size()) {
150 // For the end node, tgtNode becomes the first node in the list
151 tgtNode = nodes.get(0);
153 tgtNode = nodes.get(nodeIndex + 1);
155 // tgtNode srcTp is null in this if cond
156 String supportingOtuInterface = this.openRoadmInterfaceFactory
157 .createOpenRoadmOtu4Interface(nodeId, destTp, supportingOchInterface,
158 tgtNode.getNodeId(), tgtNode.getDestTp());
159 createdOtuInterfaces.add(supportingOtuInterface);
161 otnNodesProvisioned.add(node);
163 createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
164 destTp, supportingOtuInterface));
167 if ((srcTp != null) && srcTp.contains(StringConstants.CLIENT_TOKEN)) {
168 LOG.info("Adding supporting EThernet interface for node {}, src tp {}", nodeId, srcTp);
170 // create OpenRoadm Xponder Client Interfaces
171 createdEthInterfaces.add(
172 this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(nodeId, srcTp));
174 if ((srcTp != null) && srcTp.contains(StringConstants.NETWORK_TOKEN)) {
175 LOG.info("Adding supporting OCH interface for node {}, src tp {}, spectrumInformation {}",
176 nodeId, srcTp, spectrumInformation);
178 // create OpenRoadm Xponder Line Interfaces
179 String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
180 nodeId, srcTp, spectrumInformation);
181 createdOchInterfaces.add(supportingOchInterface);
182 String supportingOtuInterface = this.openRoadmInterfaceFactory
183 .createOpenRoadmOtu4Interface(nodeId, srcTp, supportingOchInterface);
184 createdOtuInterfaces.add(supportingOtuInterface);
185 createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
186 srcTp, supportingOtuInterface));
187 Mapping mapping = this.portMapping.getMapping(nodeId,srcTp);
188 if (mapping != null && mapping.getXponderType() != null
189 && (mapping.getXponderType().getIntValue() == 3
190 || mapping.getXponderType().getIntValue() == 2)) {
191 createdOduInterfaces.add(this.openRoadmInterfaceFactory
192 .createOpenRoadmOtnOdu4Interface(nodeId, destTp, supportingOtuInterface));
194 createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
195 destTp, supportingOtuInterface));
198 if ((destTp != null) && destTp.contains(StringConstants.CLIENT_TOKEN)) {
199 LOG.info("Adding supporting EThernet interface for node {}, dest tp {}", nodeId, destTp);
201 // create OpenRoadm Xponder Client Interfaces
202 createdEthInterfaces.add(
203 this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(nodeId, destTp));
205 if ((srcTp != null) && (srcTp.contains(StringConstants.TTP_TOKEN)
206 || srcTp.contains(StringConstants.PP_TOKEN))) {
207 LOG.info("Adding supporting OCH interface for node {}, src tp {}, spectrumInformation {}",
208 nodeId, srcTp, spectrumInformation);
209 createdOchInterfaces.addAll(this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaces(nodeId,
210 srcTp, spectrumInformation));
212 if ((destTp != null) && (destTp.contains(StringConstants.TTP_TOKEN)
213 || destTp.contains(StringConstants.PP_TOKEN))) {
214 LOG.info("Adding supporting OCH interface for node {}, dest tp {}, spectrumInformation {}",
215 nodeId, destTp, spectrumInformation);
216 createdOchInterfaces.addAll(this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaces(nodeId,
217 destTp, spectrumInformation));
219 if (crossConnectFlag < 1) {
220 LOG.info("Creating cross connect between source {} and destination {} for node {}", srcTp,
222 Optional<String> connectionNameOpt =
223 this.crossConnect.postCrossConnect(nodeId, srcTp, destTp, spectrumInformation);
224 if (connectionNameOpt.isPresent()) {
225 nodesProvisioned.add(nodeId);
226 createdConnections.add(connectionNameOpt.get());
228 processErrorMessage("Unable to post Roadm-connection for node " + nodeId, forkJoinPool,
234 processErrorMessage(nodeId + IS_NOT_MOUNTED_ON_THE_CONTROLLER, forkJoinPool, results);
237 } catch (OpenRoadmInterfaceException ex) {
238 processErrorMessage("Setup service path failed! Exception:" + ex.toString(), forkJoinPool, results);
241 NodeInterfaceBuilder nodeInterfaceBuilder = new NodeInterfaceBuilder()
242 .withKey(new NodeInterfaceKey(nodeId))
244 .setConnectionId(createdConnections)
245 .setEthInterfaceId(createdEthInterfaces)
246 .setOtuInterfaceId(createdOtuInterfaces)
247 .setOduInterfaceId(createdOduInterfaces)
248 .setOchInterfaceId(createdOchInterfaces);
249 NodeInterface nodeInterface = nodeInterfaceBuilder.build();
250 nodeInterfaces.put(nodeInterface.key(),nodeInterface);
254 } catch (InterruptedException | ExecutionException e) {
255 LOG.error("Error while setting up service paths!", e);
257 forkJoinPool.shutdown();
260 results.add("Roadm-connection successfully created for nodes: " + String.join(", ", nodesProvisioned));
262 // setting topology in the service list data store
264 setTopologyForService(input.getServiceName(), topology.getTopology());
265 updateOtnTopology(otnNodesProvisioned, false);
266 } catch (InterruptedException | TimeoutException | ExecutionException e) {
267 LOG.warn("Failed to write topologies for service {}.", input.getServiceName(), e);
269 if (!alarmSuppressionNodeRemoval(input.getServiceName())) {
270 LOG.error("Alarm suppresion node removal failed!!!!");
272 ServicePathOutputBuilder setServBldr = new ServicePathOutputBuilder()
273 .setNodeInterface(nodeInterfaces)
274 .setSuccess(success.get())
275 .setResult(String.join("\n", results));
276 return setServBldr.build();
279 private ConcurrentLinkedQueue<String> processErrorMessage(String message, ForkJoinPool forkJoinPool,
280 ConcurrentLinkedQueue<String> messages) {
281 LOG.warn("Received error message {}", message);
282 messages.add(message);
283 forkJoinPool.shutdown();
288 public ServicePathOutput deleteServicePath(ServicePathInput input) {
289 List<Nodes> nodes = input.getNodes();
290 AtomicBoolean success = new AtomicBoolean(true);
291 ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<>();
292 if (!alarmSuppressionNodeRegistration(input)) {
293 LOG.warn("Alarm suppresion node registraion failed!!!!");
295 CopyOnWriteArrayList<Nodes> otnNodesProvisioned = new CopyOnWriteArrayList<>();
296 ForkJoinPool forkJoinPool = new ForkJoinPool();
297 ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
298 List<String> interfacesToDelete = new LinkedList<>();
299 String nodeId = node.getNodeId();
300 LOG.info("Deleting service setup on node {}", nodeId);
303 if (node.getDestTp() == null) {
304 LOG.error("Destination termination point must not be null.");
307 destTp = node.getDestTp();
309 if (node.getSrcTp() != null) {
310 srcTp = node.getSrcTp();
313 otnNodesProvisioned.add(node);
315 // if the node is currently mounted then proceed.
316 if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
317 interfacesToDelete.addAll(getInterfaces2delete(nodeId, srcTp, destTp,
318 input.getLowerSpectralSlotNumber().intValue(),
319 input.getHigherSpectralSlotNumber().intValue()));
321 String result = nodeId + IS_NOT_MOUNTED_ON_THE_CONTROLLER;
325 forkJoinPool.shutdown();
327 //TODO should deletion end here?
329 for (String interfaceId : interfacesToDelete) {
331 this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
332 } catch (OpenRoadmInterfaceException e) {
333 String result = String.format("Failed to delete interface %s on node %s!", interfaceId, nodeId);
335 LOG.error(result, e);
342 } catch (InterruptedException | ExecutionException e) {
343 LOG.error("Error while deleting service paths!", e);
345 forkJoinPool.shutdown();
346 updateOtnTopology(otnNodesProvisioned, true);
347 if (!alarmSuppressionNodeRemoval(input.getServiceName())) {
348 LOG.error("Alarm suppresion node removal failed!!!!");
350 ServicePathOutputBuilder delServBldr = new ServicePathOutputBuilder();
351 delServBldr.setSuccess(success.get());
352 if (results.isEmpty()) {
353 return delServBldr.setResult("Request processed").build();
355 return delServBldr.setResult(String.join("\n", results)).build();
359 private List<String> getInterfaces2delete(
360 String nodeId, String srcTp, String destTp, int lowerSpectralSlotNumber, int higherSpectralSlotNumber) {
361 String spectralSlotName = String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR,
362 String.valueOf(lowerSpectralSlotNumber),
363 String.valueOf(higherSpectralSlotNumber));
364 OpenroadmNodeVersion nodeOpenRoadmVersion = this.portMapping.getNode(nodeId).getNodeInfo()
365 .getOpenroadmVersion();
366 List<String> interfacesToDelete = new LinkedList<>();
367 if (destTp.contains(StringConstants.NETWORK_TOKEN)
368 || srcTp.contains(StringConstants.CLIENT_TOKEN)
369 || srcTp.contains(StringConstants.NETWORK_TOKEN)
370 || destTp.contains(StringConstants.CLIENT_TOKEN)) {
371 if (destTp.contains(StringConstants.NETWORK_TOKEN)) {
372 if (nodeOpenRoadmVersion.equals(OpenroadmNodeVersion._71)) {
374 if (this.openRoadmInterfaces.getInterface(nodeId, destTp + "-ODUFLEX").isPresent()) {
375 interfacesToDelete.add(destTp + "-ODUFLEX");
377 if (this.openRoadmInterfaces.getInterface(nodeId, destTp + "-ODUC4").isPresent()) {
378 interfacesToDelete.add(destTp + "-ODUC4");
380 } catch (OpenRoadmInterfaceException e) {
381 LOG.error("impossible to get interface {} or {}", destTp + "-ODUFLEX", destTp + "-ODUC4", e);
383 interfacesToDelete.add(destTp + "-OTUC4");
384 interfacesToDelete.add(destTp + "-OTSI-GROUP");
385 interfacesToDelete.add(destTp + "-" + lowerSpectralSlotNumber + ":" + higherSpectralSlotNumber);
388 if (this.openRoadmInterfaces.getInterface(nodeId, destTp + "-ODU").isPresent()) {
389 interfacesToDelete.add(destTp + "-ODU");
391 if (this.openRoadmInterfaces.getInterface(nodeId, destTp + ODU4).isPresent()) {
392 interfacesToDelete.add(destTp + ODU4);
395 catch (OpenRoadmInterfaceException e) {
396 LOG.error("impossible to get interface {} or {}", destTp + "-ODU", destTp + ODU4, e);
398 interfacesToDelete.add(destTp + "-OTU");
399 interfacesToDelete.add(
400 this.openRoadmInterfaceFactory
401 .createOpenRoadmOchInterfaceName(destTp,spectralSlotName));
404 if (srcTp.contains(StringConstants.NETWORK_TOKEN)) {
405 if (nodeOpenRoadmVersion.equals(OpenroadmNodeVersion._71)) {
406 interfacesToDelete.add(srcTp + "-ODUC4");
407 interfacesToDelete.add(srcTp + "-OTUC4");
408 interfacesToDelete.add(srcTp + "-OTSI-GROUP");
409 interfacesToDelete.add(srcTp + "-" + lowerSpectralSlotNumber + ":" + higherSpectralSlotNumber);
411 interfacesToDelete.add(srcTp + "-ODU");
412 interfacesToDelete.add(srcTp + "-OTU");
414 .add(this.openRoadmInterfaceFactory
415 .createOpenRoadmOchInterfaceName(srcTp, spectralSlotName));
418 if (srcTp.contains(StringConstants.CLIENT_TOKEN)) {
419 interfacesToDelete.add(srcTp + "-ETHERNET");
421 if (destTp.contains(StringConstants.CLIENT_TOKEN)) {
422 interfacesToDelete.add(destTp + "-ETHERNET");
425 String connectionNumber = String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, destTp,
427 List<String> intToDelete = this.crossConnect.deleteCrossConnect(nodeId, connectionNumber, false);
428 connectionNumber = String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, srcTp, spectralSlotName);
429 if (intToDelete != null) {
430 for (String interf : intToDelete) {
431 if (!this.openRoadmInterfaceFactory.isUsedByXc(nodeId, interf, connectionNumber,
432 this.deviceTransactionManager)) {
433 interfacesToDelete.add(interf);
438 return interfacesToDelete;
442 public RendererRollbackOutput rendererRollback(RendererRollbackInput input) {
443 boolean success = true;
444 Map<FailedToRollbackKey,FailedToRollback> failedToRollbackList = new HashMap<>();
445 for (NodeInterface nodeInterfaces : input.nonnullNodeInterface().values()) {
446 List<String> failedInterfaces = new ArrayList<>();
447 String nodeId = nodeInterfaces.getNodeId();
448 for (String connectionId : nodeInterfaces.getConnectionId()) {
449 List<String> listInter = this.crossConnect.deleteCrossConnect(nodeId, connectionId, false);
450 if (listInter != null) {
451 LOG.info("Cross connect {} on node {} successfully deleted.", connectionId, nodeId);
453 LOG.error("Failed to delete cross connect {} on node {}!", connectionId, nodeId);
455 failedInterfaces.add(connectionId);
458 // Interfaces needs to be in specific order to delete. Order is:
463 LinkedList<String> interfacesToDelete = new LinkedList<>();
464 if (nodeInterfaces.getOduInterfaceId() != null) {
465 interfacesToDelete.addAll(nodeInterfaces.getOduInterfaceId());
467 if (nodeInterfaces.getOtuInterfaceId() != null) {
468 interfacesToDelete.addAll(nodeInterfaces.getOtuInterfaceId());
470 if (nodeInterfaces.getOchInterfaceId() != null) {
471 interfacesToDelete.addAll(nodeInterfaces.getOchInterfaceId());
473 if (nodeInterfaces.getEthInterfaceId() != null) {
474 interfacesToDelete.addAll(nodeInterfaces.getEthInterfaceId());
476 LOG.info("Going to execute rollback on node {}. Interfaces to rollback: {}", nodeId,
477 String.join(", ", interfacesToDelete));
478 for (String interfaceId : interfacesToDelete) {
480 this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
481 LOG.info("Interface {} on node {} successfully deleted.", interfaceId, nodeId);
482 } catch (OpenRoadmInterfaceException e) {
483 LOG.error("Failed to delete interface {} on node {}!", interfaceId, nodeId);
485 failedInterfaces.add(interfaceId);
488 FailedToRollback failedToRollack = new FailedToRollbackBuilder().withKey(new FailedToRollbackKey(nodeId))
489 .setNodeId(nodeId).setInterface(failedInterfaces).build();
490 failedToRollbackList.put(failedToRollack.key(),failedToRollack);
492 return new RendererRollbackOutputBuilder().setSuccess(success).setFailedToRollback(failedToRollbackList)
496 private boolean alarmSuppressionNodeRegistration(ServicePathInput input) {
497 NodelistBuilder nodeListBuilder = new NodelistBuilder()
498 .withKey(new NodelistKey(input.getServiceName()))
499 .setServiceName(input.getServiceName());
500 Map<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service
501 .nodelist.nodelist.NodesKey,
502 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service
503 .nodelist.nodelist.Nodes> nodeList =
505 if (input.getNodes() != null) {
506 for (Nodes node : input.getNodes()) {
507 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
508 .service.nodelist.nodelist.Nodes nodes =
509 new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
510 .service.nodelist.nodelist.NodesBuilder().setNodeId(node.getNodeId()).build();
511 nodeList.put(nodes.key(),nodes);
514 nodeListBuilder.setNodes(nodeList);
515 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
516 .service.nodelist.Nodelist> nodeListIID =
517 InstanceIdentifier.create(ServiceNodelist.class)
518 .child(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
519 .service.nodelist.Nodelist.class, new NodelistKey(input.getServiceName()));
520 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
521 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodeListIID, nodeListBuilder.build());
522 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
524 commit.get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
525 LOG.info("Nodes are register for alarm suppression for service: {}", input.getServiceName());
527 } catch (ExecutionException | InterruptedException | TimeoutException e) {
528 LOG.warn("Failed to alarm suppresslist for service: {}", input.getServiceName(), e);
533 private boolean alarmSuppressionNodeRemoval(String serviceName) {
534 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
535 .service.nodelist.Nodelist> nodeListIID =
536 InstanceIdentifier.create(ServiceNodelist.class)
537 .child(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
538 .service.nodelist.Nodelist.class, new NodelistKey(serviceName));
539 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
540 writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, nodeListIID);
541 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
543 commit.get(Timeouts.DATASTORE_DELETE, TimeUnit.MILLISECONDS);
544 LOG.info("Nodes are unregister for alarm suppression for service: {}", serviceName);
546 } catch (InterruptedException | TimeoutException | ExecutionException e) {
547 LOG.warn("Failed to alarm suppresslist for service: {}", serviceName, e);
552 private void setTopologyForService(String name, Topology topo)
553 throws InterruptedException, ExecutionException, TimeoutException {
554 ServicesBuilder servicesBuilder;
555 // Get the service from the service list inventory
556 ServicesKey serviceKey = new ServicesKey(name);
557 InstanceIdentifier<Services> iid =
558 InstanceIdentifier.create(ServiceList.class).child(Services.class, serviceKey);
559 Optional<Services> services;
560 try (ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
561 Future<java.util.Optional<Services>> future =
562 readTx.read(LogicalDatastoreType.OPERATIONAL, iid);
563 services = future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS);
564 } catch (InterruptedException | ExecutionException | TimeoutException e) {
567 if (services.isPresent()) {
568 LOG.info("service {} already exists", name);
569 servicesBuilder = new ServicesBuilder(services.get()).setTopology(topo);
570 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
571 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, servicesBuilder.build());
572 writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
574 LOG.warn("Service {} does not exist - topology can not be updated", name);
579 public CreateOtsOmsOutput createOtsOms(CreateOtsOmsInput input) throws OpenRoadmInterfaceException {
580 CreateOtsOmsOutputBuilder output = new CreateOtsOmsOutputBuilder();
582 Boolean success = false;
583 // if the node is currently mounted then proceed.
584 if (this.deviceTransactionManager.isDeviceMounted(input.getNodeId())) {
585 Mapping oldMapping = null;
586 Mapping newMapping = null;
587 oldMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
588 if (oldMapping != null) {
589 String otsInterface =
590 this.openRoadmInterfaceFactory.createOpenRoadmOtsInterface(input.getNodeId(), oldMapping);
591 newMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
593 Boolean isSupportingOtsPresent = isSupportingOtsPresent(newMapping);
594 while (!isSupportingOtsPresent && (count < 6)) {
595 LOG.info("waiting for post interface operation on node '{}'...", input.getNodeId());
598 this.portMapping.updateMapping(input.getNodeId(), oldMapping);
599 } catch (InterruptedException e) {
600 LOG.error("Failed to wait for post interface operation ");
602 newMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
603 isSupportingOtsPresent = isSupportingOtsPresent(newMapping);
607 String omsInterface =
608 this.openRoadmInterfaceFactory.createOpenRoadmOmsInterface(input.getNodeId(), newMapping);
609 if (omsInterface != null) {
610 result = "Interfaces " + otsInterface + " - " + omsInterface + " successfully created on node "
614 LOG.error("Fail to create OpenRoadmOms Interface for node '{}'", input.getNodeId());
615 result = "Fail to create OpenRoadmOms Interface for node : " + input.getNodeId();
618 LOG.error("Unable to get ots interface from mapping {} for node {}",
619 oldMapping.getLogicalConnectionPoint(), input.getNodeId());
620 result = String.format("Unable to get ots interface from mapping %s - %s",
621 oldMapping.getLogicalConnectionPoint(), input.getNodeId());
624 result = "Logical Connection point " + input.getLogicalConnectionPoint() + " does not exist for "
628 result = input.getNodeId() + IS_NOT_MOUNTED_ON_THE_CONTROLLER;
629 LOG.warn("{} is not mounted on the controller",input.getNodeId());
631 return output.setResult(result).setSuccess(success).build();
634 private Boolean isSupportingOtsPresent(Mapping mapping) {
635 Boolean result = false;
636 if (mapping != null) {
637 if (mapping.getSupportingOts() != null) {
638 LOG.info("SupportingOts info is present in mapping {}", mapping);
641 LOG.warn("SupportingOts info not present in mapping {}", mapping);
647 private void updateOtnTopology(CopyOnWriteArrayList<Nodes> nodes, boolean isDeletion) {
648 if (nodes.size() != 2) {
649 LOG.error("Error with OTU4 links to update in otn-topology");
653 LOG.info("updating otn-topology removing OTU4 links");
654 this.networkModelService.deleteOtnLinks(nodes.get(0).getNodeId(), nodes.get(0).getDestTp(),
655 nodes.get(1).getNodeId(), nodes.get(1).getDestTp(), OtnLinkType.OTU4);
657 LOG.info("updating otn-topology adding OTU4 links");
658 this.networkModelService.createOtnLinks(nodes.get(0).getNodeId(), nodes.get(0).getDestTp(),
659 nodes.get(1).getNodeId(), nodes.get(1).getDestTp(), OtnLinkType.OTU4);