Search in sources :

Example 1 with StickinessPolicy

use of com.cloud.network.rules.StickinessPolicy in project CloudStack-archive by CloudStack-extras.

the class DeleteLBStickinessPolicyCmd method getSyncObjId.

@Override
public Long getSyncObjId() {
    StickinessPolicy policy = _entityMgr.findById(StickinessPolicy.class, getId());
    if (policy == null) {
        throw new InvalidParameterValueException("Unable to find LB stickiness rule: " + id);
    }
    LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
    if (lb == null) {
        throw new InvalidParameterValueException("Unable to find load balancer rule for stickiness rule: " + id);
    }
    return lb.getNetworkId();
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) LoadBalancer(com.cloud.network.rules.LoadBalancer) StickinessPolicy(com.cloud.network.rules.StickinessPolicy)

Example 2 with StickinessPolicy

use of com.cloud.network.rules.StickinessPolicy 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 3 with StickinessPolicy

use of com.cloud.network.rules.StickinessPolicy 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 4 with StickinessPolicy

use of com.cloud.network.rules.StickinessPolicy 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)

Example 5 with StickinessPolicy

use of com.cloud.network.rules.StickinessPolicy in project cosmic by MissionCriticalCloud.

the class CreateLBStickinessPolicyCmd method create.

@Override
public void create() {
    try {
        final StickinessPolicy result = _lbService.createLBStickinessPolicy(this);
        this.setEntityId(result.getId());
        this.setEntityUuid(result.getUuid());
    } catch (final NetworkRuleConflictException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) StickinessPolicy(com.cloud.network.rules.StickinessPolicy)

Aggregations

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