Search in sources :

Example 86 with Asset

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

the class NlyteDataService method SyncAlldata.

private void SyncAlldata(FacilitySoftwareConfig nlyte) {
    NlyteAPIClient nlyteAPIclient = createClient(nlyte);
    restClient.setServiceKey(serviceKeyConfig.getServiceKey());
    HandleAssetUtil assetUtil = new HandleAssetUtil();
    List<NlyteAsset> nlyteAssets = null;
    try {
        nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.Cabinet);
    } catch (HttpClientErrorException e) {
        logger.error("Failed to query data from Nlyte", e);
        IntegrationStatus integrationStatus = nlyte.getIntegrationStatus();
        if (integrationStatus == null) {
            integrationStatus = new IntegrationStatus();
        }
        integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
        integrationStatus.setDetail(e.getMessage());
        integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
        updateIntegrationStatus(nlyte);
        return;
    } catch (ResourceAccessException e1) {
        if (e1.getCause().getCause() instanceof ConnectException) {
            checkAndUpdateIntegrationStatus(nlyte, e1.getMessage());
            return;
        }
    }
    HashMap<Long, String> chassisMountedAssetNumberAndChassisIdMap = null;
    HashMap<Integer, LocationGroup> locationMap = assetUtil.initLocationGroupMap(nlyteAPIclient);
    HashMap<Integer, Manufacturer> manufacturerMap = assetUtil.initManufacturersMap(nlyteAPIclient);
    HashMap<Integer, Material> cabinetMaterialMap = new HashMap<Integer, Material>();
    List<Material> cabinetMaterials = nlyteAPIclient.getMaterials(true, HandleAssetUtil.cabinetMaterials);
    for (Material material : cabinetMaterials) {
        material.setMaterialType(AssetCategory.Cabinet);
        cabinetMaterialMap.put(material.getMaterialID(), material);
    }
    List<Asset> cabinetsNeedToSaveOrUpdate = generateAssets(nlyte.getId(), nlyteAssets, locationMap, manufacturerMap, cabinetMaterialMap, AssetCategory.Cabinet, chassisMountedAssetNumberAndChassisIdMap);
    if (cabinetsNeedToSaveOrUpdate.isEmpty()) {
        logger.info("No cabinet asset need to save");
    } else {
        restClient.saveAssets(cabinetsNeedToSaveOrUpdate);
        logger.info("Finish sync the cabinets data for: " + nlyte.getName() + ", size: " + cabinetsNeedToSaveOrUpdate.size());
    }
    // init cabinetIdAndNameMap
    HashMap<Integer, String> cabinetIdAndNameMap = getCabinetIdAndNameMap(nlyteAssets);
    nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.Chassis);
    nlyteAssets = supplementCabinetName(cabinetIdAndNameMap, nlyteAssets);
    List<Material> chassisMaterials = nlyteAPIclient.getMaterials(true, HandleAssetUtil.chassisMaterials);
    HashMap<Integer, Material> chassisMaterialMap = new HashMap<Integer, Material>();
    for (Material material : chassisMaterials) {
        material.setMaterialType(AssetCategory.Chassis);
        chassisMaterialMap.put(material.getMaterialID(), material);
    }
    List<Asset> chassisNeedToSaveOrUpdate = generateAssets(nlyte.getId(), nlyteAssets, locationMap, manufacturerMap, chassisMaterialMap, AssetCategory.Chassis, chassisMountedAssetNumberAndChassisIdMap);
    if (chassisNeedToSaveOrUpdate.isEmpty()) {
        logger.info("No chassis asset need to save");
    } else {
        restClient.saveAssets(chassisNeedToSaveOrUpdate);
        logger.info("Finish sync the chassis data for: " + nlyte.getName() + ", size: " + chassisNeedToSaveOrUpdate.size());
    }
    List<Asset> chassisFromFlowgate = restClient.getAllAssetsBySourceAndType(nlyte.getId(), AssetCategory.Chassis);
    chassisMountedAssetNumberAndChassisIdMap = generateMountedAssetNumberAndChassisAssetIdMap(chassisFromFlowgate);
    nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.Server);
    nlyteAssets = supplementCabinetName(cabinetIdAndNameMap, nlyteAssets);
    HashMap<Integer, Material> materialMap = assetUtil.initServerMaterialsMap(nlyteAPIclient);
    List<Asset> serversNeedToSaveOrUpdate = generateAssets(nlyte.getId(), nlyteAssets, locationMap, manufacturerMap, materialMap, AssetCategory.Server, chassisMountedAssetNumberAndChassisIdMap);
    if (serversNeedToSaveOrUpdate.isEmpty()) {
        logger.info("No server asset need to save");
    } else {
        restClient.saveAssets(serversNeedToSaveOrUpdate);
        logger.info("Finish sync the servers data for: " + nlyte.getName() + ", size: " + serversNeedToSaveOrUpdate.size());
    }
    HashMap<Integer, Material> pduMaterialMap = new HashMap<Integer, Material>();
    nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.PDU);
    nlyteAssets = supplementCabinetName(cabinetIdAndNameMap, nlyteAssets);
    List<Material> powerStripMaterials = nlyteAPIclient.getMaterials(true, HandleAssetUtil.powerStripMaterial);
    for (Material material : powerStripMaterials) {
        material.setMaterialType(AssetCategory.PDU);
        pduMaterialMap.put(material.getMaterialID(), material);
    }
    List<Asset> pDUsNeedToSaveOrUpdate = generateAssets(nlyte.getId(), nlyteAssets, locationMap, manufacturerMap, pduMaterialMap, AssetCategory.PDU, chassisMountedAssetNumberAndChassisIdMap);
    if (pDUsNeedToSaveOrUpdate.isEmpty()) {
        logger.info("No pdu asset need to save");
    } else {
        savePduAssetAndUpdatePduUsageFormula(pDUsNeedToSaveOrUpdate);
        logger.info("Finish sync the pdus data for: " + nlyte.getName() + ", size: " + pDUsNeedToSaveOrUpdate.size());
    }
    HashMap<Integer, Material> networkMaterialMap = new HashMap<Integer, Material>();
    nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.Networks);
    nlyteAssets = supplementCabinetName(cabinetIdAndNameMap, nlyteAssets);
    List<Material> networkMaterials = nlyteAPIclient.getMaterials(true, HandleAssetUtil.networkMaterials);
    for (Material material : networkMaterials) {
        material.setMaterialType(AssetCategory.Networks);
        networkMaterialMap.put(material.getMaterialID(), material);
    }
    List<Asset> networkersNeedToSaveOrUpdate = generateAssets(nlyte.getId(), nlyteAssets, locationMap, manufacturerMap, networkMaterialMap, AssetCategory.Networks, chassisMountedAssetNumberAndChassisIdMap);
    if (networkersNeedToSaveOrUpdate.isEmpty()) {
        logger.info("No network asset need to save");
    } else {
        restClient.saveAssets(networkersNeedToSaveOrUpdate);
        logger.info("Finish sync the networks data for: " + nlyte.getName() + ", size: " + networkersNeedToSaveOrUpdate.size());
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HashMap(java.util.HashMap) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Material(com.vmware.flowgate.nlyteworker.model.Material) ResourceAccessException(org.springframework.web.client.ResourceAccessException) NlyteAPIClient(com.vmware.flowgate.nlyteworker.restclient.NlyteAPIClient) HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) Manufacturer(com.vmware.flowgate.nlyteworker.model.Manufacturer) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) LocationGroup(com.vmware.flowgate.nlyteworker.model.LocationGroup) ConnectException(java.net.ConnectException)

Example 87 with Asset

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

the class NlyteDataService method saveAssetForMappedData.

public void saveAssetForMappedData(String nlyteSource, List<NlyteAsset> nlyteAssets, HashMap<Integer, LocationGroup> locationMap, HashMap<Integer, Material> materialMap, HashMap<Integer, Manufacturer> manufacturerMap, AssetCategory category) {
    HandleAssetUtil assetUtil = new HandleAssetUtil();
    restClient.setServiceKey(serviceKeyConfig.getServiceKey());
    List<Asset> allMappedAssets = Arrays.asList(restClient.getMappedAsset(category).getBody());
    if (allMappedAssets.isEmpty()) {
        return;
    }
    assetUtil.filterAssetBySourceAndCategory(allMappedAssets, nlyteSource, category);
    List<Asset> assetsFromNlyte = assetUtil.getAssetsFromNlyte(nlyteSource, nlyteAssets, locationMap, materialMap, manufacturerMap, null);
    Map<Long, Asset> assetsFromNlyteMap = assetUtil.generateAssetsMap(assetsFromNlyte);
    List<Asset> updateAssets = new ArrayList<Asset>();
    for (Asset asset : allMappedAssets) {
        if (assetsFromNlyteMap.containsKey(asset.getAssetNumber())) {
            Asset assetFromNlyte = assetsFromNlyteMap.get(asset.getAssetNumber());
            asset.setTag(assetFromNlyte.getTag());
            asset.setSerialnumber(assetFromNlyte.getSerialnumber());
            asset.setAssetName(assetFromNlyte.getAssetName());
            asset.setRegion(assetFromNlyte.getRegion());
            asset.setCountry(assetFromNlyte.getCountry());
            asset.setCity(assetFromNlyte.getCity());
            asset.setBuilding(assetFromNlyte.getBuilding());
            asset.setFloor(assetFromNlyte.getFloor());
            asset.setRoom(assetFromNlyte.getRoom());
            asset.setModel(assetFromNlyte.getModel());
            asset.setManufacturer(assetFromNlyte.getManufacturer());
            asset.setCategory(assetFromNlyte.getCategory());
            asset.setSubCategory(assetFromNlyte.getSubCategory());
            asset.setLastupdate(System.currentTimeMillis());
            asset.setMountingSide(assetFromNlyte.getMountingSide());
            asset.setTenant(assetFromNlyte.getTenant());
            updateAssets.add(asset);
        }
    }
    if (!updateAssets.isEmpty()) {
        restClient.saveAssets(updateAssets);
    }
}
Also used : HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) ArrayList(java.util.ArrayList) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset)

Example 88 with Asset

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

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

the class CleanDataJobTest method removePduFromServerTest.

@Test
public void removePduFromServerTest() {
    List<Asset> servers = new ArrayList<Asset>();
    Asset server = new Asset();
    List<String> pdus = new ArrayList<String>();
    pdus.add("0364");
    pdus.add("po09");
    server.setPdus(pdus);
    HashMap<String, String> justifications = new HashMap<String, String>();
    justifications.put(FlowgateConstant.PDU_PORT_FOR_SERVER, "pci-2:hba:1_FIELDSPLIT_cloud-fc02-sha1_FIELDSPLIT_05_FIELDSPLIT_0364,onboard:1gb-nic:4_FIELDSPLIT_cloud-sw02-sha1_FIELDSPLIT_08_FIELDSPLIT_3fc319e50d21476684d841aa0842bd52");
    server.setJustificationfields(justifications);
    Map<String, String> formulars = new HashMap<>();
    Map<String, Map<String, String>> pduMap = new HashMap<String, Map<String, String>>();
    Map<String, String> metricNameAndId = new HashMap<String, String>();
    metricNameAndId.put(MetricName.PDU_CURRENT_LOAD, "5x4ff46982db22e1b040e0f2");
    metricNameAndId.put(MetricName.PDU_TOTAL_POWER, "5x4ff46982db22e1b040e0f2");
    metricNameAndId.put(MetricName.PDU_VOLTAGE, "5x4ff46982db22e1b040e0f2");
    pduMap.put("5x4ff46982db22e1b040e0f2", metricNameAndId);
    try {
        formulars.put(FlowgateConstant.PDU, mapper.writeValueAsString(pduMap));
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
    server.setMetricsformulars(formulars);
    servers.add(server);
    Asset server2 = new Asset();
    List<String> pdusfor2 = new ArrayList<String>();
    pdusfor2.add("oi23");
    pdusfor2.add("sd23");
    server2.setPdus(pdusfor2);
    servers.add(server2);
    servers = nlyteDataService.removePduFromServer(servers, "0364");
    TestCase.assertEquals(1, servers.size());
    TestCase.assertEquals(1, servers.get(0).getPdus().size());
    TestCase.assertEquals(1, servers.get(0).getMetricsformulars().size());
    Map<String, Map<String, String>> pduMetricsformulas = new HashMap<>();
    try {
        pduMetricsformulas = mapper.readValue(servers.get(0).getMetricsformulars().get(FlowgateConstant.PDU), new TypeReference<Map<String, Map<String, String>>>() {
        });
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
    TestCase.assertEquals("5x4ff46982db22e1b040e0f2", pduMetricsformulas.entrySet().iterator().next().getKey());
    TestCase.assertEquals("onboard:1gb-nic:4_FIELDSPLIT_cloud-sw02-sha1_FIELDSPLIT_08_FIELDSPLIT_3fc319e50d21476684d841aa0842bd52", servers.get(0).getJustificationfields().get(FlowgateConstant.PDU_PORT_FOR_SERVER));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Asset(com.vmware.flowgate.common.model.Asset) TypeReference(com.fasterxml.jackson.core.type.TypeReference) HashMap(java.util.HashMap) Map(java.util.Map) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 90 with Asset

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

Asset (com.vmware.flowgate.common.model.Asset)173 Test (org.junit.Test)96 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)90 HashMap (java.util.HashMap)86 ArrayList (java.util.ArrayList)82 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)36 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)35 Map (java.util.Map)34 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)31 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)23 IOException (java.io.IOException)23 ServerMapping (com.vmware.flowgate.common.model.ServerMapping)22 MetricData (com.vmware.flowgate.common.model.MetricData)16 HandleAssetUtil (com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil)16 HashSet (java.util.HashSet)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)13 List (java.util.List)12 MvcResult (org.springframework.test.web.servlet.MvcResult)12 TypeReference (com.fasterxml.jackson.core.type.TypeReference)10