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.Arrays;
14 import java.util.HashMap;
15 import java.util.LinkedList;
16 import java.util.List;
18 import java.util.Optional;
20 import java.util.concurrent.ConcurrentHashMap;
21 import java.util.concurrent.ConcurrentLinkedQueue;
22 import java.util.concurrent.CopyOnWriteArrayList;
23 import java.util.concurrent.ExecutionException;
24 import java.util.concurrent.ForkJoinPool;
25 import java.util.concurrent.ForkJoinTask;
26 import java.util.concurrent.Future;
27 import java.util.concurrent.TimeUnit;
28 import java.util.concurrent.TimeoutException;
29 import java.util.concurrent.atomic.AtomicBoolean;
30 import org.eclipse.jdt.annotation.NonNull;
31 import org.opendaylight.mdsal.binding.api.DataBroker;
32 import org.opendaylight.mdsal.binding.api.ReadTransaction;
33 import org.opendaylight.mdsal.binding.api.WriteTransaction;
34 import org.opendaylight.mdsal.common.api.CommitInfo;
35 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
36 import org.opendaylight.transportpce.common.StringConstants;
37 import org.opendaylight.transportpce.common.Timeouts;
38 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
39 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
40 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
41 import org.opendaylight.transportpce.common.fixedflex.GridUtils;
42 import org.opendaylight.transportpce.common.fixedflex.SpectrumInformation;
43 import org.opendaylight.transportpce.common.mapping.PortMapping;
44 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
45 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
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.rev220114.OpenroadmNodeVersion;
67 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220114.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.rev210930.link.tp.LinkTp;
74 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.link.tp.LinkTpBuilder;
75 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.node.interfaces.NodeInterface;
76 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.node.interfaces.NodeInterfaceBuilder;
77 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.node.interfaces.NodeInterfaceKey;
78 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.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 static final String PT_07 = "07";
88 private final DataBroker dataBroker;
89 private final DeviceTransactionManager deviceTransactionManager;
90 private final OpenRoadmInterfaceFactory openRoadmInterfaceFactory;
91 private final OpenRoadmInterfaces openRoadmInterfaces;
92 private final CrossConnect crossConnect;
93 private final PortMapping portMapping;
95 public DeviceRendererServiceImpl(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
96 OpenRoadmInterfaceFactory openRoadmInterfaceFactory, OpenRoadmInterfaces openRoadmInterfaces,
97 CrossConnect crossConnect, PortMapping portMapping) {
98 this.dataBroker = dataBroker;
99 this.deviceTransactionManager = deviceTransactionManager;
100 this.openRoadmInterfaceFactory = openRoadmInterfaceFactory;
101 this.openRoadmInterfaces = openRoadmInterfaces;
102 this.crossConnect = crossConnect;
103 this.portMapping = portMapping;
106 @SuppressWarnings("rawtypes")
107 // FIXME check if the ForkJoinTask raw type can be avoided
108 // Raw types use are discouraged since they lack type safety.
109 // Resulting Problems are observed at run time and not at compile time
111 public ServicePathOutput setupServicePath(ServicePathInput input, ServicePathDirection direction) {
112 LOG.info("setup service path for input {} and direction {}", input, direction);
113 List<Nodes> nodes = new ArrayList<>();
114 if (input.getNodes() != null) {
115 nodes.addAll(input.getNodes());
117 SpectrumInformation spectrumInformation = GridUtils.initSpectrumInformationFromServicePathInput(input);
118 // Register node for suppressing alarms
119 if (!alarmSuppressionNodeRegistration(input)) {
120 LOG.warn("Alarm suppresion node registration failed!!!!");
122 ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<>();
123 Map<NodeInterfaceKey,NodeInterface> nodeInterfaces = new ConcurrentHashMap<>();
124 Set<String> nodesProvisioned = Sets.newConcurrentHashSet();
125 CopyOnWriteArrayList<LinkTp> otnLinkTps = new CopyOnWriteArrayList<>();
126 ServiceListTopology topology = new ServiceListTopology();
127 AtomicBoolean success = new AtomicBoolean(true);
128 ForkJoinPool forkJoinPool = new ForkJoinPool();
129 ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
130 String nodeId = node.getNodeId();
131 LOG.info("Starting provisioning for node : {}", nodeId);
132 AEndApiInfo apiInfoA = null;
133 ZEndApiInfo apiInfoZ = null;
134 if (input.getAEndApiInfo() != null && input.getAEndApiInfo().getNodeId().contains(nodeId)) {
135 apiInfoA = input.getAEndApiInfo();
137 if (input.getZEndApiInfo() != null && input.getZEndApiInfo().getNodeId().contains(nodeId)) {
138 apiInfoZ = input.getZEndApiInfo();
140 List<String> createdEthInterfaces = new ArrayList<>();
141 List<String> createdOtuInterfaces = new ArrayList<>();
142 List<String> createdOduInterfaces = new ArrayList<>();
143 List<String> createdOchInterfaces = new ArrayList<>();
144 List<String> createdConnections = new ArrayList<>();
145 int crossConnectFlag = 0;
147 // if the node is currently mounted then proceed
148 if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
149 String srcTp = node.getSrcTp();
150 String destTp = node.getDestTp();
151 if ((destTp != null) && destTp.contains(StringConstants.NETWORK_TOKEN)) {
152 LOG.info("Adding supporting OCH interface for node {}, dest tp {}, spectrumInformation {}",
153 nodeId, destTp, spectrumInformation);
155 String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
156 nodeId, destTp, spectrumInformation);
157 // Split the string based on # pass the last element as the supported Interface
158 // This is needed for 7.1 device models with B100G, we have OTSI, OTSI-group combined as OCH
159 String[] listOfSuppOchInf = supportingOchInterface.split("#");
160 createdOchInterfaces = Arrays.asList(listOfSuppOchInf);
161 // Taking the last element
162 supportingOchInterface = createdOchInterfaces.get(createdOchInterfaces.size() - 1);
163 String supportingOtuInterface = this.openRoadmInterfaceFactory.createOpenRoadmOtu4Interface(
164 nodeId, destTp, supportingOchInterface, apiInfoA, apiInfoZ);
165 createdOtuInterfaces.add(supportingOtuInterface);
167 otnLinkTps.add(new LinkTpBuilder().setNodeId(nodeId).setTpId(destTp).build());
169 // This is needed for 7.1 device models for 400GE, since we have ODUC4 and ODUflex
171 createdOduInterfaces = Arrays.asList(this.openRoadmInterfaceFactory
172 .createOpenRoadmOdu4HOInterface(
173 nodeId, destTp, false, apiInfoA, apiInfoZ, PT_07).split("#"));
176 if ((srcTp != null) && srcTp.contains(StringConstants.CLIENT_TOKEN)) {
177 LOG.info("Adding supporting EThernet interface for node {}, src tp {}", nodeId, srcTp);
179 // create OpenRoadm Xponder Client Interfaces
180 createdEthInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(
183 if ((srcTp != null) && srcTp.contains(StringConstants.NETWORK_TOKEN)) {
184 LOG.info("Adding supporting OCH interface for node {}, src tp {}, spectrumInformation {}",
185 nodeId, srcTp, spectrumInformation);
187 // create OpenRoadm Xponder Line Interfaces
188 String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
189 nodeId, srcTp, spectrumInformation);
190 createdOchInterfaces.add(supportingOchInterface);
191 // Split the string based on # pass the last element as the supported Interface
192 // This is needed for 7.1 device models with B100G, we have OTSI, OTSI-group combined as OCH
193 String[] listOfSuppOchInf = supportingOchInterface.split("#");
194 createdOchInterfaces = Arrays.asList(listOfSuppOchInf);
195 // Taking the last element
196 supportingOchInterface = createdOchInterfaces.get(createdOchInterfaces.size() - 1);
197 String supportingOtuInterface = this.openRoadmInterfaceFactory.createOpenRoadmOtu4Interface(
198 nodeId, srcTp, supportingOchInterface, apiInfoA, apiInfoZ);
199 createdOtuInterfaces.add(supportingOtuInterface);
200 if (destTp == null) {
201 otnLinkTps.add(new LinkTpBuilder().setNodeId(nodeId).setTpId(srcTp).build());
203 createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4HOInterface(
204 nodeId, srcTp, false, apiInfoA, apiInfoZ, PT_07));
207 if ((destTp != null) && destTp.contains(StringConstants.CLIENT_TOKEN)) {
208 LOG.info("Adding supporting EThernet interface for node {}, dest tp {}", nodeId, destTp);
210 // create OpenRoadm Xponder Client Interfaces
211 createdEthInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(
214 if ((srcTp != null) && (srcTp.contains(StringConstants.TTP_TOKEN)
215 || srcTp.contains(StringConstants.PP_TOKEN))) {
216 LOG.info("Adding supporting OCH interface for node {}, src tp {}, spectrumInformation {}",
217 nodeId, srcTp, spectrumInformation);
218 createdOchInterfaces.addAll(this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaces(
219 nodeId, srcTp, spectrumInformation));
221 if ((destTp != null) && (destTp.contains(StringConstants.TTP_TOKEN)
222 || destTp.contains(StringConstants.PP_TOKEN))) {
223 LOG.info("Adding supporting OCH interface for node {}, dest tp {}, spectrumInformation {}",
224 nodeId, destTp, spectrumInformation);
225 createdOchInterfaces.addAll(this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaces(
226 nodeId, destTp, spectrumInformation));
228 if (crossConnectFlag < 1) {
229 LOG.info("Creating cross connect between source {} and destination {} for node {}", srcTp,
231 Optional<String> connectionNameOpt =
232 this.crossConnect.postCrossConnect(nodeId, srcTp, destTp, spectrumInformation);
233 if (connectionNameOpt.isPresent()) {
234 nodesProvisioned.add(nodeId);
235 createdConnections.add(connectionNameOpt.get());
237 processErrorMessage("Unable to post Roadm-connection for node " + nodeId, forkJoinPool,
243 processErrorMessage(nodeId + IS_NOT_MOUNTED_ON_THE_CONTROLLER, forkJoinPool, results);
246 } catch (OpenRoadmInterfaceException ex) {
247 processErrorMessage("Setup service path failed! Exception:" + ex.toString(), forkJoinPool, results);
250 NodeInterface nodeInterface = new NodeInterfaceBuilder()
251 .withKey(new NodeInterfaceKey(nodeId))
253 .setConnectionId(createdConnections)
254 .setEthInterfaceId(createdEthInterfaces)
255 .setOtuInterfaceId(createdOtuInterfaces)
256 .setOduInterfaceId(createdOduInterfaces)
257 .setOchInterfaceId(createdOchInterfaces)
259 nodeInterfaces.put(nodeInterface.key(),nodeInterface);
263 } catch (InterruptedException | ExecutionException e) {
264 LOG.error("Error while setting up service paths!", e);
266 forkJoinPool.shutdown();
269 results.add("Interfaces created successfully for nodes: " + String.join(", ", nodesProvisioned));
271 // setting topology in the service list data store
273 setTopologyForService(input.getServiceName(), topology.getTopology());
274 } catch (InterruptedException | TimeoutException | ExecutionException e) {
275 LOG.warn("Failed to write topologies for service {}.", input.getServiceName(), e);
277 if (!alarmSuppressionNodeRemoval(input.getServiceName())) {
278 LOG.error("Alarm suppresion node removal failed!!!!");
280 return new ServicePathOutputBuilder()
281 .setNodeInterface(nodeInterfaces)
282 .setSuccess(success.get())
283 .setResult(String.join("\n", results))
284 .setLinkTp(otnLinkTps)
288 private ConcurrentLinkedQueue<String> processErrorMessage(String message, ForkJoinPool forkJoinPool,
289 ConcurrentLinkedQueue<String> messages) {
290 LOG.warn("Received error message {}", message);
291 messages.add(message);
292 forkJoinPool.shutdown();
296 @SuppressWarnings("rawtypes")
297 // FIXME check if the ForkJoinTask raw type can be avoided
298 // Raw types use are discouraged since they lack type safety.
299 // Resulting Problems are observed at run time and not at compile time
301 public ServicePathOutput deleteServicePath(ServicePathInput input) {
302 if (!alarmSuppressionNodeRegistration(input)) {
303 LOG.warn("Alarm suppression node registration failed!!!!");
305 List<Nodes> nodes = input.getNodes();
306 AtomicBoolean success = new AtomicBoolean(true);
307 ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<>();
308 CopyOnWriteArrayList<LinkTp> otnLinkTps = new CopyOnWriteArrayList<>();
309 ForkJoinPool forkJoinPool = new ForkJoinPool();
310 ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
311 String nodeId = node.getNodeId();
312 LOG.info("Deleting service setup on node {}", nodeId);
313 if (node.getDestTp() == null) {
314 LOG.error("Destination termination point must not be null.");
317 if (!this.deviceTransactionManager.isDeviceMounted(nodeId)) {
318 String result = nodeId + IS_NOT_MOUNTED_ON_THE_CONTROLLER;
322 forkJoinPool.shutdown();
324 //TODO should deletion end here?
326 // if the node is currently mounted then proceed.
328 String destTp = node.getDestTp();
330 if (node.getSrcTp() == null) {
331 otnLinkTps.add(new LinkTpBuilder()
336 srcTp = node.getSrcTp();
338 List<String> interfacesToDelete = new LinkedList<>();
339 interfacesToDelete.addAll(getInterfaces2delete(nodeId, srcTp, destTp,
340 input.getLowerSpectralSlotNumber().intValue(),
341 input.getHigherSpectralSlotNumber().intValue()));
342 for (String interfaceId : interfacesToDelete) {
344 this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
345 } catch (OpenRoadmInterfaceException e) {
346 String result = String.format("Failed to delete interface %s on node %s!", interfaceId, nodeId);
348 LOG.error(result, e);
355 } catch (InterruptedException | ExecutionException e) {
356 LOG.error("Error while deleting service paths!", e);
358 forkJoinPool.shutdown();
359 if (!alarmSuppressionNodeRemoval(input.getServiceName())) {
360 LOG.error("Alarm suppresion node removal failed!!!!");
362 return new ServicePathOutputBuilder()
363 .setSuccess(success.get())
364 .setLinkTp(otnLinkTps)
367 ? "Request processed"
368 : String.join("\n", results))
372 private List<String> getInterfaces2delete(
373 String nodeId, String srcTp, String destTp, int lowerSpectralSlotNumber, int higherSpectralSlotNumber) {
374 String spectralSlotName = String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR,
375 String.valueOf(lowerSpectralSlotNumber),
376 String.valueOf(higherSpectralSlotNumber));
378 if (destTp.contains(StringConstants.NETWORK_TOKEN)
379 || srcTp.contains(StringConstants.CLIENT_TOKEN)
380 || srcTp.contains(StringConstants.NETWORK_TOKEN)
381 || destTp.contains(StringConstants.CLIENT_TOKEN)) {
382 return getInterfacesTodelete(nodeId, srcTp, destTp, spectralSlotName);
385 List<String> interfacesToDelete = new LinkedList<>();
386 String connectionNumber = String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, destTp, spectralSlotName);
387 List<String> intToDelete = this.crossConnect.deleteCrossConnect(nodeId, connectionNumber, false);
388 for (String interf : intToDelete == null ? new ArrayList<String>() : intToDelete) {
389 if (!this.openRoadmInterfaceFactory.isUsedByXc(
390 nodeId, interf, connectionNumber, this.deviceTransactionManager)) {
391 interfacesToDelete.add(interf);
394 return interfacesToDelete;
397 private List<String> getInterfacesTodelete(String nodeId, String srcTp, String destTp, String spectralSlotName) {
399 OpenroadmNodeVersion nodeOpenRoadmVersion =
400 this.portMapping.getNode(nodeId).getNodeInfo().getOpenroadmVersion();
402 List<String> interfacesToDelete = new LinkedList<>();
403 Map<String, List<String>> suffixListMap =
404 nodeOpenRoadmVersion.equals(OpenroadmNodeVersion._71)
406 // We don't need ODUC2, ODUC3 here, since they are handled in OTN service-path
407 // This has to be in an order of deletion
408 "ODU", List.of("ODU4", "ODUFLEX", "ODUC4", "ODUC1"),
409 // Add intermediate OTUCn rates (OTUC2, OTUC3)
410 // OTU4 is used in 100G service on 7.1 model
411 "other", List.of("OTU4", "OTUC1", "OTUC2", "OTUC3", "OTUC4",
412 "OTSIGROUP-400G", "OTSIGROUP-300G", "OTSIGROUP-200G", "OTSIGROUP-100G",
415 "ODU", List.of("ODU", "ODU4"),
416 "other", List.of("OTU", spectralSlotName));
417 // this last suffix used to be retrieved from openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName
418 // i.e. String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, spectralSlotName) with
419 // common GridConstant that states NAME_PARAMETERS_SEPARATOR = "-"
421 if (destTp.contains(StringConstants.NETWORK_TOKEN)) {
423 for (String suffix : suffixListMap.get("ODU")) {
424 if (this.openRoadmInterfaces.getInterface(
425 nodeId, String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix)).isPresent()) {
426 interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix));
430 catch (OpenRoadmInterfaceException e) {
431 LOG.error("impossible to get one of the interfaces {}",
432 destTp + GridConstant.NAME_PARAMETERS_SEPARATOR + String.join(
433 " or " + destTp + GridConstant.NAME_PARAMETERS_SEPARATOR,
434 suffixListMap.get("ODU")),
438 for (String suffix : suffixListMap.get("other")) {
439 if (this.openRoadmInterfaces.getInterface(
440 nodeId, String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix)).isPresent()) {
441 LOG.info("Deleting the interface {}",
442 String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix));
443 interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, suffix));
447 catch (OpenRoadmInterfaceException e) {
448 LOG.error("impossible to get one of the interfaces {}",
449 destTp + GridConstant.NAME_PARAMETERS_SEPARATOR + String.join(
450 " or " + destTp + GridConstant.NAME_PARAMETERS_SEPARATOR,
451 suffixListMap.get("ODU")),
455 if (srcTp.contains(StringConstants.NETWORK_TOKEN)) {
456 interfacesToDelete.add(
457 String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, suffixListMap.get("ODU").get(0)));
458 for (String suffix : suffixListMap.get("other")) {
459 interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, suffix));
463 if (srcTp.contains(StringConstants.CLIENT_TOKEN)) {
464 interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, srcTp, "ETHERNET"));
466 if (destTp.contains(StringConstants.CLIENT_TOKEN)) {
468 interfacesToDelete.add(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, destTp, "ETHERNET"));
470 return interfacesToDelete;
476 public RendererRollbackOutput rendererRollback(RendererRollbackInput input) {
477 boolean success = true;
478 Map<FailedToRollbackKey,FailedToRollback> failedToRollbackList = new HashMap<>();
479 for (NodeInterface nodeInterfaces : input.nonnullNodeInterface().values()) {
480 List<String> failedInterfaces = new ArrayList<>();
481 String nodeId = nodeInterfaces.getNodeId();
482 for (String connectionId : nodeInterfaces.getConnectionId()) {
483 List<String> listInter = this.crossConnect.deleteCrossConnect(nodeId, connectionId, false);
484 if (listInter != null) {
485 LOG.info("Cross connect {} on node {} successfully deleted.", connectionId, nodeId);
487 LOG.error("Failed to delete cross connect {} on node {}!", connectionId, nodeId);
489 failedInterfaces.add(connectionId);
492 // Interfaces needs to be in specific order to delete. Order is:
497 LinkedList<String> interfacesToDelete = new LinkedList<>();
498 if (nodeInterfaces.getOduInterfaceId() != null) {
499 interfacesToDelete.addAll(nodeInterfaces.getOduInterfaceId());
501 if (nodeInterfaces.getOtuInterfaceId() != null) {
502 interfacesToDelete.addAll(nodeInterfaces.getOtuInterfaceId());
504 if (nodeInterfaces.getOchInterfaceId() != null) {
505 interfacesToDelete.addAll(nodeInterfaces.getOchInterfaceId());
507 if (nodeInterfaces.getEthInterfaceId() != null) {
508 interfacesToDelete.addAll(nodeInterfaces.getEthInterfaceId());
510 LOG.info("Going to execute rollback on node {}. Interfaces to rollback: {}", nodeId,
511 String.join(", ", interfacesToDelete));
512 for (String interfaceId : interfacesToDelete) {
514 this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
515 LOG.info("Interface {} on node {} successfully deleted.", interfaceId, nodeId);
516 } catch (OpenRoadmInterfaceException e) {
517 LOG.error("Failed to delete interface {} on node {}!", interfaceId, nodeId);
519 failedInterfaces.add(interfaceId);
522 FailedToRollback failedToRollack = new FailedToRollbackBuilder().withKey(new FailedToRollbackKey(nodeId))
523 .setNodeId(nodeId).setInterface(failedInterfaces).build();
524 failedToRollbackList.put(failedToRollack.key(),failedToRollack);
526 return new RendererRollbackOutputBuilder()
528 .setFailedToRollback(failedToRollbackList)
532 private boolean alarmSuppressionNodeRegistration(ServicePathInput input) {
533 Map<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service
534 .nodelist.nodelist.NodesKey,
535 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service
536 .nodelist.nodelist.Nodes> nodeList = new HashMap<>();
537 if (input.getNodes() != null) {
538 for (Nodes node : input.getNodes()) {
539 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
540 .service.nodelist.nodelist.Nodes nodes =
541 new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
542 .service.nodelist.nodelist.NodesBuilder().setNodeId(node.getNodeId()).build();
543 nodeList.put(nodes.key(),nodes);
546 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
547 .service.nodelist.Nodelist> nodeListIID =
548 InstanceIdentifier.create(ServiceNodelist.class)
549 .child(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
550 .service.nodelist.Nodelist.class, new NodelistKey(input.getServiceName()));
551 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
552 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION,
554 new NodelistBuilder()
555 .withKey(new NodelistKey(input.getServiceName()))
556 .setServiceName(input.getServiceName())
559 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
561 commit.get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
562 LOG.info("Nodes are register for alarm suppression for service: {}", input.getServiceName());
564 } catch (ExecutionException | InterruptedException | TimeoutException e) {
565 LOG.warn("Failed to alarm suppresslist for service: {}", input.getServiceName(), e);
570 private boolean alarmSuppressionNodeRemoval(String serviceName) {
571 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
572 .service.nodelist.Nodelist> nodeListIID =
573 InstanceIdentifier.create(ServiceNodelist.class)
574 .child(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
575 .service.nodelist.Nodelist.class, new NodelistKey(serviceName));
576 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
577 writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, nodeListIID);
578 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
580 commit.get(Timeouts.DATASTORE_DELETE, TimeUnit.MILLISECONDS);
581 LOG.info("Nodes are unregister for alarm suppression for service: {}", serviceName);
583 } catch (InterruptedException | TimeoutException | ExecutionException e) {
584 LOG.warn("Failed to alarm suppresslist for service: {}", serviceName, e);
589 private void setTopologyForService(String name, Topology topo)
590 throws InterruptedException, ExecutionException, TimeoutException {
591 ServicesBuilder servicesBuilder;
592 // Get the service from the service list inventory
593 ServicesKey serviceKey = new ServicesKey(name);
594 InstanceIdentifier<Services> iid =
595 InstanceIdentifier.create(ServiceList.class).child(Services.class, serviceKey);
596 Optional<Services> services;
597 try (ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
598 Future<java.util.Optional<Services>> future =
599 readTx.read(LogicalDatastoreType.OPERATIONAL, iid);
600 services = future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS);
601 } catch (InterruptedException | ExecutionException | TimeoutException e) {
604 if (services.isPresent()) {
605 LOG.info("service {} already exists", name);
606 servicesBuilder = new ServicesBuilder(services.get()).setTopology(topo);
607 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
608 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, servicesBuilder.build());
609 writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
611 LOG.warn("Service {} does not exist - topology can not be updated", name);
615 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
616 value = "SLF4J_FORMAT_SHOULD_BE_CONST",
617 justification = "Log messages content needs to be formatted before"
618 + "since they are used in the returned object")
620 public CreateOtsOmsOutput createOtsOms(CreateOtsOmsInput input) throws OpenRoadmInterfaceException {
621 if (!this.deviceTransactionManager.isDeviceMounted(input.getNodeId())) {
622 String result = input.getNodeId() + IS_NOT_MOUNTED_ON_THE_CONTROLLER;
624 return new CreateOtsOmsOutputBuilder().setResult(result).setSuccess(false).build();
626 // if the node is currently mounted then proceed.
627 Mapping oldMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
628 if (oldMapping == null) {
629 return new CreateOtsOmsOutputBuilder()
630 .setResult(String.format("Logical Connection point %s does not exist for %s",
631 input.getLogicalConnectionPoint(), input.getNodeId()))
636 String otsInterface = this.openRoadmInterfaceFactory.createOpenRoadmOtsInterface(input.getNodeId(), oldMapping);
638 Mapping newMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
639 while (!isSupportingOtsPresent(newMapping)) {
640 LOG.info("waiting for post interface operation on node '{}'...", input.getNodeId());
643 this.portMapping.updateMapping(input.getNodeId(), oldMapping);
644 } catch (InterruptedException e) {
645 LOG.error("Failed to wait for post interface operation");
649 String result = String.format("Unable to get ots interface from mapping %s - %s",
650 oldMapping.getLogicalConnectionPoint(), input.getNodeId());
652 return new CreateOtsOmsOutputBuilder().setResult(result).setSuccess(false).build();
654 newMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
657 String omsInterface = this.openRoadmInterfaceFactory.createOpenRoadmOmsInterface(input.getNodeId(), newMapping);
658 if (omsInterface == null) {
659 String result = String.format("Fail to create OpenRoadmOms Interface for node : %s", input.getNodeId());
661 return new CreateOtsOmsOutputBuilder().setResult(result).setSuccess(false).build();
663 return new CreateOtsOmsOutputBuilder()
664 .setResult(String.format("Interfaces %s - %s successfully created on node %s",
665 otsInterface, omsInterface, input.getNodeId()))
670 private Boolean isSupportingOtsPresent(Mapping mapping) {
671 if (mapping == null) {
674 if (mapping.getSupportingOts() == null) {
675 LOG.warn("SupportingOts info is not present in mapping {}", mapping);
678 LOG.info("SupportingOts info is present in mapping {}", mapping);