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
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public class APIChangeLoadBalancerListenerMsg extends APIMessage implements Load
@APIParam(required = false)
private List<String> httpCompressAlgos;

@APIParam(validValues = {LoadBalancerConstants.FORWARD_MODE_FULL_NAT, LoadBalancerConstants.FORWARD_MODE_NAT, LoadBalancerConstants.FORWARD_MODE_DR}, required = false)
private String forwardMode;

@APINoSee
private String loadBalancerUuid;

Expand Down Expand Up @@ -318,6 +321,14 @@ public void setHttpCompressAlgos(List<String> httpCompressAlgos) {
this.httpCompressAlgos = httpCompressAlgos;
}

public String getForwardMode() {
return forwardMode;
}

public void setForwardMode(String forwardMode) {
this.forwardMode = forwardMode;
}

public static APIChangeLoadBalancerListenerMsg __example__() {
APIChangeLoadBalancerListenerMsg msg = new APIChangeLoadBalancerListenerMsg();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ doc {
optional true
since "3.9"
}
column {
name "forwardMode"
enclosedIn "changeLoadBalancerListener"
desc "监听器使用 IPVS 数据平面时的转发模式。该参数只允许在创建监听器时指定,创建后不允许修改。"
location "body"
type "String"
optional true
since "5.5.28"
values ("full_nat","nat","dr")
}
column {
name "aclStatus"
enclosedIn "changeLoadBalancerListener"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ doc {
column {
name "forwardMode"
enclosedIn "params"
desc "监听器使用 IPVS 数据平面时的转发模式。当前 TCP IPVS 监听器支持 full_nat。"
desc "监听器使用 IPVS 数据平面时的转发模式。当前 TCP IPVS 监听器支持 full_nat、nat、dr。"
location "body"
type "String"
optional true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,21 +785,21 @@ private boolean hasIpv6ServerIp(String serverGroupUuid) {
private void validateTcpIpvsDoesNotUseIpv6Vip(LoadBalancerVO lbVO) {
if (lbVO != null && !StringUtils.isEmpty(lbVO.getIpv6VipUuid())) {
throw new ApiMessageInterceptionException(
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10179, "tcp ipvs listener doesn't support ipv6 vip"));
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10180, "tcp ipvs listener doesn't support ipv6 vip"));
}
}

private void validateTcpIpvsDoesNotUseIpv6ServerGroup(LoadBalancerServerGroupVO groupVO) {
if (groupVO != null && groupVO.getIpVersion() != null && IPv6Constants.IPv6 == groupVO.getIpVersion()) {
throw new ApiMessageInterceptionException(
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10179, "tcp ipvs listener doesn't support ipv6 server group"));
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10181, "tcp ipvs listener doesn't support ipv6 server group"));
}
}

private void validateTcpIpvsDoesNotUseIpv6BackendIp(String ipAddress) {
if (IPv6NetworkUtils.isIpv6Address(ipAddress)) {
throw new ApiMessageInterceptionException(
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10179, "tcp ipvs listener doesn't support ipv6 backend server ip"));
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10182, "tcp ipvs listener doesn't support ipv6 backend server ip"));
}
}

Expand Down Expand Up @@ -899,29 +899,33 @@ private void validate(APICreateLoadBalancerListenerMsg msg) {
if (LoadBalancerConstants.DATA_PLANE_IPVS.equals(msg.getDataPlane())) {
if (!LB_PROTOCOL_TCP.equals(msg.getProtocol())) {
throw new ApiMessageInterceptionException(
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10179, "data plane [%s] only supports tcp listener", msg.getDataPlane()));
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10183, "data plane [%s] only supports tcp listener", msg.getDataPlane()));
}
validateTcpIpvsDoesNotUseIpv6Vip(lbVO);

if (msg.getForwardMode() == null) {
msg.setForwardMode(LoadBalancerConstants.FORWARD_MODE_FULL_NAT);
}

if (!LoadBalancerConstants.FORWARD_MODE_FULL_NAT.equals(msg.getForwardMode())) {
List<String> supportedForwardModes = Arrays.asList(
LoadBalancerConstants.FORWARD_MODE_FULL_NAT,
LoadBalancerConstants.FORWARD_MODE_NAT,
LoadBalancerConstants.FORWARD_MODE_DR);
if (!supportedForwardModes.contains(msg.getForwardMode())) {
throw new ApiMessageInterceptionException(
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10179, "TCP IPVS only supports forwardMode[%s] in current version, but got [%s]",
LoadBalancerConstants.FORWARD_MODE_FULL_NAT, msg.getForwardMode()));
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10184, "TCP IPVS only supports forwardMode%s, but got [%s]",
supportedForwardModes, msg.getForwardMode()));
}

} else {
if (!LoadBalancerConstants.DATA_PLANE_HAPROXY.equals(msg.getDataPlane())) {
throw new ApiMessageInterceptionException(
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10179, "invalid dataPlane[%s], valid dataPlanes are [haproxy, ipvs]", msg.getDataPlane()));
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10185, "invalid dataPlane[%s], valid dataPlanes are [haproxy, ipvs]", msg.getDataPlane()));
}

if (msg.getForwardMode() != null) {
throw new ApiMessageInterceptionException(
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10179, "forwardMode is only supported when dataPlane is ipvs"));
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10186, "forwardMode is only supported when dataPlane is ipvs"));
}
}
String dataPlane = msg.getDataPlane();
Expand Down Expand Up @@ -960,7 +964,11 @@ private void validate(APICreateLoadBalancerListenerMsg msg) {
if (isTcpIpvsListener(msg.getProtocol(), dataPlane) &&
(hasHttpHealthCheckParameters(msg) || hasTag(msg, LoadBalancerSystemTags.HEALTH_PARAMETER))) {
throw new ApiMessageInterceptionException(
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10179, "tcp ipvs listener doesn't support http health check parameters"));
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10187, "tcp ipvs listener doesn't support http health check parameters"));
}
if (isTcpIpvsListener(msg.getProtocol(), dataPlane) && hasTag(msg, LoadBalancerSystemTags.HEALTH_TIMEOUT)) {
throw new ApiMessageInterceptionException(
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10189, "tcp ipvs listener doesn't support healthCheckTimeout"));
}

if (isHealthCheckProtocolNotSupportedByListenerProtocol(msg.getProtocol(), dataPlane, msg.getHealthCheckProtocol())) {
Expand Down Expand Up @@ -1031,12 +1039,14 @@ private void validate(APICreateLoadBalancerListenerMsg msg) {
)
);

insertTagIfNotExisting(
msg, LoadBalancerSystemTags.HEALTH_TIMEOUT,
LoadBalancerSystemTags.HEALTH_TIMEOUT.instantiateTag(
map(e(LoadBalancerSystemTags.HEALTH_TIMEOUT_TOKEN, LoadBalancerGlobalConfig.HEALTH_TIMEOUT.value(Long.class)))
)
);
if (!isTcpIpvsListener(msg.getProtocol(), dataPlane)) {
insertTagIfNotExisting(
msg, LoadBalancerSystemTags.HEALTH_TIMEOUT,
LoadBalancerSystemTags.HEALTH_TIMEOUT.instantiateTag(
map(e(LoadBalancerSystemTags.HEALTH_TIMEOUT_TOKEN, LoadBalancerGlobalConfig.HEALTH_TIMEOUT.value(Long.class)))
)
);
}

insertTagIfNotExisting(
msg, LoadBalancerSystemTags.UNHEALTHY_THRESHOLD,
Expand Down Expand Up @@ -1451,6 +1461,11 @@ private void validate(APIRemoveCertificateFromLoadBalancerListenerMsg msg) {
}

private void validate(APIChangeLoadBalancerListenerMsg msg) {
if (msg.getForwardMode() != null) {
throw new ApiMessageInterceptionException(
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10188, "forwardMode cannot be changed after load balancer listener is created"));
}

normalizeChangeHealthCheckTarget(msg);
String target = msg.getHealthCheckTarget();
if (target != null) {
Expand Down Expand Up @@ -1632,7 +1647,11 @@ private void validate(APIChangeLoadBalancerListenerMsg msg) {

if (isTcpIpvsListener(listenerVO.getProtocol(), dataPlane) && hasHttpHealthCheckParameters(msg)) {
throw new ApiMessageInterceptionException(
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10179, "tcp ipvs listener doesn't support http health check parameters"));
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10187, "tcp ipvs listener doesn't support http health check parameters"));
}
if (isTcpIpvsListener(listenerVO.getProtocol(), dataPlane) && msg.getHealthCheckTimeout() != null) {
throw new ApiMessageInterceptionException(
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10189, "tcp ipvs listener doesn't support healthCheckTimeout"));
}

if (msg.getHealthCheckProtocol() != null) {
Expand Down Expand Up @@ -2056,7 +2075,7 @@ private void validate(APIAddServerGroupToLoadBalancerListenerMsg msg){
validateTcpIpvsDoesNotUseIpv6ServerGroup(groupVO);
if (hasIpv6ServerIp(msg.getServerGroupUuid())) {
throw new ApiMessageInterceptionException(
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10179, "tcp ipvs listener doesn't support ipv6 backend server ip"));
operr(ORG_ZSTACK_NETWORK_SERVICE_LB_10182, "tcp ipvs listener doesn't support ipv6 backend server ip"));
}
}
if (listenerVO.getProtocol().equals(LB_PROTOCOL_UDP)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,9 @@ private void createListener(final APICreateLoadBalancerListenerMsg msg, final No

tagMgr.createNonInherentSystemTags(msg.getSystemTags(), vo.getUuid(), LoadBalancerListenerVO.class.getSimpleName());
vo = dbf.updateAndRefresh(vo);
evt.setInventory(LoadBalancerListenerInventory.valueOf(vo));
LoadBalancerListenerInventory inv = LoadBalancerListenerInventory.valueOf(vo);
inv.applyTcpIpvsSupportedParameterSystemTags(msg.getSystemTags());
evt.setInventory(inv);
bus.publish(evt);
completion.done();
}
Expand Down Expand Up @@ -2509,7 +2511,9 @@ public void run(MessageReply reply) {
}
}
} else {
evt.setInventory(LoadBalancerListenerInventory.valueOf(lblVo));
LoadBalancerListenerInventory inv = LoadBalancerListenerInventory.valueOf(lblVo);
inv.applyTcpIpvsSupportedParameters(msg.getBalancerAlgorithm(), msg.getMaxConnection());
evt.setInventory(inv);
}
bus.publish(evt);
}
Expand All @@ -2518,7 +2522,9 @@ public void run(MessageReply reply) {
chain.next();
return;
}
evt.setInventory( LoadBalancerListenerInventory.valueOf(lblVo));
LoadBalancerListenerInventory inv = LoadBalancerListenerInventory.valueOf(lblVo);
inv.applyTcpIpvsSupportedParameters(msg.getBalancerAlgorithm(), msg.getMaxConnection());
evt.setInventory(inv);
bus.publish(evt);
chain.next();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class LoadBalancerListenerInventory implements Serializable {
private String protocol;
private String dataPlane;
private String forwardMode;
private String balancerAlgorithm;
private Integer maxConnection;
private String serverGroupUuid;
private Timestamp createDate;
private Timestamp lastOpDate;
Expand All @@ -61,6 +63,13 @@ public static LoadBalancerListenerInventory valueOf(LoadBalancerListenerVO vo) {
LoadBalancerConstants.DATA_PLANE_IPVS.equals(vo.getDataPlane())) {
inv.setDataPlane(vo.getDataPlane());
inv.setForwardMode(vo.getForwardMode());
inv.setBalancerAlgorithm(LoadBalancerSystemTags.BALANCER_ALGORITHM.getTokenByResourceUuid(
vo.getUuid(), LoadBalancerSystemTags.BALANCER_ALGORITHM_TOKEN));
String maxConnection = LoadBalancerSystemTags.MAX_CONNECTION.getTokenByResourceUuid(
vo.getUuid(), LoadBalancerSystemTags.MAX_CONNECTION_TOKEN);
if (maxConnection != null) {
inv.setMaxConnection(Integer.valueOf(maxConnection));
}
}
inv.setSecurityPolicyType(vo.getSecurityPolicyType());
inv.setName(vo.getName());
Expand Down Expand Up @@ -99,6 +108,35 @@ public static List<LoadBalancerListenerInventory> valueOf(Collection<LoadBalance
return invs;
}

public void applyTcpIpvsSupportedParameters(String balancerAlgorithm, Integer maxConnection) {
if (!LoadBalancerConstants.LB_PROTOCOL_TCP.equals(protocol) ||
!LoadBalancerConstants.DATA_PLANE_IPVS.equals(dataPlane)) {
return;
}

if (balancerAlgorithm != null) {
setBalancerAlgorithm(balancerAlgorithm);
}
if (maxConnection != null) {
setMaxConnection(maxConnection);
}
}

public void applyTcpIpvsSupportedParameterSystemTags(Collection<String> systemTags) {
if (systemTags == null || !LoadBalancerConstants.LB_PROTOCOL_TCP.equals(protocol) ||
!LoadBalancerConstants.DATA_PLANE_IPVS.equals(dataPlane)) {
return;
}

for (String tag : systemTags) {
if (tag.startsWith(LoadBalancerSystemTags.BALANCER_ALGORITHM_TOKEN + "::")) {
setBalancerAlgorithm(tag.substring((LoadBalancerSystemTags.BALANCER_ALGORITHM_TOKEN + "::").length()));
} else if (tag.startsWith(LoadBalancerSystemTags.MAX_CONNECTION_TOKEN + "::")) {
setMaxConnection(Integer.valueOf(tag.substring((LoadBalancerSystemTags.MAX_CONNECTION_TOKEN + "::").length())));
}
}
}

public List<LoadBalancerListenerVmNicRefInventory> getVmNicRefs() {
return vmNicRefs;
}
Expand Down Expand Up @@ -187,6 +225,22 @@ public void setForwardMode(String forwardMode) {
this.forwardMode = forwardMode;
}

public String getBalancerAlgorithm() {
return balancerAlgorithm;
}

public void setBalancerAlgorithm(String balancerAlgorithm) {
this.balancerAlgorithm = balancerAlgorithm;
}

public Integer getMaxConnection() {
return maxConnection;
}

public void setMaxConnection(Integer maxConnection) {
this.maxConnection = maxConnection;
}

public String getSecurityPolicyType() {
return securityPolicyType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public Result throwExceptionIfError() {
@Param(required = false, nonempty = false, nullElements = false, emptyString = true, noTrim = false)
public java.util.List httpCompressAlgos;

@Param(required = false, validValues = {"full_nat","nat","dr"}, nonempty = false, nullElements = false, emptyString = true, noTrim = false)
public java.lang.String forwardMode;

@Param(required = false)
public java.util.List systemTags;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ public java.lang.String getForwardMode() {
return this.forwardMode;
}

public java.lang.String balancerAlgorithm;
public void setBalancerAlgorithm(java.lang.String balancerAlgorithm) {
this.balancerAlgorithm = balancerAlgorithm;
}
public java.lang.String getBalancerAlgorithm() {
return this.balancerAlgorithm;
}

public java.lang.Integer maxConnection;
public void setMaxConnection(java.lang.Integer maxConnection) {
this.maxConnection = maxConnection;
}
public java.lang.Integer getMaxConnection() {
return this.maxConnection;
}

public java.lang.String serverGroupUuid;
public void setServerGroupUuid(java.lang.String serverGroupUuid) {
this.serverGroupUuid = serverGroupUuid;
Expand Down
Loading