Search in sources :

Example 1 with ChassisMountedAssetMap

use of com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap in project flowgate by vmware.

the class SycnRealTimeDataJobTest method testHandleChassisSolts3.

@Test
public void testHandleChassisSolts3() {
    Asset asset = createAsset();
    List<ChassisMountedAssetMap> chassisMaps = new ArrayList<ChassisMountedAssetMap>();
    ChassisMountedAssetMap cMap1 = new ChassisMountedAssetMap();
    cMap1.setMountedAssetID(105);
    cMap1.setColumnPosition(1);
    cMap1.setRowPosition(1);
    cMap1.setMountingSide("Front");
    cMap1.setSlotName("1");
    chassisMaps.add(cMap1);
    ChassisMountedAssetMap cMap2 = new ChassisMountedAssetMap();
    cMap2.setMountedAssetID(198);
    cMap2.setColumnPosition(1);
    cMap2.setRowPosition(2);
    cMap2.setMountingSide("Back");
    cMap2.setSlotName("2");
    chassisMaps.add(cMap2);
    NlyteAsset nlyteAsset = getNlyteAsset().get(0);
    nlyteAsset.setChassisMountedAssetMaps(chassisMaps);
    HandleAssetUtil util = new HandleAssetUtil();
    util.handleChassisSolts(asset, nlyteAsset);
    String chassisInfo = asset.getJustificationfields().get(FlowgateConstant.CHASSIS);
    ObjectMapper mapper = new ObjectMapper();
    try {
        Map<String, String> chassisInfoMap = mapper.readValue(chassisInfo, new TypeReference<Map<String, String>>() {
        });
        List<FlowgateChassisSlot> slots = mapper.readValue(chassisInfoMap.get(FlowgateConstant.CHASSISSLOTS), new TypeReference<List<FlowgateChassisSlot>>() {
        });
        for (FlowgateChassisSlot chassisslot : slots) {
            if (chassisslot.getSlotName().equals("1")) {
                TestCase.assertEquals("Front", chassisslot.getMountingSide());
                TestCase.assertEquals(Integer.valueOf(105), chassisslot.getMountedAssetNumber());
            } else if (chassisslot.getSlotName().equals("2")) {
                TestCase.assertEquals("Back", chassisslot.getMountingSide());
                TestCase.assertEquals(Integer.valueOf(198), chassisslot.getMountedAssetNumber());
            } else {
                TestCase.fail();
            }
        }
    } catch (JsonProcessingException e) {
        TestCase.fail(e.getMessage());
    }
}
Also used : NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) ArrayList(java.util.ArrayList) ChassisMountedAssetMap(com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap) FlowgateChassisSlot(com.vmware.flowgate.common.model.FlowgateChassisSlot) HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ChassisMountedAssetMap(com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 2 with ChassisMountedAssetMap

use of com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap in project flowgate by vmware.

the class HandleAssetUtil method handleChassisSolts.

public void handleChassisSolts(Asset asset, NlyteAsset nlyteAsset) {
    List<ChassisSlot> chassisSolts = nlyteAsset.getChassisSlots();
    List<ChassisMountedAssetMap> chassisMountedAssets = nlyteAsset.getChassisMountedAssetMaps();
    List<FlowgateChassisSlot> flowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
    int usedSolts = 0;
    if (chassisSolts == null || chassisSolts.isEmpty()) {
        if (chassisMountedAssets == null || chassisMountedAssets.isEmpty()) {
            return;
        }
        usedSolts = chassisMountedAssets.size();
        for (ChassisMountedAssetMap caMap : chassisMountedAssets) {
            FlowgateChassisSlot solt = new FlowgateChassisSlot();
            solt.setColumnPosition(caMap.getColumnPosition());
            solt.setMountingSide(caMap.getMountingSide());
            solt.setRowPosition(caMap.getRowPosition());
            solt.setSlotName(caMap.getSlotName());
            solt.setMountedAssetNumber(caMap.getMountedAssetID());
            flowgateChassisSlots.add(solt);
        }
    } else {
        HashMap<String, Integer> soltsAndmountedAssetNumberMap = new HashMap<String, Integer>();
        if (chassisMountedAssets != null && !chassisMountedAssets.isEmpty()) {
            usedSolts = chassisMountedAssets.size();
            for (ChassisMountedAssetMap caMap : chassisMountedAssets) {
                soltsAndmountedAssetNumberMap.put(caMap.getMountingSide() + caMap.getSlotName(), caMap.getMountedAssetID());
            }
        }
        for (ChassisSlot chassisSolt : chassisSolts) {
            FlowgateChassisSlot solt = new FlowgateChassisSlot();
            solt.setColumnPosition(chassisSolt.getColumnPosition());
            solt.setMountingSide(chassisSolt.getMountingSide());
            solt.setRowPosition(chassisSolt.getRowPosition());
            solt.setSlotName(chassisSolt.getSlotName());
            solt.setMountedAssetNumber(soltsAndmountedAssetNumberMap.get(solt.getMountingSide() + solt.getSlotName()));
            flowgateChassisSlots.add(solt);
        }
    }
    asset.setFreeCapacity(asset.getCapacity() - usedSolts);
    try {
        String chassisSoltsInfo = mapper.writeValueAsString(flowgateChassisSlots);
        supplementChassisInfo(asset, FlowgateConstant.CHASSISSLOTS, chassisSoltsInfo);
    } catch (JsonProcessingException e) {
        logger.error("Failed to get info of chassisSolts.");
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ChassisMountedAssetMap(com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap) FlowgateChassisSlot(com.vmware.flowgate.common.model.FlowgateChassisSlot) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ChassisSlot(com.vmware.flowgate.nlyteworker.model.ChassisSlot) FlowgateChassisSlot(com.vmware.flowgate.common.model.FlowgateChassisSlot)

Example 3 with ChassisMountedAssetMap

use of com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap in project flowgate by vmware.

the class SycnRealTimeDataJobTest method testHandleChassisSolts2.

@Test
public void testHandleChassisSolts2() {
    Asset asset = createAsset();
    List<ChassisSlot> chassisSolts = new ArrayList<ChassisSlot>();
    ChassisSlot slot = new ChassisSlot();
    slot.setChassisAssetID(105);
    slot.setColumnPosition(1);
    slot.setRowPosition(1);
    slot.setMountingSide("Front");
    slot.setSlotName("1");
    slot.setId(78);
    chassisSolts.add(slot);
    ChassisSlot slot2 = new ChassisSlot();
    slot2.setChassisAssetID(105);
    slot2.setColumnPosition(1);
    slot2.setRowPosition(2);
    slot2.setMountingSide("Back");
    slot2.setSlotName("2");
    slot2.setId(79);
    chassisSolts.add(slot2);
    List<ChassisMountedAssetMap> cmAssets = new ArrayList<ChassisMountedAssetMap>();
    ChassisMountedAssetMap cmAsset = new ChassisMountedAssetMap();
    cmAsset.setMountedAssetID(197);
    cmAsset.setMountingSide("Front");
    cmAsset.setSlotName("1");
    cmAssets.add(cmAsset);
    ChassisMountedAssetMap cmAsset2 = new ChassisMountedAssetMap();
    cmAsset2.setMountedAssetID(198);
    cmAsset2.setMountingSide("Back");
    cmAsset2.setSlotName("2");
    cmAssets.add(cmAsset2);
    NlyteAsset nlyteAsset = getNlyteAsset().get(0);
    nlyteAsset.setChassisSlots(chassisSolts);
    nlyteAsset.setChassisMountedAssetMaps(cmAssets);
    HandleAssetUtil util = new HandleAssetUtil();
    util.handleChassisSolts(asset, nlyteAsset);
    String chassisInfo = asset.getJustificationfields().get(FlowgateConstant.CHASSIS);
    ObjectMapper mapper = new ObjectMapper();
    try {
        Map<String, String> chassisInfoMap = mapper.readValue(chassisInfo, new TypeReference<Map<String, String>>() {
        });
        List<FlowgateChassisSlot> slots = mapper.readValue(chassisInfoMap.get(FlowgateConstant.CHASSISSLOTS), new TypeReference<List<FlowgateChassisSlot>>() {
        });
        for (FlowgateChassisSlot chassisslot : slots) {
            if (chassisslot.getSlotName().equals("1")) {
                TestCase.assertEquals("Front", chassisslot.getMountingSide());
                TestCase.assertEquals(Integer.valueOf(197), chassisslot.getMountedAssetNumber());
            } else if (chassisslot.getSlotName().equals("2")) {
                TestCase.assertEquals("Back", chassisslot.getMountingSide());
                TestCase.assertEquals(Integer.valueOf(198), chassisslot.getMountedAssetNumber());
            } else {
                TestCase.fail();
            }
        }
    } catch (JsonProcessingException e) {
        TestCase.fail(e.getMessage());
    }
}
Also used : NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) ArrayList(java.util.ArrayList) ChassisMountedAssetMap(com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap) FlowgateChassisSlot(com.vmware.flowgate.common.model.FlowgateChassisSlot) HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ChassisMountedAssetMap(com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FlowgateChassisSlot(com.vmware.flowgate.common.model.FlowgateChassisSlot) ChassisSlot(com.vmware.flowgate.nlyteworker.model.ChassisSlot) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 FlowgateChassisSlot (com.vmware.flowgate.common.model.FlowgateChassisSlot)3 ChassisMountedAssetMap (com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Asset (com.vmware.flowgate.common.model.Asset)2 ChassisSlot (com.vmware.flowgate.nlyteworker.model.ChassisSlot)2 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)2 HandleAssetUtil (com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil)2 List (java.util.List)2 Map (java.util.Map)2 Test (org.junit.Test)2 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2