Search in sources :

Example 1 with ResourceCountResponse

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

the class ApiResponseHelper method createResourceCountResponse.

@Override
public ResourceCountResponse createResourceCountResponse(ResourceCount resourceCount) {
    ResourceCountResponse resourceCountResponse = new ResourceCountResponse();
    if (resourceCount.getResourceOwnerType() == ResourceOwnerType.Account) {
        Account accountTemp = ApiDBUtils.findAccountById(resourceCount.getOwnerId());
        if (accountTemp != null) {
            populateAccount(resourceCountResponse, accountTemp.getId());
            populateDomain(resourceCountResponse, accountTemp.getDomainId());
        }
    } else if (resourceCount.getResourceOwnerType() == ResourceOwnerType.Domain) {
        populateDomain(resourceCountResponse, resourceCount.getOwnerId());
    }
    resourceCountResponse.setResourceType(Integer.toString(resourceCount.getType().getOrdinal()));
    resourceCountResponse.setResourceCount(resourceCount.getCount());
    resourceCountResponse.setObjectName("resourcecount");
    return resourceCountResponse;
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) ResourceCountResponse(org.apache.cloudstack.api.response.ResourceCountResponse)

Example 2 with ResourceCountResponse

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

the class UpdateResourceCountCmd method execute.

@Override
public void execute() {
    List<? extends ResourceCount> result = _resourceLimitService.recalculateResourceCount(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), getResourceType());
    if ((result != null) && (result.size() > 0)) {
        ListResponse<ResourceCountResponse> response = new ListResponse<ResourceCountResponse>();
        List<ResourceCountResponse> countResponses = new ArrayList<ResourceCountResponse>();
        for (ResourceCount count : result) {
            ResourceCountResponse resourceCountResponse = _responseGenerator.createResourceCountResponse(count);
            resourceCountResponse.setObjectName("resourcecount");
            countResponses.add(resourceCountResponse);
        }
        response.setResponses(countResponses);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to recalculate resource counts");
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceCount(com.cloud.configuration.ResourceCount) ArrayList(java.util.ArrayList) ResourceCountResponse(org.apache.cloudstack.api.response.ResourceCountResponse)

Aggregations

ResourceCountResponse (org.apache.cloudstack.api.response.ResourceCountResponse)2 ResourceCount (com.cloud.configuration.ResourceCount)1 ProjectAccount (com.cloud.projects.ProjectAccount)1 Account (com.cloud.user.Account)1 UserAccount (com.cloud.user.UserAccount)1 ArrayList (java.util.ArrayList)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1