Search in sources :

Example 1 with NlyteWorkerException

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;
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) NlyteAsset(com.vmware.flowgate.nlyteworker.model.NlyteAsset) NlyteWorkerException(com.vmware.flowgate.nlyteworker.exception.NlyteWorkerException)

Example 2 with NlyteWorkerException

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;
}
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 3 with NlyteWorkerException

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;
}
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

NlyteWorkerException (com.vmware.flowgate.nlyteworker.exception.NlyteWorkerException)3 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)2 URLDecoder (java.net.URLDecoder)2 LinkedList (java.util.LinkedList)2 JsonResultForAsset (com.vmware.flowgate.nlyteworker.model.JsonResultForAsset)1 JsonResultForMaterial (com.vmware.flowgate.nlyteworker.model.JsonResultForMaterial)1 Material (com.vmware.flowgate.nlyteworker.model.Material)1 HandleAssetUtil (com.vmware.flowgate.nlyteworker.scheduler.job.common.HandleAssetUtil)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1 HttpServerErrorException (org.springframework.web.client.HttpServerErrorException)1