CtrlPhysicalStorageApiCallHandler { public static List<JsonGenTypes.PhysicalStorage> groupPhysicalStorageByDevice( Map<NodeName, List<LsBlkEntry>> mapData ) { Map<JsonGenTypes.PhysicalStorage, JsonGenTypes.PhysicalStorage> phys = new TreeMap<>( Comparator.comparingLong((JsonGenTypes.PhysicalStorage physicalStorage) -> physicalStorage.size) .thenComparing(physicalStorage -> physicalStorage.rotational)); for (Map.Entry<NodeName, List<LsBlkEntry>> entry : mapData.entrySet()) { for (LsBlkEntry lsblkEntry : entry.getValue()) { JsonGenTypes.PhysicalStorage physEntry = new JsonGenTypes.PhysicalStorage(); physEntry.size = lsblkEntry.getSize(); physEntry.rotational = lsblkEntry.isRotational(); JsonGenTypes.PhysicalStorageDevice physDev = new JsonGenTypes.PhysicalStorageDevice(); physDev.device = lsblkEntry.getName(); physDev.model = lsblkEntry.getModel(); physDev.serial = lsblkEntry.getSerial(); physDev.wwn = lsblkEntry.getWwn(); final String nodeName = entry.getKey().displayValue; if (phys.containsKey(physEntry)) { JsonGenTypes.PhysicalStorage physicalStorage = phys.get(physEntry); List<JsonGenTypes.PhysicalStorageDevice> nodeDevs = physicalStorage.nodes.get(nodeName); if (nodeDevs != null) { nodeDevs.add(physDev); } else { List<JsonGenTypes.PhysicalStorageDevice> physDevices = new ArrayList<>(); physDevices.add(physDev); phys.get(physEntry).nodes.put(nodeName, physDevices); } } else { physEntry.nodes = new HashMap<>(); List<JsonGenTypes.PhysicalStorageDevice> physDevices = new ArrayList<>(); physDevices.add(physDev); physEntry.nodes.put(nodeName, physDevices); phys.put(physEntry, physEntry); } } } return new ArrayList<>(phys.values()); } @Inject  CtrlPhysicalStorageApiCallHandler(
        ErrorReporter errorReporterRef,
        @PeerContext Provider<AccessContext> peerAccCtxRef,
        ScopeRunner scopeRunnerRef,
        LockGuardFactory lockGuardFactoryRef,
        CtrlStltSerializer ctrlStltSerializerRef,
        CtrlApiDataLoader ctrlApiDataLoaderRef,
        NodeRepository nodeRepositoryRef
    ); Flux<Map<NodeName, List<LsBlkEntry>>> listPhysicalStorage(); static String getDevicePoolName(final String devicePoolName, final List<String> devicePaths); Flux<ApiCallRc> createDevicePool(
        String nodeNameStr,
        List<String> devicePaths,
        DeviceProviderKind providerKindRef,
        RaidLevel raidLevel,
        String poolName,
        boolean vdoEnabled,
        long vdoLogicalSizeKib,
        long vdoSlabSize
    ); Flux<ApiCallRc> deleteDevicePool(
        String nodeNameStr,
        List<String> devicePaths,
        DeviceProviderKind providerKindRef,
        String poolName
    ); static List<JsonGenTypes.PhysicalStorage> groupPhysicalStorageByDevice(
        Map<NodeName, List<LsBlkEntry>> mapData
    );  }
@Test public void testGroupLsBlkEntriesByNode() throws InvalidNameException { Map<NodeName, List<LsBlkEntry>> testData = new HashMap<>(); final NodeName alpha = new NodeName("alpha"); final NodeName bravo = new NodeName("bravo"); final NodeName charlie = new NodeName("charlie"); List<LsBlkEntry> data = new ArrayList<>(); data.add( new LsBlkEntry( "sde", 512L*1024*1024*1024, false, "", "sde", "", 8, 9, "", "", "" ) ); testData.put(alpha, data); testData.put(bravo, data); List<LsBlkEntry> dataCharlie = new ArrayList<>(); dataCharlie.add( new LsBlkEntry( "sde", 512L*1024*1024*1024, false, "", "sde", "", 8, 9, "", "", "" ) ); dataCharlie.add( new LsBlkEntry( "sdd", 640L*1024*1024*1024, true, "", "sdd", "", 9, 0, "", "", "" ) ); dataCharlie.add( new LsBlkEntry( "sdf", 512L*1024*1024*1024, true, "", "sdf", "", 9, 10, "", "", "" ) ); testData.put(charlie, dataCharlie); final List<JsonGenTypes.PhysicalStorage> physicalStorages = CtrlPhysicalStorageApiCallHandler.groupPhysicalStorageByDevice(testData); Assert.assertEquals(3, physicalStorages.size()); Assert.assertEquals(3, physicalStorages.get(0).nodes.size()); Assert.assertEquals(1, physicalStorages.get(1).nodes.size()); Assert.assertEquals(1, physicalStorages.get(2).nodes.size()); Assert.assertTrue(physicalStorages.get(1).nodes.containsKey("charlie")); Assert.assertEquals("sdf", physicalStorages.get(1).nodes.get("charlie").get(0).device); }