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;
12 import java.util.ArrayList;
13 import java.util.LinkedList;
14 import java.util.List;
15 import java.util.Optional;
17 import java.util.concurrent.ConcurrentLinkedQueue;
18 import java.util.concurrent.ExecutionException;
19 import java.util.concurrent.ForkJoinPool;
20 import java.util.concurrent.ForkJoinTask;
21 import java.util.concurrent.Future;
22 import java.util.concurrent.TimeUnit;
23 import java.util.concurrent.TimeoutException;
24 import java.util.concurrent.atomic.AtomicBoolean;
26 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
27 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
28 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
29 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
30 import org.opendaylight.transportpce.common.Timeouts;
31 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
32 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
33 import org.opendaylight.transportpce.common.mapping.PortMapping;
34 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
35 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
36 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
37 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
38 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServiceListTopology;
39 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServicePathDirection;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.ServiceNodelist;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service.nodelist.NodelistBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service.nodelist.NodelistKey;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.network.nodes.Mapping;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.CreateOtsOmsInput;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.CreateOtsOmsOutput;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.CreateOtsOmsOutputBuilder;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.RendererRollbackInput;
48 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.RendererRollbackOutput;
49 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.RendererRollbackOutputBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.ServicePathInput;
51 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.ServicePathOutput;
52 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.ServicePathOutputBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.renderer.rollback.output.FailedToRollback;
54 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.renderer.rollback.output.FailedToRollbackBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.renderer.rollback.output.FailedToRollbackKey;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.Topology;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.get.connection.port.trail.output.Ports;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnections;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsKey;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.OchAttributes.ModulationFormat;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.R100G;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceList;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesBuilder;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesKey;
67 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.node.interfaces.NodeInterface;
68 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.node.interfaces.NodeInterfaceBuilder;
69 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.node.interfaces.NodeInterfaceKey;
70 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.olm.renderer.input.Nodes;
71 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
72 import org.slf4j.Logger;
73 import org.slf4j.LoggerFactory;
75 public class DeviceRendererServiceImpl implements DeviceRendererService {
76 private static final Logger LOG = LoggerFactory.getLogger(DeviceRendererServiceImpl.class);
77 private final DataBroker dataBroker;
78 private final DeviceTransactionManager deviceTransactionManager;
79 private final OpenRoadmInterfaceFactory openRoadmInterfaceFactory;
80 private final OpenRoadmInterfaces openRoadmInterfaces;
81 private final CrossConnect crossConnect;
82 private final PortMapping portMapping;
84 public DeviceRendererServiceImpl(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
85 OpenRoadmInterfaceFactory openRoadmInterfaceFactory, OpenRoadmInterfaces openRoadmInterfaces,
86 CrossConnect crossConnect, PortMapping portMapping) {
87 this.dataBroker = dataBroker;
88 this.deviceTransactionManager = deviceTransactionManager;
89 this.openRoadmInterfaceFactory = openRoadmInterfaceFactory;
90 this.openRoadmInterfaces = openRoadmInterfaces;
91 this.crossConnect = crossConnect;
92 this.portMapping = portMapping;
96 public ServicePathOutput setupServicePath(ServicePathInput input, ServicePathDirection direction) {
97 List<Nodes> nodes = input.getNodes();
98 // Register node for suppressing alarms
99 if (!alarmSuppressionNodeRegistration(input)) {
100 LOG.warn("Alarm suppresion node registration failed!!!!");
102 ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<>();
103 Set<NodeInterface> nodeInterfaces = Sets.newConcurrentHashSet();
104 Set<String> nodesProvisioned = Sets.newConcurrentHashSet();
105 ServiceListTopology topology = new ServiceListTopology();
106 AtomicBoolean success = new AtomicBoolean(true);
107 ForkJoinPool forkJoinPool = new ForkJoinPool();
108 ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
109 String nodeId = node.getNodeId();
110 LOG.info("Starting provisioning for node : {}", nodeId);
111 List<String> createdEthInterfaces = new ArrayList<>();
112 List<String> createdOtuInterfaces = new ArrayList<>();
113 List<String> createdOduInterfaces = new ArrayList<>();
114 List<String> createdOchInterfaces = new ArrayList<>();
115 List<String> createdConnections = new ArrayList<>();
116 int crossConnectFlag = 0;
118 // if the node is currently mounted then proceed
119 if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
120 String srcTp = node.getSrcTp();
121 String destTp = node.getDestTp();
122 Long waveNumber = input.getWaveNumber();
123 if ((destTp != null) && destTp.contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)) {
125 // create OpenRoadm Xponder Line Interfaces
126 String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
127 nodeId, destTp, waveNumber, R100G.class, ModulationFormat.DpQpsk);
128 createdOchInterfaces.add(supportingOchInterface);
129 String supportingOtuInterface = this.openRoadmInterfaceFactory
130 .createOpenRoadmOtu4Interface(nodeId, destTp, supportingOchInterface);
131 createdOtuInterfaces.add(supportingOtuInterface);
132 createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
133 destTp, supportingOtuInterface));
135 if ((srcTp != null) && srcTp.contains(OpenRoadmInterfacesImpl.CLIENT_TOKEN)) {
137 // create OpenRoadm Xponder Client Interfaces
138 createdEthInterfaces.add(
139 this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(nodeId, srcTp));
141 if ((srcTp != null) && srcTp.contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)) {
143 // create OpenRoadm Xponder Line Interfaces
144 String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
145 nodeId, srcTp, waveNumber, R100G.class, ModulationFormat.DpQpsk);
146 createdOchInterfaces.add(supportingOchInterface);
147 String supportingOtuInterface = this.openRoadmInterfaceFactory
148 .createOpenRoadmOtu4Interface(nodeId, srcTp, supportingOchInterface);
149 createdOtuInterfaces.add(supportingOtuInterface);
150 createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
151 srcTp, supportingOtuInterface));
153 if ((destTp != null) && destTp.contains(OpenRoadmInterfacesImpl.CLIENT_TOKEN)) {
155 // create OpenRoadm Xponder Client Interfaces
156 createdEthInterfaces.add(
157 this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(nodeId, destTp));
159 if ((srcTp != null) && (srcTp.contains(OpenRoadmInterfacesImpl.TTP_TOKEN)
160 || srcTp.contains(OpenRoadmInterfacesImpl.PP_TOKEN))) {
161 createdOchInterfaces.add(
162 this.openRoadmInterfaceFactory
163 .createOpenRoadmOchInterface(nodeId, srcTp, waveNumber));
165 if ((destTp != null) && (destTp.contains(OpenRoadmInterfacesImpl.TTP_TOKEN)
166 || destTp.contains(OpenRoadmInterfacesImpl.PP_TOKEN))) {
167 createdOchInterfaces.add(
168 this.openRoadmInterfaceFactory
169 .createOpenRoadmOchInterface(nodeId, destTp, waveNumber));
171 if (crossConnectFlag < 1) {
172 LOG.info("Creating cross connect between source {} and destination {} for node {}", srcTp,
174 Optional<String> connectionNameOpt =
175 this.crossConnect.postCrossConnect(nodeId, waveNumber, srcTp, destTp);
176 if (connectionNameOpt.isPresent()) {
177 nodesProvisioned.add(nodeId);
179 this.crossConnect.getConnectionPortTrail(nodeId, waveNumber, srcTp, destTp);
180 if (ServicePathDirection.A_TO_Z.equals(direction)) {
181 topology.updateAtoZTopologyList(ports, nodeId);
183 if (ServicePathDirection.Z_TO_A.equals(direction)) {
184 topology.updateZtoATopologyList(ports, nodeId);
186 createdConnections.add(connectionNameOpt.get());
188 processErrorMessage("Unable to post Roadm-connection for node " + nodeId, forkJoinPool,
194 processErrorMessage(nodeId + " is not mounted on the controller", forkJoinPool, results);
197 } catch (OpenRoadmInterfaceException ex) {
198 processErrorMessage("Setup service path failed! Exception:" + ex.toString(), forkJoinPool, results);
201 NodeInterfaceBuilder nodeInterfaceBuilder = new NodeInterfaceBuilder();
202 nodeInterfaceBuilder.withKey(new NodeInterfaceKey(nodeId));
203 nodeInterfaceBuilder.setNodeId(nodeId);
204 nodeInterfaceBuilder.setConnectionId(createdConnections);
205 nodeInterfaceBuilder.setEthInterfaceId(createdEthInterfaces);
206 nodeInterfaceBuilder.setOtuInterfaceId(createdOtuInterfaces);
207 nodeInterfaceBuilder.setOduInterfaceId(createdOduInterfaces);
208 nodeInterfaceBuilder.setOchInterfaceId(createdOchInterfaces);
209 nodeInterfaces.add(nodeInterfaceBuilder.build());
213 } catch (InterruptedException | ExecutionException e) {
214 LOG.error("Error while setting up service paths!", e);
216 forkJoinPool.shutdown();
218 results.add("Roadm-connection successfully created for nodes: " + String.join(", ", nodesProvisioned));
220 ServicePathOutputBuilder setServBldr = new ServicePathOutputBuilder();
221 setServBldr.setNodeInterface(new ArrayList<>(nodeInterfaces));
222 setServBldr.setSuccess(success.get());
223 setServBldr.setResult(String.join("\n", results));
224 // setting topology in the service list data store
226 setTopologyForService(input.getServiceName(), topology.getTopology());
227 } catch (InterruptedException | TimeoutException | ExecutionException e) {
228 LOG.warn("Failed to write topologies for service {}.", input.getServiceName(), e);
230 if (!alarmSuppressionNodeRemoval(input.getServiceName())) {
231 LOG.error("Alarm suppresion node removal failed!!!!");
233 return setServBldr.build();
236 private ConcurrentLinkedQueue<String> processErrorMessage(String message, ForkJoinPool forkJoinPool,
237 ConcurrentLinkedQueue<String> messages) {
239 messages.add(message);
240 forkJoinPool.shutdown();
245 public ServicePathOutput deleteServicePath(ServicePathInput input) {
246 List<Nodes> nodes = input.getNodes();
247 AtomicBoolean success = new AtomicBoolean(true);
248 ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<>();
249 if (!alarmSuppressionNodeRegistration(input)) {
250 LOG.warn("Alarm suppresion node registraion failed!!!!");
252 ForkJoinPool forkJoinPool = new ForkJoinPool();
253 ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
254 List<String> interfacesToDelete = new LinkedList<>();
255 String nodeId = node.getNodeId();
256 LOG.info("Deleting service setup on node {}", nodeId);
257 String srcTp = node.getSrcTp();
258 String destTp = node.getDestTp();
259 Long waveNumber = input.getWaveNumber();
260 if ((srcTp == null) || (destTp == null)) {
261 LOG.error("Source ({}) or destination ({}) termination point is null.", srcTp, destTp);
264 // if the node is currently mounted then proceed.
265 if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
266 if (destTp.contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)
267 || srcTp.contains(OpenRoadmInterfacesImpl.CLIENT_TOKEN)
268 || srcTp.contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)
269 || destTp.contains(OpenRoadmInterfacesImpl.CLIENT_TOKEN)) {
270 if (destTp.contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)) {
271 interfacesToDelete.add(destTp + "-ODU");
272 interfacesToDelete.add(destTp + "-OTU");
273 interfacesToDelete.add(
274 this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName(destTp, waveNumber));
276 if (srcTp.contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)) {
277 interfacesToDelete.add(srcTp + "-ODU");
278 interfacesToDelete.add(srcTp + "-OTU");
280 .add(this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName(srcTp, waveNumber));
282 if (srcTp.contains(OpenRoadmInterfacesImpl.CLIENT_TOKEN)) {
283 interfacesToDelete.add(srcTp + "-ETHERNET");
285 if (destTp.contains(OpenRoadmInterfacesImpl.CLIENT_TOKEN)) {
286 interfacesToDelete.add(destTp + "-ETHERNET");
289 String connectionNumber = srcTp + "-" + destTp + "-" + waveNumber;
290 if (!this.crossConnect.deleteCrossConnect(nodeId, connectionNumber)) {
291 LOG.error("Failed to delete cross connect {}", connectionNumber);
293 connectionNumber = destTp + "-" + srcTp + "-" + waveNumber;
295 this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName(srcTp, waveNumber);
296 if (!isUsedByXc(nodeId, interfName, connectionNumber)) {
297 interfacesToDelete.add(interfName);
299 interfName = this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName(destTp, waveNumber);
300 if (!isUsedByXc(nodeId, interfName, connectionNumber)) {
301 interfacesToDelete.add(interfName);
305 String result = nodeId + " is not mounted on the controller";
309 forkJoinPool.shutdown();
310 return; // TODO should deletion end here?
312 for (String interfaceId : interfacesToDelete) {
314 this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
315 } catch (OpenRoadmInterfaceException e) {
316 String result = String.format("Failed to delete interface %s on node %s!", interfaceId, nodeId);
318 LOG.error(result, e);
325 } catch (InterruptedException | ExecutionException e) {
326 LOG.error("Error while deleting service paths!", e);
328 forkJoinPool.shutdown();
329 if (!alarmSuppressionNodeRemoval(input.getServiceName())) {
330 LOG.error("Alarm suppresion node removal failed!!!!");
332 ServicePathOutputBuilder delServBldr = new ServicePathOutputBuilder();
333 delServBldr.setSuccess(success.get());
334 if (results.isEmpty()) {
335 return delServBldr.setResult("Request processed").build();
337 return delServBldr.setResult(String.join("\n", results)).build();
342 public RendererRollbackOutput rendererRollback(RendererRollbackInput input) {
343 boolean success = true;
344 List<FailedToRollback> failedToRollbackList = new ArrayList<>();
345 for (NodeInterface nodeInterfaces : input.getNodeInterface()) {
346 List<String> failedInterfaces = new ArrayList<>();
347 String nodeId = nodeInterfaces.getNodeId();
348 for (String connectionId : nodeInterfaces.getConnectionId()) {
349 if (this.crossConnect.deleteCrossConnect(nodeId, connectionId)) {
350 LOG.info("Cross connect {} on node {} successfully deleted.", connectionId, nodeId);
352 LOG.error("Failed to delete cross connect {} on node {}!", connectionId, nodeId);
354 failedInterfaces.add(connectionId);
357 // Interfaces needs to be in specific order to delete. Order is:
362 LinkedList<String> interfacesToDelete = new LinkedList<>();
363 if (nodeInterfaces.getOduInterfaceId() != null) {
364 interfacesToDelete.addAll(nodeInterfaces.getOduInterfaceId());
366 if (nodeInterfaces.getOtuInterfaceId() != null) {
367 interfacesToDelete.addAll(nodeInterfaces.getOtuInterfaceId());
369 if (nodeInterfaces.getOchInterfaceId() != null) {
370 interfacesToDelete.addAll(nodeInterfaces.getOchInterfaceId());
372 if (nodeInterfaces.getEthInterfaceId() != null) {
373 interfacesToDelete.addAll(nodeInterfaces.getEthInterfaceId());
375 LOG.info("Going to execute rollback on node {}. Interfaces to rollback: {}", nodeId,
376 String.join(", ", interfacesToDelete));
377 for (String interfaceId : interfacesToDelete) {
379 this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
380 LOG.info("Interface {} on node {} successfully deleted.", interfaceId, nodeId);
381 } catch (OpenRoadmInterfaceException e) {
382 LOG.error("Failed to delete interface {} on node {}!", interfaceId, nodeId);
384 failedInterfaces.add(interfaceId);
387 failedToRollbackList.add(new FailedToRollbackBuilder().withKey(new FailedToRollbackKey(nodeId))
388 .setNodeId(nodeId).setInterface(failedInterfaces).build());
390 return new RendererRollbackOutputBuilder().setSuccess(success).setFailedToRollback(failedToRollbackList)
394 private boolean alarmSuppressionNodeRegistration(ServicePathInput input) {
395 NodelistBuilder nodeListBuilder = new NodelistBuilder();
396 nodeListBuilder.withKey(new NodelistKey(input.getServiceName()));
397 nodeListBuilder.setServiceName(input.getServiceName());
398 List<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service
399 .nodelist.nodelist.Nodes> nodeList =
401 for (Nodes node : input.getNodes()) {
403 new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
404 .service.nodelist.nodelist.NodesBuilder()
405 .setNodeId(node.getNodeId()).build());
407 nodeListBuilder.setNodes(nodeList);
408 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
409 .service.nodelist.Nodelist> nodeListIID =
410 InstanceIdentifier.create(ServiceNodelist.class).child(
411 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression
412 .rev171102.service.nodelist.Nodelist.class,
413 new NodelistKey(input.getServiceName()));
414 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
415 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodeListIID, nodeListBuilder.build());
416 Future<Void> submit = writeTransaction.submit();
418 submit.get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
419 LOG.info("Nodes are register for alarm suppression for service: {}", input.getServiceName());
421 } catch (ExecutionException | InterruptedException | TimeoutException e) {
422 LOG.warn("Failed to alarm suppresslist for service: {}", input.getServiceName(), e);
427 private boolean alarmSuppressionNodeRemoval(String serviceName) {
428 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102
429 .service.nodelist.Nodelist> nodeListIID =
430 InstanceIdentifier.create(ServiceNodelist.class).child(
431 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression
432 .rev171102.service.nodelist.Nodelist.class,
433 new NodelistKey(serviceName));
434 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
435 writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, nodeListIID);
436 Future<Void> submit = writeTransaction.submit();
438 submit.get(Timeouts.DATASTORE_DELETE, TimeUnit.MILLISECONDS);
439 LOG.info("Nodes are unregister for alarm suppression for service: {}", serviceName);
441 } catch (InterruptedException | TimeoutException | ExecutionException e) {
442 LOG.warn("Failed to alarm suppresslist for service: {}", serviceName, e);
447 private void setTopologyForService(String name, Topology topo)
448 throws InterruptedException, ExecutionException, TimeoutException {
449 ServicesBuilder servicesBuilder;
450 // Get the service from the service list inventory
451 ServicesKey serviceKey = new ServicesKey(name);
452 InstanceIdentifier<Services> iid =
453 InstanceIdentifier.create(ServiceList.class).child(Services.class, serviceKey);
454 Optional<Services> services;
455 try (ReadOnlyTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
456 Future<com.google.common.base.Optional<Services>> future =
457 readTx.read(LogicalDatastoreType.OPERATIONAL, iid);
458 services = future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS).toJavaUtil();
459 } catch (InterruptedException | ExecutionException | TimeoutException e) {
462 if (services.isPresent()) {
463 servicesBuilder = new ServicesBuilder(services.get());
465 servicesBuilder = new ServicesBuilder();
466 servicesBuilder.withKey(serviceKey);
468 servicesBuilder.setTopology(topo);
469 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
470 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, servicesBuilder.build());
471 writeTx.submit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
474 private boolean isUsedByXc(String nodeid, String interfaceid, String xcid) {
475 InstanceIdentifier<RoadmConnections> xciid = InstanceIdentifier.create(OrgOpenroadmDevice.class)
476 .child(RoadmConnections.class, new RoadmConnectionsKey(xcid));
477 LOG.info("reading xc {} in node {}", xcid, nodeid);
478 Optional<RoadmConnections> crossconnection =
479 this.deviceTransactionManager.getDataFromDevice(nodeid, LogicalDatastoreType.CONFIGURATION, xciid,
480 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
481 if (crossconnection.isPresent()) {
482 RoadmConnections xc = crossconnection.get();
483 LOG.info("xd {} found", xcid);
484 if (xc.getSource().getSrcIf().equals(interfaceid) || xc.getDestination().getDstIf().equals(interfaceid)) {
488 LOG.info("xd {} not found !", xcid);
494 public CreateOtsOmsOutput createOtsOms(CreateOtsOmsInput input) throws OpenRoadmInterfaceException {
495 CreateOtsOmsOutputBuilder output = new CreateOtsOmsOutputBuilder();
497 Boolean success = false;
498 // if the node is currently mounted then proceed.
499 if (this.deviceTransactionManager.isDeviceMounted(input.getNodeId())) {
500 Mapping oldMapping = null;
501 Mapping newMapping = null;
502 oldMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
503 if (oldMapping != null) {
504 String otsInterface =
505 this.openRoadmInterfaceFactory.createOpenRoadmOtsInterface(input.getNodeId(), oldMapping);
506 newMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
508 Boolean isSupportingOtsPresent = isSupportingOtsPresent(newMapping);
509 while (!isSupportingOtsPresent && (count < 6)) {
510 LOG.info("waiting for post interface operation on node '{}'...", input.getNodeId());
513 this.portMapping.updateMapping(input.getNodeId(), oldMapping);
514 } catch (InterruptedException e) {
515 LOG.error("Failed to wait for post interface operation ");
517 newMapping = this.portMapping.getMapping(input.getNodeId(), input.getLogicalConnectionPoint());
518 isSupportingOtsPresent = isSupportingOtsPresent(newMapping);
522 String omsInterface =
523 this.openRoadmInterfaceFactory.createOpenRoadmOmsInterface(input.getNodeId(), newMapping);
524 if (omsInterface != null) {
525 result = "Interfaces " + otsInterface + " - " + omsInterface + " successfully created on node "
529 LOG.error("Fail to create OpenRoadmOms Interface for node '{}'", input.getNodeId());
530 result = "Fail to create OpenRoadmOms Interface for node : " + input.getNodeId();
533 LOG.error("Unable to get ots interface from mapping {} for node {}",
534 oldMapping.getLogicalConnectionPoint(), input.getNodeId());
535 result = String.format("Unable to get ots interface from mapping %s - %s",
536 oldMapping.getLogicalConnectionPoint(), input.getNodeId());
539 result = "Logical Connection point " + input.getLogicalConnectionPoint() + " does not exist for "
543 result = input.getNodeId() + " is not mounted on the controller";
546 return output.setResult(result).setSuccess(success).build();
549 private Boolean isSupportingOtsPresent(Mapping mapping) {
550 Boolean result = false;
551 if (mapping != null) {
552 if (mapping.getSupportingOts() != null) {
553 LOG.info("SupportingOts info is present in mapping {}", mapping);
556 LOG.warn("SupportingOts info not present in mapping {}", mapping);