Search in sources :

Example 1 with ResourceDetailResponse

use of com.cloud.api.response.ResourceDetailResponse in project cosmic by MissionCriticalCloud.

the class QueryManagerImpl method listResourceDetails.

@Override
public List<ResourceDetailResponse> listResourceDetails(final ListResourceDetailsCmd cmd) {
    final String key = cmd.getKey();
    final Boolean forDisplay = cmd.getDisplay();
    final ResourceTag.ResourceObjectType resourceType = cmd.getResourceType();
    final String resourceIdStr = cmd.getResourceId();
    final 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 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);
    }
    final List<ResourceDetailResponse> responseList = new ArrayList<>();
    if (requestedDetail != null) {
        final ResourceDetailResponse detailResponse = createResourceDetailsResponse(requestedDetail, resourceType);
        responseList.add(detailResponse);
    } else {
        for (final ResourceDetail detail : detailList) {
            final ResourceDetailResponse detailResponse = createResourceDetailsResponse(detail, resourceType);
            responseList.add(detailResponse);
        }
    }
    return responseList;
}
Also used : ResourceTag(com.cloud.server.ResourceTag) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) ResourceDetail(com.cloud.api.ResourceDetail) ResourceObjectType(com.cloud.server.ResourceTag.ResourceObjectType) ResourceDetailResponse(com.cloud.api.response.ResourceDetailResponse)

Example 2 with ResourceDetailResponse

use of com.cloud.api.response.ResourceDetailResponse in project cosmic by MissionCriticalCloud.

the class QueryManagerImpl method createResourceDetailsResponse.

protected ResourceDetailResponse createResourceDetailsResponse(final ResourceDetail requestedDetail, final ResourceTag.ResourceObjectType resourceType) {
    final 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(com.cloud.api.response.ResourceDetailResponse)

Aggregations

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