Search in sources :

Example 6 with Material

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

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

the class SycnRealTimeDataJobTest method testGenerateNewAsset.

@Test
public void testGenerateNewAsset() {
    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.Server);
    material.setMaterialSubtype(AssetSubCategory.Blade);
    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.Server, 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 8 with Material

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

the class SycnRealTimeDataJobTest method testGenerateNewAsset1.

@Test
public void testGenerateNewAsset1() {
    List<NlyteAsset> nlyteAssets = getNlyteAsset();
    HashMap<Integer, LocationGroup> locationMap = getLocationMap();
    HashMap<Integer, Material> materialMap = getMaterialMap();
    HashMap<Integer, Manufacturer> manufacturerMap = getManufacturerMap();
    List<Asset> assetsFromFlowgate = new ArrayList<Asset>();
    Asset preAsset = new Asset();
    preAsset.setAssetNumber(197);
    preAsset.setAssetSource("l9i8728d55368540fcba1692");
    assetsFromFlowgate.add(preAsset);
    Mockito.when(this.wormholeAPIClient.getAllAssetsBySourceAndType("l9i8728d55368540fcba1692", AssetCategory.Server)).thenReturn(assetsFromFlowgate);
    HashMap<Integer, String> cabinetIdAndNameMap = new HashMap<Integer, String>();
    cabinetIdAndNameMap.put(562, "cbName");
    nlyteAssets = nlyteDataService.supplementCabinetName(cabinetIdAndNameMap, nlyteAssets);
    List<Asset> assets = nlyteDataService.generateAssets("l9i8728d55368540fcba1692", nlyteAssets, locationMap, manufacturerMap, materialMap, AssetCategory.Server, new HashMap<Long, String>());
    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("cbName", asset.getCabinetName());
        }
    }
}
Also used : HashMap(java.util.HashMap) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) ArrayList(java.util.ArrayList) 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 9 with Material

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

the class NlyteAPIClient method getMaterials.

public List<Material> getMaterials(boolean isAllData, int materialType) {
    initAuthenticationWebToken();
    String getMaterialsURL = null;
    switch(materialType) {
        case HandleAssetUtil.bladeServerMaterial:
            getMaterialsURL = getNlyteServiceEndpoint() + GetBladeServerMaterialsURL;
            break;
        case HandleAssetUtil.standardServerMaterial:
            getMaterialsURL = getNlyteServiceEndpoint() + GetStandardServerMaterialsURL;
            break;
        case HandleAssetUtil.powerStripMaterial:
            getMaterialsURL = getNlyteServiceEndpoint() + GetPowerStripMaterialsURL;
            break;
        case HandleAssetUtil.cabinetMaterials:
            getMaterialsURL = getNlyteServiceEndpoint() + GetCabinetMaterialsURL;
            break;
        case HandleAssetUtil.networkMaterials:
            getMaterialsURL = getNlyteServiceEndpoint() + GetNetworkMaterialsURL;
            break;
        case HandleAssetUtil.chassisMaterials:
            getMaterialsURL = getNlyteServiceEndpoint() + GetChassisMaterialsURL;
            break;
        default:
            throw new NlyteWorkerException("category should be 'Blade' or 'Standard' for server matreial");
    }
    List<Material> materials = new LinkedList<Material>();
    JsonResultForMaterial materialResult = this.restTemplate.exchange(getMaterialsURL, HttpMethod.GET, getDefaultEntity(), JsonResultForMaterial.class).getBody();
    materials.addAll(materialResult.getValue());
    if (!isAllData) {
        return materials;
    }
    List<Material> nextPageMaterials = null;
    URLDecoder decoder = new URLDecoder();
    String nextLink = materialResult.getOdatanextLink();
    while (nextLink != null && !nextLink.equals("")) {
        nextLink = decoder.decode(nextLink);
        nextPageMaterials = new LinkedList<Material>();
        try {
            materialResult = this.restTemplate.exchange(nextLink, HttpMethod.GET, getDefaultEntity(), JsonResultForMaterial.class).getBody();
        } catch (HttpServerErrorException e) {
            logger.error("Internal Server Error.The url is " + nextLink);
            break;
        }
        nextPageMaterials = materialResult.getValue();
        materials.addAll(nextPageMaterials);
        nextLink = materialResult.getOdatanextLink();
    }
    return materials;
}
Also used : JsonResultForMaterial(com.vmware.flowgate.nlyteworker.model.JsonResultForMaterial) JsonResultForMaterial(com.vmware.flowgate.nlyteworker.model.JsonResultForMaterial) Material(com.vmware.flowgate.nlyteworker.model.Material) URLDecoder(java.net.URLDecoder) NlyteWorkerException(com.vmware.flowgate.nlyteworker.exception.NlyteWorkerException) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) LinkedList(java.util.LinkedList)

Example 10 with Material

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

Aggregations

Material (com.vmware.flowgate.nlyteworker.model.Material)10 Manufacturer (com.vmware.flowgate.nlyteworker.model.Manufacturer)7 HashMap (java.util.HashMap)7 LocationGroup (com.vmware.flowgate.nlyteworker.model.LocationGroup)6 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)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 NlyteWorkerException (com.vmware.flowgate.nlyteworker.exception.NlyteWorkerException)1 JsonResultForMaterial (com.vmware.flowgate.nlyteworker.model.JsonResultForMaterial)1 URLDecoder (java.net.URLDecoder)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 HttpServerErrorException (org.springframework.web.client.HttpServerErrorException)1