Search in sources :

Example 1 with ResourceLimitResponse

use of com.cloud.api.response.ResourceLimitResponse in project CloudStack-archive by CloudStack-extras.

the class UpdateResourceLimitCmd method execute.

@Override
public void execute() {
    ResourceLimit result = _resourceLimitService.updateResourceLimit(finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), resourceType, max);
    if (result != null || (result == null && max != null && max.longValue() == -1L)) {
        ResourceLimitResponse response = _responseGenerator.createResourceLimitResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update resource limit");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) ResourceLimitResponse(com.cloud.api.response.ResourceLimitResponse) ResourceLimit(com.cloud.configuration.ResourceLimit)

Example 2 with ResourceLimitResponse

use of com.cloud.api.response.ResourceLimitResponse in project CloudStack-archive by CloudStack-extras.

the class ListResourceLimitsCmd method execute.

@Override
public void execute() {
    List<? extends ResourceLimit> result = _resourceLimitService.searchForLimits(id, finalyzeAccountId(this.getAccountName(), this.getDomainId(), this.getProjectId(), false), this.getDomainId(), resourceType, this.getStartIndex(), this.getPageSizeVal());
    ListResponse<ResourceLimitResponse> response = new ListResponse<ResourceLimitResponse>();
    List<ResourceLimitResponse> limitResponses = new ArrayList<ResourceLimitResponse>();
    for (ResourceLimit limit : result) {
        ResourceLimitResponse resourceLimitResponse = _responseGenerator.createResourceLimitResponse(limit);
        resourceLimitResponse.setObjectName("resourcelimit");
        limitResponses.add(resourceLimitResponse);
    }
    response.setResponses(limitResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ResourceLimitResponse(com.cloud.api.response.ResourceLimitResponse) ArrayList(java.util.ArrayList) ResourceLimit(com.cloud.configuration.ResourceLimit)

Example 3 with ResourceLimitResponse

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

the class UpdateResourceLimitCmd method execute.

@Override
public void execute() {
    final ResourceLimit result = _resourceLimitService.updateResourceLimit(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), resourceType, max);
    if (result != null || (result == null && max != null && max.longValue() == -1L)) {
        final ResourceLimitResponse response = _responseGenerator.createResourceLimitResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update resource limit");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) ResourceLimitResponse(com.cloud.api.response.ResourceLimitResponse) ResourceLimit(com.cloud.configuration.ResourceLimit)

Example 4 with ResourceLimitResponse

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

the class ApiResponseHelper method createResourceLimitResponse.

@Override
public ResourceLimitResponse createResourceLimitResponse(final ResourceLimit limit) {
    final ResourceLimitResponse resourceLimitResponse = new ResourceLimitResponse();
    if (limit.getResourceOwnerType() == ResourceOwnerType.Domain) {
        populateDomain(resourceLimitResponse, limit.getOwnerId());
    } else if (limit.getResourceOwnerType() == ResourceOwnerType.Account) {
        final Account accountTemp = ApiDBUtils.findAccountById(limit.getOwnerId());
        populateAccount(resourceLimitResponse, limit.getOwnerId());
        populateDomain(resourceLimitResponse, accountTemp.getDomainId());
    }
    resourceLimitResponse.setResourceType(Integer.toString(limit.getType().getOrdinal()));
    if ((limit.getType() == ResourceType.primary_storage || limit.getType() == ResourceType.secondary_storage) && limit.getMax() >= 0) {
        resourceLimitResponse.setMax((long) Math.ceil((double) limit.getMax() / ResourceType.bytesToGiB));
    } else {
        resourceLimitResponse.setMax(limit.getMax());
    }
    resourceLimitResponse.setObjectName("resourcelimit");
    return resourceLimitResponse;
}
Also used : UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) ResourceLimitResponse(com.cloud.api.response.ResourceLimitResponse)

Example 5 with ResourceLimitResponse

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

the class ListResourceLimitsCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final List<? extends ResourceLimit> result = _resourceLimitService.searchForLimits(id, _accountService.finalyzeAccountId(this.getAccountName(), this.getDomainId(), this.getProjectId(), false), this.getDomainId(), resourceType, this.getStartIndex(), this.getPageSizeVal());
    final ListResponse<ResourceLimitResponse> response = new ListResponse<>();
    final List<ResourceLimitResponse> limitResponses = new ArrayList<>();
    for (final ResourceLimit limit : result) {
        final ResourceLimitResponse resourceLimitResponse = _responseGenerator.createResourceLimitResponse(limit);
        resourceLimitResponse.setObjectName("resourcelimit");
        limitResponses.add(resourceLimitResponse);
    }
    response.setResponses(limitResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ResourceLimitResponse(com.cloud.api.response.ResourceLimitResponse) ArrayList(java.util.ArrayList) ResourceLimit(com.cloud.configuration.ResourceLimit)

Aggregations

ResourceLimitResponse (com.cloud.api.response.ResourceLimitResponse)5 ResourceLimit (com.cloud.configuration.ResourceLimit)4 ServerApiException (com.cloud.api.ServerApiException)2 ListResponse (com.cloud.api.response.ListResponse)2 ArrayList (java.util.ArrayList)2 Account (com.cloud.user.Account)1 UserAccount (com.cloud.user.UserAccount)1