Search in sources :

Example 1 with Manufacturer

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

the class HandleAssetUtil method supplementMaterial.

/**
 * Supplemental Material information
 * @return
 */
public Asset supplementMaterial(Asset asset, int materialID, HashMap<Integer, Manufacturer> manufacturerMap, HashMap<Integer, Material> materialMap) {
    Material material = materialMap.get(materialID);
    if (material == null) {
        return asset;
    }
    Manufacturer manufacturer = manufacturerMap.get(material.getManufacturerID());
    asset.setManufacturer(manufacturer.getDetail());
    asset.setModel(material.getMaterialName());
    asset.setSubCategory(material.getMaterialSubtype());
    asset.setCategory(material.getMaterialType());
    Integer uHeight = material.getuHeight();
    switch(asset.getCategory()) {
        case Cabinet:
            if (uHeight != null) {
                asset.setCapacity(uHeight);
            }
            break;
        case Networks:
            int totalSize = material.getTotalCopperPorts() + material.getTotalFibreOpticPorts() + material.getTotalUndefinedPorts();
            asset.setCapacity(totalSize);
            break;
        case Chassis:
            int columnsBack = material.getNumberOfColumnsBack();
            int rowsBack = material.getNumberOfRowsBack();
            int columnsFront = material.getNumberOfColumnsFront();
            int rowsFront = material.getNumberOfRowsFront();
            asset.setCapacity(columnsBack * rowsBack + columnsFront * rowsFront);
            supplementChassisInfo(asset, FlowgateConstant.CHASSIS_AIR_FLOW_TYPE, material.getAirflowTypeID());
            break;
        default:
            break;
    }
    return asset;
}
Also used : Manufacturer(com.vmware.flowgate.nlyteworker.model.Manufacturer) Material(com.vmware.flowgate.nlyteworker.model.Material)

Example 2 with Manufacturer

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

the class SycnRealTimeDataJobTest method testGenerateNewAsset2.

@Test
public void testGenerateNewAsset2() {
    List<NlyteAsset> nlyteAssets = getNlyteAsset();
    HashMap<Integer, LocationGroup> locationMap = getLocationMap();
    HashMap<Integer, Material> materialMap = new HashMap<Integer, Material>();
    Material material = new Material();
    material.setMaterialID(6251);
    material.setManufacturerID(14);
    material.setMaterialName("Cisco 1721 Modular Access Router");
    material.setMaterialType(AssetCategory.Networks);
    materialMap.put(6251, material);
    HashMap<Integer, Manufacturer> manufacturerMap = new HashMap<Integer, Manufacturer>();
    Manufacturer manufacturer = new Manufacturer();
    manufacturer.setManufacturerID(14);
    manufacturer.setDetail("Cisco");
    manufacturerMap.put(14, manufacturer);
    Mockito.when(this.wormholeAPIClient.getAllAssetsBySourceAndType("l9i8728d55368540fcba1692", AssetCategory.Server)).thenReturn(new ArrayList<Asset>());
    HashMap<Long, String> chassisMountedAssetNumberAndChassisIDMap = new HashMap<Long, String>();
    chassisMountedAssetNumberAndChassisIDMap.put(197L, "asdqe945kjsdf09uw45ms");
    List<Asset> assets = nlyteDataService.generateAssets("l9i8728d55368540fcba1692", nlyteAssets, locationMap, manufacturerMap, materialMap, AssetCategory.Networks, chassisMountedAssetNumberAndChassisIDMap);
    for (Asset asset : assets) {
        if ("sin2-blrqeops-esxstress024".equals(asset.getAssetName())) {
            TestCase.assertEquals(197, asset.getAssetNumber());
            TestCase.assertEquals("SG-07-04", asset.getRoom());
            TestCase.assertEquals("Cisco 1721 Modular Access Router", asset.getModel());
            TestCase.assertEquals("Cisco", asset.getManufacturer());
            TestCase.assertEquals("asdqe945kjsdf09uw45ms", asset.getParent().getParentId());
        }
    }
}
Also used : HashMap(java.util.HashMap) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Material(com.vmware.flowgate.nlyteworker.model.Material) 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 3 with Manufacturer

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

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

the class HandleAssetUtil method initManufacturersMap.

/**
 * init ManufacturersMap information
 */
public HashMap<Integer, Manufacturer> initManufacturersMap(NlyteAPIClient nlyteAPIclient) {
    List<Manufacturer> manufacturers = nlyteAPIclient.getManufacturers(true);
    HashMap<Integer, Manufacturer> manufacturerMap = null;
    if (manufacturers.isEmpty()) {
        return null;
    }
    manufacturerMap = new HashMap<Integer, Manufacturer>();
    for (Manufacturer manufacturer : manufacturers) {
        manufacturerMap.put(manufacturer.getManufacturerID(), manufacturer);
    }
    return manufacturerMap;
}
Also used : Manufacturer(com.vmware.flowgate.nlyteworker.model.Manufacturer)

Example 5 with Manufacturer

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

Aggregations

Manufacturer (com.vmware.flowgate.nlyteworker.model.Manufacturer)10 Material (com.vmware.flowgate.nlyteworker.model.Material)7 LocationGroup (com.vmware.flowgate.nlyteworker.model.LocationGroup)6 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)6 HashMap (java.util.HashMap)6 Asset (com.vmware.flowgate.common.model.Asset)5 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 HandleAssetUtil (com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil)3 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)2 NlyteAPIClient (com.vmware.flowgate.nlyteworker.restclient.NlyteAPIClient)2 ConnectException (java.net.ConnectException)2 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)2 ResourceAccessException (org.springframework.web.client.ResourceAccessException)2 JsonResultForManufacturer (com.vmware.flowgate.nlyteworker.model.JsonResultForManufacturer)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1