Search in sources :

Example 6 with FlowgateChassisSlot

use of com.vmware.flowgate.common.model.FlowgateChassisSlot in project flowgate by vmware.

the class SycnRealTimeDataJobTest method testChassisSlotsIsChanged2.

@Test
public void testChassisSlotsIsChanged2() {
    List<FlowgateChassisSlot> oldFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
    FlowgateChassisSlot slot = createFlowgateChassisSlot();
    oldFlowgateChassisSlots.add(slot);
    HandleAssetUtil util = new HandleAssetUtil();
    TestCase.assertEquals(true, util.chassisSlotsIsChanged(oldFlowgateChassisSlots, new ArrayList<FlowgateChassisSlot>()));
}
Also used : FlowgateChassisSlot(com.vmware.flowgate.common.model.FlowgateChassisSlot) HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) ArrayList(java.util.ArrayList) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 7 with FlowgateChassisSlot

use of com.vmware.flowgate.common.model.FlowgateChassisSlot in project flowgate by vmware.

the class SycnRealTimeDataJobTest method testHandleAssets2.

@Test
public void testHandleAssets2() {
    List<Asset> toUpdateAssets = new ArrayList<Asset>();
    Map<Long, Asset> exsitingaAssetMap = new HashMap<Long, Asset>();
    Asset asset = createAsset();
    asset.setAssetNumber(127);
    asset.setTag("tag1");
    toUpdateAssets.add(asset);
    Asset asset2 = createAsset();
    asset2.setAssetNumber(128);
    asset2.setTag("tag2");
    asset2.setCabinetName("cabinet1");
    Tenant tenant = new Tenant();
    tenant.setOwner("admin");
    tenant.setTenant("tenant");
    tenant.setTenantManager("manager");
    asset2.setTenant(tenant);
    asset2.setRoom("room1");
    asset2.setRow("r2");
    asset2.setCol("c2");
    asset2.setMountingSide(MountingSide.Front);
    asset2.setCategory(AssetCategory.Chassis);
    HashMap<String, String> justficationMap = new HashMap<String, String>();
    List<FlowgateChassisSlot> slots = new ArrayList<FlowgateChassisSlot>();
    FlowgateChassisSlot slot1 = createFlowgateChassisSlot();
    slots.add(slot1);
    Map<String, String> chassisInfoMap = new HashMap<String, String>();
    chassisInfoMap.put(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE, "frontToBack");
    ObjectMapper mapper = new ObjectMapper();
    try {
        String slotsString = mapper.writeValueAsString(slots);
        chassisInfoMap.put(FlowgateConstant.CHASSISSLOTS, slotsString);
        String chassisInfo = mapper.writeValueAsString(chassisInfoMap);
        justficationMap.put(FlowgateConstant.CHASSIS, chassisInfo);
        asset2.setJustificationfields(justficationMap);
    } catch (JsonProcessingException e) {
        TestCase.fail(e.getMessage());
    }
    toUpdateAssets.add(asset2);
    Asset oldAsset1 = createAsset();
    oldAsset1.setAssetNumber(127);
    oldAsset1.setTag("oldtag1");
    exsitingaAssetMap.put(oldAsset1.getAssetNumber(), oldAsset1);
    Asset oldAsset2 = createAsset();
    oldAsset2.setAssetNumber(128);
    oldAsset2.setTag("oldtag2");
    HashMap<String, String> oldjustficationMap = new HashMap<String, String>();
    List<FlowgateChassisSlot> oldslots = new ArrayList<FlowgateChassisSlot>();
    FlowgateChassisSlot oldslot1 = createFlowgateChassisSlot();
    oldslot1.setMountingSide("Back");
    oldslot1.setMountedAssetNumber(5523);
    oldslots.add(oldslot1);
    Map<String, String> oldChassisInfoMap = new HashMap<String, String>();
    oldChassisInfoMap.put(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE, "frontToBack");
    try {
        String oldSlotsString = mapper.writeValueAsString(oldslots);
        oldChassisInfoMap.put(FlowgateConstant.CHASSISSLOTS, oldSlotsString);
        String oldChassisInfo = mapper.writeValueAsString(oldChassisInfoMap);
        oldjustficationMap.put(FlowgateConstant.CHASSIS, oldChassisInfo);
        oldAsset2.setJustificationfields(oldjustficationMap);
    } catch (JsonProcessingException e) {
        TestCase.fail(e.getMessage());
    }
    exsitingaAssetMap.put(oldAsset2.getAssetNumber(), oldAsset2);
    HandleAssetUtil util = new HandleAssetUtil();
    List<Asset> assets = util.handleAssets(toUpdateAssets, exsitingaAssetMap);
    for (Asset assetTosave : assets) {
        if (assetTosave.getAssetNumber() == 128) {
            TestCase.assertEquals(asset2.getTag(), assetTosave.getTag());
            TestCase.assertEquals(asset2.getRoom(), assetTosave.getRoom());
            TestCase.assertEquals(asset2.getRow(), assetTosave.getRow());
            TestCase.assertEquals(asset2.getCol(), assetTosave.getCol());
            TestCase.assertEquals(asset2.getMountingSide(), assetTosave.getMountingSide());
            TestCase.assertEquals(asset2.getTenant().getOwner(), assetTosave.getTenant().getOwner());
            HashMap<String, String> justfications = assetTosave.getJustificationfields();
            String chassisInfo = justfications.get(FlowgateConstant.CHASSIS);
            try {
                Map<String, String> newChassisInfoMap = mapper.readValue(chassisInfo, new TypeReference<Map<String, String>>() {
                });
                TestCase.assertEquals(chassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE), newChassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE));
                String chassisSlots = newChassisInfoMap.get(FlowgateConstant.CHASSISSLOTS);
                List<FlowgateChassisSlot> flowgateSlots = mapper.readValue(chassisSlots, new TypeReference<List<FlowgateChassisSlot>>() {
                });
                TestCase.assertEquals(slot1.getMountingSide(), flowgateSlots.get(0).getMountingSide());
                TestCase.assertEquals(slot1.getMountedAssetNumber(), flowgateSlots.get(0).getMountedAssetNumber());
                TestCase.assertEquals(slot1.getColumnPosition(), flowgateSlots.get(0).getColumnPosition());
                TestCase.assertEquals(slot1.getRowPosition(), flowgateSlots.get(0).getRowPosition());
                TestCase.assertEquals(slot1.getSlotName(), flowgateSlots.get(0).getSlotName());
            } catch (Exception e) {
                TestCase.fail(e.getMessage());
            }
        } else if (assetTosave.getAssetNumber() == 127) {
            TestCase.assertEquals(asset.getTag(), assetTosave.getTag());
        } else {
            TestCase.fail("Invalid assetNumber");
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) FlowgateChassisSlot(com.vmware.flowgate.common.model.FlowgateChassisSlot) Tenant(com.vmware.flowgate.common.model.Tenant) 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) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Map(java.util.Map) HashMap(java.util.HashMap) ChassisMountedAssetMap(com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 8 with FlowgateChassisSlot

use of com.vmware.flowgate.common.model.FlowgateChassisSlot in project flowgate by vmware.

the class SycnRealTimeDataJobTest method testGenerateMountedAssetNumberAndChassisAssetIdMap.

@Test
public void testGenerateMountedAssetNumberAndChassisAssetIdMap() {
    List<Asset> assets = new ArrayList<Asset>();
    Asset chassisAsset = createAsset();
    chassisAsset.setAssetNumber(127);
    chassisAsset.setTag("oldtag1");
    chassisAsset.setId("asdoiqawe129012fdsfpa");
    HashMap<String, String> justficationMap = new HashMap<String, String>();
    List<FlowgateChassisSlot> slots = new ArrayList<FlowgateChassisSlot>();
    FlowgateChassisSlot slot = createFlowgateChassisSlot();
    slot.setMountingSide("Back");
    slot.setMountedAssetNumber(5523);
    slots.add(slot);
    Map<String, String> chassisInfoMap = new HashMap<String, String>();
    chassisInfoMap.put(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE, "frontToBack");
    try {
        ObjectMapper mapper = new ObjectMapper();
        String slotsString = mapper.writeValueAsString(slots);
        chassisInfoMap.put(FlowgateConstant.CHASSISSLOTS, slotsString);
        String oldChassisInfo = mapper.writeValueAsString(chassisInfoMap);
        justficationMap.put(FlowgateConstant.CHASSIS, oldChassisInfo);
        chassisAsset.setJustificationfields(justficationMap);
    } catch (JsonProcessingException e) {
        TestCase.fail(e.getMessage());
    }
    assets.add(chassisAsset);
    HashMap<Long, String> map = nlyteDataService.generateMountedAssetNumberAndChassisAssetIdMap(assets);
    TestCase.assertEquals(true, map.containsKey(slot.getMountedAssetNumber().longValue()));
    TestCase.assertEquals(chassisAsset.getId(), map.get(slot.getMountedAssetNumber().longValue()));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FlowgateChassisSlot(com.vmware.flowgate.common.model.FlowgateChassisSlot) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 9 with FlowgateChassisSlot

use of com.vmware.flowgate.common.model.FlowgateChassisSlot in project flowgate by vmware.

the class SycnRealTimeDataJobTest method testChassisSlotsIsChanged.

@Test
public void testChassisSlotsIsChanged() {
    List<FlowgateChassisSlot> oldFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
    FlowgateChassisSlot slot = createFlowgateChassisSlot();
    oldFlowgateChassisSlots.add(slot);
    List<FlowgateChassisSlot> newFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
    FlowgateChassisSlot slot1 = createFlowgateChassisSlot();
    newFlowgateChassisSlots.add(slot1);
    HandleAssetUtil util = new HandleAssetUtil();
    TestCase.assertEquals(false, util.chassisSlotsIsChanged(oldFlowgateChassisSlots, newFlowgateChassisSlots));
}
Also used : FlowgateChassisSlot(com.vmware.flowgate.common.model.FlowgateChassisSlot) HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) ArrayList(java.util.ArrayList) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 10 with FlowgateChassisSlot

use of com.vmware.flowgate.common.model.FlowgateChassisSlot 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)

Aggregations

FlowgateChassisSlot (com.vmware.flowgate.common.model.FlowgateChassisSlot)18 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)13 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 HandleAssetUtil (com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil)12 HashMap (java.util.HashMap)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)9 Asset (com.vmware.flowgate.common.model.Asset)9 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)9 ChassisMountedAssetMap (com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 Map (java.util.Map)7 List (java.util.List)6 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)6 Tenant (com.vmware.flowgate.common.model.Tenant)4 ChassisSlot (com.vmware.flowgate.nlyteworker.model.ChassisSlot)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 WormholeException (com.vmware.flowgate.common.exception.WormholeException)1 Parent (com.vmware.flowgate.common.model.Parent)1 NlyteWorkerException (com.vmware.flowgate.nlyteworker.exception.NlyteWorkerException)1