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());
}
}
}
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());
}
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());
}
}
}
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;
}
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;
}
Aggregations