X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=common%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fcommon%2Fmapping%2FPortMappingImpl.java;h=7ac0f2c3d0163fd96ebd8a1681512b718082c0fd;hb=refs%2Fchanges%2F91%2F74091%2F1;hp=e8e9e10fa28e6332f7d3ba08ea4a659937ce1ae7;hpb=f8f1b05b6eefd0f5c18e22c22b4d4e023f61faf6;p=transportpce.git diff --git a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingImpl.java b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingImpl.java index e8e9e10fa..7ac0f2c3d 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingImpl.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingImpl.java @@ -15,6 +15,8 @@ import java.util.Comparator; import java.util.List; import java.util.Optional; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; import org.opendaylight.controller.md.sal.binding.api.DataBroker; @@ -83,7 +85,7 @@ public class PortMappingImpl implements PortMapping { List portMapList = new ArrayList<>(); InstanceIdentifier infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class); Optional deviceInfoOptional = - deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, infoIID, + this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, infoIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); Info deviceInfo; @@ -158,7 +160,7 @@ public class PortMappingImpl implements PortMapping { LOG.info("Fetching logical Connection Point value for port {} at circuit pack {}", portName, circuitPackName); Optional portObject = - deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, portIID, + this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, portIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); if (portObject.isPresent()) { Ports port = portObject.get(); @@ -196,8 +198,8 @@ public class PortMappingImpl implements PortMapping { InstanceIdentifier deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) .child(Degree.class, new DegreeKey(degreeCounter)); Optional ordmDegreeObject = - deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.CONFIGURATION, deviceIID, - Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); + this.deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.CONFIGURATION, + deviceIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); if (ordmDegreeObject.isPresent()) { degrees.add(ordmDegreeObject.get()); } else { @@ -231,10 +233,10 @@ public class PortMappingImpl implements PortMapping { InstanceIdentifier cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName)); Optional circuitPackObject = - deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, cpIID, + this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, cpIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); - if (!circuitPackObject.isPresent() || circuitPackObject.get().getPorts() == null) { + if (!circuitPackObject.isPresent() || (circuitPackObject.get().getPorts() == null)) { LOG.warn("Circuit pack was not found or ports are mission for name: {}", circuitPackName); continue; // TODO continue or return false? } @@ -281,21 +283,22 @@ public class PortMappingImpl implements PortMapping { maxSrg = 20; } - for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) { + int srgCounter = 1; + Integer nbSrg = 0; + while (srgCounter <= maxSrg) { LOG.info("Getting Circuitpacks for Srg Number {}", srgCounter); InstanceIdentifier srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) .child(SharedRiskGroup.class, new SharedRiskGroupKey(srgCounter)); Optional ordmSrgObject = - deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.CONFIGURATION, srgIID, - Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); - + this.deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.CONFIGURATION, + srgIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); if (ordmSrgObject.isPresent()) { srgCps.addAll(ordmSrgObject.get().getCircuitPacks()); - } else { - LOG.info("Device has {} Srg", srgCounter - 1); - break; + nbSrg++; } + srgCounter++; } + LOG.info("Device has {} Srg", nbSrg); return srgCps; } @@ -320,14 +323,14 @@ public class PortMappingImpl implements PortMapping { // Creating for Xponder Line and Client Ports InstanceIdentifier deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class); Optional deviceObject = - deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID, + this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); // Variable to keep track of number of line ports int line = 1; // Variable to keep track of number of client ports int client = 1; - if (!deviceObject.isPresent() || deviceObject.get().getCircuitPacks() == null) { + if (!deviceObject.isPresent() || (deviceObject.get().getCircuitPacks() == null)) { LOG.warn("Circuit Packs are not present for {}", nodeId); return false; // TODO return false or continue? } @@ -376,11 +379,11 @@ public class PortMappingImpl implements PortMapping { .setSupportingCircuitPackName(circuitPackName).setSupportingPort(port.getPortName()); // Get OMS and OTS interface provisioned on the TTP's - if (logicalConnectionPoint.contains(OpenRoadmInterfacesImpl.TTP_TOKEN) && port.getInterfaces() != null) { + if (logicalConnectionPoint.contains(OpenRoadmInterfacesImpl.TTP_TOKEN) && (port.getInterfaces() != null)) { for (Interfaces interfaces : port.getInterfaces()) { try { Optional openRoadmInterface = - openRoadmInterfaces.getInterface(nodeId, interfaces.getInterfaceName()); + this.openRoadmInterfaces.getInterface(nodeId, interfaces.getInterfaceName()); if (openRoadmInterface.isPresent()) { Class interfaceType = openRoadmInterface.get().getType(); // Check if interface type is OMS or OTS @@ -455,7 +458,7 @@ public class PortMappingImpl implements PortMapping { NetworkBuilder nwBldr = new NetworkBuilder(); nwBldr.setNodes(nodesList); - final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); + final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction(); InstanceIdentifier nodesIID = InstanceIdentifier.builder(Network.class).build(); Network network = nwBldr.build(); writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network); @@ -478,7 +481,7 @@ public class PortMappingImpl implements PortMapping { */ InstanceIdentifier portMappingIID = InstanceIdentifier.builder(Network.class).child(Nodes.class, new NodesKey(nodeId)).child(Mapping.class, new MappingKey(logicalConnPoint)).build(); - try (ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction()) { + try (ReadOnlyTransaction readTx = this.dataBroker.newReadOnlyTransaction()) { Optional mapObject = readTx.read(LogicalDatastoreType.CONFIGURATION, portMappingIID).get().toJavaUtil(); if (mapObject.isPresent()) { @@ -522,4 +525,20 @@ public class PortMappingImpl implements PortMapping { return ""; // TODO return false or continue? } + @Override + public void deleteMappingData(String nodeId) { + LOG.info("Deleting Mapping Data corresponding at node '{}'",nodeId); + WriteTransaction rw = this.dataBroker.newWriteOnlyTransaction(); + InstanceIdentifier nodesIID = InstanceIdentifier.create(Network.class) + .child(Nodes.class, new NodesKey(nodeId)); + rw.delete(LogicalDatastoreType.CONFIGURATION, nodesIID); + try { + rw.submit().get(1, TimeUnit.SECONDS); + LOG.info("Port mapping removal for node '{}'", nodeId); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + LOG.error("Error for removing port mapping infos for node '{}'",nodeId); + } + + } + }