2 * Copyright © 2017 AT&T and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.renderer.provisiondevice;
10 import com.google.common.collect.Sets;
11 import com.google.common.util.concurrent.FluentFuture;
13 import java.util.ArrayList;
14 import java.util.LinkedList;
15 import java.util.List;
16 import java.util.Optional;
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;
27 import org.eclipse.jdt.annotation.NonNull;
28 import org.opendaylight.mdsal.binding.api.DataBroker;
29 import org.opendaylight.mdsal.binding.api.ReadTransaction;
30 import org.opendaylight.mdsal.binding.api.WriteTransaction;
31 import org.opendaylight.mdsal.common.api.CommitInfo;
32 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
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.rev200128.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.yangtools.yang.binding.InstanceIdentifier;
70 import org.slf4j.Logger;
71 import org.slf4j.LoggerFactory;
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;
85 public DeviceRendererServiceImpl(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
86 OpenRoadmInterfaceFactory openRoadmInterfaceFactory, OpenRoadmInterfaces openRoadmInterfaces,
87 CrossConnect crossConnect, PortMapping portMapping) {
88 this.dataBroker = dataBroker;
89 this.deviceTransactionManager = deviceTransactionManager;
90 this.openRoadmInterfaceFactory = openRoadmInterfaceFactory;
91 this.openRoadmInterfaces = openRoadmInterfaces;
92 this.crossConnect = crossConnect;
93 this.portMapping = portMapping;
97 public ServicePathOutput setupServicePath(ServicePathInput input, ServicePathDirection direction) {
98 List<Nodes> nodes = input.getNodes();
99 // Register node for suppressing alarms
100 if (!alarmSuppressionNodeRegistration(input)) {
101 LOG.warn("Alarm suppresion node registration failed!!!!");
103 ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<>();
104 Set<NodeInterface> nodeInterfaces = Sets.newConcurrentHashSet();
105 Set<String> nodesProvisioned = Sets.newConcurrentHashSet();
106 ServiceListTopology topology = new ServiceListTopology();
107 AtomicBoolean success = new AtomicBoolean(true);
108 ForkJoinPool forkJoinPool = new ForkJoinPool();
109 ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
110 String nodeId = node.getNodeId();
111 LOG.info("Starting provisioning for node : {}", nodeId);
112 List<String> createdEthInterfaces = new ArrayList<>();
113 List<String> createdOtuInterfaces = new ArrayList<>();
114 List<String> createdOduInterfaces = new ArrayList<>();
115 List<String> createdOchInterfaces = new ArrayList<>();
116 List<String> createdConnections = new ArrayList<>();
117 int crossConnectFlag = 0;
119 // if the node is currently mounted then proceed
120 if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
121 String srcTp = node.getSrcTp();
122 String destTp = node.getDestTp();
123 Long waveNumber = input.getWaveNumber().toJava();
124 if ((destTp != null) && destTp.contains(StringConstants.NETWORK_TOKEN)) {
126 Mapping mapping = this.portMapping.getMapping(nodeId,destTp);
127 String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
128 nodeId, destTp, waveNumber, ModulationFormat.DpQpsk);
129 createdOchInterfaces.add(supportingOchInterface);
130 String supportingOtuInterface = this.openRoadmInterfaceFactory
131 .createOpenRoadmOtu4Interface(nodeId, destTp, supportingOchInterface);
132 createdOtuInterfaces.add(supportingOtuInterface);
133 if (mapping != null && mapping.getXponderType() != null
134 && (mapping.getXponderType().getIntValue() == 3
135 || mapping.getXponderType().getIntValue() == 2)) {
136 createdOduInterfaces.add(this.openRoadmInterfaceFactory
137 .createOpenRoadmOtnOdu4Interface(nodeId,destTp, supportingOtuInterface));
139 createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
140 destTp, supportingOtuInterface));
143 if ((srcTp != null) && srcTp.contains(StringConstants.CLIENT_TOKEN)) {
145 // create OpenRoadm Xponder Client Interfaces
146 createdEthInterfaces.add(
147 this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(nodeId, srcTp));
149 if ((srcTp != null) && srcTp.contains(StringConstants.NETWORK_TOKEN)) {
151 // create OpenRoadm Xponder Line Interfaces
152 String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
153 nodeId, srcTp, waveNumber, ModulationFormat.DpQpsk);
154 createdOchInterfaces.add(supportingOchInterface);
155 String supportingOtuInterface = this.openRoadmInterfaceFactory
156 .createOpenRoadmOtu4Interface(nodeId, srcTp, supportingOchInterface);
157 createdOtuInterfaces.add(supportingOtuInterface);
158 createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
159 srcTp, supportingOtuInterface));
160 Mapping mapping = this.portMapping.getMapping(nodeId,srcTp);
161 if (mapping != null && mapping.getXponderType() != null
162 && (mapping.getXponderType().getIntValue() == 3
163 || mapping.getXponderType().getIntValue() == 2)) {
164 createdOduInterfaces.add(this.openRoadmInterfaceFactory
165 .createOpenRoadmOtnOdu4Interface(nodeId, destTp, supportingOtuInterface));
167 createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
168 destTp, supportingOtuInterface));
171 if ((destTp != null) && destTp.contains(StringConstants.CLIENT_TOKEN)) {
173 // create OpenRoadm Xponder Client Interfaces
174 createdEthInterfaces.add(
175 this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(nodeId, destTp));
177 if ((srcTp != null) && (srcTp.contains(StringConstants.TTP_TOKEN)
178 || srcTp.contains(StringConstants.PP_TOKEN))) {
179 createdOchInterfaces.addAll(
180 this.openRoadmInterfaceFactory
181 .createOpenRoadmOchInterface(nodeId, srcTp, waveNumber));
183 if ((destTp != null) && (destTp.contains(StringConstants.TTP_TOKEN)
184 || destTp.contains(StringConstants.PP_TOKEN))) {
185 createdOchInterfaces.addAll(
186 this.openRoadmInterfaceFactory
187 .createOpenRoadmOchInterface(nodeId, destTp, waveNumber));
189 if (crossConnectFlag < 1) {
190 LOG.info("Creating cross connect between source {} and destination {} for node {}", srcTp,
192 Optional<String> connectionNameOpt =
193 this.crossConnect.postCrossConnect(nodeId, waveNumber, srcTp, destTp);
194 if (connectionNameOpt.isPresent()) {
195 nodesProvisioned.add(nodeId);
196 createdConnections.add(connectionNameOpt.get());
198 processErrorMessage("Unable to post Roadm-connection for node " + nodeId, forkJoinPool,
204 processErrorMessage(nodeId + " is not mounted on the controller", forkJoinPool, results);
207 } catch (OpenRoadmInterfaceException ex) {
208 processErrorMessage("Setup service path failed! Exception:" + ex.toString(), forkJoinPool, results);
211 NodeInterfaceBuilder nodeInterfaceBuilder = new NodeInterfaceBuilder()
212 .withKey(new NodeInterfaceKey(nodeId))
214 .setConnectionId(createdConnections)
215 .setEthInterfaceId(createdEthInterfaces)
216 .setOtuInterfaceId(createdOtuInterfaces)
217 .setOduInterfaceId(createdOduInterfaces)
218 .setOchInterfaceId(createdOchInterfaces);
219 nodeInterfaces.add(nodeInterfaceBuilder.build());
223 } catch (InterruptedException | ExecutionException e) {
224 LOG.error("Error while setting up service paths!", e);
226 forkJoinPool.shutdown();
229 results.add("Roadm-connection successfully created for nodes: " + String.join(", ", nodesProvisioned));
231 ServicePathOutputBuilder setServBldr = new ServicePathOutputBuilder()
232 .setNodeInterface(new ArrayList<>(nodeInterfaces))
233 .setSuccess(success.get())
234 .setResult(String.join("\n", results));
235 // setting topology in the service list data store
237 setTopologyForService(input.getServiceName(), topology.getTopology());
238 } catch (InterruptedException | TimeoutException | ExecutionException e) {
239 LOG.warn("Failed to write topologies for service {}.", input.getServiceName(), e);
241 if (!alarmSuppressionNodeRemoval(input.getServiceName())) {
242 LOG.error("Alarm suppresion node removal failed!!!!");
244 return setServBldr.build();
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();
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!!!!");
263 ForkJoinPool forkJoinPool = new ForkJoinPool();
264 ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
265 List<String> interfacesToDelete = new LinkedList<>();
266 String nodeId = node.getNodeId();
267 LOG.info("Deleting service setup on node {}", nodeId);
270 Long waveNumber = input.getWaveNumber().toJava();
271 if (node.getDestTp() == null) {
272 LOG.error("Destination termination point must not be null.");
275 destTp = node.getDestTp();
277 if (node.getSrcTp() != null) {
278 srcTp = node.getSrcTp();
282 // if the node is currently mounted then proceed.
283 if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
284 interfacesToDelete.addAll(getInterfaces2delete(nodeId, srcTp, destTp, waveNumber));
286 String result = nodeId + " is not mounted on the controller";
290 forkJoinPool.shutdown();
292 //TODO should deletion end here?
294 for (String interfaceId : interfacesToDelete) {
296 this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
297 } catch (OpenRoadmInterfaceException e) {
298 String result = String.format("Failed to delete interface %s on node %s!", interfaceId, nodeId);
300 LOG.error(result, e);
307 } catch (InterruptedException | ExecutionException e) {
308 LOG.error("Error while deleting service paths!", e);
310 forkJoinPool.shutdown();
311 if (!alarmSuppressionNodeRemoval(input.getServiceName())) {
312 LOG.error("Alarm suppresion node removal failed!!!!");
314 ServicePathOutputBuilder delServBldr = new ServicePathOutputBuilder();
315 delServBldr.setSuccess(success.get());
316 if (results.isEmpty()) {
317 return delServBldr.setResult("Request processed").build();
319 return delServBldr.setResult(String.join("\n", results)).build();
323 private List<String> getInterfaces2delete(
324 String nodeId, String srcTp, String destTp, Long waveNumber) {
325 List<String> interfacesToDelete = new LinkedList<>();
326 if (destTp.contains(StringConstants.NETWORK_TOKEN)
327 || srcTp.contains(StringConstants.CLIENT_TOKEN)
328 || srcTp.contains(StringConstants.NETWORK_TOKEN)
329 || destTp.contains(StringConstants.CLIENT_TOKEN)) {
330 if (destTp.contains(StringConstants.NETWORK_TOKEN)) {
332 if (this.openRoadmInterfaces.getInterface(nodeId, destTp + "-ODU").isPresent()) {
333 interfacesToDelete.add(destTp + "-ODU");
335 if (this.openRoadmInterfaces.getInterface(nodeId, destTp + ODU4).isPresent()) {
336 interfacesToDelete.add(destTp + ODU4);
339 catch (OpenRoadmInterfaceException e) {
340 LOG.error("impossible to get interface {} or {}", destTp + "-ODU", destTp + ODU4, e);
342 interfacesToDelete.add(destTp + "-OTU");
343 interfacesToDelete.add(
344 this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName(destTp, waveNumber));
346 if (srcTp.contains(StringConstants.NETWORK_TOKEN)) {
347 interfacesToDelete.add(srcTp + "-ODU");
348 interfacesToDelete.add(srcTp + "-OTU");
350 .add(this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName(srcTp, waveNumber));
352 if (srcTp.contains(StringConstants.CLIENT_TOKEN)) {
353 interfacesToDelete.add(srcTp + "-ETHERNET");
355 if (destTp.contains(StringConstants.CLIENT_TOKEN)) {
356 interfacesToDelete.add(destTp + "-ETHERNET");
359 String connectionNumber = srcTp + "-" + destTp + "-" + waveNumber;
360 List<String> intToDelete = this.crossConnect.deleteCrossConnect(nodeId, connectionNumber, false);
361 connectionNumber = destTp + "-" + srcTp + "-" + waveNumber;
362 if (intToDelete != null) {
363 for (String interf : intToDelete) {
364 if (!this.openRoadmInterfaceFactory.isUsedByXc(nodeId, interf, connectionNumber,
365 this.deviceTransactionManager)) {
366 interfacesToDelete.add(interf);
371 return interfacesToDelete;
375 public RendererRollbackOutput rendererRollback(RendererRollbackInput input) {
376 boolean success = true;
377 List<FailedToRollback> failedToRollbackList = new ArrayList<>();
378 for (NodeInterface nodeInterfaces : input.getNodeInterface()) {
379 List<String> failedInterfaces = new ArrayList<>();
380 String nodeId = nodeInterfaces.getNodeId();
381 for (String connectionId : nodeInterfaces.getConnectionId()) {
382 List<String> listInter = this.crossConnect.deleteCrossConnect(nodeId, connectionId, false);
383 if (listInter != null) {
384 LOG.info("Cross connect {} on node {} successfully deleted.", connectionId, nodeId);
386 LOG.error("Failed to delete cross connect {} on node {}!", connectionId, nodeId);
388 failedInterfaces.add(connectionId);
391 // Interfaces needs to be in specific order to delete. Order is:
396 LinkedList<String> interfacesToDelete = new LinkedList<>();
397 if (nodeInterfaces.getOduInterfaceId() != null) {
398 interfacesToDelete.addAll(nodeInterfaces.getOduInterfaceId());
400 if (nodeInterfaces.getOtuInterfaceId() != null) {
401 interfacesToDelete.addAll(nodeInterfaces.getOtuInterfaceId());
403 if (nodeInterfaces.getOchInterfaceId() != null) {
404 interfacesToDelete.addAll(nodeInterfaces.getOchInterfaceId());
406 if (nodeInterfaces.getEthInterfaceId() != null) {
407 interfacesToDelete.addAll(nodeInterfaces.getEthInterfaceId());
409 LOG.info("Going to execute rollback on node {}. Interfaces to rollback: {}", nodeId,
410 String.join(", ", interfacesToDelete));
411 for (String interfaceId : interfacesToDelete) {
413 this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
414 LOG.info("Interface {} on node {} successfully deleted.", interfaceId, nodeId);
415 } catch (OpenRoadmInterfaceException e) {
416 LOG.error("Failed to delete interface {} on node {}!", interfaceId, nodeId);
418 failedInterfaces.add(interfaceId);
421 failedToRollbackList.add(new FailedToRollbackBuilder().withKey(new FailedToRollbackKey(nodeId))
422 .setNodeId(nodeId).setInterface(failedInterfaces).build());
424 return new RendererRollbackOutputBuilder().setSuccess(success).setFailedToRollback(failedToRollbackList)
428 private boolean alarmSuppressionNodeRegistration(ServicePathInput input) {
429 NodelistBuilder nodeListBuilder = new NodelistBuilder()
430 .withKey(new NodelistKey(input.getServiceName()))
431 .setServiceName(input.getServiceName());
432 List<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service
433 .nodelist.nodelist.Nodes> nodeList =
435 for (Nodes node : input.getNodes()) {
437 new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
438 .service.nodelist.nodelist.NodesBuilder()
439 .setNodeId(node.getNodeId()).build());
441 nodeListBuilder.setNodes(nodeList);
442 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
443 .service.nodelist.Nodelist> nodeListIID =
444 InstanceIdentifier.create(ServiceNodelist.class).child(
445 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression
446 .rev171102.service.nodelist.Nodelist.class,
447 new NodelistKey(input.getServiceName()));
448 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
449 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodeListIID, nodeListBuilder.build());
450 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
452 commit.get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
453 LOG.info("Nodes are register for alarm suppression for service: {}", input.getServiceName());
455 } catch (ExecutionException | InterruptedException | TimeoutException e) {
456 LOG.warn("Failed to alarm suppresslist for service: {}", input.getServiceName(), e);
461 private boolean alarmSuppressionNodeRemoval(String serviceName) {
462 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
463 .service.nodelist.Nodelist> nodeListIID =
464 InstanceIdentifier.create(ServiceNodelist.class).child(
465 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression
466 .rev171102.service.nodelist.Nodelist.class,
467 new NodelistKey(serviceName));
468 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
469 writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, nodeListIID);
470 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
472 commit.get(Timeouts.DATASTORE_DELETE, TimeUnit.MILLISECONDS);
473 LOG.info("Nodes are unregister for alarm suppression for service: {}", serviceName);
475 } catch (InterruptedException | TimeoutException | ExecutionException e) {
476 LOG.warn("Failed to alarm suppresslist for service: {}", serviceName, e);
481 private void setTopologyForService(String name, Topology topo)
482 throws InterruptedException, ExecutionException, TimeoutException {
483 ServicesBuilder servicesBuilder;
484 // Get the service from the service list inventory
485 ServicesKey serviceKey = new ServicesKey(name);
486 InstanceIdentifier<Services> iid =
487 InstanceIdentifier.create(ServiceList.class).child(Services.class, serviceKey);
488 Optional<Services> services;
489 try (ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
490 Future<java.util.Optional<Services>> future =
491 readTx.read(LogicalDatastoreType.OPERATIONAL, iid);
492 services = future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS);
493 } catch (InterruptedException | ExecutionException | TimeoutException e) {
496 if (services.isPresent()) {
497 LOG.info("service {} already exists", name);
498 servicesBuilder = new ServicesBuilder(services.get()).setTopology(topo);
499 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
500 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, servicesBuilder.build());
501 writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
503 LOG.warn("Service {} does not exist - topology can not be updated", name);
508 public CreateOtsOmsOutput createOtsOms(CreateOtsOmsInput input) throws OpenRoadmInterfaceException {
509 CreateOtsOmsOutputBuilder output = new CreateOtsOmsOutputBuilder();
511 Boolean success = false;
512 // if the node is currently mounted then proceed.
513 if (this.deviceTransactionManager.isDeviceMounted(input.getNodeId())) {
514 Mapping oldMapping = null;
515 Mapping newMapping = null;
516 oldMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
517 if (oldMapping != null) {
518 String otsInterface =
519 this.openRoadmInterfaceFactory.createOpenRoadmOtsInterface(input.getNodeId(), oldMapping);
520 newMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
522 Boolean isSupportingOtsPresent = isSupportingOtsPresent(newMapping);
523 while (!isSupportingOtsPresent && (count < 6)) {
524 LOG.info("waiting for post interface operation on node '{}'...", input.getNodeId());
527 this.portMapping.updateMapping(input.getNodeId(), oldMapping);
528 } catch (InterruptedException e) {
529 LOG.error("Failed to wait for post interface operation ");
531 newMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
532 isSupportingOtsPresent = isSupportingOtsPresent(newMapping);
536 String omsInterface =
537 this.openRoadmInterfaceFactory.createOpenRoadmOmsInterface(input.getNodeId(), newMapping);
538 if (omsInterface != null) {
539 result = "Interfaces " + otsInterface + " - " + omsInterface + " successfully created on node "
543 LOG.error("Fail to create OpenRoadmOms Interface for node '{}'", input.getNodeId());
544 result = "Fail to create OpenRoadmOms Interface for node : " + input.getNodeId();
547 LOG.error("Unable to get ots interface from mapping {} for node {}",
548 oldMapping.getLogicalConnectionPoint(), input.getNodeId());
549 result = String.format("Unable to get ots interface from mapping %s - %s",
550 oldMapping.getLogicalConnectionPoint(), input.getNodeId());
553 result = "Logical Connection point " + input.getLogicalConnectionPoint() + " does not exist for "
557 result = input.getNodeId() + " is not mounted on the controller";
558 LOG.warn("{} is not mounted on the controller",input.getNodeId());
560 return output.setResult(result).setSuccess(success).build();
563 private Boolean isSupportingOtsPresent(Mapping mapping) {
564 Boolean result = false;
565 if (mapping != null) {
566 if (mapping.getSupportingOts() != null) {
567 LOG.info("SupportingOts info is present in mapping {}", mapping);
570 LOG.warn("SupportingOts info not present in mapping {}", mapping);