CLOUDSTACK-6923: updated listLBStickinessPolicies API to list using stickinesspolicy id

(cherry picked from commit b0d726a872)

Conflicts:
	api/src/com/cloud/network/lb/LoadBalancingRulesService.java
This commit is contained in:
Jayapal 2014-06-17 16:14:33 +05:30 committed by Daan Hoogland
parent 6b9ac8be8b
commit 335f165b5b
2 changed files with 54 additions and 5 deletions

View File

@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.loadbalancer;
import java.util.ArrayList;
import java.util.List;
import com.cloud.exception.InvalidParameterValueException;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
@ -47,10 +48,16 @@ public class ListLBStickinessPoliciesCmd extends BaseListCmd {
@Parameter(name = ApiConstants.LBID,
type = CommandType.UUID,
entityType = FirewallRuleResponse.class,
required = true,
description = "the ID of the load balancer rule")
private Long lbRuleId;
@Parameter(name = ApiConstants.ID,
type = CommandType.UUID,
entityType = LBStickinessResponse.class,
description = "the ID of the load balancer stickiness policy")
private Long id;
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "list resources by display flag; only ROOT admin is eligible to pass this parameter", since = "4.4", authorized = {RoleType.Admin})
private Boolean display;
@ -61,6 +68,10 @@ public class ListLBStickinessPoliciesCmd extends BaseListCmd {
return lbRuleId;
}
public Long getId() {
return id;
}
public boolean getDisplay() {
if (display != null) {
return display;
@ -79,8 +90,28 @@ public class ListLBStickinessPoliciesCmd extends BaseListCmd {
@Override
public void execute() {
LoadBalancer lb = null;
if (lbRuleId == null && id == null) {
throw new InvalidParameterValueException("LB 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>();
LoadBalancer lb = _lbService.findById(getLbRuleId());
ListResponse<LBStickinessResponse> response = new ListResponse<LBStickinessResponse>();
if (lb != null) {

View File

@ -2213,16 +2213,24 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
public List<LBStickinessPolicyVO> searchForLBStickinessPolicies(ListLBStickinessPoliciesCmd cmd) throws PermissionDeniedException {
Account caller = CallContext.current().getCallingAccount();
Long loadBalancerId = cmd.getLbRuleId();
boolean forDisplay = cmd.getDisplay();
Long stickinessId = cmd.getId();
boolean forDisplay = cmd.getDisplay();
LoadBalancerVO loadBalancer = null;
if (loadBalancerId == null) {
loadBalancer = findLbByStickinessId(stickinessId);
} else {
loadBalancer = _lbDao.findById(loadBalancerId);
}
LoadBalancerVO loadBalancer = _lbDao.findById(loadBalancerId);
if (loadBalancer == null) {
return null;
}
_accountMgr.checkAccess(caller, null, true, loadBalancer);
List<LBStickinessPolicyVO> sDbpolicies = _lb2stickinesspoliciesDao.listByLoadBalancerIdAndDisplayFlag(cmd.getLbRuleId(), forDisplay);
List<LBStickinessPolicyVO> sDbpolicies = _lb2stickinesspoliciesDao.listByLoadBalancerIdAndDisplayFlag(loadBalancer.getId(), forDisplay);
return sDbpolicies;
}
@ -2365,6 +2373,16 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
return _lbDao.findById(lbId);
}
@Override
public LoadBalancerVO findLbByStickinessId(long stickinessPolicyId) {
LBStickinessPolicyVO stickinessPolicy = _lb2stickinesspoliciesDao.findById(stickinessPolicyId);
if (stickinessPolicy == null) {
return null;
}
return _lbDao.findById(stickinessPolicy.getLoadBalancerId());
}
@Override
public void removeLBRule(LoadBalancer rule) {
// remove the rule