Search in sources :

Example 11 with FlowgateChassisSlot

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

the class HandleAssetUtil method handleAssets.

public List<Asset> handleAssets(List<Asset> toUpdateAssets, Map<Long, Asset> exsitingaAssetMap) {
    List<Asset> resultAsset = new ArrayList<Asset>();
    List<Asset> updateAsset = new ArrayList<Asset>();
    Asset exsitingAsset = null;
    if (exsitingaAssetMap == null) {
        return toUpdateAssets;
    }
    for (Asset asset : toUpdateAssets) {
        boolean isUpdated = false;
        if (exsitingaAssetMap.containsKey(asset.getAssetNumber())) {
            exsitingAsset = exsitingaAssetMap.get(asset.getAssetNumber());
            if (valueIsChanged(exsitingAsset.getCabinetName(), asset.getCabinetName())) {
                exsitingAsset.setCabinetName(asset.getCabinetName());
                isUpdated = true;
            }
            if (valueIsChanged(exsitingAsset.getTag(), asset.getTag())) {
                exsitingAsset.setTag(asset.getTag());
                isUpdated = true;
            }
            if (valueIsChanged(exsitingAsset.getCapacity(), asset.getCapacity())) {
                exsitingAsset.setCapacity(asset.getCapacity());
                isUpdated = true;
            }
            if (valueIsChanged(exsitingAsset.getFreeCapacity(), asset.getFreeCapacity())) {
                exsitingAsset.setFreeCapacity(asset.getFreeCapacity());
            }
            exsitingAsset.setSerialnumber(asset.getSerialnumber());
            exsitingAsset.setAssetName(asset.getAssetName());
            exsitingAsset.setRegion(asset.getRegion());
            exsitingAsset.setCountry(asset.getCountry());
            exsitingAsset.setCity(asset.getCity());
            exsitingAsset.setBuilding(asset.getBuilding());
            exsitingAsset.setFloor(asset.getFloor());
            if (valueIsChanged(exsitingAsset.getRoom(), asset.getRoom())) {
                exsitingAsset.setRoom(asset.getRoom());
                isUpdated = true;
            }
            exsitingAsset.setModel(asset.getModel());
            exsitingAsset.setManufacturer(asset.getManufacturer());
            exsitingAsset.setCategory(asset.getCategory());
            exsitingAsset.setSubCategory(asset.getSubCategory());
            exsitingAsset.setLastupdate(System.currentTimeMillis());
            if (valueIsChanged(exsitingAsset.getRow(), asset.getRow())) {
                exsitingAsset.setRow(asset.getRow());
                isUpdated = true;
            }
            if (valueIsChanged(exsitingAsset.getCol(), asset.getCol())) {
                exsitingAsset.setCol(asset.getCol());
                isUpdated = true;
            }
            if (exsitingAsset.getMountingSide() != asset.getMountingSide()) {
                exsitingAsset.setMountingSide(asset.getMountingSide());
                isUpdated = true;
            }
            String oldOwner = null;
            String newOwner = null;
            String oldTenantValue = null;
            String newTenantValue = null;
            String oldTenantManager = null;
            String newTenantManager = null;
            Tenant oldTenant = exsitingAsset.getTenant();
            Tenant newTenant = asset.getTenant();
            if (oldTenant != null) {
                oldOwner = oldTenant.getOwner();
                oldTenantValue = oldTenant.getTenant();
                oldTenantManager = oldTenant.getTenantManager();
            }
            if (newTenant != null) {
                newOwner = newTenant.getOwner();
                newTenantValue = newTenant.getTenant();
                newTenantManager = newTenant.getTenantManager();
            }
            if (valueIsChanged(oldOwner, newOwner) || valueIsChanged(oldTenantValue, newTenantValue) || valueIsChanged(oldTenantManager, newTenantManager)) {
                exsitingAsset.setTenant(asset.getTenant());
                isUpdated = true;
            }
            if (exsitingAsset.getCategory().equals(AssetCategory.Cabinet)) {
                if (asset.getJustificationfields() != null && asset.getJustificationfields().get(FlowgateConstant.CABINETUNITS) != null) {
                    exsitingAsset.getJustificationfields().put(FlowgateConstant.CABINETUNITS, asset.getJustificationfields().get(FlowgateConstant.CABINETUNITS));
                    isUpdated = true;
                }
            }
            if (exsitingAsset.getCategory().equals(AssetCategory.Chassis)) {
                if (asset.getJustificationfields() != null && asset.getJustificationfields().get(FlowgateConstant.CHASSIS) != null) {
                    HashMap<String, String> newJustficationMap = asset.getJustificationfields();
                    HashMap<String, String> oldJustficationMap = exsitingAsset.getJustificationfields();
                    String newChassisInfo = newJustficationMap.get(FlowgateConstant.CHASSIS);
                    String oldChassisInfo = oldJustficationMap.get(FlowgateConstant.CHASSIS);
                    Map<String, String> newChassisInfoMap = null;
                    Map<String, String> oldChassisInfoMap = null;
                    try {
                        if (newChassisInfo != null) {
                            newChassisInfoMap = mapper.readValue(newChassisInfo, new TypeReference<Map<String, String>>() {
                            });
                        }
                        if (oldChassisInfo != null) {
                            oldChassisInfoMap = mapper.readValue(oldChassisInfo, new TypeReference<Map<String, String>>() {
                            });
                        }
                    } catch (Exception e) {
                        logger.error("Failed to read the data of chassis");
                    }
                    if (oldChassisInfoMap == null) {
                        if (newChassisInfoMap != null) {
                            oldJustficationMap.put(FlowgateConstant.CHASSIS, newChassisInfo);
                            exsitingAsset.setJustificationfields(oldJustficationMap);
                            isUpdated = true;
                        }
                    } else {
                        if (newChassisInfoMap != null) {
                            if (valueIsChanged(oldChassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE), newChassisInfoMap.get(FlowgateConstant.CHASSIS_AIR_FLOW_TYPE))) {
                                oldJustficationMap.put(FlowgateConstant.CHASSIS, newChassisInfo);
                                exsitingAsset.setJustificationfields(oldJustficationMap);
                                isUpdated = true;
                            } else {
                                String newChassisSlots = newChassisInfoMap.get(FlowgateConstant.CHASSISSLOTS);
                                String oldChassisSlots = oldChassisInfoMap.get(FlowgateConstant.CHASSISSLOTS);
                                List<FlowgateChassisSlot> newFlowgateChassisSlots = null;
                                List<FlowgateChassisSlot> oldFlowgateChassisSlots = null;
                                if (newChassisSlots != null) {
                                    if (oldChassisSlots != null) {
                                        try {
                                            newFlowgateChassisSlots = mapper.readValue(newChassisSlots, new TypeReference<List<FlowgateChassisSlot>>() {
                                            });
                                            oldFlowgateChassisSlots = mapper.readValue(oldChassisSlots, new TypeReference<List<FlowgateChassisSlot>>() {
                                            });
                                        } catch (Exception e) {
                                            logger.error("Failed to read the data of chassis");
                                        }
                                        if (chassisSlotsIsChanged(oldFlowgateChassisSlots, newFlowgateChassisSlots)) {
                                            oldJustficationMap.put(FlowgateConstant.CHASSIS, newChassisInfo);
                                            exsitingAsset.setJustificationfields(oldJustficationMap);
                                            isUpdated = true;
                                        }
                                    } else {
                                        oldJustficationMap.put(FlowgateConstant.CHASSIS, newChassisInfo);
                                        exsitingAsset.setJustificationfields(oldJustficationMap);
                                        isUpdated = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (exsitingAsset.getCategory().equals(AssetCategory.Server) || exsitingAsset.getCategory().equals(AssetCategory.Networks)) {
                Parent oldParent = exsitingAsset.getParent();
                String oldParentId = null;
                String oldParentType = null;
                if (oldParent != null) {
                    oldParentId = oldParent.getParentId();
                    oldParentType = oldParent.getType();
                }
                Parent newParent = asset.getParent();
                String newParentId = null;
                String newParentType = null;
                if (newParent != null) {
                    newParentId = newParent.getParentId();
                    newParentType = newParent.getType();
                }
                if (valueIsChanged(oldParentId, newParentId) || valueIsChanged(oldParentType, newParentType)) {
                    exsitingAsset.setParent(newParent);
                    isUpdated = true;
                }
            }
            if (isUpdated) {
                updateAsset.add(exsitingAsset);
            }
        } else {
            asset.setCreated(System.currentTimeMillis());
            resultAsset.add(asset);
        }
    }
    resultAsset.addAll(updateAsset);
    return resultAsset;
}
Also used : Parent(com.vmware.flowgate.common.model.Parent) ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) FlowgateChassisSlot(com.vmware.flowgate.common.model.FlowgateChassisSlot) Tenant(com.vmware.flowgate.common.model.Tenant) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) TypeReference(com.fasterxml.jackson.core.type.TypeReference)

Example 12 with FlowgateChassisSlot

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

the class HandleAssetUtil method chassisSlotsIsChanged.

public boolean chassisSlotsIsChanged(List<FlowgateChassisSlot> oldFlowgateChassisSlots, List<FlowgateChassisSlot> newFlowgateChassisSlots) {
    Map<String, FlowgateChassisSlot> oldSlotsMap = new HashMap<String, FlowgateChassisSlot>();
    if (oldFlowgateChassisSlots != null) {
        for (FlowgateChassisSlot slot : oldFlowgateChassisSlots) {
            oldSlotsMap.put(slot.getMountingSide() + slot.getSlotName(), slot);
        }
    }
    Map<String, FlowgateChassisSlot> newSlotsMap = new HashMap<String, FlowgateChassisSlot>();
    if (newFlowgateChassisSlots != null) {
        for (FlowgateChassisSlot slot : newFlowgateChassisSlots) {
            newSlotsMap.put(slot.getMountingSide() + slot.getSlotName(), slot);
        }
    }
    if (oldSlotsMap.size() != newSlotsMap.size()) {
        return true;
    }
    for (Map.Entry<String, FlowgateChassisSlot> newSlotMap : newSlotsMap.entrySet()) {
        String key = newSlotMap.getKey();
        if (!oldSlotsMap.containsKey(key)) {
            return true;
        } else {
            FlowgateChassisSlot newSlot = newSlotMap.getValue();
            FlowgateChassisSlot oldSlot = oldSlotsMap.get(key);
            if (valueIsChanged(oldSlot.getMountedAssetNumber(), newSlot.getMountedAssetNumber())) {
                return true;
            }
            if (valueIsChanged(oldSlot.getColumnPosition(), newSlot.getColumnPosition())) {
                return true;
            }
            if (valueIsChanged(oldSlot.getRowPosition(), newSlot.getRowPosition())) {
                return true;
            }
        }
    }
    return false;
}
Also used : FlowgateChassisSlot(com.vmware.flowgate.common.model.FlowgateChassisSlot) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ChassisMountedAssetMap(com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap)

Example 13 with FlowgateChassisSlot

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

Example 14 with FlowgateChassisSlot

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

the class SycnRealTimeDataJobTest method testChassisSlotsIsChanged5.

@Test
public void testChassisSlotsIsChanged5() {
    List<FlowgateChassisSlot> oldFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
    FlowgateChassisSlot slot = createFlowgateChassisSlot();
    oldFlowgateChassisSlots.add(slot);
    List<FlowgateChassisSlot> newFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
    FlowgateChassisSlot slot1 = createFlowgateChassisSlot();
    slot1.setColumnPosition(2);
    newFlowgateChassisSlots.add(slot1);
    HandleAssetUtil util = new HandleAssetUtil();
    TestCase.assertEquals(true, 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 15 with FlowgateChassisSlot

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

the class SycnRealTimeDataJobTest method testChassisSlotsIsChanged6.

@Test
public void testChassisSlotsIsChanged6() {
    List<FlowgateChassisSlot> oldFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
    FlowgateChassisSlot slot = createFlowgateChassisSlot();
    oldFlowgateChassisSlots.add(slot);
    List<FlowgateChassisSlot> newFlowgateChassisSlots = new ArrayList<FlowgateChassisSlot>();
    FlowgateChassisSlot slot1 = createFlowgateChassisSlot();
    slot1.setRowPosition(2);
    newFlowgateChassisSlots.add(slot1);
    HandleAssetUtil util = new HandleAssetUtil();
    TestCase.assertEquals(true, 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)

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