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