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