Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions api/src/main/java/com/cloud/agent/api/to/LoadBalancerTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public class LoadBalancerTO {
final static int MAX_HEALTHCHECK_POLICIES = 1;

private String cidrList;
private Boolean keepAlive;
private Long idleTimeout;
private Long keepAliveTimeout;

public LoadBalancerTO(String uuid, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, boolean inline,
List<LbDestination> destinations) {
Expand Down Expand Up @@ -249,6 +252,30 @@ public String getCidrList() {
return cidrList;
}

public void setKeepAlive(Boolean keepAlive) {
this.keepAlive = keepAlive;
}

public Boolean getKeepAlive() {
return keepAlive;
}

public void setIdleTimeout(Long idleTimeout) {
this.idleTimeout = idleTimeout;
}

public Long getIdleTimeout() {
return idleTimeout;
}

public void setKeepAliveTimeout(Long keepAliveTimeout) {
this.keepAliveTimeout = keepAliveTimeout;
}

public Long getKeepAliveTimeout() {
return keepAliveTimeout;
}

public static class StickinessPolicyTO {
private String methodName;
private List<Pair<String, String>> params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ LoadBalancer createPublicLoadBalancerRule(String xId, String name, String descri

LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd);

/**
* Stores the optional per rule haproxy settings. A null leaves the current value alone.
*
* @param cleanup remove all three first, so the rule inherits again, then store any non null value given
* @return true if any value changed
*/
boolean updateLoadBalancerConnectionSettings(long lbRuleId, Boolean keepAlive, Long idleTimeout, Long keepAliveTimeout, boolean cleanup);

boolean deleteLoadBalancerRule(long lbRuleId, boolean apply);

/**
Expand Down
5 changes: 5 additions & 0 deletions api/src/main/java/com/cloud/network/rules/LoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
*/
public interface LoadBalancer extends FirewallRule, LoadBalancerContainer {

// Optional per rule haproxy settings, held as firewall rule details. Absent means inherit.
String KEEPALIVE = "keepalive";
String IDLE_TIMEOUT = "idletimeout";
String KEEPALIVE_TIMEOUT = "keepalivetimeout";

int getDefaultPortStart();

int getDefaultPortEnd();
Expand Down
4 changes: 4 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ public class ApiConstants {
public static final String IS_ISO = "isiso";
public static final String IS_PORTABLE = "isportable";
public static final String IS_PUBLIC = "ispublic";
public static final String IDLE_TIMEOUT = "idletimeout";
public static final String IS_PERSISTENT = "ispersistent";
public static final String EGRESS_DEFAULT_POLICY = "egressdefaultpolicy";
public static final String IS_READY = "isready";
Expand All @@ -368,6 +369,8 @@ public class ApiConstants {
public static final String JAVA_VERSION = "javaversion";
public static final String JOB_ID = "jobid";
public static final String JOB_STATUS = "jobstatus";
public static final String KEEPALIVE = "keepalive";
public static final String KEEPALIVE_TIMEOUT = "keepalivetimeout";
public static final String KEEPALIVE_ENABLED = "keepaliveenabled";
public static final String KERNEL_VERSION = "kernelversion";
public static final String KEYPAIR_ID = "keypairid";
Expand Down Expand Up @@ -1207,6 +1210,7 @@ public class ApiConstants {
public static final String OVM3_POOL = "ovm3pool";
public static final String OVM3_CLUSTER = "ovm3cluster";
public static final String OVM3_VIP = "ovm3vip";
public static final String CLEAN_UP_CONNECTION_SETTINGS = "cleanupconnectionsettings";
public static final String CLEAN_UP_DETAILS = "cleanupdetails";
public static final String CLEAN_UP_EXTERNAL_DETAILS = "cleanupexternaldetails";
public static final String CLEAN_UP_EXTRA_CONFIG = "cleanupextraconfig";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements L
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "An optional field, whether to the display the rule to the end user or not", since = "4.4", authorized = {RoleType.Admin})
private Boolean display;

@Parameter(name = ApiConstants.KEEPALIVE, type = CommandType.BOOLEAN, since = "24.0",
description = "Whether the load balancer keeps client connections open between requests. "
+ "Only applies to rules the router serves in HTTP mode. If not set, the network offering's setting is used.")
private Boolean keepAlive;

@Parameter(name = ApiConstants.IDLE_TIMEOUT, type = CommandType.LONG, since = "24.0",
description = "How long an idle connection is held open, in milliseconds. Use 0 for infinite. "
+ "If not set, the global setting network.loadbalancer.haproxy.idle.timeout is used.")
private Long idleTimeout;

@Parameter(name = ApiConstants.KEEPALIVE_TIMEOUT, type = CommandType.LONG, since = "24.0",
description = "How long an idle keepalive connection is held open waiting for the next request, "
+ "in milliseconds. Only applies to rules the router serves in HTTP mode. "
+ "If not set, idletimeout applies.")
private Long keepAliveTimeout;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand All @@ -135,6 +151,18 @@ public boolean isDisplay() {
public String getAlgorithm() {
return algorithm;
}
public Boolean getKeepAlive() {
return keepAlive;
}

public Long getIdleTimeout() {
return idleTimeout;
}
public Long getKeepAliveTimeout() {
return keepAliveTimeout;
}



public String getDescription() {
return description;
Expand Down Expand Up @@ -307,6 +335,7 @@ public void create() {
getCidrList());
this.setEntityId(result.getId());
this.setEntityUuid(result.getUuid());
_lbService.updateLoadBalancerConnectionSettings(result.getId(), getKeepAlive(), getIdleTimeout(), getKeepAliveTimeout(), false);
} catch (NetworkRuleConflictException e) {
logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,54 @@ public class UpdateLoadBalancerRuleCmd extends BaseAsyncCustomIdCmd {
@Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING, description = "the cidr list to forward traffic from", since = "4.22")
private List<String> cidrList;

@Parameter(name = ApiConstants.KEEPALIVE, type = CommandType.BOOLEAN, since = "24.0",
description = "Whether the load balancer keeps client connections open between requests. "
+ "Only applies to rules the router serves in HTTP mode. If not set, the rule's current value is kept; "
+ "use cleanupconnectionsettings to go back to the network offering's setting.")
private Boolean keepAlive;

@Parameter(name = ApiConstants.IDLE_TIMEOUT, type = CommandType.LONG, since = "24.0",
description = "How long an idle connection is held open, in milliseconds. Use 0 for infinite. "
+ "If not set, the rule's current value is kept; use cleanupconnectionsettings to go back to "
+ "the global setting network.loadbalancer.haproxy.idle.timeout.")
private Long idleTimeout;

@Parameter(name = ApiConstants.KEEPALIVE_TIMEOUT, type = CommandType.LONG, since = "24.0",
description = "How long an idle keepalive connection is held open waiting for the next request, "
+ "in milliseconds. Only applies to rules the router serves in HTTP mode. "
+ "If not set, the rule's current value is kept; use cleanupconnectionsettings to go back to "
+ "following idletimeout.")
private Long keepAliveTimeout;

@Parameter(name = ApiConstants.CLEAN_UP_CONNECTION_SETTINGS, type = CommandType.BOOLEAN, since = "24.0",
description = "If true, the rule's own keepalive, idletimeout and keepalivetimeout are removed, so the rule goes back "
+ "to the network offering and global settings. Any of the three passed in the same call are then set again, "
+ "so a single call can reset one and keep the others. If false or not set, no action.")
private Boolean cleanupConnectionSettings;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////

public String getAlgorithm() {
return algorithm;
}
public Boolean getKeepAlive() {
return keepAlive;
}

public Long getIdleTimeout() {
return idleTimeout;
}
public Long getKeepAliveTimeout() {
return keepAliveTimeout;
}

public boolean isCleanupConnectionSettings() {
return Boolean.TRUE.equals(cleanupConnectionSettings);
}



public String getDescription() {
return description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ public class LoadBalancerResponse extends BaseResponse implements ControlledEnti
@Param(description = "The ID of the guest Network the LB rule belongs to")
private String networkId;

@SerializedName(ApiConstants.KEEPALIVE)
@Param(description = "whether the load balancer keeps client connections open between requests, unset means the network offering's setting is used", since = "24.0")
private Boolean keepAlive;

@SerializedName(ApiConstants.IDLE_TIMEOUT)
@Param(description = "how long an idle connection is held open, in milliseconds, unset means the global setting is used", since = "24.0")
private Long idleTimeout;

@SerializedName(ApiConstants.KEEPALIVE_TIMEOUT)
@Param(description = "how long an idle keepalive connection is held open waiting for the next request, in milliseconds", since = "24.0")
private Long keepAliveTimeout;

@SerializedName(ApiConstants.CIDR_LIST)
@Param(description = "The CIDR list to allow traffic, all other CIDRs will be blocked. Multiple entries must be separated by a single comma character (,).")
private String cidrList;
Expand Down Expand Up @@ -143,6 +155,18 @@ public void setCidrList(String cidrs) {
this.cidrList = cidrs;
}

public void setKeepAlive(Boolean keepAlive) {
this.keepAlive = keepAlive;
}

public void setIdleTimeout(Long idleTimeout) {
this.idleTimeout = idleTimeout;
}

public void setKeepAliveTimeout(Long keepAliveTimeout) {
this.keepAliveTimeout = keepAliveTimeout;
}

public void setAlgorithm(String algorithm) {
this.algorithm = algorithm;
}
Expand Down
Loading
Loading