Migrate Optional.get() callers
[transportpce.git] / common / src / main / java / org / opendaylight / transportpce / common / mapping / PortMappingVersion710.java
index 45ea9981f4af960a5162be0d1b3e00bedac3a06d..567a6f9949d389d94f793f69dbe375b9616c14b2 100644 (file)
@@ -147,7 +147,7 @@ public class PortMappingVersion710 {
             LOG.warn(PortMappingUtils.DEVICE_HAS_LOGMSG, nodeId, "no info", "subtree");
             return false;
         }
-        Info deviceInfo = deviceInfoOptional.get();
+        Info deviceInfo = deviceInfoOptional.orElseThrow();
         NodeInfo nodeInfo = createNodeInfo(deviceInfo);
         if (nodeInfo == null) {
             return false;
@@ -216,7 +216,7 @@ public class PortMappingVersion710 {
             .build();
         try {
             Ports port = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL,
-                portId, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).get();
+                portId, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).orElseThrow();
             Mapping newMapping = updateMappingObject(nodeId, port, oldMapping);
             LOG.debug(PortMappingUtils.UPDATE_MAPPING_LOGMSG,
                 nodeId, oldMapping, oldMapping.getLogicalConnectionPoint(), newMapping);
@@ -242,7 +242,7 @@ public class PortMappingVersion710 {
             InstanceIdentifier.create(Network.class).child(Nodes.class, new NodesKey(nodeId));
         Nodes portmappingNode = null;
         try (ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
-            portmappingNode = readTx.read(LogicalDatastoreType.CONFIGURATION, portMappingNodeIID).get().get();
+            portmappingNode = readTx.read(LogicalDatastoreType.CONFIGURATION, portMappingNodeIID).get().orElseThrow();
         } catch (InterruptedException | ExecutionException ex) {
             LOG.error("Unable to read the port-mapping for nodeId {}", nodeId, ex);
         }
@@ -251,7 +251,7 @@ public class PortMappingVersion710 {
         }
 
         OduSwitchingPools osp = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL,
-            ospIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).get();
+            ospIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).orElseThrow();
         Uint16 ospNumber = osp.getSwitchingPoolNumber();
         Map<SwitchingPoolLcpKey, SwitchingPoolLcp> splMap =
             new HashMap<SwitchingPoolLcpKey, SwitchingPoolLcp>(portmappingNode.nonnullSwitchingPoolLcp());
@@ -291,7 +291,7 @@ public class PortMappingVersion710 {
         Set<String> lcpList = nblBldr.getLcpList() != null ? nblBldr.getLcpList() : new HashSet<>();
         for (InstanceIdentifier<PortList> id : entry.getValue()) {
             PortList portList = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL,
-                id, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).get();
+                id, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).orElseThrow();
             String lcp = getLcpFromCpAndPort(mappings, portList.getCircuitPackName(), portList.getPortName());
             if (lcp == null || lcpList.contains(lcp)) {
                 return null;
@@ -348,7 +348,7 @@ public class PortMappingVersion710 {
             LOG.error(PortMappingUtils.CANNOT_GET_DEV_CONF_LOGMSG, nodeId);
             return null;
         }
-        OrgOpenroadmDevice device = deviceObject.get();
+        OrgOpenroadmDevice device = deviceObject.orElseThrow();
         if (device.getCircuitPacks() == null) {
             LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, PortMappingUtils.FOUND);
             return null;
@@ -419,14 +419,14 @@ public class PortMappingVersion710 {
                 nodeId, circuitPackName);
             return null;
         }
-        Optional<Ports> portsList = cpList.get().nonnullPorts().values().stream()
+        Optional<Ports> portsList = cpList.orElseThrow().nonnullPorts().values().stream()
                 .filter(p -> p.getPortName().equals(portName)).findFirst();
         if (portsList.isEmpty()) {
             LOG.warn(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
                 nodeId, portName, circuitPackName, "in the device");
             return null;
         }
-        return portsList.get();
+        return portsList.orElseThrow();
     }
 
     private List<SwitchingPoolLcp> getSwitchingPoolList(OrgOpenroadmDevice device,
@@ -506,8 +506,8 @@ public class PortMappingVersion710 {
                 LogicalDatastoreType.OPERATIONAL, srgIID,
                 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
             if (ordmSrgObject.isPresent()) {
-                srgCps.addAll(ordmSrgObject.get().nonnullCircuitPacks().values());
-                cpPerSrg.put(ordmSrgObject.get().getSrgNumber().toJava(), srgCps);
+                srgCps.addAll(ordmSrgObject.orElseThrow().nonnullCircuitPacks().values());
+                cpPerSrg.put(ordmSrgObject.orElseThrow().getSrgNumber().toJava(), srgCps);
             }
         }
         LOG.info(PortMappingUtils.DEVICE_HAS_LOGMSG, deviceId, cpPerSrg.size(), "SRG");
@@ -588,13 +588,13 @@ public class PortMappingVersion710 {
             .getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port2ID,
                 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
         if (port2Object.isEmpty()
-                || port2Object.get().getPortQual().getIntValue() != PortQual.RoadmExternal.getIntValue()) {
+                || port2Object.orElseThrow().getPortQual().getIntValue() != PortQual.RoadmExternal.getIntValue()) {
             LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_GET_ERROR_LOGMSG,
                 nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName(),
                 port.getPortName(), circuitPackName);
             return null;
         }
-        Ports port2 = port2Object.get();
+        Ports port2 = port2Object.orElseThrow();
         if (!checkPartnerPort(circuitPackName, port, port2)) {
             LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_CONF_ERROR_LOGMSG,
                 nodeId, port2.getPortName(), port.getPartnerPort().getCircuitPackName(),
@@ -619,11 +619,11 @@ public class PortMappingVersion710 {
                 nodeId, circuitPackName);
             return new ArrayList<>();
         }
-        if (circuitPackObject.get().getPorts() == null) {
+        if (circuitPackObject.orElseThrow().getPorts() == null) {
             LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, PortMappingUtils.FOUND, circuitPackName);
             return new ArrayList<>();
         }
-        return new ArrayList<>(circuitPackObject.get().nonnullPorts().values());
+        return new ArrayList<>(circuitPackObject.orElseThrow().nonnullPorts().values());
     }
 
     private String createLogicalConnectionPort(Ports port, int index, int portIndex) {
@@ -649,7 +649,7 @@ public class PortMappingVersion710 {
             LOG.warn("MC-capabilities profile will be empty for node {}", deviceId);
             return mcCapabilityProfiles;
         }
-        device = deviceObject.get();
+        device = deviceObject.orElseThrow();
         mcCapabilityProfiles = device.getMcCapabilityProfile();
         return mcCapabilityProfiles;
     }
@@ -674,7 +674,7 @@ public class PortMappingVersion710 {
                 LogicalDatastoreType.OPERATIONAL, deviceIID,
                 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
             if (ordmDegreeObject.isPresent()) {
-                degrees.put(degreeCounter, ordmDegreeObject.get());
+                degrees.put(degreeCounter, ordmDegreeObject.orElseThrow());
             }
         }
         LOG.info(PortMappingUtils.DEVICE_HAS_LOGMSG,
@@ -704,7 +704,7 @@ public class PortMappingVersion710 {
                 LogicalDatastoreType.OPERATIONAL, srgIID,
                 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
             if (ordmSrgObject.isPresent()) {
-                srgs.add(ordmSrgObject.get());
+                srgs.add(ordmSrgObject.orElseThrow());
 
             }
         }
@@ -720,12 +720,12 @@ public class PortMappingVersion710 {
         Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
             LogicalDatastoreType.OPERATIONAL, protocoliid, Timeouts.DEVICE_READ_TIMEOUT,
             Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-        if (protocolObject.isEmpty() || protocolObject.get().augmentation(Protocols1.class).getLldp() == null) {
+        if (protocolObject.isEmpty() || protocolObject.orElseThrow().augmentation(Protocols1.class).getLldp() == null) {
             LOG.warn(PortMappingUtils.PROCESSING_DONE_LOGMSG, nodeId, PortMappingUtils.CANNOT_GET_LLDP_CONF_LOGMSG);
             return new HashMap<>();
         }
         Map<String, String> cpToInterfaceMap = new HashMap<>();
-        Lldp lldp = protocolObject.get().augmentation(Protocols1.class).getLldp();
+        Lldp lldp = protocolObject.orElseThrow().augmentation(Protocols1.class).getLldp();
         for (PortConfig portConfig : lldp.nonnullPortConfig().values()) {
             if (!portConfig.getAdminStatus().equals(PortConfig.AdminStatus.Txandrx)) {
                 continue;
@@ -737,10 +737,10 @@ public class PortMappingVersion710 {
             Optional<Interface> interfaceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
                 LogicalDatastoreType.OPERATIONAL, interfaceIID, Timeouts.DEVICE_READ_TIMEOUT,
                 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-            if (interfaceObject.isEmpty() || interfaceObject.get().getSupportingCircuitPackName() == null) {
+            if (interfaceObject.isEmpty() || interfaceObject.orElseThrow().getSupportingCircuitPackName() == null) {
                 continue;
             }
-            String supportingCircuitPackName = interfaceObject.get().getSupportingCircuitPackName();
+            String supportingCircuitPackName = interfaceObject.orElseThrow().getSupportingCircuitPackName();
             cpToInterfaceMap.put(supportingCircuitPackName, portConfig.getIfName());
             InstanceIdentifier<CircuitPacks> circuitPacksIID = InstanceIdentifier
                 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
@@ -749,10 +749,10 @@ public class PortMappingVersion710 {
             Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(
                 nodeId, LogicalDatastoreType.OPERATIONAL, circuitPacksIID, Timeouts.DEVICE_READ_TIMEOUT,
                 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-            if (circuitPackObject.isEmpty() || circuitPackObject.get().getParentCircuitPack() == null) {
+            if (circuitPackObject.isEmpty() || circuitPackObject.orElseThrow().getParentCircuitPack() == null) {
                 continue;
             }
-            cpToInterfaceMap.put(circuitPackObject.get().getParentCircuitPack().getCircuitPackName(),
+            cpToInterfaceMap.put(circuitPackObject.orElseThrow().getParentCircuitPack().getCircuitPackName(),
                 portConfig.getIfName());
         }
         LOG.info(PortMappingUtils.PROCESSING_DONE_LOGMSG, nodeId, " - success");
@@ -984,8 +984,9 @@ public class PortMappingVersion710 {
                     nodeId, interfaces.getInterfaceName() + "- empty interface");
                 continue;
             }
-            InterfaceType interfaceType = openRoadmInterface.get().getType();
-            LOG.debug(PortMappingUtils.GOT_INTF_LOGMSG, nodeId, openRoadmInterface.get().getName(), interfaceType);
+            InterfaceType interfaceType = openRoadmInterface.orElseThrow().getType();
+            LOG.debug(PortMappingUtils.GOT_INTF_LOGMSG, nodeId, openRoadmInterface.orElseThrow().getName(),
+                    interfaceType);
             // Check if interface type is OMS or OTS
             // Switch/Case might be more indicated here but is not possible in jdk17 w/o enable-preview
             if (interfaceType.equals(OpenROADMOpticalMultiplex.VALUE)) {
@@ -1073,7 +1074,7 @@ public class PortMappingVersion710 {
                 // Here we assume all the supported-interfaces has the support same rates, and the
                 // trib-slot numbers are assumed to be the same
                 String mxpProfileName = sic1.getOtnCapability().getMpdrClientRestriction().get(0).getMuxpProfileName()
-                    .stream().findFirst().get();
+                    .stream().findFirst().orElseThrow();
                 // From this muxponder-profile get the min-trib-slot and the max-trib-slot
                 LOG.info("{}: Muxp-profile used for trib information {}", nodeId, mxpProfileName);
                 // This provides the tribSlot information from muxProfile
@@ -1114,7 +1115,7 @@ public class PortMappingVersion710 {
             LogicalDatastoreType.OPERATIONAL, deviceIID,
             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
 
-        Set<OpucnTribSlotDef> ntwHoOduOpucnTribSlots = muxpProfileObject.get().getNetworkHoOduOpucnTribSlots();
+        Set<OpucnTribSlotDef> ntwHoOduOpucnTribSlots = muxpProfileObject.orElseThrow().getNetworkHoOduOpucnTribSlots();
         // Sort the tib-slots in ascending order and pick min and max
         List<OpucnTribSlotDef> sortedNtwHoOduOpucnTribSlots = ntwHoOduOpucnTribSlots.stream().sorted(
             Comparator.comparingDouble(x -> Double.parseDouble(
@@ -1144,7 +1145,7 @@ public class PortMappingVersion710 {
             LOG.error(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, port.getPartnerPort().getCircuitPackName());
             return null;
         }
-        Optional<Ports> poOpt = cpOpt.get().nonnullPorts().values().stream()
+        Optional<Ports> poOpt = cpOpt.orElseThrow().nonnullPorts().values().stream()
             .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName()))
             .findFirst();
         if (poOpt.isEmpty()) {
@@ -1152,8 +1153,8 @@ public class PortMappingVersion710 {
                 nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName());
             return null;
         }
-        Ports port2 = poOpt.get();
-        circuitPackName2.append(cpOpt.get().getCircuitPackName());
+        Ports port2 = poOpt.orElseThrow();
+        circuitPackName2.append(cpOpt.orElseThrow().getCircuitPackName());
         if (!checkPartnerPort(circuitPackName, port, port2)) {
             LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
                 nodeId, port2.getPortName(), circuitPackName2, port.getPortName(), circuitPackName);
@@ -1375,7 +1376,7 @@ public class PortMappingVersion710 {
             LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp.getPortName(), cpName);
             return null;
         }
-        return portObject.get();
+        return portObject.orElseThrow();
     }
 
     private boolean checkPortQual(Ports port, String cpName, String nodeId) {