fix checkstyle and fix bug
This commit is contained in:
parent
fc3bb2f42c
commit
d4e9b836d2
@ -16,11 +16,11 @@
|
||||
|
||||
package com.alibaba.nacos.api.remote.request;
|
||||
|
||||
import com.alibaba.nacos.api.ability.ClientAbilities;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ConnectionSetupRequestTest extends BasicRequestTest {
|
||||
|
||||
@ -28,7 +28,7 @@ public class ConnectionSetupRequestTest extends BasicRequestTest {
|
||||
public void testSerialize() throws Exception {
|
||||
ConnectionSetupRequest request = new ConnectionSetupRequest();
|
||||
request.setClientVersion("2.2.2");
|
||||
request.setAbilities(new ClientAbilities());
|
||||
request.setAbilityTable(new HashMap<>());
|
||||
request.setTenant("testNamespaceId");
|
||||
request.setLabels(Collections.singletonMap("labelKey", "labelValue"));
|
||||
request.setRequestId("1");
|
||||
@ -37,7 +37,7 @@ public class ConnectionSetupRequestTest extends BasicRequestTest {
|
||||
Assert.assertTrue(json.contains("\"clientVersion\":\"2.2.2\""));
|
||||
Assert.assertTrue(json.contains("\"tenant\":\"testNamespaceId\""));
|
||||
Assert.assertTrue(json.contains("\"labels\":{\"labelKey\":\"labelValue\"}"));
|
||||
Assert.assertTrue(json.contains("\"abilities\":{"));
|
||||
Assert.assertTrue(json.contains("\"abilityTable\":{"));
|
||||
Assert.assertTrue(json.contains("\"module\":\"internal\""));
|
||||
Assert.assertTrue(json.contains("\"requestId\":\"1\""));
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class ServerCheckResponseTest {
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws JsonProcessingException {
|
||||
ServerCheckResponse response = new ServerCheckResponse("35643245_1.1.1.1_3306");
|
||||
ServerCheckResponse response = new ServerCheckResponse("35643245_1.1.1.1_3306", false);
|
||||
String actual = mapper.writeValueAsString(response);
|
||||
assertTrue(actual.contains("\"connectionId\":\"35643245_1.1.1.1_3306\""));
|
||||
}
|
||||
|
@ -66,7 +66,6 @@ import com.alibaba.nacos.common.utils.MD5Utils;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.alibaba.nacos.common.utils.ThreadUtils;
|
||||
import com.alibaba.nacos.common.utils.VersionUtils;
|
||||
import com.alibaba.nacos.plugin.auth.api.RequestResource;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -23,10 +23,10 @@ import com.alibaba.nacos.client.env.NacosClientProperties;
|
||||
import com.alibaba.nacos.plugin.auth.api.RequestResource;
|
||||
import com.alibaba.nacos.client.config.filter.impl.ConfigResponse;
|
||||
import com.alibaba.nacos.client.security.SecurityProxy;
|
||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||
import com.alibaba.nacos.common.utils.ConvertUtils;
|
||||
import com.alibaba.nacos.common.utils.MD5Utils;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -23,7 +23,6 @@ import com.alibaba.nacos.client.env.NacosClientProperties;
|
||||
import com.alibaba.nacos.client.utils.ContextPathUtil;
|
||||
import com.alibaba.nacos.client.utils.EnvUtil;
|
||||
import com.alibaba.nacos.client.utils.LogUtils;
|
||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||
import com.alibaba.nacos.client.utils.TemplateUtils;
|
||||
import com.alibaba.nacos.common.http.HttpRestResult;
|
||||
import com.alibaba.nacos.common.http.client.NacosRestTemplate;
|
||||
@ -48,6 +47,7 @@ import java.util.StringTokenizer;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import com.alibaba.nacos.client.utils.ParamUtil;
|
||||
|
||||
import static com.alibaba.nacos.common.constant.RequestUrlConstants.HTTPS_PREFIX;
|
||||
import static com.alibaba.nacos.common.constant.RequestUrlConstants.HTTP_PREFIX;
|
||||
|
@ -25,8 +25,9 @@ import com.alibaba.nacos.api.remote.request.Request;
|
||||
import com.alibaba.nacos.api.remote.response.Response;
|
||||
import com.alibaba.nacos.client.naming.remote.TestConnection;
|
||||
import com.alibaba.nacos.common.remote.ConnectionType;
|
||||
import com.alibaba.nacos.common.remote.client.Connection;
|
||||
import com.alibaba.nacos.common.remote.client.RpcClient;
|
||||
import com.alibaba.nacos.common.remote.client.Connection;
|
||||
import com.alibaba.nacos.common.remote.client.RpcClientConfig;
|
||||
import com.alibaba.nacos.common.remote.client.ServerListFactory;
|
||||
import com.alibaba.nacos.common.remote.client.ServerRequestHandler;
|
||||
import org.junit.After;
|
||||
@ -34,6 +35,7 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AbilityTest {
|
||||
|
||||
@ -43,7 +45,42 @@ public class AbilityTest {
|
||||
|
||||
@Test
|
||||
public void testReceive() throws Exception {
|
||||
rpcClient = new RpcClient("name") {
|
||||
rpcClient = new RpcClient(new RpcClientConfig() {
|
||||
@Override
|
||||
public String name() {
|
||||
return "test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int retryTimes() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long timeOutMills() {
|
||||
return 3000L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long connectionKeepAlive() {
|
||||
return 5000L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int healthCheckRetryTimes() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long healthCheckTimeOut() {
|
||||
return 3000L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> labels() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
}) {
|
||||
|
||||
@Override
|
||||
public ConnectionType getConnectionType() {
|
||||
|
@ -43,7 +43,6 @@ import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.alibaba.nacos.common.utils.VersionUtils;
|
||||
import com.alibaba.nacos.common.utils.TlsTypeResolve;
|
||||
import com.alibaba.nacos.common.utils.ThreadFactoryBuilder;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import io.grpc.CompressorRegistry;
|
||||
import io.grpc.DecompressorRegistry;
|
||||
@ -65,7 +64,6 @@ import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
@ -421,9 +419,8 @@ public abstract class GrpcClient extends RpcClient {
|
||||
if (synResponse != null) {
|
||||
// try to wait for notify response
|
||||
synResponse.blocker.await(5000L, TimeUnit.MICROSECONDS);
|
||||
}
|
||||
// leave for adapting old version server
|
||||
else {
|
||||
} else {
|
||||
// leave for adapting old version server
|
||||
//wait to register connection setup
|
||||
Thread.sleep(100L);
|
||||
}
|
||||
@ -505,7 +502,7 @@ public abstract class GrpcClient extends RpcClient {
|
||||
|
||||
RpcClientTlsConfig tlsConfig = clientConfig.tlsConfig();
|
||||
if (!tlsConfig.getEnableTls()) {
|
||||
return Optional.absent();
|
||||
return Optional.empty();
|
||||
}
|
||||
try {
|
||||
SslContextBuilder builder = GrpcSslContexts.forClient();
|
||||
|
@ -31,16 +31,16 @@ server.port=8848
|
||||
|
||||
#*************** Config Module Related Configurations ***************#
|
||||
### Deprecated configuration property, it is recommended to use `spring.sql.init.platform` replaced.
|
||||
# spring.datasource.platform=mysql
|
||||
# nacos.plugin.datasource.log.enabled=true
|
||||
#spring.sql.init.platform=mysql
|
||||
### Count of DB:
|
||||
# db.num=1
|
||||
spring.datasource.platform=mysql
|
||||
nacos.plugin.datasource.log.enabled=true
|
||||
spring.sql.init.platform=mysql
|
||||
## Count of DB:
|
||||
db.num=1
|
||||
|
||||
### Connect URL of DB:
|
||||
# db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
|
||||
# db.user=nacos
|
||||
# db.password=nacos
|
||||
## Connect URL of DB:
|
||||
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
|
||||
db.user=root
|
||||
db.password=123456
|
||||
|
||||
#*************** Naming Module Related Configurations ***************#
|
||||
### Data dispatch task execution period in milliseconds:
|
||||
|
@ -56,7 +56,7 @@ public class Member implements Comparable<Member>, Cloneable, Serializable {
|
||||
@Deprecated
|
||||
private ServerAbilities abilities = new ServerAbilities();
|
||||
|
||||
private boolean supportRemoteConnection;
|
||||
private boolean grpcReportEnabled;
|
||||
|
||||
public Member() {
|
||||
String prefix = "nacos.core.member.meta.";
|
||||
@ -68,12 +68,12 @@ public class Member implements Comparable<Member>, Cloneable, Serializable {
|
||||
.put(MemberMetaDataConstants.WEIGHT, EnvUtil.getProperty(prefix + MemberMetaDataConstants.WEIGHT, "1"));
|
||||
}
|
||||
|
||||
public boolean isSupportRemoteConnection() {
|
||||
return supportRemoteConnection;
|
||||
public boolean isGrpcReportEnabled() {
|
||||
return grpcReportEnabled;
|
||||
}
|
||||
|
||||
public void setSupportRemoteConnection(boolean supportRemoteConnection) {
|
||||
this.supportRemoteConnection = supportRemoteConnection;
|
||||
public void setGrpcReportEnabled(boolean grpcReportEnabled) {
|
||||
this.grpcReportEnabled = grpcReportEnabled;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
@ -66,7 +66,7 @@ public class MemberUtil {
|
||||
oldMember.setExtendInfo(newMember.getExtendInfo());
|
||||
oldMember.setAddress(newMember.getAddress());
|
||||
oldMember.setAbilities(newMember.getAbilities());
|
||||
oldMember.setSupportRemoteConnection(newMember.isSupportRemoteConnection());
|
||||
oldMember.setGrpcReportEnabled(newMember.isGrpcReportEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,6 +95,8 @@ public class MemberUtil {
|
||||
extendInfo.put(MemberMetaDataConstants.RAFT_PORT, String.valueOf(calculateRaftPort(target)));
|
||||
extendInfo.put(MemberMetaDataConstants.READY_TO_UPGRADE, true);
|
||||
target.setExtendInfo(extendInfo);
|
||||
// use grpc to report default
|
||||
target.setGrpcReportEnabled(true);
|
||||
return target;
|
||||
}
|
||||
|
||||
@ -111,7 +113,7 @@ public class MemberUtil {
|
||||
|
||||
boolean oldVerJudge = member.getAbilities().getRemoteAbility().isSupportRemoteConnection();
|
||||
|
||||
return member.isSupportRemoteConnection() || oldVerJudge;
|
||||
return member.isGrpcReportEnabled() || oldVerJudge;
|
||||
}
|
||||
|
||||
public static int calculateRaftPort(Member member) {
|
||||
@ -281,7 +283,7 @@ public class MemberUtil {
|
||||
}
|
||||
|
||||
// if change
|
||||
if (expected.isSupportRemoteConnection() != actual.isSupportRemoteConnection()) {
|
||||
if (expected.isGrpcReportEnabled() != actual.isGrpcReportEnabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ public class ServerMemberManager implements ApplicationListener<WebServerInitial
|
||||
this.localAddress = InetUtils.getSelfIP() + ":" + port;
|
||||
this.self = MemberUtil.singleParse(this.localAddress);
|
||||
this.self.setExtendVal(MemberMetaDataConstants.VERSION, VersionUtils.version);
|
||||
this.self.setSupportRemoteConnection(true);
|
||||
this.self.setGrpcReportEnabled(true);
|
||||
|
||||
// init abilities.
|
||||
this.self.setAbilities(initMemberAbilities());
|
||||
@ -573,8 +573,9 @@ public class ServerMemberManager implements ApplicationListener<WebServerInitial
|
||||
Member target = members.get(cursor);
|
||||
|
||||
Loggers.CLUSTER.debug("report the metadata to the node : {}", target.getAddress());
|
||||
|
||||
if (target.getAbilities().getRemoteAbility().isGrpcReportEnabled()) {
|
||||
|
||||
// adapt old version
|
||||
if (target.getAbilities().getRemoteAbility().isGrpcReportEnabled() || target.isGrpcReportEnabled()) {
|
||||
reportByGrpc(target);
|
||||
} else {
|
||||
reportByHttp(target);
|
||||
@ -598,6 +599,9 @@ public class ServerMemberManager implements ApplicationListener<WebServerInitial
|
||||
Loggers.CLUSTER.warn("failed to report new info to target node : {}, result : {}",
|
||||
target.getAddress(), result);
|
||||
MemberUtil.onFail(ServerMemberManager.this, target);
|
||||
// try to connect by grpc next time, adapt old version
|
||||
target.setGrpcReportEnabled(true);
|
||||
target.getAbilities().getRemoteAbility().setGrpcReportEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -606,6 +610,9 @@ public class ServerMemberManager implements ApplicationListener<WebServerInitial
|
||||
Loggers.CLUSTER.error("failed to report new info to target node : {}, error : {}",
|
||||
target.getAddress(), ExceptionUtil.getAllExceptionMsg(throwable));
|
||||
MemberUtil.onFail(ServerMemberManager.this, target, throwable);
|
||||
// try to connect by grpc next time, adapt old version
|
||||
target.setGrpcReportEnabled(true);
|
||||
target.getAbilities().getRemoteAbility().setGrpcReportEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -616,6 +623,9 @@ public class ServerMemberManager implements ApplicationListener<WebServerInitial
|
||||
} catch (Throwable ex) {
|
||||
Loggers.CLUSTER.error("failed to report new info to target node by http : {}, error : {}",
|
||||
target.getAddress(), ExceptionUtil.getAllExceptionMsg(ex));
|
||||
// try to connect by grpc next time, adapt old version
|
||||
target.setGrpcReportEnabled(true);
|
||||
target.getAbilities().getRemoteAbility().setGrpcReportEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -643,6 +653,7 @@ public class ServerMemberManager implements ApplicationListener<WebServerInitial
|
||||
} catch (NacosException e) {
|
||||
if (e.getErrCode() == NacosException.NO_HANDLER) {
|
||||
target.getAbilities().getRemoteAbility().setGrpcReportEnabled(false);
|
||||
target.setGrpcReportEnabled(false);
|
||||
}
|
||||
Loggers.CLUSTER.error("failed to report new info to target node by grpc : {}, error : {}",
|
||||
target.getAddress(), ExceptionUtil.getAllExceptionMsg(e));
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
package com.alibaba.nacos.core.remote;
|
||||
|
||||
import com.alibaba.nacos.api.ability.ClientAbilities;
|
||||
import com.alibaba.nacos.api.remote.Requester;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -33,9 +33,10 @@ import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**.
|
||||
/**
|
||||
* test for ability in config.
|
||||
*
|
||||
* @author Daydreamer
|
||||
* @description
|
||||
* @date 2022/9/3 12:27
|
||||
**/
|
||||
public class AbilityConfigsTest {
|
||||
@ -72,9 +73,13 @@ public class AbilityConfigsTest {
|
||||
abilityConfigs.setAbilityHandlerRegistry(serverAbilityControlManager);
|
||||
this.serverAbilityControlManager = serverAbilityControlManager;
|
||||
}
|
||||
|
||||
|
||||
public void fill() throws NoSuchFieldException, IllegalAccessException {
|
||||
|
||||
/**
|
||||
* fill field.
|
||||
*
|
||||
* @throws Exception ignore
|
||||
*/
|
||||
public void fill() throws Exception {
|
||||
Field instanceField = ServerAbilities.class.getDeclaredField("INSTANCE");
|
||||
Field abilitiesField = AbstractAbilityRegistry.class.getDeclaredField("supportedAbilities");
|
||||
abilitiesField.setAccessible(true);
|
||||
@ -86,7 +91,7 @@ public class AbilityConfigsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadAbilities() throws NoSuchFieldException, IllegalAccessException, InterruptedException {
|
||||
public void testLoadAbilities() throws Exception {
|
||||
environment.setProperty(AbilityConfigs.PREFIX + AbilityKey.TEST_1.getName(), Boolean.TRUE.toString());
|
||||
environment.setProperty(AbilityConfigs.PREFIX + AbilityKey.TEST_2.getName(), Boolean.FALSE.toString());
|
||||
// test load
|
||||
|
@ -243,7 +243,7 @@ public class MemberUtilTest {
|
||||
@Test
|
||||
public void testIsBasicInfoChangedForChangedAbilities() {
|
||||
Member newMember = buildMember();
|
||||
newMember.getAbilities().getRemoteAbility().setSupportRemoteConnection(true);
|
||||
newMember.setGrpcReportEnabled(true);
|
||||
assertTrue(MemberUtil.isBasicInfoChanged(newMember, originalMember));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user