Search in sources :

Example 16 with NlyteAsset

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

the class NlyteDataService method syncMappedData.

private void syncMappedData(FacilitySoftwareConfig nlyte) {
    NlyteAPIClient nlyteAPIclient = new NlyteAPIClient(nlyte);
    HandleAssetUtil assetUtil = new HandleAssetUtil();
    List<NlyteAsset> nlyteAssets = null;
    try {
        nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.Server);
    } 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<Integer, LocationGroup> locationMap = assetUtil.initLocationGroupMap(nlyteAPIclient);
    HashMap<Integer, Material> materialMap = assetUtil.initServerMaterialsMap(nlyteAPIclient);
    HashMap<Integer, Manufacturer> manufacturerMap = assetUtil.initManufacturersMap(nlyteAPIclient);
    saveAssetForMappedData(nlyte.getId(), nlyteAssets, locationMap, materialMap, manufacturerMap, AssetCategory.Server);
    HashMap<Integer, Material> pduMaterialMap = new HashMap<Integer, Material>();
    nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.PDU);
    List<Material> powerStripMaterials = nlyteAPIclient.getMaterials(true, HandleAssetUtil.powerStripMaterial);
    for (Material material : powerStripMaterials) {
        material.setMaterialType(AssetCategory.PDU);
        pduMaterialMap.put(material.getMaterialID(), material);
    }
    saveAssetForMappedData(nlyte.getId(), nlyteAssets, locationMap, pduMaterialMap, manufacturerMap, AssetCategory.PDU);
    HashMap<Integer, Material> networksMaterialMap = new HashMap<Integer, Material>();
    nlyteAssets = nlyteAPIclient.getAssets(true, AssetCategory.Networks);
    List<Material> networkMaterials = nlyteAPIclient.getMaterials(true, HandleAssetUtil.networkMaterials);
    for (Material material : networkMaterials) {
        material.setMaterialType(AssetCategory.Networks);
        networksMaterialMap.put(material.getMaterialID(), material);
    }
    saveAssetForMappedData(nlyte.getId(), nlyteAssets, locationMap, networksMaterialMap, manufacturerMap, AssetCategory.Networks);
}
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) LocationGroup(com.vmware.flowgate.nlyteworker.model.LocationGroup) ConnectException(java.net.ConnectException)

Example 17 with NlyteAsset

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

the class NlyteDataService method generateAssets.

public List<Asset> generateAssets(String nlyteSource, List<NlyteAsset> nlyteAssets, HashMap<Integer, LocationGroup> locationMap, HashMap<Integer, Manufacturer> manufacturerMap, HashMap<Integer, Material> materialMap, AssetCategory category, HashMap<Long, String> chassisMountedAssetNumberAndChassisIdMap) {
    HandleAssetUtil assetUtil = new HandleAssetUtil();
    List<Asset> oldAssetsFromWormhole = restClient.getAllAssetsBySourceAndType(nlyteSource, category);
    Map<Long, Asset> assetsFromWormholeMap = assetUtil.generateAssetsMap(oldAssetsFromWormhole);
    List<Asset> allAssetsFromNlyte = assetUtil.getAssetsFromNlyte(nlyteSource, nlyteAssets, locationMap, materialMap, manufacturerMap, chassisMountedAssetNumberAndChassisIdMap);
    return assetUtil.handleAssets(allAssetsFromNlyte, assetsFromWormholeMap);
}
Also used : HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset)

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