use of com.vmware.flowgate.nlyteworker.exception.NlyteWorkerException 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.exception.NlyteWorkerException 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;
}
use of com.vmware.flowgate.nlyteworker.exception.NlyteWorkerException 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