CLOUDSTACK-6920 Support listing of LBHealthcheck policy with LBHealthcheck policy ID

This commit is contained in:
Rajesh Battala 2014-06-18 15:42:23 +05:30
parent 15b348632d
commit c7b23d0a10
3 changed files with 35 additions and 4 deletions

View File

@ -161,4 +161,6 @@ public interface LoadBalancingRulesService {
HealthCheckPolicy updateLBHealthCheckPolicy(long id, String customId, Boolean forDisplay); HealthCheckPolicy updateLBHealthCheckPolicy(long id, String customId, Boolean forDisplay);
LoadBalancer findLbByStickinessId(long stickinessPolicyId); LoadBalancer findLbByStickinessId(long stickinessPolicyId);
Long findLBIdByHealtCheckPolicyId(long lbHealthCheckPolicy);
} }

View File

@ -29,6 +29,8 @@ import org.apache.cloudstack.api.response.LBHealthCheckResponse;
import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ListResponse;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.rules.HealthCheckPolicy; import com.cloud.network.rules.HealthCheckPolicy;
import com.cloud.network.rules.LoadBalancer; import com.cloud.network.rules.LoadBalancer;
@ -45,13 +47,15 @@ public class ListLBHealthCheckPoliciesCmd extends BaseListCmd {
@Parameter(name = ApiConstants.LBID, @Parameter(name = ApiConstants.LBID,
type = CommandType.UUID, type = CommandType.UUID,
entityType = FirewallRuleResponse.class, entityType = FirewallRuleResponse.class,
required = true,
description = "the ID of the load balancer rule") description = "the ID of the load balancer rule")
private Long lbRuleId; private Long lbRuleId;
@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}) @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; private Boolean display;
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = LBHealthCheckResponse.class, description = "the ID of the healthcheck policy", since = "4.4")
private Long id;
// /////////////////////////////////////////////////// // ///////////////////////////////////////////////////
// ///////////////// Accessors /////////////////////// // ///////////////// Accessors ///////////////////////
// /////////////////////////////////////////////////// // ///////////////////////////////////////////////////
@ -59,6 +63,10 @@ public class ListLBHealthCheckPoliciesCmd extends BaseListCmd {
return lbRuleId; return lbRuleId;
} }
public Long getId() {
return id;
}
public boolean getDisplay() { public boolean getDisplay() {
if (display != null) { if (display != null) {
return display; return display;
@ -78,9 +86,18 @@ public class ListLBHealthCheckPoliciesCmd extends BaseListCmd {
@Override @Override
public void execute() { public void execute() {
List<LBHealthCheckResponse> hcpResponses = new ArrayList<LBHealthCheckResponse>(); List<LBHealthCheckResponse> hcpResponses = new ArrayList<LBHealthCheckResponse>();
LoadBalancer lb = _lbService.findById(getLbRuleId());
ListResponse<LBHealthCheckResponse> response = new ListResponse<LBHealthCheckResponse>(); ListResponse<LBHealthCheckResponse> response = new ListResponse<LBHealthCheckResponse>();
Long lbRuleId = getLbRuleId();
Long hId = getId();
if(lbRuleId == null) {
if(hId != null) {
lbRuleId = _lbService.findLBIdByHealtCheckPolicyId(hId);
} else {
throw new InvalidParameterValueException("Either LB Ruleid or HealthCheckpolicy Id should be specified");
}
}
LoadBalancer lb = _lbService.findById(lbRuleId);
if (lb != null) { if (lb != null) {
List<? extends HealthCheckPolicy> healthCheckPolicies = _lbService.searchForLBHealthCheckPolicies(this); List<? extends HealthCheckPolicy> healthCheckPolicies = _lbService.searchForLBHealthCheckPolicies(this);
LBHealthCheckResponse spResponse = _responseGenerator.createLBHealthCheckPolicyResponse(healthCheckPolicies, lb); LBHealthCheckResponse spResponse = _responseGenerator.createLBHealthCheckPolicyResponse(healthCheckPolicies, lb);

View File

@ -2263,15 +2263,18 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
public List<LBHealthCheckPolicyVO> searchForLBHealthCheckPolicies(ListLBHealthCheckPoliciesCmd cmd) throws PermissionDeniedException { public List<LBHealthCheckPolicyVO> searchForLBHealthCheckPolicies(ListLBHealthCheckPoliciesCmd cmd) throws PermissionDeniedException {
Account caller = CallContext.current().getCallingAccount(); Account caller = CallContext.current().getCallingAccount();
Long loadBalancerId = cmd.getLbRuleId(); Long loadBalancerId = cmd.getLbRuleId();
Long policyId = cmd.getId();
boolean forDisplay = cmd.getDisplay(); boolean forDisplay = cmd.getDisplay();
if(loadBalancerId == null) {
loadBalancerId = findLBIdByHealtCheckPolicyId(policyId);
}
LoadBalancerVO loadBalancer = _lbDao.findById(loadBalancerId); LoadBalancerVO loadBalancer = _lbDao.findById(loadBalancerId);
if (loadBalancer == null) { if (loadBalancer == null) {
return null; return null;
} }
_accountMgr.checkAccess(caller, null, true, loadBalancer); _accountMgr.checkAccess(caller, null, true, loadBalancer);
List<LBHealthCheckPolicyVO> hcDbpolicies = _lb2healthcheckDao.listByLoadBalancerIdAndDisplayFlag(cmd.getLbRuleId(), forDisplay); List<LBHealthCheckPolicyVO> hcDbpolicies = _lb2healthcheckDao.listByLoadBalancerIdAndDisplayFlag(loadBalancerId, forDisplay);
return hcDbpolicies; return hcDbpolicies;
} }
@ -2569,4 +2572,13 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
return _lb2healthcheckDao.findById(id); return _lb2healthcheckDao.findById(id);
} }
@Override
public Long findLBIdByHealtCheckPolicyId(long lbHealthCheckPolicy) {
LBHealthCheckPolicyVO policy= _lb2healthcheckDao.findById(lbHealthCheckPolicy);
if(policy != null) {
return policy.getLoadBalancerId();
}
return null;
}
} }