Search in sources :

Example 1 with Parent

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

the class HandleAssetUtil method getAssetsFromNlyte.

/**
 * @param nlyteAssets
 * @return
 */
public List<Asset> getAssetsFromNlyte(String nlyteSource, List<NlyteAsset> nlyteAssets, HashMap<Integer, LocationGroup> locationMap, HashMap<Integer, Material> materialMap, HashMap<Integer, Manufacturer> manufacturerMap, HashMap<Long, String> chassisMountedAssetNumberAndChassisIdMap) {
    List<Asset> assetsFromNlyte = new ArrayList<Asset>();
    Asset asset;
    for (NlyteAsset nlyteAsset : nlyteAssets) {
        asset = new Asset();
        asset.setAssetNumber(nlyteAsset.getAssetNumber());
        asset.setCabinetAssetNumber(String.valueOf(nlyteAsset.getCabinetAssetID()));
        asset.setCabinetName(nlyteAsset.getCabinetName());
        asset.setTag(nlyteAsset.getTag());
        asset.setSerialnumber(nlyteAsset.getSerialNumber());
        asset.setAssetName(nlyteAsset.getAssetName());
        asset.setRow(nlyteAsset.getGridReferenceRow());
        asset.setCol(nlyteAsset.getGridReferenceColumn());
        asset = supplementLocation(asset, nlyteAsset.getLocationGroupID(), locationMap);
        asset = supplementMaterial(asset, nlyteAsset.getMaterialID(), manufacturerMap, materialMap);
        // we need to refactor the code
        if (asset.getCategory() == null) {
            continue;
        }
        if (asset.getCategory() == AssetCategory.Server) {
            if (chassisMountedAssetNumberAndChassisIdMap != null && chassisMountedAssetNumberAndChassisIdMap.containsKey(asset.getAssetNumber())) {
                Parent parent = new Parent();
                parent.setType(AssetCategory.Chassis.name());
                parent.setParentId(chassisMountedAssetNumberAndChassisIdMap.get(asset.getAssetNumber()));
                asset.setParent(parent);
            }
            // set the tenant information.
            List<CustomField> fields = nlyteAsset.getCustomFields();
            if (fields != null) {
                Tenant tenant = new Tenant();
                for (CustomField cf : fields) {
                    if (cf.getDataLabel().equals(CustomField.Owner)) {
                        String dataValue = cf.getDataValueString();
                        if (!StringUtils.isEmpty(dataValue)) {
                            tenant.setOwner(dataValue);
                            tenant.setTenant(dataValue);
                        }
                    } else if (cf.getDataLabel().equals(CustomField.Tenant_EndUser)) {
                        String dataValue = cf.getDataValueString();
                        if (!StringUtils.isEmpty(dataValue)) {
                            tenant.setTenant(dataValue);
                        }
                    } else if (cf.getDataLabel().equals(CustomField.HaaS_RequestedBy)) {
                        String dataValue = cf.getDataValueString();
                        if (!StringUtils.isEmpty(dataValue)) {
                            tenant.setTenant(dataValue);
                        }
                    } else if (cf.getDataLabel().equals(CustomField.Tenant_Manager)) {
                        String dataValue = cf.getDataValueString();
                        if (!StringUtils.isEmpty(dataValue)) {
                            tenant.setTenantManager(dataValue);
                        }
                    }
                }
                asset.setTenant(tenant);
            }
        }
        if (asset.getCategory().equals(AssetCategory.Cabinet)) {
            String contiguousUSpace = nlyteAsset.getContiguousUSpace();
            if (contiguousUSpace != null) {
                int freeSize = 0;
                String[] contiguousUSpaces = contiguousUSpace.split(FlowgateConstant.SPILIT_FLAG);
                for (String uSpace : contiguousUSpaces) {
                    freeSize += Integer.parseInt(uSpace);
                }
                asset.setFreeCapacity(freeSize);
            }
            List<CabinetU> cabinetus = nlyteAsset.getCabinetUs();
            if (cabinetus != null && !cabinetus.isEmpty()) {
                List<com.vmware.flowgate.common.model.CabinetU> flowgateCabinetUs = new ArrayList<com.vmware.flowgate.common.model.CabinetU>();
                for (CabinetU cabinetu : cabinetus) {
                    com.vmware.flowgate.common.model.CabinetU flowgateCabinetU = new com.vmware.flowgate.common.model.CabinetU();
                    flowgateCabinetU.setAssetsOnUnit(cabinetu.getAssetsOnU());
                    flowgateCabinetU.setCabinetUNumber(cabinetu.getCabinetUNumber());
                    if (CabinetU_State_Full.equals(cabinetu.getCabinetUState())) {
                        flowgateCabinetU.setUsed(true);
                    } else if (CabinetU_State_Free.equals(cabinetu.getCabinetUState())) {
                        flowgateCabinetU.setUsed(false);
                    }
                    flowgateCabinetUs.add(flowgateCabinetU);
                }
                try {
                    String cabinetUsInfo = mapper.writeValueAsString(flowgateCabinetUs);
                    HashMap<String, String> justficationfields = new HashMap<String, String>();
                    justficationfields.put(FlowgateConstant.CABINETUNITS, cabinetUsInfo);
                    asset.setJustificationfields(justficationfields);
                } catch (JsonProcessingException e) {
                    logger.error("Failed to get info of cabinetUs.");
                }
            }
        }
        if (asset.getCategory().equals(AssetCategory.Chassis)) {
            handleChassisSolts(asset, nlyteAsset);
        }
        if (asset.getCategory().equals(AssetCategory.Networks)) {
            if (chassisMountedAssetNumberAndChassisIdMap != null && chassisMountedAssetNumberAndChassisIdMap.containsKey(asset.getAssetNumber())) {
                Parent parent = new Parent();
                parent.setType(AssetCategory.Chassis.name());
                parent.setParentId(chassisMountedAssetNumberAndChassisIdMap.get(asset.getAssetNumber()));
                asset.setParent(parent);
            }
        }
        asset.setAssetSource(nlyteSource);
        AssetStatus status = new AssetStatus();
        status.setNetworkMapping(NetworkMapping.UNMAPPED);
        status.setPduMapping(PduMapping.UNMAPPED);
        asset.setStatus(status);
        UMounting uMounting = nlyteAsset.getuMounting();
        if (uMounting != null) {
            asset.setCabinetUnitPosition(uMounting.getCabinetUNumber());
            switch(MountingSide.valueOf(uMounting.getMountingSide())) {
                case Front:
                    asset.setMountingSide(MountingSide.Front);
                    break;
                case Back:
                    asset.setMountingSide(MountingSide.Back);
                    break;
                case Unmounted:
                    asset.setMountingSide(MountingSide.Unmounted);
                    break;
                default:
                    break;
            }
        }
        asset.setCreated(System.currentTimeMillis());
        assetsFromNlyte.add(asset);
    }
    return assetsFromNlyte;
}
Also used : Parent(com.vmware.flowgate.common.model.Parent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AssetStatus(com.vmware.flowgate.common.AssetStatus) Tenant(com.vmware.flowgate.common.model.Tenant) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) UMounting(com.vmware.flowgate.nlyteworker.model.UMounting) CustomField(com.vmware.flowgate.nlyteworker.model.CustomField) CabinetU(com.vmware.flowgate.nlyteworker.model.CabinetU)

Example 2 with Parent

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

the class SycnRealTimeDataJobTest method testHandleAssets3.

@Test
public void testHandleAssets3() {
    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.Server);
    Parent parent = new Parent();
    parent.setParentId("ouqwenkja72hoas9034a");
    parent.setType("Chassis");
    asset2.setParent(parent);
    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");
    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();
            TestCase.assertEquals("ouqwenkja72hoas9034a", assetTosave.getParent().getParentId());
        } else if (assetTosave.getAssetNumber() == 127) {
            TestCase.assertEquals(asset.getTag(), assetTosave.getTag());
        } else {
            TestCase.fail("Invalid assetNumber");
        }
    }
}
Also used : Tenant(com.vmware.flowgate.common.model.Tenant) HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) HashMap(java.util.HashMap) Parent(com.vmware.flowgate.common.model.Parent) ArrayList(java.util.ArrayList) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with Parent

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

the class SyncPduAssetJobTest method testUpdatePduMetricformular2.

@Test
public void testUpdatePduMetricformular2() throws JsonProcessingException {
    List<Asset> assets = new ArrayList<>();
    Asset asset = createAsset();
    asset.setCabinetUnitPosition(1);
    asset.setId("po09imkhdplbvf540fwusy67n");
    asset.setCategory(AssetCategory.Sensors);
    asset.setSubCategory(AssetSubCategory.Humidity);
    Map<String, String> sensorInfoMap = new HashMap<String, String>();
    sensorInfoMap.put(FlowgateConstant.POSITION, "INLET");
    ObjectMapper mapper = new ObjectMapper();
    HashMap<String, String> justfication = new HashMap<String, String>();
    try {
        justfication.put(FlowgateConstant.SENSOR, mapper.writeValueAsString(sensorInfoMap));
    } catch (JsonProcessingException e1) {
        TestCase.fail();
    }
    asset.setJustificationfields(justfication);
    Parent parent = new Parent();
    parent.setParentId("125");
    parent.setType("PDU");
    asset.setParent(parent);
    assets.add(asset);
    Map<String, Asset> pduIdAndAssetMap = new HashMap<String, Asset>();
    Asset pduAsset = createAsset();
    pduIdAndAssetMap.put("125", pduAsset);
    Set<Asset> pduNeedTosave = powerIQService.updatePduMetricformular(assets, pduIdAndAssetMap);
    TestCase.assertEquals(1, pduNeedTosave.size());
    Asset pdu = pduNeedTosave.iterator().next();
    TestCase.assertEquals(pduAsset.getAssetName(), pdu.getAssetName());
    try {
        Map<String, String> formulars = pdu.getMetricsformulars();
        Map<String, Map<String, String>> sensorFormulars = mapper.readValue(formulars.get(FlowgateConstant.SENSOR), new TypeReference<Map<String, Map<String, String>>>() {
        });
        Map<String, String> humidityLocationAndIdMap = sensorFormulars.get(MetricName.PDU_HUMIDITY);
        TestCase.assertEquals("po09imkhdplbvf540fwusy67n", humidityLocationAndIdMap.get(FlowgateConstant.RACK_UNIT_PREFIX + "1" + FlowgateConstant.SEPARATOR + sensorInfoMap.get(FlowgateConstant.POSITION)));
    } catch (Exception e) {
        TestCase.fail();
    }
}
Also used : HashMap(java.util.HashMap) Parent(com.vmware.flowgate.common.model.Parent) ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Asset(com.vmware.flowgate.common.model.Asset) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Parent

use of com.vmware.flowgate.common.model.Parent 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 5 with Parent

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

the class SycnRealTimeDataJobTest method testHandleAssets4.

@Test
public void testHandleAssets4() {
    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.Networks);
    Parent parent = new Parent();
    parent.setParentId("ouqwenkja72hoas9034a");
    parent.setType("Chassis");
    asset2.setParent(parent);
    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");
    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();
            TestCase.assertEquals("ouqwenkja72hoas9034a", assetTosave.getParent().getParentId());
        } else if (assetTosave.getAssetNumber() == 127) {
            TestCase.assertEquals(asset.getTag(), assetTosave.getTag());
        } else {
            TestCase.fail("Invalid assetNumber");
        }
    }
}
Also used : Tenant(com.vmware.flowgate.common.model.Tenant) HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) HashMap(java.util.HashMap) Parent(com.vmware.flowgate.common.model.Parent) ArrayList(java.util.ArrayList) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

Asset (com.vmware.flowgate.common.model.Asset)7 Parent (com.vmware.flowgate.common.model.Parent)7 ArrayList (java.util.ArrayList)6 Tenant (com.vmware.flowgate.common.model.Tenant)5 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)4 HandleAssetUtil (com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil)2 Map (java.util.Map)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AssetStatus (com.vmware.flowgate.common.AssetStatus)1 AssetSubCategory (com.vmware.flowgate.common.AssetSubCategory)1 MountingSide (com.vmware.flowgate.common.MountingSide)1 AssetAddress (com.vmware.flowgate.common.model.AssetAddress)1 AssetRealtimeDataSpec (com.vmware.flowgate.common.model.AssetRealtimeDataSpec)1 FlowgateChassisSlot (com.vmware.flowgate.common.model.FlowgateChassisSlot)1 CabinetU (com.vmware.flowgate.nlyteworker.model.CabinetU)1