Search in sources :

Example 1 with LBStickinessResponse

use of org.apache.cloudstack.api.response.LBStickinessResponse 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 2 with LBStickinessResponse

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

the class CreateLBStickinessPolicyCmd method execute.

@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
    StickinessPolicy policy = null;
    boolean success = false;
    try {
        CallContext.current().setEventDetails("Rule Id: " + getEntityId());
        success = _lbService.applyLBStickinessPolicy(this);
        if (success) {
            // State might be different after the rule is applied, so get new object here
            policy = _entityMgr.findById(StickinessPolicy.class, getEntityId());
            LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
            LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(policy, lb);
            setResponseObject(spResponse);
            spResponse.setResponseName(getCommandName());
        }
    } finally {
        if (!success || (policy == null)) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create stickiness policy");
        }
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) LoadBalancer(com.cloud.network.rules.LoadBalancer) StickinessPolicy(com.cloud.network.rules.StickinessPolicy) LBStickinessResponse(org.apache.cloudstack.api.response.LBStickinessResponse)

Example 3 with LBStickinessResponse

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

the class UpdateLBStickinessPolicyCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() {
    StickinessPolicy policy = _lbService.updateLBStickinessPolicy(this.getId(), this.getCustomId(), this.getDisplay());
    LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
    LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(policy, lb);
    setResponseObject(spResponse);
    spResponse.setResponseName(getCommandName());
}
Also used : LoadBalancer(com.cloud.network.rules.LoadBalancer) StickinessPolicy(com.cloud.network.rules.StickinessPolicy) LBStickinessResponse(org.apache.cloudstack.api.response.LBStickinessResponse)

Example 4 with LBStickinessResponse

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

the class ApiResponseHelper method createLBStickinessPolicyResponse.

@Override
public LBStickinessResponse createLBStickinessPolicyResponse(StickinessPolicy stickinessPolicy, LoadBalancer lb) {
    LBStickinessResponse spResponse = new LBStickinessResponse();
    spResponse.setlbRuleId(lb.getUuid());
    Account accountTemp = ApiDBUtils.findAccountById(lb.getAccountId());
    if (accountTemp != null) {
        spResponse.setAccountName(accountTemp.getAccountName());
        Domain domain = ApiDBUtils.findDomainById(accountTemp.getDomainId());
        if (domain != null) {
            spResponse.setDomainId(domain.getUuid());
            spResponse.setDomainName(domain.getName());
        }
    }
    List<LBStickinessPolicyResponse> responses = new ArrayList<LBStickinessPolicyResponse>();
    LBStickinessPolicyResponse ruleResponse = new LBStickinessPolicyResponse(stickinessPolicy);
    responses.add(ruleResponse);
    spResponse.setRules(responses);
    spResponse.setObjectName("stickinesspolicies");
    return spResponse;
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) Domain(com.cloud.domain.Domain) LBStickinessPolicyResponse(org.apache.cloudstack.api.response.LBStickinessPolicyResponse) LBStickinessResponse(org.apache.cloudstack.api.response.LBStickinessResponse)

Example 5 with LBStickinessResponse

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

the class ApiResponseHelper method createLBStickinessPolicyResponse.

@Override
public LBStickinessResponse createLBStickinessPolicyResponse(List<? extends StickinessPolicy> stickinessPolicies, LoadBalancer lb) {
    LBStickinessResponse spResponse = new LBStickinessResponse();
    if (lb == null) {
        return spResponse;
    }
    spResponse.setlbRuleId(lb.getUuid());
    Account account = ApiDBUtils.findAccountById(lb.getAccountId());
    if (account != null) {
        spResponse.setAccountName(account.getAccountName());
        Domain domain = ApiDBUtils.findDomainById(account.getDomainId());
        if (domain != null) {
            spResponse.setDomainId(domain.getUuid());
            spResponse.setDomainName(domain.getName());
        }
    }
    List<LBStickinessPolicyResponse> responses = new ArrayList<LBStickinessPolicyResponse>();
    for (StickinessPolicy stickinessPolicy : stickinessPolicies) {
        LBStickinessPolicyResponse ruleResponse = new LBStickinessPolicyResponse(stickinessPolicy);
        responses.add(ruleResponse);
    }
    spResponse.setRules(responses);
    spResponse.setObjectName("stickinesspolicies");
    return spResponse;
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) Domain(com.cloud.domain.Domain) LBStickinessPolicyResponse(org.apache.cloudstack.api.response.LBStickinessPolicyResponse) LBStickinessResponse(org.apache.cloudstack.api.response.LBStickinessResponse) StickinessPolicy(com.cloud.network.rules.StickinessPolicy)

Aggregations

LBStickinessResponse (org.apache.cloudstack.api.response.LBStickinessResponse)5 LoadBalancer (com.cloud.network.rules.LoadBalancer)3 StickinessPolicy (com.cloud.network.rules.StickinessPolicy)3 Account (com.cloud.user.Account)3 ArrayList (java.util.ArrayList)3 Domain (com.cloud.domain.Domain)2 ProjectAccount (com.cloud.projects.ProjectAccount)2 UserAccount (com.cloud.user.UserAccount)2 LBStickinessPolicyResponse (org.apache.cloudstack.api.response.LBStickinessPolicyResponse)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1