Search in sources :

Example 1 with LBStickinessResponse

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

the class ListLBStickinessPoliciesCmd method execute.

@Override
public void execute() {
    List<LBStickinessResponse> spResponses = new ArrayList<LBStickinessResponse>();
    LoadBalancer lb = _lbService.findById(getLbRuleId());
    ListResponse<LBStickinessResponse> response = new ListResponse<LBStickinessResponse>();
    if (lb != null) {
        //check permissions
        Account caller = UserContext.current().getCaller();
        _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(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.network.rules.LoadBalancer) LBStickinessResponse(com.cloud.api.response.LBStickinessResponse)

Example 2 with LBStickinessResponse

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

the class CreateLBStickinessPolicyCmd method execute.

@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
    StickinessPolicy policy = null;
    boolean success = false;
    try {
        UserContext.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(BaseCmd.INTERNAL_ERROR, "Failed to create stickiness policy ");
        }
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) LoadBalancer(com.cloud.network.rules.LoadBalancer) StickinessPolicy(com.cloud.network.rules.StickinessPolicy) LBStickinessResponse(com.cloud.api.response.LBStickinessResponse)

Aggregations

LBStickinessResponse (com.cloud.api.response.LBStickinessResponse)2 LoadBalancer (com.cloud.network.rules.LoadBalancer)2 ServerApiException (com.cloud.api.ServerApiException)1 ListResponse (com.cloud.api.response.ListResponse)1 StickinessPolicy (com.cloud.network.rules.StickinessPolicy)1 Account (com.cloud.user.Account)1 ArrayList (java.util.ArrayList)1