Search in sources :

Example 1 with ResourceDetailResponse

use of org.apache.cloudstack.api.response.ResourceDetailResponse in project cloudstack by apache.

the class QueryManagerImpl method listResourceDetails.

@Override
public List<ResourceDetailResponse> listResourceDetails(ListResourceDetailsCmd cmd) {
    String key = cmd.getKey();
    Boolean forDisplay = cmd.getDisplay();
    ResourceTag.ResourceObjectType resourceType = cmd.getResourceType();
    String resourceIdStr = cmd.getResourceId();
    String value = cmd.getValue();
    Long resourceId = null;
    //Validation - 1.1 - resourceId and value cant be null.
    if (resourceIdStr == null && value == null) {
        throw new InvalidParameterValueException("Insufficient parameters passed for listing by resourceId OR key,value pair. Please check your params and try again.");
    }
    //Validation - 1.2 - Value has to be passed along with key.
    if (value != null && key == null) {
        throw new InvalidParameterValueException("Listing by (key, value) but key is null. Please check the params and try again");
    }
    //Validation - 1.3
    if (resourceIdStr != null) {
        resourceId = _taggedResourceMgr.getResourceId(resourceIdStr, resourceType);
        if (resourceId == null) {
            throw new InvalidParameterValueException("Cannot find resource with resourceId " + resourceIdStr + " and of resource type " + resourceType);
        }
    }
    List<? extends ResourceDetail> detailList = new ArrayList<ResourceDetail>();
    ResourceDetail requestedDetail = null;
    if (key == null) {
        detailList = _resourceMetaDataMgr.getDetailsList(resourceId, resourceType, forDisplay);
    } else if (value == null) {
        requestedDetail = _resourceMetaDataMgr.getDetail(resourceId, resourceType, key);
        if (requestedDetail != null && forDisplay != null && requestedDetail.isDisplay() != forDisplay) {
            requestedDetail = null;
        }
    } else {
        detailList = _resourceMetaDataMgr.getDetails(resourceType, key, value, forDisplay);
    }
    List<ResourceDetailResponse> responseList = new ArrayList<ResourceDetailResponse>();
    if (requestedDetail != null) {
        ResourceDetailResponse detailResponse = createResourceDetailsResponse(requestedDetail, resourceType);
        responseList.add(detailResponse);
    } else {
        for (ResourceDetail detail : detailList) {
            ResourceDetailResponse detailResponse = createResourceDetailsResponse(detail, resourceType);
            responseList.add(detailResponse);
        }
    }
    return responseList;
}
Also used : ResourceTag(com.cloud.server.ResourceTag) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) ResourceDetail(org.apache.cloudstack.api.ResourceDetail) ResourceObjectType(com.cloud.server.ResourceTag.ResourceObjectType) ResourceDetailResponse(org.apache.cloudstack.api.response.ResourceDetailResponse)

Example 2 with ResourceDetailResponse

use of org.apache.cloudstack.api.response.ResourceDetailResponse in project cloudstack by apache.

the class QueryManagerImpl method createResourceDetailsResponse.

protected ResourceDetailResponse createResourceDetailsResponse(ResourceDetail requestedDetail, ResourceTag.ResourceObjectType resourceType) {
    ResourceDetailResponse resourceDetailResponse = new ResourceDetailResponse();
    resourceDetailResponse.setResourceId(String.valueOf(requestedDetail.getResourceId()));
    resourceDetailResponse.setName(requestedDetail.getName());
    resourceDetailResponse.setValue(requestedDetail.getValue());
    resourceDetailResponse.setForDisplay(requestedDetail.isDisplay());
    resourceDetailResponse.setResourceType(resourceType.toString().toString());
    resourceDetailResponse.setObjectName("resourcedetail");
    return resourceDetailResponse;
}
Also used : ResourceDetailResponse(org.apache.cloudstack.api.response.ResourceDetailResponse)

Aggregations

ResourceDetailResponse (org.apache.cloudstack.api.response.ResourceDetailResponse)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 ResourceTag (com.cloud.server.ResourceTag)1 ResourceObjectType (com.cloud.server.ResourceTag.ResourceObjectType)1 ArrayList (java.util.ArrayList)1 ResourceDetail (org.apache.cloudstack.api.ResourceDetail)1