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;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.LinkedList;
15 import java.util.List;
17 import java.util.Optional;
19 import java.util.concurrent.ConcurrentHashMap;
20 import java.util.concurrent.ConcurrentLinkedQueue;
21 import java.util.concurrent.CopyOnWriteArrayList;
22 import java.util.concurrent.ExecutionException;
23 import java.util.concurrent.ForkJoinPool;
24 import java.util.concurrent.ForkJoinTask;
25 import java.util.concurrent.Future;
26 import java.util.concurrent.TimeUnit;
27 import java.util.concurrent.TimeoutException;
28 import java.util.concurrent.atomic.AtomicBoolean;
29 import org.eclipse.jdt.annotation.NonNull;
30 import org.opendaylight.mdsal.binding.api.DataBroker;
31 import org.opendaylight.mdsal.binding.api.ReadTransaction;
32 import org.opendaylight.mdsal.binding.api.WriteTransaction;
33 import org.opendaylight.mdsal.common.api.CommitInfo;
34 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
35 import org.opendaylight.transportpce.common.StringConstants;
36 import org.opendaylight.transportpce.common.Timeouts;
37 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
38 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
39 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
40 import org.opendaylight.transportpce.common.fixedflex.GridUtils;
41 import org.opendaylight.transportpce.common.fixedflex.SpectrumInformation;
42 import org.opendaylight.transportpce.common.mapping.PortMapping;
43 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
44 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
45 import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
46 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
47 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServiceListTopology;
48 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServicePathDirection;
49 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.ServiceNodelist;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service.nodelist.NodelistBuilder;
51 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service.nodelist.NodelistKey;
52 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.CreateOtsOmsInput;
53 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.CreateOtsOmsOutput;
54 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.CreateOtsOmsOutputBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.RendererRollbackInput;
56 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.RendererRollbackOutput;
57 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.RendererRollbackOutputBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInput;
59 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathOutput;
60 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathOutputBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.AEndApiInfo;
62 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.ZEndApiInfo;
63 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.renderer.rollback.output.FailedToRollback;
64 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.renderer.rollback.output.FailedToRollbackBuilder;
65 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.renderer.rollback.output.FailedToRollbackKey;
66 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.OpenroadmNodeVersion;
67 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.mapping.Mapping;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.Topology;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceList;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesBuilder;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesKey;
73 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.link.tp.LinkTp;
74 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.link.tp.LinkTpBuilder;
75 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.node.interfaces.NodeInterface;
76 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.node.interfaces.NodeInterfaceBuilder;
77 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.node.interfaces.NodeInterfaceKey;
78 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.optical.renderer.nodes.Nodes;
79 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
80 import org.slf4j.Logger;
81 import org.slf4j.LoggerFactory;
84 public class DeviceRendererServiceImpl implements DeviceRendererService {
85 private static final String IS_NOT_MOUNTED_ON_THE_CONTROLLER = " is not mounted on the controller";
86 private static final Logger LOG = LoggerFactory.getLogger(DeviceRendererServiceImpl.class);
87 private final DataBroker dataBroker;
88 private final DeviceTransactionManager deviceTransactionManager;
89 private final OpenRoadmInterfaceFactory openRoadmInterfaceFactory;
90 private final OpenRoadmInterfaces openRoadmInterfaces;
91 private final CrossConnect crossConnect;
92 private final PortMapping portMapping;
93 private final NetworkModelService networkModelService;
95 public DeviceRendererServiceImpl(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
96 OpenRoadmInterfaceFactory openRoadmInterfaceFactory, OpenRoadmInterfaces openRoadmInterfaces,
97 CrossConnect crossConnect, PortMapping portMapping, NetworkModelService networkModelService) {
98 this.dataBroker = dataBroker;
99 this.deviceTransactionManager = deviceTransactionManager;
100 this.openRoadmInterfaceFactory = openRoadmInterfaceFactory;
101 this.openRoadmInterfaces = openRoadmInterfaces;
102 this.crossConnect = crossConnect;
103 this.portMapping = portMapping;
104 this.networkModelService = networkModelService;
107 @SuppressWarnings("rawtypes")
108 // FIXME check if the ForkJoinTask raw type can be avoided
109 // Raw types use are discouraged since they lack type safety.
110 // Resulting Problems are observed at run time and not at compile time
112 public ServicePathOutput setupServicePath(ServicePathInput input, ServicePathDirection direction) {
113 LOG.info("setup service path for input {} and direction {}", input, direction);
114 List<Nodes> nodes = new ArrayList<>();
115 if (input.getNodes() != null) {
116 nodes.addAll(input.getNodes());
118 SpectrumInformation spectrumInformation = GridUtils.initSpectrumInformationFromServicePathInput(input);
119 // Register node for suppressing alarms
120 if (!alarmSuppressionNodeRegistration(input)) {
121 LOG.warn("Alarm suppresion node registration failed!!!!");
123 ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<>();
124 Map<NodeInterfaceKey,NodeInterface> nodeInterfaces = new ConcurrentHashMap<>();
125 Set<String> nodesProvisioned = Sets.newConcurrentHashSet();
126 CopyOnWriteArrayList<LinkTp> otnLinkTps = new CopyOnWriteArrayList<>();
127 ServiceListTopology topology = new ServiceListTopology();
128 AtomicBoolean success = new AtomicBoolean(true);
129 ForkJoinPool forkJoinPool = new ForkJoinPool();
130 ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
131 String nodeId = node.getNodeId();
132 // take the index of the node
133 int nodeIndex = nodes.indexOf(node);
134 LOG.info("Starting provisioning for node : {}", nodeId);
135 AEndApiInfo apiInfoA = null;
136 ZEndApiInfo apiInfoZ = null;
137 if (input.getAEndApiInfo() != null && input.getAEndApiInfo().getNodeId().contains(nodeId)) {
138 apiInfoA = input.getAEndApiInfo();
140 if (input.getZEndApiInfo() != null && input.getZEndApiInfo().getNodeId().contains(nodeId)) {
141 apiInfoZ = input.getZEndApiInfo();
143 List<String> createdEthInterfaces = new ArrayList<>();
144 List<String> createdOtuInterfaces = new ArrayList<>();
145 List<String> createdOduInterfaces = new ArrayList<>();
146 List<String> createdOchInterfaces = new ArrayList<>();
147 List<String> createdConnections = new ArrayList<>();
148 int crossConnectFlag = 0;
150 // if the node is currently mounted then proceed
151 if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
152 String srcTp = node.getSrcTp();
153 String destTp = node.getDestTp();
154 if ((destTp != null) && destTp.contains(StringConstants.NETWORK_TOKEN)) {
155 LOG.info("Adding supporting OCH interface for node {}, dest tp {}, spectrumInformation {}",
156 nodeId, destTp, spectrumInformation);
158 String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
159 nodeId, destTp, spectrumInformation);
160 createdOchInterfaces.add(supportingOchInterface);
161 String supportingOtuInterface = this.openRoadmInterfaceFactory.createOpenRoadmOtu4Interface(
162 nodeId, destTp, supportingOchInterface, apiInfoA, apiInfoZ);
163 createdOtuInterfaces.add(supportingOtuInterface);
165 otnLinkTps.add(new LinkTpBuilder().setNodeId(nodeId).setTpId(destTp).build());
167 createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4HOInterface(
168 nodeId, destTp, false, apiInfoA, apiInfoZ, "07"));
171 if ((srcTp != null) && srcTp.contains(StringConstants.CLIENT_TOKEN)) {
172 LOG.info("Adding supporting EThernet interface for node {}, src tp {}", nodeId, srcTp);
174 // create OpenRoadm Xponder Client Interfaces
175 createdEthInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(
178 if ((srcTp != null) && srcTp.contains(StringConstants.NETWORK_TOKEN)) {
179 LOG.info("Adding supporting OCH interface for node {}, src tp {}, spectrumInformation {}",
180 nodeId, srcTp, spectrumInformation);
182 // create OpenRoadm Xponder Line Interfaces
183 String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
184 nodeId, srcTp, spectrumInformation);
185 createdOchInterfaces.add(supportingOchInterface);
186 String supportingOtuInterface = this.openRoadmInterfaceFactory.createOpenRoadmOtu4Interface(
187 nodeId, srcTp, supportingOchInterface, apiInfoA, apiInfoZ);
188 createdOtuInterfaces.add(supportingOtuInterface);
189 createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(
190 nodeId, srcTp, supportingOtuInterface));
191 Mapping mapping = this.portMapping.getMapping(nodeId,srcTp);
192 createdOduInterfaces.add(
194 && mapping.getXponderType() != null
195 && (mapping.getXponderType().getIntValue() == 3
196 || mapping.getXponderType().getIntValue() == 2)
197 ? this.openRoadmInterfaceFactory.createOpenRoadmOtnOdu4Interface(
198 nodeId, destTp, supportingOtuInterface)
199 : this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(
200 nodeId, destTp, supportingOtuInterface));
202 if ((destTp != null) && destTp.contains(StringConstants.CLIENT_TOKEN)) {
203 LOG.info("Adding supporting EThernet interface for node {}, dest tp {}", nodeId, destTp);
205 // create OpenRoadm Xponder Client Interfaces
206 createdEthInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(
209 if ((srcTp != null) && (srcTp.contains(StringConstants.TTP_TOKEN)
210 || srcTp.contains(StringConstants.PP_TOKEN))) {
211 LOG.info("Adding supporting OCH interface for node {}, src tp {}, spectrumInformation {}",
212 nodeId, srcTp, spectrumInformation);
213 createdOchInterfaces.addAll(this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaces(
214 nodeId, srcTp, spectrumInformation));
216 if ((destTp != null) && (destTp.contains(StringConstants.TTP_TOKEN)
217 || destTp.contains(StringConstants.PP_TOKEN))) {
218 LOG.info("Adding supporting OCH interface for node {}, dest tp {}, spectrumInformation {}",
219 nodeId, destTp, spectrumInformation);
220 createdOchInterfaces.addAll(this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaces(
221 nodeId, destTp, spectrumInformation));
223 if (crossConnectFlag < 1) {
224 LOG.info("Creating cross connect between source {} and destination {} for node {}", srcTp,
226 Optional<String> connectionNameOpt =
227 this.crossConnect.postCrossConnect(nodeId, srcTp, destTp, spectrumInformation);
228 if (connectionNameOpt.isPresent()) {
229 nodesProvisioned.add(nodeId);
230 createdConnections.add(connectionNameOpt.get());
232 processErrorMessage("Unable to post Roadm-connection for node " + nodeId, forkJoinPool,
238 processErrorMessage(nodeId + IS_NOT_MOUNTED_ON_THE_CONTROLLER, forkJoinPool, results);
241 } catch (OpenRoadmInterfaceException ex) {
242 processErrorMessage("Setup service path failed! Exception:" + ex.toString(), forkJoinPool, results);
245 NodeInterface nodeInterface = new NodeInterfaceBuilder()
246 .withKey(new NodeInterfaceKey(nodeId))
248 .setConnectionId(createdConnections)
249 .setEthInterfaceId(createdEthInterfaces)
250 .setOtuInterfaceId(createdOtuInterfaces)
251 .setOduInterfaceId(createdOduInterfaces)
252 .setOchInterfaceId(createdOchInterfaces)
254 nodeInterfaces.put(nodeInterface.key(),nodeInterface);
258 } catch (InterruptedException | ExecutionException e) {
259 LOG.error("Error while setting up service paths!", e);
261 forkJoinPool.shutdown();
264 results.add("Roadm-connection successfully created for nodes: " + String.join(", ", nodesProvisioned));
266 // setting topology in the service list data store
268 setTopologyForService(input.getServiceName(), topology.getTopology());
269 } catch (InterruptedException | TimeoutException | ExecutionException e) {
270 LOG.warn("Failed to write topologies for service {}.", input.getServiceName(), e);
272 if (!alarmSuppressionNodeRemoval(input.getServiceName())) {
273 LOG.error("Alarm suppresion node removal failed!!!!");
275 return new ServicePathOutputBuilder()
276 .setNodeInterface(nodeInterfaces)
277 .setSuccess(success.get())
278 .setResult(String.join("\n", results))
279 .setLinkTp(otnLinkTps)
283 private ConcurrentLinkedQueue<String> processErrorMessage(String message, ForkJoinPool forkJoinPool,
284 ConcurrentLinkedQueue<String> messages) {
285 LOG.warn("Received error message {}", message);
286 messages.add(message);
287 forkJoinPool.shutdown();
291 @SuppressWarnings("rawtypes")
292 // FIXME check if the ForkJoinTask raw type can be avoided
293 // Raw types use are discouraged since they lack type safety.
294 // Resulting Problems are observed at run time and not at compile time
296 public ServicePathOutput deleteServicePath(ServicePathInput input) {
297 if (!alarmSuppressionNodeRegistration(input)) {
298 LOG.warn("Alarm suppresion node registraion failed!!!!");
300 List<Nodes> nodes = input.getNodes();
301 AtomicBoolean success = new AtomicBoolean(true);
302 ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<>();
303 CopyOnWriteArrayList<LinkTp> otnLinkTps = new CopyOnWriteArrayList<>();
304 ForkJoinPool forkJoinPool = new ForkJoinPool();
305 ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
306 String nodeId = node.getNodeId();
307 LOG.info("Deleting service setup on node {}", nodeId);
308 if (node.getDestTp() == null) {
309 LOG.error("Destination termination point must not be null.");
312 if (!this.deviceTransactionManager.isDeviceMounted(nodeId)) {
313 String result = nodeId + IS_NOT_MOUNTED_ON_THE_CONTROLLER;
317 forkJoinPool.shutdown();
319 //TODO should deletion end here?
321 // if the node is currently mounted then proceed.
323 String destTp = node.getDestTp();
325 if (node.getSrcTp() == null) {
326 otnLinkTps.add(new LinkTpBuilder()
331 srcTp = node.getSrcTp();
333 List<String> interfacesToDelete = new LinkedList<>();
334 interfacesToDelete.addAll(getInterfaces2delete(nodeId, srcTp, destTp,
335 input.getLowerSpectralSlotNumber().intValue(),
336 input.getHigherSpectralSlotNumber().intValue()));
337 for (String interfaceId : interfacesToDelete) {
339 this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
340 } catch (OpenRoadmInterfaceException e) {
341 String result = String.format("Failed to delete interface %s on node %s!", interfaceId, nodeId);
343 LOG.error(result, e);
350 } catch (InterruptedException | ExecutionException e) {
351 LOG.error("Error while deleting service paths!", e);
353 forkJoinPool.shutdown();
354 if (!alarmSuppressionNodeRemoval(input.getServiceName())) {
355 LOG.error("Alarm suppresion node removal failed!!!!");
357 return new ServicePathOutputBuilder()
358 .setSuccess(success.get())
359 .setLinkTp(otnLinkTps)
362 ? "Request processed"
363 : String.join("\n", results))
367 private List<String> getInterfaces2delete(
368 String nodeId, String srcTp, String destTp, int lowerSpectralSlotNumber, int higherSpectralSlotNumber) {
369 String spectralSlotName = String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR,
370 String.valueOf(lowerSpectralSlotNumber),
371 String.valueOf(higherSpectralSlotNumber));
372 if (destTp.contains(StringConstants.NETWORK_TOKEN)
373 || srcTp.contains(StringConstants.CLIENT_TOKEN)
374 || srcTp.contains(StringConstants.NETWORK_TOKEN)
375 || destTp.contains(StringConstants.CLIENT_TOKEN)) {
376 return getInterfacesTodelete(nodeId, srcTp, destTp, spectralSlotName);
379 List<String> interfacesToDelete = new LinkedList<>();
380 String connectionNumber = String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, destTp, spectralSlotName);
381 List<String> intToDelete = this.crossConnect.deleteCrossConnect(nodeId, connectionNumber, false);
382 for (String interf : intToDelete == null ? new ArrayList<String>() : intToDelete) {
383 if (!this.openRoadmInterfaceFactory.isUsedByXc(
384 nodeId, interf, connectionNumber, this.deviceTransactionManager)) {
385 interfacesToDelete.add(interf);
388 return interfacesToDelete;
391 private List<String> getInterfacesTodelete(String nodeId, String srcTp, String destTp, String spectralSlotName) {
393 OpenroadmNodeVersion nodeOpenRoadmVersion =
394 this.portMapping.getNode(nodeId).getNodeInfo().getOpenroadmVersion();
395 List<String> interfacesToDelete = new LinkedList<>();
396 Map<String, List<String>> suffixListMap =
397 nodeOpenRoadmVersion.equals(OpenroadmNodeVersion._71)
399 "ODU", List.of("ODUC4","ODUFLEX"),
400 "other", List.of("OTUC4", "OTSI-GROUP", spectralSlotName))
402 "ODU", List.of("ODU", "ODU4"),
403 "other", List.of("OTU", spectralSlotName));
404 // this last suffix used to be retrieved from openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName
405 // i.e. String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, spectralSlotName) with
406 // common GridConstant that states NAME_PARAMETERS_SEPARATOR = "-"
408 if (destTp.contains(StringConstants.NETWORK_TOKEN)) {
410 for (String suffix : suffixListMap.get("ODU")) {
411 if (this.openRoadmInterfaces.getInterface(
412 nodeId, String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix)).isPresent()) {
413 interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix));
417 catch (OpenRoadmInterfaceException e) {
418 LOG.error("impossible to get one of the interfaces {}",
419 destTp + GridConstant.NAME_PARAMETERS_SEPARATOR + String.join(
420 " or " + destTp + GridConstant.NAME_PARAMETERS_SEPARATOR,
421 suffixListMap.get("ODU")),
424 for (String suffix : suffixListMap.get("other")) {
425 interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix));
428 if (srcTp.contains(StringConstants.NETWORK_TOKEN)) {
429 interfacesToDelete.add(
430 String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, suffixListMap.get("ODU").get(0)));
431 for (String suffix : suffixListMap.get("other")) {
432 interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, suffix));
435 if (srcTp.contains(StringConstants.CLIENT_TOKEN)) {
436 interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, "ETHERNET"));
438 if (destTp.contains(StringConstants.CLIENT_TOKEN)) {
439 interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, "ETHERNET"));
441 return interfacesToDelete;
447 public RendererRollbackOutput rendererRollback(RendererRollbackInput input) {
448 boolean success = true;
449 Map<FailedToRollbackKey,FailedToRollback> failedToRollbackList = new HashMap<>();
450 for (NodeInterface nodeInterfaces : input.nonnullNodeInterface().values()) {
451 List<String> failedInterfaces = new ArrayList<>();
452 String nodeId = nodeInterfaces.getNodeId();
453 for (String connectionId : nodeInterfaces.getConnectionId()) {
454 List<String> listInter = this.crossConnect.deleteCrossConnect(nodeId, connectionId, false);
455 if (listInter != null) {
456 LOG.info("Cross connect {} on node {} successfully deleted.", connectionId, nodeId);
458 LOG.error("Failed to delete cross connect {} on node {}!", connectionId, nodeId);
460 failedInterfaces.add(connectionId);
463 // Interfaces needs to be in specific order to delete. Order is:
468 LinkedList<String> interfacesToDelete = new LinkedList<>();
469 if (nodeInterfaces.getOduInterfaceId() != null) {
470 interfacesToDelete.addAll(nodeInterfaces.getOduInterfaceId());
472 if (nodeInterfaces.getOtuInterfaceId() != null) {
473 interfacesToDelete.addAll(nodeInterfaces.getOtuInterfaceId());
475 if (nodeInterfaces.getOchInterfaceId() != null) {
476 interfacesToDelete.addAll(nodeInterfaces.getOchInterfaceId());
478 if (nodeInterfaces.getEthInterfaceId() != null) {
479 interfacesToDelete.addAll(nodeInterfaces.getEthInterfaceId());
481 LOG.info("Going to execute rollback on node {}. Interfaces to rollback: {}", nodeId,
482 String.join(", ", interfacesToDelete));
483 for (String interfaceId : interfacesToDelete) {
485 this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
486 LOG.info("Interface {} on node {} successfully deleted.", interfaceId, nodeId);
487 } catch (OpenRoadmInterfaceException e) {
488 LOG.error("Failed to delete interface {} on node {}!", interfaceId, nodeId);
490 failedInterfaces.add(interfaceId);
493 FailedToRollback failedToRollack = new FailedToRollbackBuilder().withKey(new FailedToRollbackKey(nodeId))
494 .setNodeId(nodeId).setInterface(failedInterfaces).build();
495 failedToRollbackList.put(failedToRollack.key(),failedToRollack);
497 return new RendererRollbackOutputBuilder()
499 .setFailedToRollback(failedToRollbackList)
503 private boolean alarmSuppressionNodeRegistration(ServicePathInput input) {
504 Map<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service
505 .nodelist.nodelist.NodesKey,
506 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service
507 .nodelist.nodelist.Nodes> nodeList = new HashMap<>();
508 if (input.getNodes() != null) {
509 for (Nodes node : input.getNodes()) {
510 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
511 .service.nodelist.nodelist.Nodes nodes =
512 new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
513 .service.nodelist.nodelist.NodesBuilder().setNodeId(node.getNodeId()).build();
514 nodeList.put(nodes.key(),nodes);
517 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
518 .service.nodelist.Nodelist> nodeListIID =
519 InstanceIdentifier.create(ServiceNodelist.class)
520 .child(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
521 .service.nodelist.Nodelist.class, new NodelistKey(input.getServiceName()));
522 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
523 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION,
525 new NodelistBuilder()
526 .withKey(new NodelistKey(input.getServiceName()))
527 .setServiceName(input.getServiceName())
530 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
532 commit.get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
533 LOG.info("Nodes are register for alarm suppression for service: {}", input.getServiceName());
535 } catch (ExecutionException | InterruptedException | TimeoutException e) {
536 LOG.warn("Failed to alarm suppresslist for service: {}", input.getServiceName(), e);
541 private boolean alarmSuppressionNodeRemoval(String serviceName) {
542 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
543 .service.nodelist.Nodelist> nodeListIID =
544 InstanceIdentifier.create(ServiceNodelist.class)
545 .child(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
546 .service.nodelist.Nodelist.class, new NodelistKey(serviceName));
547 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
548 writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, nodeListIID);
549 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
551 commit.get(Timeouts.DATASTORE_DELETE, TimeUnit.MILLISECONDS);
552 LOG.info("Nodes are unregister for alarm suppression for service: {}", serviceName);
554 } catch (InterruptedException | TimeoutException | ExecutionException e) {
555 LOG.warn("Failed to alarm suppresslist for service: {}", serviceName, e);
560 private void setTopologyForService(String name, Topology topo)
561 throws InterruptedException, ExecutionException, TimeoutException {
562 ServicesBuilder servicesBuilder;
563 // Get the service from the service list inventory
564 ServicesKey serviceKey = new ServicesKey(name);
565 InstanceIdentifier<Services> iid =
566 InstanceIdentifier.create(ServiceList.class).child(Services.class, serviceKey);
567 Optional<Services> services;
568 try (ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
569 Future<java.util.Optional<Services>> future =
570 readTx.read(LogicalDatastoreType.OPERATIONAL, iid);
571 services = future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS);
572 } catch (InterruptedException | ExecutionException | TimeoutException e) {
575 if (services.isPresent()) {
576 LOG.info("service {} already exists", name);
577 servicesBuilder = new ServicesBuilder(services.get()).setTopology(topo);
578 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
579 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, servicesBuilder.build());
580 writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
582 LOG.warn("Service {} does not exist - topology can not be updated", name);
586 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
587 value = "SLF4J_FORMAT_SHOULD_BE_CONST",
588 justification = "Log messages content needs to be formatted before"
589 + "since they are used in the returned object")
591 public CreateOtsOmsOutput createOtsOms(CreateOtsOmsInput input) throws OpenRoadmInterfaceException {
592 if (!this.deviceTransactionManager.isDeviceMounted(input.getNodeId())) {
593 String result = input.getNodeId() + IS_NOT_MOUNTED_ON_THE_CONTROLLER;
595 return new CreateOtsOmsOutputBuilder().setResult(result).setSuccess(false).build();
597 // if the node is currently mounted then proceed.
598 Mapping oldMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
599 if (oldMapping == null) {
600 return new CreateOtsOmsOutputBuilder()
601 .setResult(String.format("Logical Connection point %s does not exist for %s",
602 input.getLogicalConnectionPoint(), input.getNodeId()))
607 String otsInterface = this.openRoadmInterfaceFactory.createOpenRoadmOtsInterface(input.getNodeId(), oldMapping);
609 Mapping newMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
610 while (!isSupportingOtsPresent(newMapping)) {
611 LOG.info("waiting for post interface operation on node '{}'...", input.getNodeId());
614 this.portMapping.updateMapping(input.getNodeId(), oldMapping);
615 } catch (InterruptedException e) {
616 LOG.error("Failed to wait for post interface operation");
620 String result = String.format("Unable to get ots interface from mapping %s - %s",
621 oldMapping.getLogicalConnectionPoint(), input.getNodeId());
623 return new CreateOtsOmsOutputBuilder().setResult(result).setSuccess(false).build();
625 newMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
628 String omsInterface = this.openRoadmInterfaceFactory.createOpenRoadmOmsInterface(input.getNodeId(), newMapping);
629 if (omsInterface == null) {
630 String result = String.format("Fail to create OpenRoadmOms Interface for node : %s", input.getNodeId());
632 return new CreateOtsOmsOutputBuilder().setResult(result).setSuccess(false).build();
634 return new CreateOtsOmsOutputBuilder()
635 .setResult(String.format("Interfaces %s - %s successfully created on node %s",
636 otsInterface, omsInterface, input.getNodeId()))
641 private Boolean isSupportingOtsPresent(Mapping mapping) {
642 if (mapping == null) {
645 if (mapping.getSupportingOts() == null) {
646 LOG.warn("SupportingOts info is not present in mapping {}", mapping);
649 LOG.info("SupportingOts info is present in mapping {}", mapping);