clean common/pom.xml
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / DeviceRendererServiceImpl.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.provisiondevice;
9
10 import com.google.common.collect.Sets;
11 import com.google.common.util.concurrent.FluentFuture;
12 import java.util.ArrayList;
13 import java.util.LinkedList;
14 import java.util.List;
15 import java.util.Optional;
16 import java.util.Set;
17 import java.util.concurrent.ConcurrentLinkedQueue;
18 import java.util.concurrent.CopyOnWriteArrayList;
19 import java.util.concurrent.ExecutionException;
20 import java.util.concurrent.ForkJoinPool;
21 import java.util.concurrent.ForkJoinTask;
22 import java.util.concurrent.Future;
23 import java.util.concurrent.TimeUnit;
24 import java.util.concurrent.TimeoutException;
25 import java.util.concurrent.atomic.AtomicBoolean;
26 import org.eclipse.jdt.annotation.NonNull;
27 import org.opendaylight.mdsal.binding.api.DataBroker;
28 import org.opendaylight.mdsal.binding.api.ReadTransaction;
29 import org.opendaylight.mdsal.binding.api.WriteTransaction;
30 import org.opendaylight.mdsal.common.api.CommitInfo;
31 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
32 import org.opendaylight.transportpce.common.StringConstants;
33 import org.opendaylight.transportpce.common.Timeouts;
34 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
35 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
36 import org.opendaylight.transportpce.common.mapping.PortMapping;
37 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
38 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
39 import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
40 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
41 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServiceListTopology;
42 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServicePathDirection;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.ServiceNodelist;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service.nodelist.NodelistBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service.nodelist.NodelistKey;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.network.nodes.Mapping;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.CreateOtsOmsInput;
48 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.CreateOtsOmsOutput;
49 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.CreateOtsOmsOutputBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.RendererRollbackInput;
51 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.RendererRollbackOutput;
52 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.RendererRollbackOutputBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.ServicePathInput;
54 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.ServicePathOutput;
55 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.ServicePathOutputBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.renderer.rollback.output.FailedToRollback;
57 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.renderer.rollback.output.FailedToRollbackBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.renderer.rollback.output.FailedToRollbackKey;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.Topology;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.OchAttributes.ModulationFormat;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceList;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesKey;
65 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200615.node.interfaces.NodeInterface;
66 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200615.node.interfaces.NodeInterfaceBuilder;
67 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200615.node.interfaces.NodeInterfaceKey;
68 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200615.olm.renderer.input.Nodes;
69 import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129.OtnLinkType;
70 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
71 import org.slf4j.Logger;
72 import org.slf4j.LoggerFactory;
73
74
75 public class DeviceRendererServiceImpl implements DeviceRendererService {
76     private static final String ODU4 = "-ODU4";
77     private static final Logger LOG = LoggerFactory.getLogger(DeviceRendererServiceImpl.class);
78     private final DataBroker dataBroker;
79     private final DeviceTransactionManager deviceTransactionManager;
80     private final OpenRoadmInterfaceFactory openRoadmInterfaceFactory;
81     private final OpenRoadmInterfaces openRoadmInterfaces;
82     private final CrossConnect crossConnect;
83     private final PortMapping portMapping;
84     private final NetworkModelService networkModelService;
85
86     public DeviceRendererServiceImpl(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
87             OpenRoadmInterfaceFactory openRoadmInterfaceFactory, OpenRoadmInterfaces openRoadmInterfaces,
88             CrossConnect crossConnect, PortMapping portMapping, NetworkModelService networkModelService) {
89         this.dataBroker = dataBroker;
90         this.deviceTransactionManager = deviceTransactionManager;
91         this.openRoadmInterfaceFactory = openRoadmInterfaceFactory;
92         this.openRoadmInterfaces = openRoadmInterfaces;
93         this.crossConnect = crossConnect;
94         this.portMapping = portMapping;
95         this.networkModelService = networkModelService;
96     }
97
98     @Override
99     public ServicePathOutput setupServicePath(ServicePathInput input, ServicePathDirection direction) {
100         List<Nodes> nodes = input.getNodes();
101         Nodes srcNode = nodes.get(0);
102         // If the Node list size is one, then src and tgt are same;
103         // sapi/dapi all have the same value
104         Nodes tgtNode = nodes.get(nodes.size() - 1);
105
106
107         // Register node for suppressing alarms
108         if (!alarmSuppressionNodeRegistration(input)) {
109             LOG.warn("Alarm suppresion node registration failed!!!!");
110         }
111         ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<>();
112         Set<NodeInterface> nodeInterfaces = Sets.newConcurrentHashSet();
113         Set<String> nodesProvisioned = Sets.newConcurrentHashSet();
114         CopyOnWriteArrayList<Nodes> otnNodesProvisioned = new CopyOnWriteArrayList<>();
115         ServiceListTopology topology = new ServiceListTopology();
116         AtomicBoolean success = new AtomicBoolean(true);
117         ForkJoinPool forkJoinPool = new ForkJoinPool();
118         ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
119             String nodeId = node.getNodeId();
120             LOG.info("Starting provisioning for node : {}", nodeId);
121             List<String> createdEthInterfaces = new ArrayList<>();
122             List<String> createdOtuInterfaces = new ArrayList<>();
123             List<String> createdOduInterfaces = new ArrayList<>();
124             List<String> createdOchInterfaces = new ArrayList<>();
125             List<String> createdConnections = new ArrayList<>();
126             int crossConnectFlag = 0;
127             try {
128                 // if the node is currently mounted then proceed
129                 if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
130                     String srcTp = node.getSrcTp();
131                     String destTp = node.getDestTp();
132                     Long waveNumber = input.getWaveNumber().toJava();
133                     if ((destTp != null) && destTp.contains(StringConstants.NETWORK_TOKEN)) {
134                         crossConnectFlag++;
135                         String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
136                                 nodeId, destTp, waveNumber, ModulationFormat.DpQpsk);
137                         createdOchInterfaces.add(supportingOchInterface);
138                         // Here we pass logical connection-point of z-end to set SAPI and DAPI
139                         String znodeId = tgtNode.getNodeId();
140                         String zlogicalConnection = tgtNode.getDestTp();
141                         if (nodeId.equals(tgtNode.getNodeId())) {
142                             znodeId = srcNode.getNodeId(); // if it is final node, then set zSide as source side
143                             zlogicalConnection = srcNode.getDestTp();
144                         }
145                         String supportingOtuInterface = this.openRoadmInterfaceFactory
146                                 .createOpenRoadmOtu4Interface(nodeId, destTp, supportingOchInterface,
147                                     znodeId, zlogicalConnection);
148                         createdOtuInterfaces.add(supportingOtuInterface);
149                         if (srcTp == null) {
150                             otnNodesProvisioned.add(node);
151                         } else {
152                             createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
153                                     destTp, supportingOtuInterface));
154                         }
155                     }
156                     if ((srcTp != null) && srcTp.contains(StringConstants.CLIENT_TOKEN)) {
157                         crossConnectFlag++;
158                         // create OpenRoadm Xponder Client Interfaces
159                         createdEthInterfaces.add(
160                             this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(nodeId, srcTp));
161                     }
162                     if ((srcTp != null) && srcTp.contains(StringConstants.NETWORK_TOKEN)) {
163                         crossConnectFlag++;
164                         // create OpenRoadm Xponder Line Interfaces
165                         String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
166                                 nodeId, srcTp, waveNumber, ModulationFormat.DpQpsk);
167                         createdOchInterfaces.add(supportingOchInterface);
168                         String supportingOtuInterface = this.openRoadmInterfaceFactory
169                                 .createOpenRoadmOtu4Interface(nodeId, srcTp, supportingOchInterface);
170                         createdOtuInterfaces.add(supportingOtuInterface);
171                         createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
172                                 srcTp, supportingOtuInterface));
173                         Mapping mapping = this.portMapping.getMapping(nodeId,srcTp);
174                         if (mapping != null && mapping.getXponderType() != null
175                             && (mapping.getXponderType().getIntValue() == 3
176                             || mapping.getXponderType().getIntValue() == 2)) {
177                             createdOduInterfaces.add(this.openRoadmInterfaceFactory
178                                 .createOpenRoadmOtnOdu4Interface(nodeId, destTp, supportingOtuInterface));
179                         } else {
180                             createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
181                                     destTp, supportingOtuInterface));
182                         }
183                     }
184                     if ((destTp != null) && destTp.contains(StringConstants.CLIENT_TOKEN)) {
185                         crossConnectFlag++;
186                         // create OpenRoadm Xponder Client Interfaces
187                         createdEthInterfaces.add(
188                             this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(nodeId, destTp));
189                     }
190                     if ((srcTp != null) && (srcTp.contains(StringConstants.TTP_TOKEN)
191                             || srcTp.contains(StringConstants.PP_TOKEN))) {
192                         createdOchInterfaces.addAll(
193                             this.openRoadmInterfaceFactory
194                                 .createOpenRoadmOchInterface(nodeId, srcTp, waveNumber));
195                     }
196                     if ((destTp != null) && (destTp.contains(StringConstants.TTP_TOKEN)
197                             || destTp.contains(StringConstants.PP_TOKEN))) {
198                         createdOchInterfaces.addAll(
199                             this.openRoadmInterfaceFactory
200                                 .createOpenRoadmOchInterface(nodeId, destTp, waveNumber));
201                     }
202                     if (crossConnectFlag < 1) {
203                         LOG.info("Creating cross connect between source {} and destination {} for node {}", srcTp,
204                                 destTp, nodeId);
205                         Optional<String> connectionNameOpt =
206                                 this.crossConnect.postCrossConnect(nodeId, waveNumber, srcTp, destTp);
207                         if (connectionNameOpt.isPresent()) {
208                             nodesProvisioned.add(nodeId);
209                             createdConnections.add(connectionNameOpt.get());
210                         } else {
211                             processErrorMessage("Unable to post Roadm-connection for node " + nodeId, forkJoinPool,
212                                     results);
213                             success.set(false);
214                         }
215                     }
216                 } else {
217                     processErrorMessage(nodeId + " is not mounted on the controller", forkJoinPool, results);
218                     success.set(false);
219                 }
220             } catch (OpenRoadmInterfaceException ex) {
221                 processErrorMessage("Setup service path failed! Exception:" + ex.toString(), forkJoinPool, results);
222                 success.set(false);
223             }
224             NodeInterfaceBuilder nodeInterfaceBuilder = new NodeInterfaceBuilder()
225                 .withKey(new NodeInterfaceKey(nodeId))
226                 .setNodeId(nodeId)
227                 .setConnectionId(createdConnections)
228                 .setEthInterfaceId(createdEthInterfaces)
229                 .setOtuInterfaceId(createdOtuInterfaces)
230                 .setOduInterfaceId(createdOduInterfaces)
231                 .setOchInterfaceId(createdOchInterfaces);
232             nodeInterfaces.add(nodeInterfaceBuilder.build());
233         }));
234         try {
235             forkJoinTask.get();
236         } catch (InterruptedException | ExecutionException e) {
237             LOG.error("Error while setting up service paths!", e);
238         }
239         forkJoinPool.shutdown();
240
241         if (success.get()) {
242             results.add("Roadm-connection successfully created for nodes: " + String.join(", ", nodesProvisioned));
243         }
244         // setting topology in the service list data store
245         try {
246             setTopologyForService(input.getServiceName(), topology.getTopology());
247             updateOtnTopology(otnNodesProvisioned, false);
248         } catch (InterruptedException | TimeoutException | ExecutionException e) {
249             LOG.warn("Failed to write topologies for service {}.", input.getServiceName(), e);
250         }
251         if (!alarmSuppressionNodeRemoval(input.getServiceName())) {
252             LOG.error("Alarm suppresion node removal failed!!!!");
253         }
254         ServicePathOutputBuilder setServBldr = new ServicePathOutputBuilder()
255             .setNodeInterface(new ArrayList<>(nodeInterfaces))
256             .setSuccess(success.get())
257             .setResult(String.join("\n", results));
258         return setServBldr.build();
259     }
260
261     private ConcurrentLinkedQueue<String> processErrorMessage(String message, ForkJoinPool forkJoinPool,
262             ConcurrentLinkedQueue<String> messages) {
263         LOG.warn("Received error message {}", message);
264         messages.add(message);
265         forkJoinPool.shutdown();
266         return messages;
267     }
268
269     @Override
270     public ServicePathOutput deleteServicePath(ServicePathInput input) {
271         List<Nodes> nodes = input.getNodes();
272         AtomicBoolean success = new AtomicBoolean(true);
273         ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<>();
274         if (!alarmSuppressionNodeRegistration(input)) {
275             LOG.warn("Alarm suppresion node registraion failed!!!!");
276         }
277         CopyOnWriteArrayList<Nodes> otnNodesProvisioned = new CopyOnWriteArrayList<>();
278         ForkJoinPool forkJoinPool = new ForkJoinPool();
279         ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
280             List<String> interfacesToDelete = new LinkedList<>();
281             String nodeId = node.getNodeId();
282             LOG.info("Deleting service setup on node {}", nodeId);
283             String srcTp;
284             String destTp;
285             Long waveNumber = input.getWaveNumber().toJava();
286             if (node.getDestTp() == null) {
287                 LOG.error("Destination termination point must not be null.");
288                 return;
289             } else {
290                 destTp = node.getDestTp();
291             }
292             if (node.getSrcTp() != null) {
293                 srcTp = node.getSrcTp();
294             } else {
295                 srcTp = "";
296                 otnNodesProvisioned.add(node);
297             }
298             // if the node is currently mounted then proceed.
299             if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
300                 interfacesToDelete.addAll(getInterfaces2delete(nodeId, srcTp, destTp, waveNumber));
301             } else {
302                 String result = nodeId + " is not mounted on the controller";
303                 results.add(result);
304                 success.set(false);
305                 LOG.warn(result);
306                 forkJoinPool.shutdown();
307                 return;
308                 //TODO should deletion end here?
309             }
310             for (String interfaceId : interfacesToDelete) {
311                 try {
312                     this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
313                 } catch (OpenRoadmInterfaceException e) {
314                     String result = String.format("Failed to delete interface %s on node %s!", interfaceId, nodeId);
315                     success.set(false);
316                     LOG.error(result, e);
317                     results.add(result);
318                 }
319             }
320         }));
321         try {
322             forkJoinTask.get();
323         } catch (InterruptedException | ExecutionException e) {
324             LOG.error("Error while deleting service paths!", e);
325         }
326         forkJoinPool.shutdown();
327         updateOtnTopology(otnNodesProvisioned, true);
328         if (!alarmSuppressionNodeRemoval(input.getServiceName())) {
329             LOG.error("Alarm suppresion node removal failed!!!!");
330         }
331         ServicePathOutputBuilder delServBldr = new ServicePathOutputBuilder();
332         delServBldr.setSuccess(success.get());
333         if (results.isEmpty()) {
334             return delServBldr.setResult("Request processed").build();
335         } else {
336             return delServBldr.setResult(String.join("\n", results)).build();
337         }
338     }
339
340     private List<String>  getInterfaces2delete(
341             String nodeId, String srcTp, String destTp, Long waveNumber) {
342         List<String> interfacesToDelete = new LinkedList<>();
343         if (destTp.contains(StringConstants.NETWORK_TOKEN)
344                 || srcTp.contains(StringConstants.CLIENT_TOKEN)
345                 || srcTp.contains(StringConstants.NETWORK_TOKEN)
346                 || destTp.contains(StringConstants.CLIENT_TOKEN)) {
347             if (destTp.contains(StringConstants.NETWORK_TOKEN)) {
348                 try {
349                     if (this.openRoadmInterfaces.getInterface(nodeId, destTp + "-ODU").isPresent()) {
350                         interfacesToDelete.add(destTp + "-ODU");
351                     }
352                     if (this.openRoadmInterfaces.getInterface(nodeId, destTp + ODU4).isPresent()) {
353                         interfacesToDelete.add(destTp + ODU4);
354                     }
355                 }
356                 catch (OpenRoadmInterfaceException e) {
357                     LOG.error("impossible to get interface {} or {}", destTp + "-ODU", destTp + ODU4, e);
358                 }
359                 interfacesToDelete.add(destTp + "-OTU");
360                 interfacesToDelete.add(
361                         this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName(destTp, waveNumber));
362             }
363             if (srcTp.contains(StringConstants.NETWORK_TOKEN)) {
364                 interfacesToDelete.add(srcTp + "-ODU");
365                 interfacesToDelete.add(srcTp + "-OTU");
366                 interfacesToDelete
367                         .add(this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName(srcTp, waveNumber));
368             }
369             if (srcTp.contains(StringConstants.CLIENT_TOKEN)) {
370                 interfacesToDelete.add(srcTp + "-ETHERNET");
371             }
372             if (destTp.contains(StringConstants.CLIENT_TOKEN)) {
373                 interfacesToDelete.add(destTp + "-ETHERNET");
374             }
375         } else {
376             String connectionNumber = srcTp + "-" + destTp + "-" + waveNumber;
377             List<String> intToDelete = this.crossConnect.deleteCrossConnect(nodeId, connectionNumber, false);
378             connectionNumber = destTp + "-" + srcTp + "-" + waveNumber;
379             if (intToDelete != null) {
380                 for (String interf : intToDelete) {
381                     if (!this.openRoadmInterfaceFactory.isUsedByXc(nodeId, interf, connectionNumber,
382                         this.deviceTransactionManager)) {
383                         interfacesToDelete.add(interf);
384                     }
385                 }
386             }
387         }
388         return interfacesToDelete;
389     }
390
391     @Override
392     public RendererRollbackOutput rendererRollback(RendererRollbackInput input) {
393         boolean success = true;
394         List<FailedToRollback> failedToRollbackList = new ArrayList<>();
395         for (NodeInterface nodeInterfaces : input.getNodeInterface()) {
396             List<String> failedInterfaces = new ArrayList<>();
397             String nodeId = nodeInterfaces.getNodeId();
398             for (String connectionId : nodeInterfaces.getConnectionId()) {
399                 List<String> listInter = this.crossConnect.deleteCrossConnect(nodeId, connectionId, false);
400                 if (listInter != null) {
401                     LOG.info("Cross connect {} on node {} successfully deleted.", connectionId, nodeId);
402                 } else {
403                     LOG.error("Failed to delete cross connect {} on node {}!", connectionId, nodeId);
404                     success = false;
405                     failedInterfaces.add(connectionId);
406                 }
407             }
408             // Interfaces needs to be in specific order to delete. Order is:
409             // 1. ODU interfaces
410             // 2. OTU interfaces
411             // 3. OCH interfaces
412             // 4. ETH interfaces
413             LinkedList<String> interfacesToDelete = new LinkedList<>();
414             if (nodeInterfaces.getOduInterfaceId() != null) {
415                 interfacesToDelete.addAll(nodeInterfaces.getOduInterfaceId());
416             }
417             if (nodeInterfaces.getOtuInterfaceId() != null) {
418                 interfacesToDelete.addAll(nodeInterfaces.getOtuInterfaceId());
419             }
420             if (nodeInterfaces.getOchInterfaceId() != null) {
421                 interfacesToDelete.addAll(nodeInterfaces.getOchInterfaceId());
422             }
423             if (nodeInterfaces.getEthInterfaceId() != null) {
424                 interfacesToDelete.addAll(nodeInterfaces.getEthInterfaceId());
425             }
426             LOG.info("Going to execute rollback on node {}. Interfaces to rollback: {}", nodeId,
427                     String.join(", ", interfacesToDelete));
428             for (String interfaceId : interfacesToDelete) {
429                 try {
430                     this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
431                     LOG.info("Interface {} on node {} successfully deleted.", interfaceId, nodeId);
432                 } catch (OpenRoadmInterfaceException e) {
433                     LOG.error("Failed to delete interface {} on node {}!", interfaceId, nodeId);
434                     success = false;
435                     failedInterfaces.add(interfaceId);
436                 }
437             }
438             failedToRollbackList.add(new FailedToRollbackBuilder().withKey(new FailedToRollbackKey(nodeId))
439                     .setNodeId(nodeId).setInterface(failedInterfaces).build());
440         }
441         return new RendererRollbackOutputBuilder().setSuccess(success).setFailedToRollback(failedToRollbackList)
442                 .build();
443     }
444
445     private boolean alarmSuppressionNodeRegistration(ServicePathInput input) {
446         NodelistBuilder nodeListBuilder = new NodelistBuilder()
447             .withKey(new NodelistKey(input.getServiceName()))
448             .setServiceName(input.getServiceName());
449         List<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service
450             .nodelist.nodelist.Nodes> nodeList =
451                 new ArrayList<>();
452         for (Nodes node : input.getNodes()) {
453             nodeList.add(
454                     new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
455                     .service.nodelist.nodelist.NodesBuilder()
456                             .setNodeId(node.getNodeId()).build());
457         }
458         nodeListBuilder.setNodes(nodeList);
459         InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
460             .service.nodelist.Nodelist> nodeListIID =
461                         InstanceIdentifier.create(ServiceNodelist.class).child(
462                                 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression
463                                     .rev171102.service.nodelist.Nodelist.class,
464                                 new NodelistKey(input.getServiceName()));
465         final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
466         writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodeListIID, nodeListBuilder.build());
467         FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
468         try {
469             commit.get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
470             LOG.info("Nodes are register for alarm suppression for service: {}", input.getServiceName());
471             return true;
472         } catch (ExecutionException | InterruptedException | TimeoutException e) {
473             LOG.warn("Failed to alarm suppresslist for service: {}", input.getServiceName(), e);
474             return false;
475         }
476     }
477
478     private boolean alarmSuppressionNodeRemoval(String serviceName) {
479         InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
480             .service.nodelist.Nodelist> nodeListIID =
481                         InstanceIdentifier.create(ServiceNodelist.class).child(
482                                 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression
483                                     .rev171102.service.nodelist.Nodelist.class,
484                                 new NodelistKey(serviceName));
485         final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
486         writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, nodeListIID);
487         FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
488         try {
489             commit.get(Timeouts.DATASTORE_DELETE, TimeUnit.MILLISECONDS);
490             LOG.info("Nodes are unregister for alarm suppression for service: {}", serviceName);
491             return true;
492         } catch (InterruptedException | TimeoutException | ExecutionException e) {
493             LOG.warn("Failed to alarm suppresslist for service: {}", serviceName, e);
494             return false;
495         }
496     }
497
498     private void setTopologyForService(String name, Topology topo)
499             throws InterruptedException, ExecutionException, TimeoutException {
500         ServicesBuilder servicesBuilder;
501         // Get the service from the service list inventory
502         ServicesKey serviceKey = new ServicesKey(name);
503         InstanceIdentifier<Services> iid =
504                 InstanceIdentifier.create(ServiceList.class).child(Services.class, serviceKey);
505         Optional<Services> services;
506         try (ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
507             Future<java.util.Optional<Services>> future =
508                     readTx.read(LogicalDatastoreType.OPERATIONAL, iid);
509             services = future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS);
510         } catch (InterruptedException | ExecutionException | TimeoutException e) {
511             throw e;
512         }
513         if (services.isPresent()) {
514             LOG.info("service {} already exists", name);
515             servicesBuilder = new ServicesBuilder(services.get()).setTopology(topo);
516             WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
517             writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, servicesBuilder.build());
518             writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
519         } else {
520             LOG.warn("Service {} does not exist - topology can not be updated", name);
521         }
522     }
523
524     @Override
525     public CreateOtsOmsOutput createOtsOms(CreateOtsOmsInput input) throws OpenRoadmInterfaceException {
526         CreateOtsOmsOutputBuilder output = new CreateOtsOmsOutputBuilder();
527         String result = "";
528         Boolean success = false;
529         // if the node is currently mounted then proceed.
530         if (this.deviceTransactionManager.isDeviceMounted(input.getNodeId())) {
531             Mapping oldMapping = null;
532             Mapping newMapping = null;
533             oldMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
534             if (oldMapping != null) {
535                 String otsInterface =
536                         this.openRoadmInterfaceFactory.createOpenRoadmOtsInterface(input.getNodeId(), oldMapping);
537                 newMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
538                 int count = 0;
539                 Boolean isSupportingOtsPresent = isSupportingOtsPresent(newMapping);
540                 while (!isSupportingOtsPresent && (count < 6)) {
541                     LOG.info("waiting for post interface operation on node '{}'...", input.getNodeId());
542                     try {
543                         Thread.sleep(10000);
544                         this.portMapping.updateMapping(input.getNodeId(), oldMapping);
545                     } catch (InterruptedException e) {
546                         LOG.error("Failed to wait for post interface operation ");
547                     }
548                     newMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
549                     isSupportingOtsPresent = isSupportingOtsPresent(newMapping);
550                     count++;
551                 }
552                 if (count < 6) {
553                     String omsInterface =
554                             this.openRoadmInterfaceFactory.createOpenRoadmOmsInterface(input.getNodeId(), newMapping);
555                     if (omsInterface != null) {
556                         result = "Interfaces " + otsInterface + " - " + omsInterface + " successfully created on node "
557                                 + input.getNodeId();
558                         success = true;
559                     } else {
560                         LOG.error("Fail to create OpenRoadmOms Interface for node '{}'", input.getNodeId());
561                         result = "Fail to create OpenRoadmOms Interface for node : " + input.getNodeId();
562                     }
563                 } else {
564                     LOG.error("Unable to get ots interface from mapping {} for node {}",
565                             oldMapping.getLogicalConnectionPoint(), input.getNodeId());
566                     result = String.format("Unable to get ots interface from mapping %s - %s",
567                             oldMapping.getLogicalConnectionPoint(), input.getNodeId());
568                 }
569             } else {
570                 result = "Logical Connection point " + input.getLogicalConnectionPoint() + " does not exist for "
571                         + input.getNodeId();
572             }
573         } else {
574             result = input.getNodeId() + " is not mounted on the controller";
575             LOG.warn("{} is not mounted on the controller",input.getNodeId());
576         }
577         return output.setResult(result).setSuccess(success).build();
578     }
579
580     private Boolean isSupportingOtsPresent(Mapping mapping) {
581         Boolean result = false;
582         if (mapping != null) {
583             if (mapping.getSupportingOts() != null) {
584                 LOG.info("SupportingOts info is present in mapping {}", mapping);
585                 result = true;
586             } else {
587                 LOG.warn("SupportingOts info not present in mapping {}", mapping);
588             }
589         }
590         return result;
591     }
592
593     private void updateOtnTopology(CopyOnWriteArrayList<Nodes> nodes, boolean isDeletion) {
594         if (nodes.size() != 2) {
595             LOG.error("Error with OTU4 links to update in otn-topology");
596             return;
597         }
598         if (isDeletion) {
599             LOG.info("updating otn-topology removing OTU4 links");
600             this.networkModelService.deleteOtnLinks(nodes.get(0).getNodeId(), nodes.get(0).getDestTp(),
601                 nodes.get(1).getNodeId(), nodes.get(1).getDestTp(), OtnLinkType.OTU4);
602         } else {
603             LOG.info("updating otn-topology adding OTU4 links");
604             this.networkModelService.createOtnLinks(nodes.get(0).getNodeId(), nodes.get(0).getDestTp(),
605                 nodes.get(1).getNodeId(), nodes.get(1).getDestTp(), OtnLinkType.OTU4);
606         }
607     }
608 }