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.rev210618.CreateOtsOmsInput;
53 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.CreateOtsOmsOutput;
54 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.CreateOtsOmsOutputBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.RendererRollbackInput;
56 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.RendererRollbackOutput;
57 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.RendererRollbackOutputBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.ServicePathInput;
59 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.ServicePathOutput;
60 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.ServicePathOutputBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.renderer.rollback.output.FailedToRollback;
62 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.renderer.rollback.output.FailedToRollbackBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.renderer.rollback.output.FailedToRollbackKey;
64 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.OpenroadmNodeVersion;
65 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.mapping.Mapping;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.Topology;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceList;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesBuilder;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesKey;
71 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.link.tp.LinkTp;
72 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.link.tp.LinkTpBuilder;
73 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.node.interfaces.NodeInterface;
74 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.node.interfaces.NodeInterfaceBuilder;
75 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.node.interfaces.NodeInterfaceKey;
76 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.optical.renderer.nodes.Nodes;
77 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
78 import org.slf4j.Logger;
79 import org.slf4j.LoggerFactory;
82 public class DeviceRendererServiceImpl implements DeviceRendererService {
83 private static final String IS_NOT_MOUNTED_ON_THE_CONTROLLER = " is not mounted on the controller";
84 private static final Logger LOG = LoggerFactory.getLogger(DeviceRendererServiceImpl.class);
85 private final DataBroker dataBroker;
86 private final DeviceTransactionManager deviceTransactionManager;
87 private final OpenRoadmInterfaceFactory openRoadmInterfaceFactory;
88 private final OpenRoadmInterfaces openRoadmInterfaces;
89 private final CrossConnect crossConnect;
90 private final PortMapping portMapping;
91 private final NetworkModelService networkModelService;
93 public DeviceRendererServiceImpl(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
94 OpenRoadmInterfaceFactory openRoadmInterfaceFactory, OpenRoadmInterfaces openRoadmInterfaces,
95 CrossConnect crossConnect, PortMapping portMapping, NetworkModelService networkModelService) {
96 this.dataBroker = dataBroker;
97 this.deviceTransactionManager = deviceTransactionManager;
98 this.openRoadmInterfaceFactory = openRoadmInterfaceFactory;
99 this.openRoadmInterfaces = openRoadmInterfaces;
100 this.crossConnect = crossConnect;
101 this.portMapping = portMapping;
102 this.networkModelService = networkModelService;
105 @SuppressWarnings("rawtypes")
106 // FIXME check if the ForkJoinTask raw type can be avoided
107 // Raw types use are discouraged since they lack type safety.
108 // Resulting Problems are observed at run time and not at compile time
110 public ServicePathOutput setupServicePath(ServicePathInput input, ServicePathDirection direction) {
111 LOG.info("setup service path for input {} and direction {}", input, direction);
112 List<Nodes> nodes = new ArrayList<>();
113 if (input.getNodes() != null) {
114 nodes.addAll(input.getNodes());
116 SpectrumInformation spectrumInformation = GridUtils.initSpectrumInformationFromServicePathInput(input);
117 // Register node for suppressing alarms
118 if (!alarmSuppressionNodeRegistration(input)) {
119 LOG.warn("Alarm suppresion node registration failed!!!!");
121 ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<>();
122 Map<NodeInterfaceKey,NodeInterface> nodeInterfaces = new ConcurrentHashMap<>();
123 Set<String> nodesProvisioned = Sets.newConcurrentHashSet();
124 CopyOnWriteArrayList<LinkTp> otnLinkTps = new CopyOnWriteArrayList<>();
125 ServiceListTopology topology = new ServiceListTopology();
126 AtomicBoolean success = new AtomicBoolean(true);
127 ForkJoinPool forkJoinPool = new ForkJoinPool();
128 ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
129 String nodeId = node.getNodeId();
130 // take the index of the node
131 int nodeIndex = nodes.indexOf(node);
132 LOG.info("Starting provisioning for node : {}", nodeId);
133 List<String> createdEthInterfaces = new ArrayList<>();
134 List<String> createdOtuInterfaces = new ArrayList<>();
135 List<String> createdOduInterfaces = new ArrayList<>();
136 List<String> createdOchInterfaces = new ArrayList<>();
137 List<String> createdConnections = new ArrayList<>();
138 int crossConnectFlag = 0;
140 // if the node is currently mounted then proceed
141 if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
142 String srcTp = node.getSrcTp();
143 String destTp = node.getDestTp();
144 if ((destTp != null) && destTp.contains(StringConstants.NETWORK_TOKEN)) {
145 LOG.info("Adding supporting OCH interface for node {}, dest tp {}, spectrumInformation {}",
146 nodeId, destTp, spectrumInformation);
148 String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
149 nodeId, destTp, spectrumInformation);
150 createdOchInterfaces.add(supportingOchInterface);
151 // Here we pass logical connection-point of z-end to set SAPI and DAPI
153 nodeIndex + 1 == nodes.size()
154 // For the end node, tgtNode becomes the first node in the list
156 : nodes.get(nodeIndex + 1);
157 // tgtNode srcTp is null in this last cond
158 String supportingOtuInterface = this.openRoadmInterfaceFactory.createOpenRoadmOtu4Interface(
159 nodeId, destTp, supportingOchInterface, tgtNode.getNodeId(), tgtNode.getDestTp());
160 createdOtuInterfaces.add(supportingOtuInterface);
162 otnLinkTps.add(new LinkTpBuilder().setNodeId(nodeId).setTpId(destTp).build());
164 createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
165 destTp, supportingOtuInterface));
168 if ((srcTp != null) && srcTp.contains(StringConstants.CLIENT_TOKEN)) {
169 LOG.info("Adding supporting EThernet interface for node {}, src tp {}", nodeId, srcTp);
171 // create OpenRoadm Xponder Client Interfaces
172 createdEthInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(
175 if ((srcTp != null) && srcTp.contains(StringConstants.NETWORK_TOKEN)) {
176 LOG.info("Adding supporting OCH interface for node {}, src tp {}, spectrumInformation {}",
177 nodeId, srcTp, spectrumInformation);
179 // create OpenRoadm Xponder Line Interfaces
180 String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
181 nodeId, srcTp, spectrumInformation);
182 createdOchInterfaces.add(supportingOchInterface);
183 String supportingOtuInterface = this.openRoadmInterfaceFactory.createOpenRoadmOtu4Interface(
184 nodeId, srcTp, supportingOchInterface);
185 createdOtuInterfaces.add(supportingOtuInterface);
186 createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(
187 nodeId, srcTp, supportingOtuInterface));
188 Mapping mapping = this.portMapping.getMapping(nodeId,srcTp);
189 createdOduInterfaces.add(
191 && mapping.getXponderType() != null
192 && (mapping.getXponderType().getIntValue() == 3
193 || mapping.getXponderType().getIntValue() == 2)
194 ? this.openRoadmInterfaceFactory.createOpenRoadmOtnOdu4Interface(
195 nodeId, destTp, supportingOtuInterface)
196 : this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(
197 nodeId, destTp, supportingOtuInterface));
199 if ((destTp != null) && destTp.contains(StringConstants.CLIENT_TOKEN)) {
200 LOG.info("Adding supporting EThernet interface for node {}, dest tp {}", nodeId, destTp);
202 // create OpenRoadm Xponder Client Interfaces
203 createdEthInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(
206 if ((srcTp != null) && (srcTp.contains(StringConstants.TTP_TOKEN)
207 || srcTp.contains(StringConstants.PP_TOKEN))) {
208 LOG.info("Adding supporting OCH interface for node {}, src tp {}, spectrumInformation {}",
209 nodeId, srcTp, spectrumInformation);
210 createdOchInterfaces.addAll(this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaces(
211 nodeId, srcTp, spectrumInformation));
213 if ((destTp != null) && (destTp.contains(StringConstants.TTP_TOKEN)
214 || destTp.contains(StringConstants.PP_TOKEN))) {
215 LOG.info("Adding supporting OCH interface for node {}, dest tp {}, spectrumInformation {}",
216 nodeId, destTp, spectrumInformation);
217 createdOchInterfaces.addAll(this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaces(
218 nodeId, destTp, spectrumInformation));
220 if (crossConnectFlag < 1) {
221 LOG.info("Creating cross connect between source {} and destination {} for node {}", srcTp,
223 Optional<String> connectionNameOpt =
224 this.crossConnect.postCrossConnect(nodeId, srcTp, destTp, spectrumInformation);
225 if (connectionNameOpt.isPresent()) {
226 nodesProvisioned.add(nodeId);
227 createdConnections.add(connectionNameOpt.get());
229 processErrorMessage("Unable to post Roadm-connection for node " + nodeId, forkJoinPool,
235 processErrorMessage(nodeId + IS_NOT_MOUNTED_ON_THE_CONTROLLER, forkJoinPool, results);
238 } catch (OpenRoadmInterfaceException ex) {
239 processErrorMessage("Setup service path failed! Exception:" + ex.toString(), forkJoinPool, results);
242 NodeInterface nodeInterface = new NodeInterfaceBuilder()
243 .withKey(new NodeInterfaceKey(nodeId))
245 .setConnectionId(createdConnections)
246 .setEthInterfaceId(createdEthInterfaces)
247 .setOtuInterfaceId(createdOtuInterfaces)
248 .setOduInterfaceId(createdOduInterfaces)
249 .setOchInterfaceId(createdOchInterfaces)
251 nodeInterfaces.put(nodeInterface.key(),nodeInterface);
255 } catch (InterruptedException | ExecutionException e) {
256 LOG.error("Error while setting up service paths!", e);
258 forkJoinPool.shutdown();
261 results.add("Roadm-connection successfully created for nodes: " + String.join(", ", nodesProvisioned));
263 // setting topology in the service list data store
265 setTopologyForService(input.getServiceName(), topology.getTopology());
266 } catch (InterruptedException | TimeoutException | ExecutionException e) {
267 LOG.warn("Failed to write topologies for service {}.", input.getServiceName(), e);
269 if (!alarmSuppressionNodeRemoval(input.getServiceName())) {
270 LOG.error("Alarm suppresion node removal failed!!!!");
272 return new ServicePathOutputBuilder()
273 .setNodeInterface(nodeInterfaces)
274 .setSuccess(success.get())
275 .setResult(String.join("\n", results))
276 .setLinkTp(otnLinkTps)
280 private ConcurrentLinkedQueue<String> processErrorMessage(String message, ForkJoinPool forkJoinPool,
281 ConcurrentLinkedQueue<String> messages) {
282 LOG.warn("Received error message {}", message);
283 messages.add(message);
284 forkJoinPool.shutdown();
288 @SuppressWarnings("rawtypes")
289 // FIXME check if the ForkJoinTask raw type can be avoided
290 // Raw types use are discouraged since they lack type safety.
291 // Resulting Problems are observed at run time and not at compile time
293 public ServicePathOutput deleteServicePath(ServicePathInput input) {
294 if (!alarmSuppressionNodeRegistration(input)) {
295 LOG.warn("Alarm suppresion node registraion failed!!!!");
297 List<Nodes> nodes = input.getNodes();
298 AtomicBoolean success = new AtomicBoolean(true);
299 ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<>();
300 CopyOnWriteArrayList<LinkTp> otnLinkTps = new CopyOnWriteArrayList<>();
301 ForkJoinPool forkJoinPool = new ForkJoinPool();
302 ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
303 String nodeId = node.getNodeId();
304 LOG.info("Deleting service setup on node {}", nodeId);
305 if (node.getDestTp() == null) {
306 LOG.error("Destination termination point must not be null.");
309 if (!this.deviceTransactionManager.isDeviceMounted(nodeId)) {
310 String result = nodeId + IS_NOT_MOUNTED_ON_THE_CONTROLLER;
314 forkJoinPool.shutdown();
316 //TODO should deletion end here?
318 // if the node is currently mounted then proceed.
320 String destTp = node.getDestTp();
322 if (node.getSrcTp() == null) {
323 otnLinkTps.add(new LinkTpBuilder()
328 srcTp = node.getSrcTp();
330 List<String> interfacesToDelete = new LinkedList<>();
331 interfacesToDelete.addAll(getInterfaces2delete(nodeId, srcTp, destTp,
332 input.getLowerSpectralSlotNumber().intValue(),
333 input.getHigherSpectralSlotNumber().intValue()));
334 for (String interfaceId : interfacesToDelete) {
336 this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
337 } catch (OpenRoadmInterfaceException e) {
338 String result = String.format("Failed to delete interface %s on node %s!", interfaceId, nodeId);
340 LOG.error(result, e);
347 } catch (InterruptedException | ExecutionException e) {
348 LOG.error("Error while deleting service paths!", e);
350 forkJoinPool.shutdown();
351 if (!alarmSuppressionNodeRemoval(input.getServiceName())) {
352 LOG.error("Alarm suppresion node removal failed!!!!");
354 return new ServicePathOutputBuilder()
355 .setSuccess(success.get())
356 .setLinkTp(otnLinkTps)
359 ? "Request processed"
360 : String.join("\n", results))
364 private List<String> getInterfaces2delete(
365 String nodeId, String srcTp, String destTp, int lowerSpectralSlotNumber, int higherSpectralSlotNumber) {
366 String spectralSlotName = String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR,
367 String.valueOf(lowerSpectralSlotNumber),
368 String.valueOf(higherSpectralSlotNumber));
369 if (destTp.contains(StringConstants.NETWORK_TOKEN)
370 || srcTp.contains(StringConstants.CLIENT_TOKEN)
371 || srcTp.contains(StringConstants.NETWORK_TOKEN)
372 || destTp.contains(StringConstants.CLIENT_TOKEN)) {
373 return getInterfacesTodelete(nodeId, srcTp, destTp, spectralSlotName);
376 List<String> interfacesToDelete = new LinkedList<>();
377 String connectionNumber = String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, destTp, spectralSlotName);
378 List<String> intToDelete = this.crossConnect.deleteCrossConnect(nodeId, connectionNumber, false);
379 for (String interf : intToDelete == null ? new ArrayList<String>() : intToDelete) {
380 if (!this.openRoadmInterfaceFactory.isUsedByXc(
381 nodeId, interf, connectionNumber, this.deviceTransactionManager)) {
382 interfacesToDelete.add(interf);
385 return interfacesToDelete;
388 private List<String> getInterfacesTodelete(String nodeId, String srcTp, String destTp, String spectralSlotName) {
390 OpenroadmNodeVersion nodeOpenRoadmVersion =
391 this.portMapping.getNode(nodeId).getNodeInfo().getOpenroadmVersion();
392 List<String> interfacesToDelete = new LinkedList<>();
393 Map<String, List<String>> suffixListMap =
394 nodeOpenRoadmVersion.equals(OpenroadmNodeVersion._71)
396 "ODU", List.of("ODUC4","ODUFLEX"),
397 "other", List.of("OTUC4", "OTSI-GROUP", spectralSlotName))
399 "ODU", List.of("ODU", "ODU4"),
400 "other", List.of("OTU", spectralSlotName));
401 // this last suffix used to be retrieved from openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName
402 // i.e. String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, spectralSlotName) with
403 // common GridConstant that states NAME_PARAMETERS_SEPARATOR = "-"
405 if (destTp.contains(StringConstants.NETWORK_TOKEN)) {
407 for (String suffix : suffixListMap.get("ODU")) {
408 if (this.openRoadmInterfaces.getInterface(
409 nodeId, String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix)).isPresent()) {
410 interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix));
414 catch (OpenRoadmInterfaceException e) {
415 LOG.error("impossible to get one of the interfaces {}",
416 destTp + GridConstant.NAME_PARAMETERS_SEPARATOR + String.join(
417 " or " + destTp + GridConstant.NAME_PARAMETERS_SEPARATOR,
418 suffixListMap.get("ODU")),
421 for (String suffix : suffixListMap.get("other")) {
422 interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix));
425 if (srcTp.contains(StringConstants.NETWORK_TOKEN)) {
426 interfacesToDelete.add(
427 String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, suffixListMap.get("ODU").get(0)));
428 for (String suffix : suffixListMap.get("other")) {
429 interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, suffix));
432 if (srcTp.contains(StringConstants.CLIENT_TOKEN)) {
433 interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, "ETHERNET"));
435 if (destTp.contains(StringConstants.CLIENT_TOKEN)) {
436 interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, "ETHERNET"));
438 return interfacesToDelete;
444 public RendererRollbackOutput rendererRollback(RendererRollbackInput input) {
445 boolean success = true;
446 Map<FailedToRollbackKey,FailedToRollback> failedToRollbackList = new HashMap<>();
447 for (NodeInterface nodeInterfaces : input.nonnullNodeInterface().values()) {
448 List<String> failedInterfaces = new ArrayList<>();
449 String nodeId = nodeInterfaces.getNodeId();
450 for (String connectionId : nodeInterfaces.getConnectionId()) {
451 List<String> listInter = this.crossConnect.deleteCrossConnect(nodeId, connectionId, false);
452 if (listInter != null) {
453 LOG.info("Cross connect {} on node {} successfully deleted.", connectionId, nodeId);
455 LOG.error("Failed to delete cross connect {} on node {}!", connectionId, nodeId);
457 failedInterfaces.add(connectionId);
460 // Interfaces needs to be in specific order to delete. Order is:
465 LinkedList<String> interfacesToDelete = new LinkedList<>();
466 if (nodeInterfaces.getOduInterfaceId() != null) {
467 interfacesToDelete.addAll(nodeInterfaces.getOduInterfaceId());
469 if (nodeInterfaces.getOtuInterfaceId() != null) {
470 interfacesToDelete.addAll(nodeInterfaces.getOtuInterfaceId());
472 if (nodeInterfaces.getOchInterfaceId() != null) {
473 interfacesToDelete.addAll(nodeInterfaces.getOchInterfaceId());
475 if (nodeInterfaces.getEthInterfaceId() != null) {
476 interfacesToDelete.addAll(nodeInterfaces.getEthInterfaceId());
478 LOG.info("Going to execute rollback on node {}. Interfaces to rollback: {}", nodeId,
479 String.join(", ", interfacesToDelete));
480 for (String interfaceId : interfacesToDelete) {
482 this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
483 LOG.info("Interface {} on node {} successfully deleted.", interfaceId, nodeId);
484 } catch (OpenRoadmInterfaceException e) {
485 LOG.error("Failed to delete interface {} on node {}!", interfaceId, nodeId);
487 failedInterfaces.add(interfaceId);
490 FailedToRollback failedToRollack = new FailedToRollbackBuilder().withKey(new FailedToRollbackKey(nodeId))
491 .setNodeId(nodeId).setInterface(failedInterfaces).build();
492 failedToRollbackList.put(failedToRollack.key(),failedToRollack);
494 return new RendererRollbackOutputBuilder()
496 .setFailedToRollback(failedToRollbackList)
500 private boolean alarmSuppressionNodeRegistration(ServicePathInput input) {
501 Map<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service
502 .nodelist.nodelist.NodesKey,
503 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service
504 .nodelist.nodelist.Nodes> nodeList = new HashMap<>();
505 if (input.getNodes() != null) {
506 for (Nodes node : input.getNodes()) {
507 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
508 .service.nodelist.nodelist.Nodes nodes =
509 new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
510 .service.nodelist.nodelist.NodesBuilder().setNodeId(node.getNodeId()).build();
511 nodeList.put(nodes.key(),nodes);
514 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
515 .service.nodelist.Nodelist> nodeListIID =
516 InstanceIdentifier.create(ServiceNodelist.class)
517 .child(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
518 .service.nodelist.Nodelist.class, new NodelistKey(input.getServiceName()));
519 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
520 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION,
522 new NodelistBuilder()
523 .withKey(new NodelistKey(input.getServiceName()))
524 .setServiceName(input.getServiceName())
527 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
529 commit.get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
530 LOG.info("Nodes are register for alarm suppression for service: {}", input.getServiceName());
532 } catch (ExecutionException | InterruptedException | TimeoutException e) {
533 LOG.warn("Failed to alarm suppresslist for service: {}", input.getServiceName(), e);
538 private boolean alarmSuppressionNodeRemoval(String serviceName) {
539 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
540 .service.nodelist.Nodelist> nodeListIID =
541 InstanceIdentifier.create(ServiceNodelist.class)
542 .child(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
543 .service.nodelist.Nodelist.class, new NodelistKey(serviceName));
544 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
545 writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, nodeListIID);
546 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
548 commit.get(Timeouts.DATASTORE_DELETE, TimeUnit.MILLISECONDS);
549 LOG.info("Nodes are unregister for alarm suppression for service: {}", serviceName);
551 } catch (InterruptedException | TimeoutException | ExecutionException e) {
552 LOG.warn("Failed to alarm suppresslist for service: {}", serviceName, e);
557 private void setTopologyForService(String name, Topology topo)
558 throws InterruptedException, ExecutionException, TimeoutException {
559 ServicesBuilder servicesBuilder;
560 // Get the service from the service list inventory
561 ServicesKey serviceKey = new ServicesKey(name);
562 InstanceIdentifier<Services> iid =
563 InstanceIdentifier.create(ServiceList.class).child(Services.class, serviceKey);
564 Optional<Services> services;
565 try (ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
566 Future<java.util.Optional<Services>> future =
567 readTx.read(LogicalDatastoreType.OPERATIONAL, iid);
568 services = future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS);
569 } catch (InterruptedException | ExecutionException | TimeoutException e) {
572 if (services.isPresent()) {
573 LOG.info("service {} already exists", name);
574 servicesBuilder = new ServicesBuilder(services.get()).setTopology(topo);
575 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
576 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, servicesBuilder.build());
577 writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
579 LOG.warn("Service {} does not exist - topology can not be updated", name);
583 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
584 value = "SLF4J_FORMAT_SHOULD_BE_CONST",
585 justification = "Log messages content needs to be formatted before"
586 + "since they are used in the returned object")
588 public CreateOtsOmsOutput createOtsOms(CreateOtsOmsInput input) throws OpenRoadmInterfaceException {
589 if (!this.deviceTransactionManager.isDeviceMounted(input.getNodeId())) {
590 String result = input.getNodeId() + IS_NOT_MOUNTED_ON_THE_CONTROLLER;
592 return new CreateOtsOmsOutputBuilder().setResult(result).setSuccess(false).build();
594 // if the node is currently mounted then proceed.
595 Mapping oldMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
596 if (oldMapping == null) {
597 return new CreateOtsOmsOutputBuilder()
598 .setResult(String.format("Logical Connection point %s does not exist for %s",
599 input.getLogicalConnectionPoint(), input.getNodeId()))
604 String otsInterface = this.openRoadmInterfaceFactory.createOpenRoadmOtsInterface(input.getNodeId(), oldMapping);
606 Mapping newMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
607 while (!isSupportingOtsPresent(newMapping)) {
608 LOG.info("waiting for post interface operation on node '{}'...", input.getNodeId());
611 this.portMapping.updateMapping(input.getNodeId(), oldMapping);
612 } catch (InterruptedException e) {
613 LOG.error("Failed to wait for post interface operation");
617 String result = String.format("Unable to get ots interface from mapping %s - %s",
618 oldMapping.getLogicalConnectionPoint(), input.getNodeId());
620 return new CreateOtsOmsOutputBuilder().setResult(result).setSuccess(false).build();
622 newMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
625 String omsInterface = this.openRoadmInterfaceFactory.createOpenRoadmOmsInterface(input.getNodeId(), newMapping);
626 if (omsInterface == null) {
627 String result = String.format("Fail to create OpenRoadmOms Interface for node : %s", input.getNodeId());
629 return new CreateOtsOmsOutputBuilder().setResult(result).setSuccess(false).build();
631 return new CreateOtsOmsOutputBuilder()
632 .setResult(String.format("Interfaces %s - %s successfully created on node %s",
633 otsInterface, omsInterface, input.getNodeId()))
638 private Boolean isSupportingOtsPresent(Mapping mapping) {
639 if (mapping == null) {
642 if (mapping.getSupportingOts() == null) {
643 LOG.warn("SupportingOts info is not present in mapping {}", mapping);
646 LOG.info("SupportingOts info is present in mapping {}", mapping);