internalGetMutableHeaders() {
- onChanged();;
+ onChanged();
if (headers_ == null) {
headers_ = com.google.protobuf.MapField.newMapField(
HeadersDefaultEntryHolder.defaultEntry);
diff --git a/api/src/main/java/com/alibaba/nacos/api/grpc/auto/RequestGrpc.java b/api/src/main/java/com/alibaba/nacos/api/grpc/auto/RequestGrpc.java
index a6d4868e621..8c7b194919c 100644
--- a/api/src/main/java/com/alibaba/nacos/api/grpc/auto/RequestGrpc.java
+++ b/api/src/main/java/com/alibaba/nacos/api/grpc/auto/RequestGrpc.java
@@ -17,21 +17,14 @@
package com.alibaba.nacos.api.grpc.auto;
import static io.grpc.MethodDescriptor.generateFullMethodName;
-import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall;
-import static io.grpc.stub.ClientCalls.asyncClientStreamingCall;
-import static io.grpc.stub.ClientCalls.asyncServerStreamingCall;
import static io.grpc.stub.ClientCalls.asyncUnaryCall;
-import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
import static io.grpc.stub.ClientCalls.futureUnaryCall;
-import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
-import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
-import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
-import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
/**
+ *
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.14.0)",
diff --git a/api/src/main/java/com/alibaba/nacos/api/naming/NamingResponseCode.java b/api/src/main/java/com/alibaba/nacos/api/naming/NamingResponseCode.java
index 31e8f510253..0c6b31f9769 100644
--- a/api/src/main/java/com/alibaba/nacos/api/naming/NamingResponseCode.java
+++ b/api/src/main/java/com/alibaba/nacos/api/naming/NamingResponseCode.java
@@ -21,7 +21,7 @@
/**
* Business response code of naming module
*
- * Every code stays between 20001 to 29999.
+ *
Every code stays between 20001 and 29999.
*
* @author nkorange
* @author 1.2.0
diff --git a/api/src/main/java/com/alibaba/nacos/api/naming/pojo/ServiceInfo.java b/api/src/main/java/com/alibaba/nacos/api/naming/pojo/ServiceInfo.java
index 1b5281d42c3..4d8b13da19d 100644
--- a/api/src/main/java/com/alibaba/nacos/api/naming/pojo/ServiceInfo.java
+++ b/api/src/main/java/com/alibaba/nacos/api/naming/pojo/ServiceInfo.java
@@ -194,7 +194,7 @@ public boolean validate() {
continue;
}
- for (int i = 0; i < host.getWeight(); i++) {
+ if (host.getWeight() > 0) {
validHosts.add(host);
}
}
diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/RemoteConstants.java b/api/src/main/java/com/alibaba/nacos/api/remote/RemoteConstants.java
index 9016e86c72b..a5b22ffc2b4 100644
--- a/api/src/main/java/com/alibaba/nacos/api/remote/RemoteConstants.java
+++ b/api/src/main/java/com/alibaba/nacos/api/remote/RemoteConstants.java
@@ -38,4 +38,6 @@ public class RemoteConstants {
public static final String LABEL_MODULE_CONFIG = "config";
public static final String LABEL_MODULE_NAMING = "naming";
+
+ public static final String MONITOR_LABEL_NONE = "none";
}
diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/RpcScheduledExecutor.java b/api/src/main/java/com/alibaba/nacos/api/remote/RpcScheduledExecutor.java
index 05ed29500e4..af99df24fd1 100644
--- a/api/src/main/java/com/alibaba/nacos/api/remote/RpcScheduledExecutor.java
+++ b/api/src/main/java/com/alibaba/nacos/api/remote/RpcScheduledExecutor.java
@@ -31,12 +31,15 @@ public class RpcScheduledExecutor extends ScheduledThreadPoolExecutor {
public static final RpcScheduledExecutor TIMEOUT_SCHEDULER = new RpcScheduledExecutor(1,
"com.alibaba.nacos.remote.TimerScheduler");
+ public static final RpcScheduledExecutor CONTROL_SCHEDULER = new RpcScheduledExecutor(1,
+ "com.alibaba.nacos.control.DelayScheduler");
+
public static final RpcScheduledExecutor COMMON_SERVER_EXECUTOR = new RpcScheduledExecutor(1,
"com.alibaba.nacos.remote.ServerCommonScheduler");
public RpcScheduledExecutor(int corePoolSize, final String threadName) {
super(corePoolSize, new ThreadFactory() {
- private AtomicLong index = new AtomicLong();
+ private final AtomicLong index = new AtomicLong();
@Override
public Thread newThread(Runnable r) {
diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/request/ConnectResetRequest.java b/api/src/main/java/com/alibaba/nacos/api/remote/request/ConnectResetRequest.java
index 1a2e14424be..75c6fa0cade 100644
--- a/api/src/main/java/com/alibaba/nacos/api/remote/request/ConnectResetRequest.java
+++ b/api/src/main/java/com/alibaba/nacos/api/remote/request/ConnectResetRequest.java
@@ -30,11 +30,31 @@ public class ConnectResetRequest extends ServerRequest {
String serverPort;
+ String connectionId;
+
@Override
public String getModule() {
return INTERNAL_MODULE;
}
+ /**
+ * Getter method for property connectionId.
+ *
+ * @return property value of connectionId
+ */
+ public String getConnectionId() {
+ return connectionId;
+ }
+
+ /**
+ * Setter method for property connectionId.
+ *
+ * @param connectionId value to be assigned to property connectionId
+ */
+ public void setConnectionId(String connectionId) {
+ this.connectionId = connectionId;
+ }
+
/**
* Getter method for property serverIp.
*
diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/request/ConnectionSetupRequest.java b/api/src/main/java/com/alibaba/nacos/api/remote/request/ConnectionSetupRequest.java
index 56e94dad21f..3409728f576 100644
--- a/api/src/main/java/com/alibaba/nacos/api/remote/request/ConnectionSetupRequest.java
+++ b/api/src/main/java/com/alibaba/nacos/api/remote/request/ConnectionSetupRequest.java
@@ -16,8 +16,6 @@
package com.alibaba.nacos.api.remote.request;
-import com.alibaba.nacos.api.ability.ClientAbilities;
-
import java.util.HashMap;
import java.util.Map;
@@ -31,12 +29,12 @@ public class ConnectionSetupRequest extends InternalRequest {
private String clientVersion;
- private ClientAbilities abilities;
-
private String tenant;
private Map labels = new HashMap<>();
+ private Map abilityTable;
+
public ConnectionSetupRequest() {
}
@@ -64,11 +62,11 @@ public void setTenant(String tenant) {
this.tenant = tenant;
}
- public ClientAbilities getAbilities() {
- return abilities;
+ public Map getAbilityTable() {
+ return abilityTable;
}
- public void setAbilities(ClientAbilities abilities) {
- this.abilities = abilities;
+ public void setAbilityTable(Map abilityTable) {
+ this.abilityTable = abilityTable;
}
}
diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/request/RequestMeta.java b/api/src/main/java/com/alibaba/nacos/api/remote/request/RequestMeta.java
index 82eba58db1b..c633f893484 100644
--- a/api/src/main/java/com/alibaba/nacos/api/remote/request/RequestMeta.java
+++ b/api/src/main/java/com/alibaba/nacos/api/remote/request/RequestMeta.java
@@ -16,6 +16,9 @@
package com.alibaba.nacos.api.remote.request;
+import com.alibaba.nacos.api.ability.constant.AbilityKey;
+import com.alibaba.nacos.api.ability.constant.AbilityStatus;
+
import java.util.HashMap;
import java.util.Map;
@@ -34,7 +37,25 @@ public class RequestMeta {
private String clientVersion = "";
private Map labels = new HashMap<>();
-
+
+ private Map abilityTable;
+
+ public AbilityStatus getConnectionAbility(AbilityKey abilityKey) {
+ if (abilityTable == null || !abilityTable.containsKey(abilityKey.getName())) {
+ return AbilityStatus.UNKNOWN;
+ }
+ return abilityTable.get(abilityKey.getName()) ? AbilityStatus.SUPPORTED : AbilityStatus.NOT_SUPPORTED;
+ }
+
+ /**
+ * Setter method for property abilityTable.
+ *
+ * @param abilityTable property value of clientVersion
+ */
+ public void setAbilityTable(Map abilityTable) {
+ this.abilityTable = abilityTable;
+ }
+
/**
* Getter method for property clientVersion.
*
diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/request/SetupAckRequest.java b/api/src/main/java/com/alibaba/nacos/api/remote/request/SetupAckRequest.java
new file mode 100644
index 00000000000..cecdaa825d4
--- /dev/null
+++ b/api/src/main/java/com/alibaba/nacos/api/remote/request/SetupAckRequest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 1999-2022 Alibaba Group Holding Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.nacos.api.remote.request;
+
+import java.util.Map;
+
+import static com.alibaba.nacos.api.common.Constants.Remote.INTERNAL_MODULE;
+
+/**
+ * Server tells the client that the connection is established.
+ *
+ * @author Daydreamer.
+ * @date 2022/7/12 19:21
+ **/
+public class SetupAckRequest extends ServerRequest {
+
+ private Map abilityTable;
+
+ public SetupAckRequest() {
+ }
+
+ public SetupAckRequest(Map abilityTable) {
+ this.abilityTable = abilityTable;
+ }
+
+ public Map getAbilityTable() {
+ return abilityTable;
+ }
+
+ public void setAbilityTable(Map abilityTable) {
+ this.abilityTable = abilityTable;
+ }
+
+ @Override
+ public String getModule() {
+ return INTERNAL_MODULE;
+ }
+}
diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/response/ServerCheckResponse.java b/api/src/main/java/com/alibaba/nacos/api/remote/response/ServerCheckResponse.java
index fd3981cd18d..2b8e9fea84c 100644
--- a/api/src/main/java/com/alibaba/nacos/api/remote/response/ServerCheckResponse.java
+++ b/api/src/main/java/com/alibaba/nacos/api/remote/response/ServerCheckResponse.java
@@ -26,12 +26,15 @@ public class ServerCheckResponse extends Response {
private String connectionId;
+ private boolean supportAbilityNegotiation;
+
public ServerCheckResponse() {
}
- public ServerCheckResponse(String connectionId) {
+ public ServerCheckResponse(String connectionId, boolean supportAbilityNegotiation) {
this.connectionId = connectionId;
+ this.supportAbilityNegotiation = supportAbilityNegotiation;
}
public String getConnectionId() {
@@ -41,4 +44,12 @@ public String getConnectionId() {
public void setConnectionId(String connectionId) {
this.connectionId = connectionId;
}
+
+ public boolean isSupportAbilityNegotiation() {
+ return supportAbilityNegotiation;
+ }
+
+ public void setSupportAbilityNegotiation(boolean supportAbilityNegotiation) {
+ this.supportAbilityNegotiation = supportAbilityNegotiation;
+ }
}
diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/response/SetupAckResponse.java b/api/src/main/java/com/alibaba/nacos/api/remote/response/SetupAckResponse.java
new file mode 100644
index 00000000000..ce4abcb943f
--- /dev/null
+++ b/api/src/main/java/com/alibaba/nacos/api/remote/response/SetupAckResponse.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 1999-2022 Alibaba Group Holding Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.nacos.api.remote.response;
+
+/**.
+ * @author Daydreamer
+ * @description Server tells the client that the connection is established
+ * @date 2022/7/12 19:21
+ **/
+public class SetupAckResponse extends Response {
+
+}
diff --git a/api/src/main/java/com/alibaba/nacos/api/selector/Selector.java b/api/src/main/java/com/alibaba/nacos/api/selector/Selector.java
index 36c0f8ff5de..43eb5600262 100644
--- a/api/src/main/java/com/alibaba/nacos/api/selector/Selector.java
+++ b/api/src/main/java/com/alibaba/nacos/api/selector/Selector.java
@@ -64,7 +64,7 @@ public interface Selector extends Serializable {
String getType();
/**
- * Get the select context which usede by {@link #select(Object)}.
+ * Get the select context which used by {@link #select(Object)}.
*
* @return selector context type.
*/
diff --git a/api/src/main/resources/META-INF/services/com.alibaba.nacos.api.remote.Payload b/api/src/main/resources/META-INF/services/com.alibaba.nacos.api.remote.Payload
index d838e65ea2c..5e9552afd20 100644
--- a/api/src/main/resources/META-INF/services/com.alibaba.nacos.api.remote.Payload
+++ b/api/src/main/resources/META-INF/services/com.alibaba.nacos.api.remote.Payload
@@ -22,6 +22,8 @@ com.alibaba.nacos.api.remote.request.PushAckRequest
com.alibaba.nacos.api.remote.request.ServerCheckRequest
com.alibaba.nacos.api.remote.request.ServerLoaderInfoRequest
com.alibaba.nacos.api.remote.request.ServerReloadRequest
+com.alibaba.nacos.api.remote.request.SetupAckRequest
+com.alibaba.nacos.api.remote.response.SetupAckResponse
com.alibaba.nacos.api.remote.response.ClientDetectionResponse
com.alibaba.nacos.api.remote.response.ConnectResetResponse
com.alibaba.nacos.api.remote.response.ErrorResponse
diff --git a/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/ClusterClientAbilitiesTest.java b/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/ClusterClientAbilitiesTest.java
new file mode 100644
index 00000000000..b6ec8a54e66
--- /dev/null
+++ b/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/ClusterClientAbilitiesTest.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 1999-2023 Alibaba Group Holding Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.nacos.api.ability.register.impl;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class ClusterClientAbilitiesTest {
+
+ @Test
+ public void testGetStaticAbilities() {
+ // TODO add the cluster client abilities.
+ assertTrue(ClusterClientAbilities.getStaticAbilities().isEmpty());
+ }
+}
\ No newline at end of file
diff --git a/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/SdkClientAbilitiesTest.java b/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/SdkClientAbilitiesTest.java
new file mode 100644
index 00000000000..ea9cabd4653
--- /dev/null
+++ b/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/SdkClientAbilitiesTest.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 1999-2023 Alibaba Group Holding Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.nacos.api.ability.register.impl;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class SdkClientAbilitiesTest {
+
+ @Test
+ public void testGetStaticAbilities() {
+ // TODO add the sdk client abilities.
+ assertTrue(SdkClientAbilities.getStaticAbilities().isEmpty());
+ }
+}
\ No newline at end of file
diff --git a/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/ServerAbilitiesTest.java b/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/ServerAbilitiesTest.java
new file mode 100644
index 00000000000..c8d15261cb4
--- /dev/null
+++ b/api/src/test/java/com/alibaba/nacos/api/ability/register/impl/ServerAbilitiesTest.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 1999-2023 Alibaba Group Holding Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.nacos.api.ability.register.impl;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class ServerAbilitiesTest {
+
+ @Test
+ public void testGetStaticAbilities() {
+ // TODO add the server abilities.
+ assertTrue(ServerAbilities.getStaticAbilities().isEmpty());
+ }
+}
\ No newline at end of file
diff --git a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/cluster/ConfigChangeClusterSyncRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/cluster/ConfigChangeClusterSyncRequestTest.java
index 6784dc2c8d8..6145eec4a3d 100644
--- a/api/src/test/java/com/alibaba/nacos/api/config/remote/request/cluster/ConfigChangeClusterSyncRequestTest.java
+++ b/api/src/test/java/com/alibaba/nacos/api/config/remote/request/cluster/ConfigChangeClusterSyncRequestTest.java
@@ -40,6 +40,7 @@ public void before() {
configChangeClusterSyncRequest.setTag(TAG);
configChangeClusterSyncRequest.setBeta(Boolean.TRUE);
configChangeClusterSyncRequest.setLastModified(0L);
+ configChangeClusterSyncRequest.setBatch(false);
configChangeClusterSyncRequest.putAllHeader(HEADERS);
requestId = injectRequestUuId(configChangeClusterSyncRequest);
}
diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectResetRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectResetRequestTest.java
index 021b7645779..d2a7d11925a 100644
--- a/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectResetRequestTest.java
+++ b/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectResetRequestTest.java
@@ -27,20 +27,24 @@ public void testSerialize() throws Exception {
request.setServerIp("127.0.0.1");
request.setServerPort("8888");
request.setRequestId("1");
+ request.setConnectionId("11111_127.0.0.1_8888");
String json = mapper.writeValueAsString(request);
Assert.assertNotNull(json);
Assert.assertTrue(json.contains("\"serverIp\":\"127.0.0.1\""));
Assert.assertTrue(json.contains("\"serverPort\":\"8888\""));
Assert.assertTrue(json.contains("\"module\":\"internal\""));
Assert.assertTrue(json.contains("\"requestId\":\"1\""));
+ Assert.assertTrue(json.contains("\"connectionId\":\"11111_127.0.0.1_8888\""));
}
@Test
public void testDeserialize() throws Exception {
- String json = "{\"headers\":{},\"requestId\":\"1\",\"serverIp\":\"127.0.0.1\",\"serverPort\":\"8888\",\"module\":\"internal\"}";
+ String json = "{\"headers\":{},\"requestId\":\"1\",\"serverIp\":\"127.0.0.1\",\"serverPort\":\"8888\","
+ + "\"module\":\"internal\",\"connectionId\":\"11111_127.0.0.1_8888\"}";
ConnectResetRequest result = mapper.readValue(json, ConnectResetRequest.class);
Assert.assertNotNull(result);
Assert.assertEquals("127.0.0.1", result.getServerIp());
Assert.assertEquals("8888", result.getServerPort());
+ Assert.assertEquals("11111_127.0.0.1_8888", result.getConnectionId());
}
}
\ No newline at end of file
diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectionSetupRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectionSetupRequestTest.java
index e05860af9c7..03424d50a64 100644
--- a/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectionSetupRequestTest.java
+++ b/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectionSetupRequestTest.java
@@ -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 void testSerialize() throws Exception {
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\""));
}
diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/request/RequestMetaTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/request/RequestMetaTest.java
index 89e9e0fc4cc..13f60b5b34d 100644
--- a/api/src/test/java/com/alibaba/nacos/api/remote/request/RequestMetaTest.java
+++ b/api/src/test/java/com/alibaba/nacos/api/remote/request/RequestMetaTest.java
@@ -16,9 +16,12 @@
package com.alibaba.nacos.api.remote.request;
+import com.alibaba.nacos.api.ability.constant.AbilityKey;
+import com.alibaba.nacos.api.ability.constant.AbilityStatus;
import org.junit.Before;
import org.junit.Test;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -68,4 +71,19 @@ public void testToString() {
String expected = "RequestMeta{connectionId='test-connection-id', clientIp='127.0.0.1', clientVersion='1.0.0', labels={env=dev}}";
assertEquals(expected, requestMeta.toString());
}
+
+ @Test
+ public void testGetConnectionAbilityForNonExist() {
+ assertEquals(AbilityStatus.UNKNOWN, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1));
+ requestMeta.setAbilityTable(Collections.emptyMap());
+ assertEquals(AbilityStatus.UNKNOWN, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1));
+ }
+
+ @Test
+ public void testGetConnectionAbilityForExist() {
+ requestMeta.setAbilityTable(Collections.singletonMap(AbilityKey.SERVER_TEST_1.getName(), Boolean.FALSE));
+ assertEquals(AbilityStatus.NOT_SUPPORTED, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1));
+ requestMeta.setAbilityTable(Collections.singletonMap(AbilityKey.SERVER_TEST_1.getName(), Boolean.TRUE));
+ assertEquals(AbilityStatus.SUPPORTED, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1));
+ }
}
diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/request/SetupAckRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/request/SetupAckRequestTest.java
new file mode 100644
index 00000000000..b0697db5e1d
--- /dev/null
+++ b/api/src/test/java/com/alibaba/nacos/api/remote/request/SetupAckRequestTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 1999-2023 Alibaba Group Holding Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.nacos.api.remote.request;
+
+import com.alibaba.nacos.api.ability.constant.AbilityKey;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+
+public class SetupAckRequestTest extends BasicRequestTest {
+
+ @Test
+ public void testSerialize() throws Exception {
+ SetupAckRequest request = new SetupAckRequest(
+ Collections.singletonMap(AbilityKey.SERVER_TEST_1.getName(), Boolean.TRUE));
+ request.setRequestId("1");
+ String json = mapper.writeValueAsString(request);
+ System.out.println(json);
+ Assert.assertNotNull(json);
+ Assert.assertTrue(json.contains("\"abilityTable\":{\"test_1\":true}"));
+ Assert.assertTrue(json.contains("\"module\":\"internal\""));
+ Assert.assertTrue(json.contains("\"requestId\":\"1\""));
+ }
+
+ @Test
+ public void testDeserialize() throws Exception {
+ String json =
+ "{\"headers\":{},\"requestId\":\"1\",\"abilityTable\":{\"test_1\":true}," + "\"module\":\"internal\"}";
+ SetupAckRequest result = mapper.readValue(json, SetupAckRequest.class);
+ Assert.assertNotNull(result);
+ Assert.assertTrue(result.getAbilityTable().get("test_1"));
+ Assert.assertEquals("1", result.getRequestId());
+ Assert.assertEquals("internal", result.getModule());
+ }
+}
\ No newline at end of file
diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/response/EmptyContentResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/response/EmptyContentResponseTest.java
index c737c369be9..28b23af0891 100644
--- a/api/src/test/java/com/alibaba/nacos/api/remote/response/EmptyContentResponseTest.java
+++ b/api/src/test/java/com/alibaba/nacos/api/remote/response/EmptyContentResponseTest.java
@@ -92,6 +92,16 @@ public void testServerReloadResponse() throws JsonProcessingException {
assertCommonResponse(response);
}
+ @Test
+ public void testSetupAckResponse() throws JsonProcessingException {
+ SetupAckResponse response = new SetupAckResponse();
+ response.setRequestId("1");
+ String actual = mapper.writeValueAsString(response);
+ assertCommonResponseJson(actual);
+ response = mapper.readValue(COMMON_JSON, SetupAckResponse.class);
+ assertCommonResponse(response);
+ }
+
private void assertCommonResponse(Response response) {
assertTrue(response.isSuccess());
assertNull(response.getMessage());
diff --git a/api/src/test/java/com/alibaba/nacos/api/remote/response/ServerCheckResponseTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/response/ServerCheckResponseTest.java
index 80c2ac9ea6e..9a7603435c8 100644
--- a/api/src/test/java/com/alibaba/nacos/api/remote/response/ServerCheckResponseTest.java
+++ b/api/src/test/java/com/alibaba/nacos/api/remote/response/ServerCheckResponseTest.java
@@ -38,15 +38,18 @@ public void setUp() throws Exception {
@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\""));
+ assertTrue(actual.contains("\"supportAbilityNegotiation\":false"));
}
@Test
public void testDeserialization() throws JsonProcessingException {
- String json = "{\"resultCode\":200,\"errorCode\":0,\"connectionId\":\"35643245_1.1.1.1_3306\",\"success\":true}";
+ String json = "{\"resultCode\":200,\"errorCode\":0,\"connectionId\":\"35643245_1.1.1.1_3306\",\"success\":true,"
+ + "\"supportAbilityNegotiation\":true}";
ServerCheckResponse response = mapper.readValue(json, ServerCheckResponse.class);
assertEquals("35643245_1.1.1.1_3306", response.getConnectionId());
+ assertTrue(response.isSupportAbilityNegotiation());
}
}
\ No newline at end of file
diff --git a/api/src/test/java/com/alibaba/nacos/api/utils/AbilityKeyTest.java b/api/src/test/java/com/alibaba/nacos/api/utils/AbilityKeyTest.java
new file mode 100644
index 00000000000..c757d5fa043
--- /dev/null
+++ b/api/src/test/java/com/alibaba/nacos/api/utils/AbilityKeyTest.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright 1999-2022 Alibaba Group Holding Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.nacos.api.utils;
+
+import com.alibaba.nacos.api.ability.constant.AbilityKey;
+import com.alibaba.nacos.api.ability.constant.AbilityMode;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**.
+ * @author Daydreamer
+ * @description Ability key test
+ * @date 2022/9/8 12:27
+ **/
+public class AbilityKeyTest {
+
+ @Test
+ public void testMapStr() {
+ Map enumMap = new HashMap<>();
+ Map stringBooleanMap = AbilityKey.mapStr(enumMap);
+ assertEquals(0, stringBooleanMap.size());
+
+ enumMap.put(AbilityKey.SERVER_TEST_1, true);
+ enumMap.put(AbilityKey.SERVER_TEST_2, false);
+ stringBooleanMap = AbilityKey.mapStr(enumMap);
+ assertEquals(2, stringBooleanMap.size());
+ Assert.assertTrue(stringBooleanMap.get(AbilityKey.SERVER_TEST_1.getName()));
+ Assert.assertFalse(stringBooleanMap.get(AbilityKey.SERVER_TEST_2.getName()));
+
+ enumMap.put(AbilityKey.SERVER_TEST_2, true);
+ stringBooleanMap = AbilityKey.mapStr(enumMap);
+ assertEquals(2, stringBooleanMap.size());
+ Assert.assertTrue(stringBooleanMap.get(AbilityKey.SERVER_TEST_1.getName()));
+ Assert.assertTrue(stringBooleanMap.get(AbilityKey.SERVER_TEST_2.getName()));
+ }
+
+ @Test
+ public void testMapEnumForEmpty() {
+ Map actual = AbilityKey.mapEnum(AbilityMode.SERVER, Collections.emptyMap());
+ assertTrue(actual.isEmpty());
+ }
+
+ @Test
+ public void testMapEnum() {
+ Map mapStr = new HashMap<>();
+ mapStr.put("test-no-existed", true);
+ Map enumMap = AbilityKey.mapEnum(AbilityMode.SERVER, mapStr);
+ assertEquals(0, enumMap.size());
+
+ mapStr.put(AbilityKey.SERVER_TEST_2.getName(), false);
+ mapStr.put(AbilityKey.SERVER_TEST_1.getName(), true);
+ enumMap = AbilityKey.mapEnum(AbilityMode.SERVER, mapStr);
+ Assert.assertFalse(enumMap.get(AbilityKey.SERVER_TEST_2));
+ Assert.assertTrue(enumMap.get(AbilityKey.SERVER_TEST_1));
+
+ mapStr.clear();
+ mapStr.put(AbilityKey.SERVER_TEST_2.getName(), true);
+ mapStr.put(AbilityKey.SERVER_TEST_1.getName(), true);
+ enumMap = AbilityKey.mapEnum(AbilityMode.SERVER, mapStr);
+ Assert.assertTrue(enumMap.get(AbilityKey.SERVER_TEST_2));
+ Assert.assertTrue(enumMap.get(AbilityKey.SERVER_TEST_1));
+
+ }
+
+ @Test
+ public void testGetAllValues() {
+ Collection actual = AbilityKey.getAllValues(AbilityMode.SERVER);
+ assertEquals(2, actual.size());
+ actual = AbilityKey.getAllValues(AbilityMode.SDK_CLIENT);
+ assertEquals(1, actual.size());
+ actual = AbilityKey.getAllValues(AbilityMode.CLUSTER_CLIENT);
+ assertEquals(1, actual.size());
+ }
+
+ @Test
+ public void testGetAllNames() {
+ Collection actual = AbilityKey.getAllNames(AbilityMode.SERVER);
+ assertEquals(2, actual.size());
+ actual = AbilityKey.getAllNames(AbilityMode.SDK_CLIENT);
+ assertEquals(1, actual.size());
+ actual = AbilityKey.getAllNames(AbilityMode.CLUSTER_CLIENT);
+ assertEquals(1, actual.size());
+ }
+
+ @Test
+ public void testGetDescription() {
+ assertEquals("just for junit test", AbilityKey.SERVER_TEST_1.getDescription());
+ }
+}
diff --git a/auth/src/main/java/com/alibaba/nacos/auth/config/AuthConfigs.java b/auth/src/main/java/com/alibaba/nacos/auth/config/AuthConfigs.java
index 594feab5d4a..e19caa21aa1 100644
--- a/auth/src/main/java/com/alibaba/nacos/auth/config/AuthConfigs.java
+++ b/auth/src/main/java/com/alibaba/nacos/auth/config/AuthConfigs.java
@@ -107,12 +107,14 @@ private void refreshPluginProperties() {
try {
Map newProperties = new HashMap<>(1);
Properties properties = PropertiesUtil.getPropertiesWithPrefix(EnvUtil.getEnvironment(), PREFIX);
- for (String each : properties.stringPropertyNames()) {
- int typeIndex = each.indexOf('.');
- String type = each.substring(0, typeIndex);
- String subKey = each.substring(typeIndex + 1);
- newProperties.computeIfAbsent(type, key -> new Properties())
- .setProperty(subKey, properties.getProperty(each));
+ if (properties != null) {
+ for (String each : properties.stringPropertyNames()) {
+ int typeIndex = each.indexOf('.');
+ String type = each.substring(0, typeIndex);
+ String subKey = each.substring(typeIndex + 1);
+ newProperties.computeIfAbsent(type, key -> new Properties())
+ .setProperty(subKey, properties.getProperty(each));
+ }
}
authPluginProperties = newProperties;
} catch (Exception e) {
@@ -177,8 +179,8 @@ public void onEvent(ServerConfigChangeEvent event) {
cachingEnabled = EnvUtil.getProperty(Constants.Auth.NACOS_CORE_AUTH_CACHING_ENABLED, Boolean.class, true);
serverIdentityKey = EnvUtil.getProperty(Constants.Auth.NACOS_CORE_AUTH_SERVER_IDENTITY_KEY, "");
serverIdentityValue = EnvUtil.getProperty(Constants.Auth.NACOS_CORE_AUTH_SERVER_IDENTITY_VALUE, "");
- enableUserAgentAuthWhite = EnvUtil
- .getProperty(Constants.Auth.NACOS_CORE_AUTH_ENABLE_USER_AGENT_AUTH_WHITE, Boolean.class, false);
+ enableUserAgentAuthWhite = EnvUtil.getProperty(Constants.Auth.NACOS_CORE_AUTH_ENABLE_USER_AGENT_AUTH_WHITE,
+ Boolean.class, false);
nacosAuthSystemType = EnvUtil.getProperty(Constants.Auth.NACOS_CORE_AUTH_SYSTEM_TYPE, "");
refreshPluginProperties();
ModuleStateHolder.getInstance().getModuleState(AuthModuleStateBuilder.AUTH_MODULE)
diff --git a/client/src/main/java/com/alibaba/nacos/client/ability/ClientAbilityControlManager.java b/client/src/main/java/com/alibaba/nacos/client/ability/ClientAbilityControlManager.java
new file mode 100644
index 00000000000..05d8fef47b9
--- /dev/null
+++ b/client/src/main/java/com/alibaba/nacos/client/ability/ClientAbilityControlManager.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 1999-2022 Alibaba Group Holding Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.nacos.client.ability;
+
+import com.alibaba.nacos.api.ability.constant.AbilityKey;
+import com.alibaba.nacos.api.ability.constant.AbilityMode;
+import com.alibaba.nacos.api.ability.register.impl.SdkClientAbilities;
+import com.alibaba.nacos.common.ability.AbstractAbilityControlManager;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**.
+ * @author Daydreamer
+ * @description {@link AbstractAbilityControlManager} for nacos-client.
+ * @date 2022/7/13 13:38
+ **/
+public class ClientAbilityControlManager extends AbstractAbilityControlManager {
+
+ public ClientAbilityControlManager() {
+ }
+
+ @Override
+ protected Map> initCurrentNodeAbilities() {
+ Map> abilities = new HashMap<>(1);
+ abilities.put(AbilityMode.SDK_CLIENT, SdkClientAbilities.getStaticAbilities());
+ return abilities;
+ }
+
+ @Override
+ public int getPriority() {
+ // if server ability manager exist, you should choose the server one
+ return 0;
+ }
+
+}
diff --git a/client/src/main/java/com/alibaba/nacos/client/config/NacosConfigService.java b/client/src/main/java/com/alibaba/nacos/client/config/NacosConfigService.java
index a8e50c00044..3867e26f417 100644
--- a/client/src/main/java/com/alibaba/nacos/client/config/NacosConfigService.java
+++ b/client/src/main/java/com/alibaba/nacos/client/config/NacosConfigService.java
@@ -36,11 +36,12 @@
import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.client.utils.LogUtils;
import com.alibaba.nacos.client.utils.ParamUtil;
+import com.alibaba.nacos.client.utils.PreInitUtils;
import com.alibaba.nacos.client.utils.ValidatorUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import org.slf4j.Logger;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.Properties;
/**
@@ -73,6 +74,7 @@ public class NacosConfigService implements ConfigService {
private final ConfigFilterChainManager configFilterChainManager;
public NacosConfigService(Properties properties) throws NacosException {
+ PreInitUtils.asyncPreLoadCostComponent();
final NacosClientProperties clientProperties = NacosClientProperties.PROTOTYPE.derive(properties);
ValidatorUtils.checkInitParam(clientProperties);
@@ -105,7 +107,8 @@ public String getConfigAndSignListener(String dataId, String group, long timeout
.queryConfig(dataId, group, worker.getAgent().getTenant(), timeoutMs, false);
String content = configResponse.getContent();
String encryptedDataKey = configResponse.getEncryptedDataKey();
- worker.addTenantListenersWithContent(dataId, group, content, encryptedDataKey, Arrays.asList(listener));
+ worker.addTenantListenersWithContent(dataId, group, content, encryptedDataKey,
+ Collections.singletonList(listener));
// get a decryptContent, fix https://github.com/alibaba/nacos/issues/7039
ConfigResponse cr = new ConfigResponse();
@@ -119,7 +122,7 @@ public String getConfigAndSignListener(String dataId, String group, long timeout
@Override
public void addListener(String dataId, String group, Listener listener) throws NacosException {
- worker.addTenantListeners(dataId, group, Arrays.asList(listener));
+ worker.addTenantListeners(dataId, group, Collections.singletonList(listener));
}
@Override
diff --git a/client/src/main/java/com/alibaba/nacos/client/config/impl/CacheData.java b/client/src/main/java/com/alibaba/nacos/client/config/impl/CacheData.java
index 4d6f5e13b79..c194e3623ff 100644
--- a/client/src/main/java/com/alibaba/nacos/client/config/impl/CacheData.java
+++ b/client/src/main/java/com/alibaba/nacos/client/config/impl/CacheData.java
@@ -93,7 +93,7 @@ static ScheduledThreadPoolExecutor getNotifyBlockMonitor() {
LOGGER.info("nacos.cache.data.init.snapshot = {} ", initSnapshot);
}
- private final String envName;
+ public final String envName;
private final ConfigFilterChainManager configFilterChainManager;
@@ -124,13 +124,13 @@ static ScheduledThreadPoolExecutor getNotifyBlockMonitor() {
/**
* local cache change timestamp.
*/
- private volatile AtomicLong lastModifiedTs = new AtomicLong(0);
+ private final AtomicLong lastModifiedTs = new AtomicLong(0);
/**
* notify change flag,for notify&sync concurrent control. 1.reset to false if starting to sync with server. 2.update
* to true if receive config change notification.
*/
- private volatile AtomicBoolean receiveNotifyChanged = new AtomicBoolean(false);
+ private final AtomicBoolean receiveNotifyChanged = new AtomicBoolean(false);
private int taskId;
@@ -139,7 +139,7 @@ static ScheduledThreadPoolExecutor getNotifyBlockMonitor() {
/**
* if is cache data md5 sync with the server.
*/
- private volatile AtomicBoolean isConsistentWithServer = new AtomicBoolean();
+ private final AtomicBoolean isConsistentWithServer = new AtomicBoolean();
/**
* if is cache data is discard,need to remove.
diff --git a/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java b/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java
index 2736831ee74..49f840b8962 100644
--- a/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java
+++ b/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java
@@ -17,7 +17,6 @@
package com.alibaba.nacos.client.config.impl;
import com.alibaba.nacos.api.PropertyKeyConst;
-import com.alibaba.nacos.api.ability.ClientAbilities;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.config.ConfigType;
import com.alibaba.nacos.api.config.listener.Listener;
@@ -54,6 +53,7 @@
import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.common.notify.listener.Subscriber;
import com.alibaba.nacos.common.remote.ConnectionType;
+import com.alibaba.nacos.common.remote.client.Connection;
import com.alibaba.nacos.common.remote.client.ConnectionEventListener;
import com.alibaba.nacos.common.remote.client.RpcClient;
import com.alibaba.nacos.common.remote.client.RpcClientFactory;
@@ -70,6 +70,7 @@
import com.google.gson.JsonObject;
import org.slf4j.Logger;
+import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -123,11 +124,11 @@ public class ClientWorker implements Closeable {
private final ConfigFilterChainManager configFilterChainManager;
- private String uuid = UUID.randomUUID().toString();
+ private final String uuid = UUID.randomUUID().toString();
private long timeout;
- private ConfigRpcTransportClient agent;
+ private final ConfigRpcTransportClient agent;
private int taskPenaltyTime;
@@ -411,17 +412,13 @@ private void decreaseTaskIdCount(int taskId) {
private int calculateTaskId() {
int perTaskSize = (int) ParamUtil.getPerTaskConfigSize();
- int taskId = -1;
for (int index = 0; index < taskIdCacheCountList.size(); index++) {
if (taskIdCacheCountList.get(index).get() < perTaskSize) {
return index;
}
}
- if (taskId < 0) {
- taskIdCacheCountList.add(new AtomicInteger(0));
- taskId = taskIdCacheCountList.size() - 1;
- }
- return taskId;
+ taskIdCacheCountList.add(new AtomicInteger(0));
+ return taskIdCacheCountList.size() - 1;
}
public CacheData getCache(String dataId, String group) {
@@ -571,15 +568,15 @@ public boolean isHealthServer() {
public class ConfigRpcTransportClient extends ConfigTransportClient {
Map multiTaskExecutor = new HashMap<>();
-
+
private final BlockingQueue