Skip to content

Commit 6b9ac8b

Browse files
rajesh-battalaDaanHoogland
authored andcommitted
CLOUDSTACK-6920 Support listing of LBHealthcheck policy with LBHealthcheck policy ID
(cherry picked from commit 21e452f) Conflicts: api/src/com/cloud/network/lb/LoadBalancingRulesService.java
1 parent 56c2a09 commit 6b9ac8b

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

‎api/src/com/cloud/network/lb/LoadBalancingRulesService.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,8 @@ LoadBalancer createPublicLoadBalancerRule(String xId, String name, String descri
159159
StickinessPolicy updateLBStickinessPolicy(long id, String customId, Boolean forDisplay);
160160

161161
HealthCheckPolicy updateLBHealthCheckPolicy(long id, String customId, Boolean forDisplay);
162+
163+
LoadBalancer findLbByStickinessId(long stickinessPolicyId);
164+
165+
Long findLBIdByHealtCheckPolicyId(long lbHealthCheckPolicy);
162166
}

‎api/src/org/apache/cloudstack/api/command/user/loadbalancer/ListLBHealthCheckPoliciesCmd.java‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.apache.cloudstack.api.response.ListResponse;
3030
import org.apache.log4j.Logger;
3131

32+
33+
import com.cloud.exception.InvalidParameterValueException;
3234
import com.cloud.network.rules.HealthCheckPolicy;
3335
import com.cloud.network.rules.LoadBalancer;
3436

@@ -45,20 +47,26 @@ public class ListLBHealthCheckPoliciesCmd extends BaseListCmd {
4547
@Parameter(name = ApiConstants.LBID,
4648
type = CommandType.UUID,
4749
entityType = FirewallRuleResponse.class,
48-
required = true,
4950
description = "the ID of the load balancer rule")
5051
private Long lbRuleId;
5152

5253
@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})
5354
private Boolean display;
5455

56+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = LBHealthCheckResponse.class, description = "the ID of the healthcheck policy", since = "4.4")
57+
private Long id;
58+
5559
// ///////////////////////////////////////////////////
5660
// ///////////////// Accessors ///////////////////////
5761
// ///////////////////////////////////////////////////
5862
public Long getLbRuleId() {
5963
return lbRuleId;
6064
}
6165

66+
public Long getId() {
67+
return id;
68+
}
69+
6270
public boolean getDisplay() {
6371
if (display != null) {
6472
return display;
@@ -78,9 +86,18 @@ public String getCommandName() {
7886
@Override
7987
public void execute() {
8088
List<LBHealthCheckResponse> hcpResponses = new ArrayList<LBHealthCheckResponse>();
81-
LoadBalancer lb = _lbService.findById(getLbRuleId());
8289
ListResponse<LBHealthCheckResponse> response = new ListResponse<LBHealthCheckResponse>();
90+
Long lbRuleId = getLbRuleId();
91+
Long hId = getId();
92+
if(lbRuleId == null) {
93+
if(hId != null) {
94+
lbRuleId = _lbService.findLBIdByHealtCheckPolicyId(hId);
95+
} else {
96+
throw new InvalidParameterValueException("Either LB Ruleid or HealthCheckpolicy Id should be specified");
97+
}
98+
}
8399

100+
LoadBalancer lb = _lbService.findById(lbRuleId);
84101
if (lb != null) {
85102
List<? extends HealthCheckPolicy> healthCheckPolicies = _lbService.searchForLBHealthCheckPolicies(this);
86103
LBHealthCheckResponse spResponse = _responseGenerator.createLBHealthCheckPolicyResponse(healthCheckPolicies, lb);

‎server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,15 +2231,18 @@ public List<LBStickinessPolicyVO> searchForLBStickinessPolicies(ListLBStickiness
22312231
public List<LBHealthCheckPolicyVO> searchForLBHealthCheckPolicies(ListLBHealthCheckPoliciesCmd cmd) throws PermissionDeniedException {
22322232
Account caller = CallContext.current().getCallingAccount();
22332233
Long loadBalancerId = cmd.getLbRuleId();
2234+
Long policyId = cmd.getId();
22342235
boolean forDisplay = cmd.getDisplay();
2235-
2236+
if(loadBalancerId == null) {
2237+
loadBalancerId = findLBIdByHealtCheckPolicyId(policyId);
2238+
}
22362239
LoadBalancerVO loadBalancer = _lbDao.findById(loadBalancerId);
22372240
if (loadBalancer == null) {
22382241
return null;
22392242
}
22402243

22412244
_accountMgr.checkAccess(caller, null, true, loadBalancer);
2242-
List<LBHealthCheckPolicyVO> hcDbpolicies = _lb2healthcheckDao.listByLoadBalancerIdAndDisplayFlag(cmd.getLbRuleId(), forDisplay);
2245+
List<LBHealthCheckPolicyVO> hcDbpolicies = _lb2healthcheckDao.listByLoadBalancerIdAndDisplayFlag(loadBalancerId, forDisplay);
22432246

22442247
return hcDbpolicies;
22452248
}
@@ -2527,4 +2530,13 @@ public HealthCheckPolicy updateLBHealthCheckPolicy(long id, String customId, Boo
25272530
return _lb2healthcheckDao.findById(id);
25282531
}
25292532

2533+
@Override
2534+
public Long findLBIdByHealtCheckPolicyId(long lbHealthCheckPolicy) {
2535+
LBHealthCheckPolicyVO policy= _lb2healthcheckDao.findById(lbHealthCheckPolicy);
2536+
if(policy != null) {
2537+
return policy.getLoadBalancerId();
2538+
}
2539+
return null;
2540+
}
2541+
25302542
}

0 commit comments

Comments
 (0)