Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #12555] SwitchManager support http、tcp、mysql HealthParams and pushCSharpVersion update #12574

Merged
merged 1 commit into from
Sep 2, 2024
Merged
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 @@ -35,6 +35,8 @@ public class SwitchEntry {

public static final String CLIENT_C = "c";

public static final String CLIENT_CSHARP = "csharp";

public static final String CLIENT_GO = "go";

public static final String CLIENT_PYTHON = "python";
Expand Down Expand Up @@ -65,6 +67,12 @@ public class SwitchEntry {

public static final String ENABLE_STANDALONE = "enableStandalone";

public static final String HTTP_HEALTH_PARAMS = "httpHealthParams";

public static final String TCP_HEALTH_PARAMS = "tcpHealthParams";

public static final String MYSQL_HEALTH_PARAMS = "mysqlHealthParams";

public static final int MIN_PUSH_CACHE_TIME_MIILIS = 10000;

public static final int MIN_CACHE_TIME_MIILIS = 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.exception.runtime.NacosDeserializationException;
import com.alibaba.nacos.api.exception.runtime.NacosRuntimeException;
import com.alibaba.nacos.common.utils.ByteUtils;
import com.alibaba.nacos.common.utils.ConvertUtils;
Expand Down Expand Up @@ -110,31 +111,6 @@ public void update(String entry, String value, boolean debug) throws Exception {

SwitchDomain tempSwitchDomain = this.switchDomain.clone();

if (SwitchEntry.BATCH.equals(entry)) {
//batch update
SwitchDomain dom = JacksonUtils.toObj(value, SwitchDomain.class);
dom.setEnableStandalone(tempSwitchDomain.isEnableStandalone());
if (dom.getHttpHealthParams().getMin() < SwitchDomain.HttpHealthParams.MIN_MIN
|| dom.getTcpHealthParams().getMin() < SwitchDomain.HttpHealthParams.MIN_MIN) {

throw new IllegalArgumentException("min check time for http or tcp is too small(<500)");
}

if (dom.getHttpHealthParams().getMax() < SwitchDomain.HttpHealthParams.MIN_MAX
|| dom.getTcpHealthParams().getMax() < SwitchDomain.HttpHealthParams.MIN_MAX) {

throw new IllegalArgumentException("max check time for http or tcp is too small(<3000)");
}

if (dom.getHttpHealthParams().getFactor() < 0 || dom.getHttpHealthParams().getFactor() > 1
|| dom.getTcpHealthParams().getFactor() < 0 || dom.getTcpHealthParams().getFactor() > 1) {

throw new IllegalArgumentException("malformed factor");
}

tempSwitchDomain = dom;
}

if (entry.equals(SwitchEntry.DISTRO_THRESHOLD)) {
float threshold = Float.parseFloat(value);
if (threshold <= 0) {
Expand Down Expand Up @@ -166,6 +142,8 @@ public void update(String entry, String value, boolean debug) throws Exception {
tempSwitchDomain.setPushCVersion(version);
} else if (StringUtils.equals(SwitchEntry.CLIENT_GO, type)) {
tempSwitchDomain.setPushGoVersion(version);
} else if (StringUtils.equals(SwitchEntry.CLIENT_CSHARP, type)) {
tempSwitchDomain.setPushCSharpVersion(version);
} else {
throw new IllegalArgumentException("unsupported client type: " + type);
}
Expand Down Expand Up @@ -310,6 +288,24 @@ public void update(String entry, String value, boolean debug) throws Exception {
tempSwitchDomain.setAutoChangeHealthCheckEnabled(ConvertUtils.toBoolean(value));
}

try {
if (SwitchEntry.HTTP_HEALTH_PARAMS.equals(entry)) {
SwitchDomain.HttpHealthParams httpHealthParams = JacksonUtils.toObj(value, SwitchDomain.HttpHealthParams.class);
tempSwitchDomain.setHttpHealthParams(httpHealthParams);
validateHealthParams(httpHealthParams);
}
if (SwitchEntry.TCP_HEALTH_PARAMS.equals(entry)) {
SwitchDomain.TcpHealthParams tcpHealthParams = JacksonUtils.toObj(value, SwitchDomain.TcpHealthParams.class);
tempSwitchDomain.setTcpHealthParams(tcpHealthParams);
validateHealthParams(tcpHealthParams);
}
if (SwitchEntry.MYSQL_HEALTH_PARAMS.equals(entry)) {
tempSwitchDomain.setMysqlHealthParams(JacksonUtils.toObj(value, SwitchDomain.MysqlHealthParams.class));
}
} catch (NacosDeserializationException e) {
throw new IllegalArgumentException("json param invalid.");
}

if (debug) {
update(tempSwitchDomain);
} else {
Expand Down Expand Up @@ -356,12 +352,34 @@ public void update(SwitchDomain newSwitchDomain) {
switchDomain.setPushJavaVersion(newSwitchDomain.getPushJavaVersion());
switchDomain.setPushPythonVersion(newSwitchDomain.getPushPythonVersion());
switchDomain.setPushCVersion(newSwitchDomain.getPushCVersion());
switchDomain.setPushCSharpVersion(newSwitchDomain.getPushCSharpVersion());
switchDomain.setEnableAuthentication(newSwitchDomain.isEnableAuthentication());
switchDomain.setOverriddenServerStatus(newSwitchDomain.getOverriddenServerStatus());
switchDomain.setDefaultInstanceEphemeral(newSwitchDomain.isDefaultInstanceEphemeral());
switchDomain.setLightBeatEnabled(newSwitchDomain.isLightBeatEnabled());
}

/**
* Validate health params.
*
* @param healthParams health params
*/
public void validateHealthParams(SwitchDomain.HealthParams healthParams) {
if (healthParams.getMin() < SwitchDomain.HttpHealthParams.MIN_MIN) {
throw new IllegalArgumentException("min check time for http or tcp is too small(<500)");
}

if (healthParams.getMax() < SwitchDomain.HttpHealthParams.MIN_MAX) {

throw new IllegalArgumentException("max check time for http or tcp is too small(<3000)");
}

if (healthParams.getFactor() < 0 || healthParams.getFactor() > 1) {

throw new IllegalArgumentException("malformed factor");
}
}

private void updateWithConsistency(SwitchDomain tempSwitchDomain) throws NacosException {
try {
final BatchWriteRequest req = new BatchWriteRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class UpdateSwitchForm implements Serializable {

private static final long serialVersionUID = -1580959130954136990L;

private Boolean debug;
private boolean debug;

private String entry;

Expand All @@ -58,11 +58,11 @@ public void validate() throws NacosApiException {
}
}

public Boolean getDebug() {
public boolean getDebug() {
return debug;
}

public void setDebug(Boolean debug) {
public void setDebug(boolean debug) {
this.debug = debug;
}

Expand Down
Loading