Search in sources :

Example 6 with NlyteAsset

use of com.vmware.flowgate.nlyteworker.model.NlyteAsset 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 7 with NlyteAsset

use of com.vmware.flowgate.nlyteworker.model.NlyteAsset 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 8 with NlyteAsset

use of com.vmware.flowgate.nlyteworker.model.NlyteAsset 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 9 with NlyteAsset

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

the class SycnRealTimeDataJobTest method testGetAssetsFromNlytePdu.

@Test
public void testGetAssetsFromNlytePdu() {
    String nlyteSource = "3cf0f5daff8e448da449ac88d5aa9428";
    List<NlyteAsset> nlyteAssets = getNlyteAsset();
    HashMap<Integer, LocationGroup> locationMap = getLocationMap();
    HashMap<Integer, Material> materialMap = getMaterialMap();
    Material material = new Material();
    material.setMaterialID(6251);
    material.setManufacturerID(14);
    material.setMaterialName("Cisco 1721 Modular Access Router");
    material.setMaterialType(AssetCategory.Server);
    materialMap.put(6251, material);
    HashMap<Integer, Manufacturer> manufacturerMap = getManufacturerMap();
    Manufacturer manufacturer = new Manufacturer();
    manufacturer.setManufacturerID(14);
    manufacturer.setDetail("Cisco");
    manufacturerMap.put(14, manufacturer);
    HashMap<Long, String> chassisMountedAssetNumberAndChassisIdMap = null;
    HandleAssetUtil util = new HandleAssetUtil();
    List<Asset> assets = util.getAssetsFromNlyte(nlyteSource, nlyteAssets, locationMap, materialMap, manufacturerMap, chassisMountedAssetNumberAndChassisIdMap);
}
Also used : NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Material(com.vmware.flowgate.nlyteworker.model.Material) 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) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 10 with NlyteAsset

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

the class SycnRealTimeDataJobTest method getNlyteAsset.

List<NlyteAsset> getNlyteAsset() {
    List<NlyteAsset> assets = new ArrayList<NlyteAsset>();
    NlyteAsset nlyteAsset = new NlyteAsset();
    nlyteAsset.setAssetName("sin2-blrqeops-esxstress024");
    nlyteAsset.setAssetNumber(197);
    nlyteAsset.setSerialNumber("FCH1709J3E6");
    nlyteAsset.setMaterialID(6251);
    nlyteAsset.setCabinetAssetID(562);
    nlyteAsset.setLocationGroupID(8);
    nlyteAsset.setTemplateRelated(false);
    assets.add(nlyteAsset);
    return assets;
}
Also used : NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) ArrayList(java.util.ArrayList)

Aggregations

NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)17 Asset (com.vmware.flowgate.common.model.Asset)13 HandleAssetUtil (com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 Test (org.junit.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 LocationGroup (com.vmware.flowgate.nlyteworker.model.LocationGroup)6 Manufacturer (com.vmware.flowgate.nlyteworker.model.Manufacturer)6 Material (com.vmware.flowgate.nlyteworker.model.Material)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 FlowgateChassisSlot (com.vmware.flowgate.common.model.FlowgateChassisSlot)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ChassisMountedAssetMap (com.vmware.flowgate.nlyteworker.model.ChassisMountedAssetMap)3 ChassisSlot (com.vmware.flowgate.nlyteworker.model.ChassisSlot)3 NlyteAPIClient (com.vmware.flowgate.nlyteworker.restclient.NlyteAPIClient)3 List (java.util.List)3 Map (java.util.Map)3 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)3 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)3