Search in sources :

Example 26 with ListResponse

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

the class ListLBStickinessPoliciesCmd method execute.

@Override
public void execute() {
    LoadBalancer lb = null;
    if (lbRuleId == null && id == null) {
        throw new InvalidParameterValueException("load balancer rule ID and stickiness policy ID can't be null");
    }
    if (id != null) {
        lb = _lbService.findLbByStickinessId(id);
        if (lb == null) {
            throw new InvalidParameterValueException("stickiness policy ID doesn't exist");
        }
        if ((lbRuleId != null) && (lbRuleId != lb.getId())) {
            throw new InvalidParameterValueException("stickiness policy ID doesn't belong to lbId" + lbRuleId);
        }
    }
    if (lbRuleId != null && lb == null) {
        lb = _lbService.findById(getLbRuleId());
    }
    List<LBStickinessResponse> spResponses = new ArrayList<LBStickinessResponse>();
    ListResponse<LBStickinessResponse> response = new ListResponse<LBStickinessResponse>();
    if (lb != null) {
        //check permissions
        Account caller = CallContext.current().getCallingAccount();
        _accountService.checkAccess(caller, null, true, lb);
        List<? extends StickinessPolicy> stickinessPolicies = _lbService.searchForLBStickinessPolicies(this);
        LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(stickinessPolicies, lb);
        spResponses.add(spResponse);
        response.setResponses(spResponses);
    }
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : Account(com.cloud.user.Account) ListResponse(org.apache.cloudstack.api.response.ListResponse) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.network.rules.LoadBalancer) LBStickinessResponse(org.apache.cloudstack.api.response.LBStickinessResponse)

Example 27 with ListResponse

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

the class RegisterIsoCmd method execute.

@Override
public void execute() throws ResourceAllocationException {
    VirtualMachineTemplate template = _templateService.registerIso(this);
    if (template != null) {
        ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
        List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(ResponseView.Restricted, template, zoneId, false);
        response.setResponses(templateResponses);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register ISO");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse)

Example 28 with ListResponse

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

the class ListGuestOsCategoriesCmd method execute.

@Override
public void execute() {
    Pair<List<? extends GuestOsCategory>, Integer> result = _mgr.listGuestOSCategoriesByCriteria(this);
    ListResponse<GuestOSCategoryResponse> response = new ListResponse<GuestOSCategoryResponse>();
    List<GuestOSCategoryResponse> osCatResponses = new ArrayList<GuestOSCategoryResponse>();
    for (GuestOsCategory osCategory : result.first()) {
        GuestOSCategoryResponse categoryResponse = new GuestOSCategoryResponse();
        categoryResponse.setId(osCategory.getUuid());
        categoryResponse.setName(osCategory.getName());
        categoryResponse.setObjectName("oscategory");
        osCatResponses.add(categoryResponse);
    }
    response.setResponses(osCatResponses, result.second());
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : GuestOSCategoryResponse(org.apache.cloudstack.api.response.GuestOSCategoryResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) GuestOsCategory(com.cloud.storage.GuestOsCategory) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 29 with ListResponse

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

the class ListGuestOsCmd method execute.

@Override
public void execute() {
    Pair<List<? extends GuestOS>, Integer> result = _mgr.listGuestOSByCriteria(this);
    ListResponse<GuestOSResponse> response = new ListResponse<GuestOSResponse>();
    List<GuestOSResponse> osResponses = new ArrayList<GuestOSResponse>();
    for (GuestOS guestOS : result.first()) {
        GuestOSResponse guestOSResponse = _responseGenerator.createGuestOSResponse(guestOS);
        osResponses.add(guestOSResponse);
    }
    response.setResponses(osResponses, result.second());
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GuestOS(com.cloud.storage.GuestOS) GuestOSResponse(org.apache.cloudstack.api.response.GuestOSResponse)

Example 30 with ListResponse

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

the class ListIpForwardingRulesCmd method execute.

@Override
public void execute() {
    Pair<List<? extends FirewallRule>, Integer> result = _rulesService.searchStaticNatRules(publicIpAddressId, id, vmId, this.getStartIndex(), this.getPageSizeVal(), this.getAccountName(), this.getDomainId(), this.getProjectId(), this.isRecursive(), this.listAll());
    ListResponse<IpForwardingRuleResponse> response = new ListResponse<IpForwardingRuleResponse>();
    List<IpForwardingRuleResponse> ipForwardingResponses = new ArrayList<IpForwardingRuleResponse>();
    for (FirewallRule rule : result.first()) {
        StaticNatRule staticNatRule = _rulesService.buildStaticNatRule(rule, false);
        IpForwardingRuleResponse resp = _responseGenerator.createIpForwardingRuleResponse(staticNatRule);
        if (resp != null) {
            ipForwardingResponses.add(resp);
        }
    }
    response.setResponses(ipForwardingResponses, result.second());
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StaticNatRule(com.cloud.network.rules.StaticNatRule) FirewallRule(com.cloud.network.rules.FirewallRule) IpForwardingRuleResponse(org.apache.cloudstack.api.response.IpForwardingRuleResponse)

Aggregations

ListResponse (org.apache.cloudstack.api.response.ListResponse)149 ArrayList (java.util.ArrayList)134 List (java.util.List)62 ServerApiException (org.apache.cloudstack.api.ServerApiException)44 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)29 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)21 Network (com.cloud.network.Network)9 DedicatedResources (com.cloud.dc.DedicatedResources)8 NetworkResponse (org.apache.cloudstack.api.response.NetworkResponse)8 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)7 TemplateResponse (org.apache.cloudstack.api.response.TemplateResponse)7 Host (com.cloud.host.Host)6 Domain (com.cloud.domain.Domain)5 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)5 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)4 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 Account (com.cloud.user.Account)4