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