Search in sources :

Example 11 with NlyteAsset

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

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

the class SycnRealTimeDataJobTest method testHandleChassisSolts.

@Test
public void testHandleChassisSolts() {
    Asset asset = createAsset();
    List<ChassisSlot> chassisSolts = new ArrayList<ChassisSlot>();
    NlyteAsset nlyteAsset = getNlyteAsset().get(0);
    HandleAssetUtil util = new HandleAssetUtil();
    util.handleChassisSolts(asset, nlyteAsset);
    TestCase.assertEquals(true, asset.getJustificationfields().isEmpty());
}
Also used : HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) ArrayList(java.util.ArrayList) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) Asset(com.vmware.flowgate.common.model.Asset) 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 13 with NlyteAsset

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

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

the class NlyteAPIClient method getAssetbyAssetNumber.

public NlyteAsset getAssetbyAssetNumber(AssetCategory category, long assetNumber) {
    initAuthenticationWebToken();
    String getAssetsUrl = null;
    switch(category) {
        case Server:
            getAssetsUrl = getNlyteServiceEndpoint() + String.format(GetServerAssetByAssetNumberURL, assetNumber);
            break;
        case PDU:
            getAssetsUrl = getNlyteServiceEndpoint() + String.format(GetPowerStripAssetByAssetNumberURL, assetNumber);
            break;
        case Cabinet:
            getAssetsUrl = getNlyteServiceEndpoint() + String.format(GetCabinetByAssetNumberURL, assetNumber);
            break;
        case Networks:
            getAssetsUrl = getNlyteServiceEndpoint() + String.format(GetNetworkByAssetNumberURL, assetNumber);
            break;
        default:
            throw new NlyteWorkerException("no such assets of the category ");
    }
    ResponseEntity<NlyteAsset> result = null;
    NlyteAsset asset = null;
    try {
        result = this.restTemplate.exchange(getAssetsUrl, HttpMethod.GET, getDefaultEntity(), NlyteAsset.class);
    } catch (HttpClientErrorException e) {
        if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
            return asset;
        }
    }
    if (HttpStatus.OK.equals(result.getStatusCode())) {
        asset = result.getBody();
    }
    return asset;
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) NlyteWorkerException(com.vmware.flowgate.nlyteworker.exception.NlyteWorkerException)

Example 15 with NlyteAsset

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

the class NlyteAPIClient method getAssets.

public List<NlyteAsset> getAssets(boolean isAllData, AssetCategory category) {
    initAuthenticationWebToken();
    String getAssetsUrl = null;
    switch(category) {
        case Server:
            getAssetsUrl = getNlyteServiceEndpoint() + GetServerAssetsURL;
            break;
        case PDU:
            getAssetsUrl = getNlyteServiceEndpoint() + GetPowerStripAssetsURL;
            break;
        case Cabinet:
            getAssetsUrl = getNlyteServiceEndpoint() + GetCabinetsURL;
            break;
        case Networks:
            getAssetsUrl = getNlyteServiceEndpoint() + GetNetworksURL;
            break;
        case Chassis:
            getAssetsUrl = getNlyteServiceEndpoint() + GetChassisURL;
            break;
        default:
            throw new NlyteWorkerException("no such assets of the category ");
    }
    JsonResultForAsset nlyteAssetResult = this.restTemplate.exchange(getAssetsUrl, HttpMethod.GET, getDefaultEntity(), JsonResultForAsset.class).getBody();
    List<NlyteAsset> nlyteAssets = new LinkedList<NlyteAsset>();
    nlyteAssets = nlyteAssetResult.getValue();
    if (!isAllData) {
        return nlyteAssets;
    }
    URLDecoder decoder = new URLDecoder();
    List<NlyteAsset> nextPageNlyteAssets = null;
    String nextLink = nlyteAssetResult.getOdatanextLink();
    while (nextLink != null && !nextLink.equals("")) {
        nextLink = decoder.decode(nextLink);
        nextPageNlyteAssets = new ArrayList<NlyteAsset>();
        nlyteAssetResult = this.restTemplate.exchange(nextLink, HttpMethod.GET, getDefaultEntity(), JsonResultForAsset.class).getBody();
        nextPageNlyteAssets = nlyteAssetResult.getValue();
        nlyteAssets.addAll(nextPageNlyteAssets);
        nextLink = nlyteAssetResult.getOdatanextLink();
    }
    HandleAssetUtil util = new HandleAssetUtil();
    nlyteAssets = util.filterUnActivedAsset(nlyteAssets, category);
    return nlyteAssets;
}
Also used : HandleAssetUtil(com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) JsonResultForAsset(com.vmware.flowgate.nlyteworker.model.JsonResultForAsset) URLDecoder(java.net.URLDecoder) NlyteWorkerException(com.vmware.flowgate.nlyteworker.exception.NlyteWorkerException) LinkedList(java.util.LinkedList)

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