Skip to content

Commit ea6d1f0

Browse files
Adding health check destination option to loadbalancer options (api and database only)
1 parent 7aea2a9 commit ea6d1f0

9 files changed

Lines changed: 48 additions & 13 deletions

File tree

api/src/com/cloud/network/lb/LoadBalancingRule.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class LoadBalancingRule {
4040
private String lbProtocol;
4141
private String cache;
4242
private String serviceDownAction;
43+
private String healthCheckDestination;
4344
private List<Long> additionalNetworks;
4445
private List<String> additionalPortMap;
4546

@@ -171,6 +172,14 @@ public void setAdditionalNetworks(List<Long> additionalNetworks) {
171172

172173
public void setAdditionalPortMap(List<String> additionalPortMap) { this.additionalPortMap = additionalPortMap; }
173174

175+
public void setHealthCheckDestination(String healthCheckDestination) {
176+
this.healthCheckDestination = healthCheckDestination;
177+
}
178+
179+
public String getHealthCheckDestination() {
180+
return healthCheckDestination;
181+
}
182+
174183
public interface Destination {
175184
String getIpAddress();
176185

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public interface LoadBalancingRulesService {
5151
* @throws InsufficientAddressCapacityException
5252
*/
5353
LoadBalancer createPublicLoadBalancerRule(String xId, String name, String description, int srcPortStart, int srcPortEnd, int defPortStart, int defPortEnd,
54-
Long ipAddrId, String protocol, String algorithm, long networkId, long lbOwnerId, boolean openFirewall, String lbProtocol, Boolean forDisplay, List<String> additionalPortMap, String cache, String serviceDownAction)
54+
Long ipAddrId, String protocol, String algorithm, long networkId, long lbOwnerId, boolean openFirewall, String lbProtocol, Boolean forDisplay, List<String> additionalPortMap, String cache, String serviceDownAction, String heathCheckDestination)
5555
throws NetworkRuleConflictException, InsufficientAddressCapacityException;
5656

5757
LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd);

api/src/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class ApiConstants {
3737
public static final String BYTES_WRITE_RATE = "byteswriterate";
3838
public static final String CACHE = "cache";
3939
public static final String SERVICE_DOWN_ACTION = "servicedownactionid";
40+
public static final String HEALTHCHECK_DESTINATION = "healthcheckdestination";
4041
public static final String CATEGORY = "category";
4142
public static final String CAN_REVERT = "canrevert";
4243
public static final String CERTIFICATE = "certificate";

api/src/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements L
129129
@Parameter(name = ApiConstants.SERVICE_DOWN_ACTION, type = CommandType.STRING, description = "ID of the action to be executed when service is down")
130130
private String serviceDownAction;
131131

132+
@Parameter(name = ApiConstants.HEALTHCHECK_DESTINATION, type = CommandType.STRING, description = "Port to be user as health check alternative to the service port (optional)")
133+
private String heathCheckDestination;
134+
132135
/////////////////////////////////////////////////////
133136
/////////////////// Accessors ///////////////////////
134137
/////////////////////////////////////////////////////
@@ -238,6 +241,10 @@ public String getServiceDownAction() {
238241
return serviceDownAction;
239242
}
240243

244+
public String getHeathCheckDestination() {
245+
return heathCheckDestination;
246+
}
247+
241248
public Integer getPublicPort() {
242249
return publicPort;
243250
}
@@ -336,7 +343,8 @@ public void create() {
336343
try {
337344
LoadBalancer result =
338345
_lbService.createPublicLoadBalancerRule(getXid(), getName(), getDescription(), getSourcePortStart(), getSourcePortEnd(), getDefaultPortStart(),
339-
getDefaultPortEnd(), getSourceIpAddressId(), getProtocol(), getAlgorithm(), getNetworkId(), getEntityOwnerId(), getOpenFirewall(), getLbProtocol(), isDisplay(), getAdditionalPortMap(), getCache(), getServiceDownAction());
346+
getDefaultPortEnd(), getSourceIpAddressId(), getProtocol(), getAlgorithm(), getNetworkId(), getEntityOwnerId(), getOpenFirewall(), getLbProtocol(), isDisplay(),
347+
getAdditionalPortMap(), getCache(), getServiceDownAction(), getHeathCheckDestination());
340348
this.setEntityId(result.getId());
341349
this.setEntityUuid(result.getUuid());
342350
} catch (NetworkRuleConflictException e) {

engine/components-api/src/com/cloud/network/lb/LoadBalancingRulesManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
public interface LoadBalancingRulesManager {
3636

3737
LoadBalancer createPublicLoadBalancer(String xId, String name, String description, int srcPort, int destPort, long sourceIpId, String protocol, String algorithm,
38-
boolean openFirewall, CallContext caller, String lbProtocol, Boolean forDisplay, List<String> additionalPortMap, String cache, String serviceDownAction) throws NetworkRuleConflictException;
38+
boolean openFirewall, CallContext caller, String lbProtocol, Boolean forDisplay, List<String> additionalPortMap, String cache, String serviceDownAction, String healthCheckDestination) throws NetworkRuleConflictException;
3939

4040
boolean removeAllLoadBalanacersForIp(long ipId, Account caller, long callerUserId);
4141

engine/schema/src/com/cloud/network/dao/LoadBalancerOptionsVO.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@ public class LoadBalancerOptionsVO implements InternalIdentity {
4242
@Column(name="service_down_action")
4343
private String serviceDownAction;
4444

45+
@Column(name="health_check_destination")
46+
private String healthCheckDestination;
47+
4548
public LoadBalancerOptionsVO() {
4649
}
4750

48-
public LoadBalancerOptionsVO(long lbId, String cache, String serviceDownAction) {
51+
public LoadBalancerOptionsVO(long lbId, String cache, String serviceDownAction, String healthCheckDestination) {
4952
this.lbId = lbId;
5053
this.cache = cache;
5154
this.serviceDownAction = serviceDownAction;
55+
this.healthCheckDestination = healthCheckDestination;
5256
}
5357

5458
@Override

plugins/network-elements/globonetwork/src/com/globo/globonetwork/cloudstack/commands/AddOrRemoveVipInGloboNetworkCommand.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public class AddOrRemoveVipInGloboNetworkCommand extends Command {
4343

4444
private String cache;
4545

46+
private String serviceDownAction;
47+
48+
private String healthCheckDestination;
49+
4650
private String serviceName;
4751

4852
private LoadBalancingRule.LbHealthCheckPolicy healthcheckPolicy;
@@ -51,8 +55,6 @@ public class AddOrRemoveVipInGloboNetworkCommand extends Command {
5155

5256
private List<GloboNetworkVipResponse.Real> realList;
5357

54-
private String serviceDownAction;
55-
5658
@Override
5759
public boolean executeInSequence() {
5860
return false;
@@ -165,4 +167,12 @@ public void setServiceDownAction(String serviceDownAction) {
165167
public String getServiceDownAction() {
166168
return serviceDownAction;
167169
}
170+
171+
public void setHealthCheckDestination(String healthCheckDestination) {
172+
this.healthCheckDestination = healthCheckDestination;
173+
}
174+
175+
public String getHealthCheckDestination() {
176+
return healthCheckDestination;
177+
}
168178
}

plugins/network-elements/globonetwork/src/com/globo/globonetwork/cloudstack/manager/GloboNetworkManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,7 @@ public boolean applyLbRuleInGloboNetwork(final Network network, final LoadBalanc
19921992
cmd.setHost(rule.getName());
19931993
cmd.setCache(rule.getCache());
19941994
cmd.setServiceDownAction(rule.getServiceDownAction());
1995+
cmd.setHealthCheckDestination(rule.getHealthCheckDestination());
19951996
cmd.setIpv4(rule.getSourceIp().addr());
19961997
cmd.setVipEnvironmentId(gnLbNetworkVO.getGloboNetworkLoadBalancerEnvironmentId());
19971998
cmd.setPorts(ports);
@@ -2377,7 +2378,7 @@ public LoadBalancer doInTransaction(TransactionStatus status) throws CloudExcept
23772378

23782379
// Create LB
23792380
LoadBalancer lb = _lbMgr.createPublicLoadBalancer(null, globoNetworkLB.getName(), globoNetworkLB.getDetails(), Integer.parseInt(globoNetworkPorts[0], 10),
2380-
Integer.parseInt(globoNetworkPorts[1], 10), publicIp.getId(), NetUtils.TCP_PROTO, algorithm, false, CallContext.current(), null, Boolean.TRUE, additionalPortMapList, cache, null);
2381+
Integer.parseInt(globoNetworkPorts[1], 10), publicIp.getId(), NetUtils.TCP_PROTO, algorithm, false, CallContext.current(), null, Boolean.TRUE, additionalPortMapList, cache, null, null);
23812382

23822383
// If healthcheck is TCP, do nothing; otherwise, create the healthcheck policy
23832384
if (globoNetworkLB.getHealthcheckType() != null && "HTTP".equals(globoNetworkLB.getHealthcheckType())) {

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ public List<LoadBalancerVMMapVO> doInTransaction(TransactionStatus status) {
17071707
@Override
17081708
@ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_CREATE, eventDescription = "creating load balancer")
17091709
public LoadBalancer createPublicLoadBalancerRule(String xId, String name, String description, int srcPortStart, int srcPortEnd, int defPortStart, int defPortEnd,
1710-
Long ipAddrId, String protocol, String algorithm, long networkId, long lbOwnerId, boolean openFirewall, String lbProtocol, Boolean forDisplay, List<String> additionalPortMap, String cache, String serviceDownAction)
1710+
Long ipAddrId, String protocol, String algorithm, long networkId, long lbOwnerId, boolean openFirewall, String lbProtocol, Boolean forDisplay, List<String> additionalPortMap, String cache, String serviceDownAction, String healthCheckDestination)
17111711
throws NetworkRuleConflictException, InsufficientAddressCapacityException {
17121712
Account lbOwner = _accountMgr.getAccount(lbOwnerId);
17131713

@@ -1764,7 +1764,7 @@ public LoadBalancer createPublicLoadBalancerRule(String xId, String name, String
17641764
}
17651765

17661766
result = createPublicLoadBalancer(xId, name, description, srcPortStart, defPortStart, ipVO.getId(), protocol, algorithm, openFirewall, CallContext.current(),
1767-
lbProtocol, forDisplay, additionalPortMap, cache, serviceDownAction);
1767+
lbProtocol, forDisplay, additionalPortMap, cache, serviceDownAction, healthCheckDestination);
17681768
} catch (Exception ex) {
17691769
s_logger.warn("Failed to create load balancer due to ", ex);
17701770
if (ex instanceof NetworkRuleConflictException) {
@@ -1793,7 +1793,7 @@ public LoadBalancer createPublicLoadBalancerRule(String xId, String name, String
17931793
@DB
17941794
@Override
17951795
public LoadBalancer createPublicLoadBalancer(final String xId, final String name, final String description, final int srcPort, final int destPort, final long sourceIpId,
1796-
final String protocol, final String algorithm, final boolean openFirewall, final CallContext caller, final String lbProtocol, final Boolean forDisplay, final List<String> additionalPortMap, final String cache, final String serviceDownAction)
1796+
final String protocol, final String algorithm, final boolean openFirewall, final CallContext caller, final String lbProtocol, final Boolean forDisplay, final List<String> additionalPortMap, final String cache, final String serviceDownAction, final String healthCheckDestination)
17971797
throws NetworkRuleConflictException {
17981798

17991799
if (!NetUtils.isValidPort(destPort)) {
@@ -1862,6 +1862,7 @@ public LoadBalancerVO doInTransaction(TransactionStatus status) throws NetworkRu
18621862
new ArrayList<LbHealthCheckPolicy>(), sourceIp, null, lbProtocol);
18631863
loadBalancing.setCache(cache);
18641864
loadBalancing.setServiceDownAction(serviceDownAction);
1865+
loadBalancing.setHealthCheckDestination(healthCheckDestination);
18651866
loadBalancing.setAdditionalPortMap(additionalPortMap);
18661867
if (!validateLbRule(loadBalancing)) {
18671868
throw new InvalidParameterValueException("LB service provider cannot support this rule");
@@ -1917,11 +1918,12 @@ public LoadBalancerVO doInTransaction(TransactionStatus status) throws NetworkRu
19171918
}
19181919
}
19191920

1920-
// If load balancer rule was created successfully, add cache and service down action options
1921-
if (lb != null && (cache != null || serviceDownAction != null)) {
1921+
// If load balancer rule was created successfully, add cache and service down action and health check port options
1922+
if (lb != null && (cache != null || serviceDownAction != null || healthCheckDestination != null)) {
19221923
String cacheStr = cache != null ? cache.trim() : null; // Remove any white spaces on either side
19231924
String serviceDownActionStr = serviceDownAction != null ? serviceDownAction.trim() : null;
1924-
_lbOptionsDao.persist(new LoadBalancerOptionsVO(lb.getId(), cacheStr, serviceDownActionStr));
1925+
String healthCheckDestinationStr = healthCheckDestination != null ? healthCheckDestination.trim() : null;
1926+
_lbOptionsDao.persist(new LoadBalancerOptionsVO(lb.getId(), cacheStr, serviceDownActionStr, healthCheckDestinationStr));
19251927
}
19261928

19271929
return lb;

0 commit comments

Comments
 (0)