diff --git a/api/src/main/java/com/alibaba/nacos/api/ability/ClientAbilities.java b/api/src/main/java/com/alibaba/nacos/api/ability/ClientAbilities.java
index ea4dd9aa7..fe9c80e95 100644
--- a/api/src/main/java/com/alibaba/nacos/api/ability/ClientAbilities.java
+++ b/api/src/main/java/com/alibaba/nacos/api/ability/ClientAbilities.java
@@ -28,6 +28,7 @@ import java.io.Serializable;
* @author liuzunfei
* @version $Id: ClientAbilities.java, v 0.1 2021年01月24日 00:09 AM liuzunfei Exp $
*/
+@Deprecated
public class ClientAbilities implements Serializable {
private static final long serialVersionUID = -3590789441404549261L;
diff --git a/api/src/main/java/com/alibaba/nacos/api/ability/ServerAbilities.java b/api/src/main/java/com/alibaba/nacos/api/ability/ServerAbilities.java
index f6b8b5591..80d3f772d 100644
--- a/api/src/main/java/com/alibaba/nacos/api/ability/ServerAbilities.java
+++ b/api/src/main/java/com/alibaba/nacos/api/ability/ServerAbilities.java
@@ -29,6 +29,7 @@ import java.util.Objects;
* @author liuzunfei
* @version $Id: ServerAbilities.java, v 0.1 2021年01月24日 00:09 AM liuzunfei Exp $
*/
+@Deprecated
public class ServerAbilities implements Serializable {
private static final long serialVersionUID = -2120543002911304171L;
diff --git a/api/src/main/java/com/alibaba/nacos/api/ability/constant/AbilityKey.java b/api/src/main/java/com/alibaba/nacos/api/ability/constant/AbilityKey.java
new file mode 100644
index 000000000..d77460cf3
--- /dev/null
+++ b/api/src/main/java/com/alibaba/nacos/api/ability/constant/AbilityKey.java
@@ -0,0 +1,179 @@
+/*
+ * 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.ability.constant;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.stream.Collectors;
+
+/**
+ * Ability key constant. It is used to constrain the ability key.
+ * Ensure that return value of {@link AbilityKey#getName()} is unique under one specify {@link AbilityMode}.
+ *
+ * @author Daydreamer
+ * @date 2022/8/31 12:27
+ **/
+public enum AbilityKey {
+
+ /**
+ * For Test temporarily.
+ */
+ SERVER_TEST_1("test_1", "just for junit test", AbilityMode.SERVER),
+
+ /**
+ * For Test temporarily.
+ */
+ SERVER_TEST_2("test_2", "just for junit test", AbilityMode.SERVER),
+
+ /**
+ * For Test temporarily.
+ */
+ SDK_CLIENT_TEST_1("test_1", "just for junit test", AbilityMode.SDK_CLIENT),
+
+ /**
+ * For Test temporarily.
+ */
+ CLUSTER_CLIENT_TEST_1("test_1", "just for junit test", AbilityMode.CLUSTER_CLIENT);
+
+ /**
+ * the name of a certain ability.
+ */
+ private final String keyName;
+
+ /**
+ * description or comment about this ability.
+ */
+ private final String description;
+
+ /**
+ * ability mode, which endpoint hold this ability.
+ */
+ private final AbilityMode mode;
+
+ AbilityKey(String keyName, String description, AbilityMode mode) {
+ this.keyName = keyName;
+ this.description = description;
+ this.mode = mode;
+ }
+
+ public String getName() {
+ return keyName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public AbilityMode getMode() {
+ return mode;
+ }
+
+ /**
+ * All key set.
+ */
+ private static final Map> ALL_ABILITIES = new HashMap<>();
+
+ /**
+ * Get all keys.
+ *
+ * @return all keys
+ */
+ public static Collection getAllValues(AbilityMode mode) {
+ return Collections.unmodifiableCollection(ALL_ABILITIES.get(mode).values());
+ }
+
+ /**
+ * Get all names.
+ *
+ * @return all names
+ */
+ public static Collection getAllNames(AbilityMode mode) {
+ return Collections.unmodifiableCollection(ALL_ABILITIES.get(mode).keySet());
+ }
+
+ /**
+ * Whether contains this name.
+ *
+ * @param name key name
+ * @return whether contains
+ */
+ public static boolean isLegalKey(AbilityMode mode, String name) {
+ return ALL_ABILITIES.get(mode).containsKey(name);
+ }
+
+ /**
+ * Map the string key to enum.
+ *
+ * @param abilities map
+ * @return enum map
+ */
+ public static Map mapEnum(AbilityMode mode, Map abilities) {
+ if (abilities == null || abilities.isEmpty()) {
+ return Collections.emptyMap();
+ }
+ return abilities.entrySet()
+ .stream()
+ .filter(entry -> isLegalKey(mode, entry.getKey()))
+ .collect(Collectors.toMap((entry) -> getEnum(mode, entry.getKey()), Map.Entry::getValue));
+ }
+
+ /**.
+ * Map the string key to enum
+ *
+ * @param abilities map
+ * @return enum map
+ */
+ public static Map mapStr(Map abilities) {
+ if (abilities == null || abilities.isEmpty()) {
+ return Collections.emptyMap();
+ }
+ return abilities.entrySet()
+ .stream()
+ .collect(Collectors.toMap((entry) -> entry.getKey().getName(), Map.Entry::getValue));
+ }
+
+ /**.
+ * getter to obtain enum
+ *
+ * @param key string key
+ * @return enum
+ */
+ public static AbilityKey getEnum(AbilityMode mode, String key) {
+ return ALL_ABILITIES.get(mode).get(key);
+ }
+
+ static {
+ // check for developer
+ // ensure that name filed is unique under a AbilityMode
+ try {
+ for (AbilityKey value : AbilityKey.values()) {
+ AbilityMode mode = value.mode;
+ Map map = ALL_ABILITIES.getOrDefault(mode, new HashMap<>());
+ AbilityKey previous = map.putIfAbsent(value.getName(), value);
+ if (previous != null) {
+ throw new IllegalStateException("Duplicate key name field " + value + " and " + previous + " under mode: " + mode);
+ }
+ ALL_ABILITIES.put(mode, map);
+ }
+ } catch (Throwable t) {
+ // for developer checking
+ t.printStackTrace();
+ }
+ }
+}
diff --git a/api/src/main/java/com/alibaba/nacos/api/ability/constant/AbilityMode.java b/api/src/main/java/com/alibaba/nacos/api/ability/constant/AbilityMode.java
new file mode 100644
index 000000000..2355a48bf
--- /dev/null
+++ b/api/src/main/java/com/alibaba/nacos/api/ability/constant/AbilityMode.java
@@ -0,0 +1,41 @@
+/*
+ * 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.constant;
+
+/**
+ * Ability mode.
+ *
+ * @author Daydreamer
+ * @date 2023/9/25 12:32
+ **/
+public enum AbilityMode {
+
+ /**
+ * for server ability.
+ */
+ SERVER,
+
+ /**
+ * for sdk client.
+ */
+ SDK_CLIENT,
+
+ /**
+ * for cluster client.
+ */
+ CLUSTER_CLIENT;
+}
diff --git a/api/src/main/java/com/alibaba/nacos/api/ability/constant/AbilityStatus.java b/api/src/main/java/com/alibaba/nacos/api/ability/constant/AbilityStatus.java
new file mode 100644
index 000000000..a762c0373
--- /dev/null
+++ b/api/src/main/java/com/alibaba/nacos/api/ability/constant/AbilityStatus.java
@@ -0,0 +1,40 @@
+/*
+ * 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.ability.constant;
+
+/**.
+ * @author Daydreamer
+ * @description It is used to know a certain ability whether supporting.
+ * @date 2022/8/31 12:27
+ **/
+public enum AbilityStatus {
+
+ /**.
+ * Support a certain ability
+ */
+ SUPPORTED,
+
+ /**.
+ * Not support a certain ability
+ */
+ NOT_SUPPORTED,
+
+ /**.
+ * Cannot find ability table, unknown
+ */
+ UNKNOWN
+}
diff --git a/api/src/main/java/com/alibaba/nacos/api/ability/initializer/AbilityInitializer.java b/api/src/main/java/com/alibaba/nacos/api/ability/initializer/AbilityInitializer.java
index f7ad356c1..71192dffa 100644
--- a/api/src/main/java/com/alibaba/nacos/api/ability/initializer/AbilityInitializer.java
+++ b/api/src/main/java/com/alibaba/nacos/api/ability/initializer/AbilityInitializer.java
@@ -21,6 +21,7 @@ package com.alibaba.nacos.api.ability.initializer;
*
* @author xiweng.yy
*/
+@Deprecated
public interface AbilityInitializer {
/**
diff --git a/api/src/main/java/com/alibaba/nacos/api/ability/initializer/AbilityPostProcessor.java b/api/src/main/java/com/alibaba/nacos/api/ability/initializer/AbilityPostProcessor.java
new file mode 100644
index 000000000..667c21c58
--- /dev/null
+++ b/api/src/main/java/com/alibaba/nacos/api/ability/initializer/AbilityPostProcessor.java
@@ -0,0 +1,40 @@
+/*
+ * 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.initializer;
+
+import com.alibaba.nacos.api.ability.constant.AbilityKey;
+import com.alibaba.nacos.api.ability.constant.AbilityMode;
+
+import java.util.Map;
+
+/**
+ * Nacos ability post processor, load by spi.
+ *
+ * @author Daydreamer-ia
+ */
+public interface AbilityPostProcessor {
+
+
+ /**
+ * process before loading by Ability Controller
.
+ *
+ * @param mode mode: sdk client, server or cluster client
+ * @param abilities abilities
+ */
+ void process(AbilityMode mode, Map abilities);
+
+}
diff --git a/api/src/main/java/com/alibaba/nacos/api/ability/register/AbstractAbilityRegistry.java b/api/src/main/java/com/alibaba/nacos/api/ability/register/AbstractAbilityRegistry.java
new file mode 100644
index 000000000..40af9087c
--- /dev/null
+++ b/api/src/main/java/com/alibaba/nacos/api/ability/register/AbstractAbilityRegistry.java
@@ -0,0 +1,42 @@
+/*
+ * 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.ability.register;
+
+import com.alibaba.nacos.api.ability.constant.AbilityKey;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**.
+ * @author Daydreamer
+ * @description Operation for bit table.
+ * @date 2022/7/12 19:23
+ **/
+public abstract class AbstractAbilityRegistry {
+
+ protected final Map supportedAbilities = new HashMap<>();
+
+ /**.
+ * get static ability current server supports
+ *
+ * @return static ability
+ */
+ public Map getSupportedAbilities() {
+ return Collections.unmodifiableMap(supportedAbilities);
+ }
+}
diff --git a/api/src/main/java/com/alibaba/nacos/api/ability/register/impl/ClusterClientAbilities.java b/api/src/main/java/com/alibaba/nacos/api/ability/register/impl/ClusterClientAbilities.java
new file mode 100644
index 000000000..b43f43dae
--- /dev/null
+++ b/api/src/main/java/com/alibaba/nacos/api/ability/register/impl/ClusterClientAbilities.java
@@ -0,0 +1,57 @@
+/*
+ * 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 com.alibaba.nacos.api.ability.constant.AbilityKey;
+import com.alibaba.nacos.api.ability.register.AbstractAbilityRegistry;
+
+import java.util.Map;
+
+/**
+ * It is used to register cluster client abilities.
+ *
+ * @author Daydreamer
+ **/
+public class ClusterClientAbilities extends AbstractAbilityRegistry {
+
+ private static final ClusterClientAbilities INSTANCE = new ClusterClientAbilities();
+
+ {
+ /*
+ * example:
+ * There is a function named "compression".
+ * The key is from AbilityKey
, the value is whether turn on.
+ *
+ * You can add a new public field in AbilityKey
like:
+ * DATA_COMPRESSION("compression", "description about this ability")
+ *
+ * And then you need to declare whether turn on in the ability table, you can:
+ * supportedAbilities.put(AbilityKey.DATA_COMPRESSION, true);
means that current client support compression.
+ *
+ */
+ // put ability here, which you want current client supports
+ }
+
+ /**
+ * get static ability current cluster client supports.
+ *
+ * @return static ability
+ */
+ public static Map getStaticAbilities() {
+ return INSTANCE.getSupportedAbilities();
+ }
+}
diff --git a/api/src/main/java/com/alibaba/nacos/api/ability/register/impl/SdkClientAbilities.java b/api/src/main/java/com/alibaba/nacos/api/ability/register/impl/SdkClientAbilities.java
new file mode 100644
index 000000000..cb306f11d
--- /dev/null
+++ b/api/src/main/java/com/alibaba/nacos/api/ability/register/impl/SdkClientAbilities.java
@@ -0,0 +1,58 @@
+/*
+ * 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.ability.register.impl;
+
+import com.alibaba.nacos.api.ability.constant.AbilityKey;
+import com.alibaba.nacos.api.ability.register.AbstractAbilityRegistry;
+
+import java.util.Map;
+
+/**
+ * It is used to register client abilities.
+ *
+ * @author Daydreamer
+ * @date 2022/8/31 12:32
+ **/
+public class SdkClientAbilities extends AbstractAbilityRegistry {
+
+ private static final SdkClientAbilities INSTANCE = new SdkClientAbilities();
+
+ {
+ /*
+ * example:
+ * There is a function named "compression".
+ * The key is from AbilityKey
, the value is whether turn on.
+ *
+ * You can add a new public field in AbilityKey
like:
+ * DATA_COMPRESSION("compression", "description about this ability")
+ *
+ * And then you need to declare whether turn on in the ability table, you can:
+ * supportedAbilities.put(AbilityKey.DATA_COMPRESSION, true);
means that current client support compression.
+ *
+ */
+ // put ability here, which you want current client supports
+ }
+
+ /**.
+ * get static ability current server supports
+ *
+ * @return static ability
+ */
+ public static Map getStaticAbilities() {
+ return INSTANCE.getSupportedAbilities();
+ }
+}
diff --git a/api/src/main/java/com/alibaba/nacos/api/ability/register/impl/ServerAbilities.java b/api/src/main/java/com/alibaba/nacos/api/ability/register/impl/ServerAbilities.java
new file mode 100644
index 000000000..2fa8f9693
--- /dev/null
+++ b/api/src/main/java/com/alibaba/nacos/api/ability/register/impl/ServerAbilities.java
@@ -0,0 +1,59 @@
+/*
+ * 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.ability.register.impl;
+
+import com.alibaba.nacos.api.ability.constant.AbilityKey;
+import com.alibaba.nacos.api.ability.register.AbstractAbilityRegistry;
+
+import java.util.Map;
+
+/**
+ * It is used to register server abilities.
+ *
+ * @author Daydreamer
+ * @date 2022/8/31 12:32
+ **/
+public class ServerAbilities extends AbstractAbilityRegistry {
+
+ private static final ServerAbilities INSTANCE = new ServerAbilities();
+
+ {
+ /*
+ * example:
+ * There is a function named "compression".
+ * The key is from AbilityKey
, the value is whether turn on.
+ *
+ * You can add a new public field in AbilityKey
like:
+ * DATA_COMPRESSION("compression", "description about this ability")
+ *
+ * And then you need to declare whether turn on in the ability table, you can:
+ * supportedAbilities.put(AbilityKey.DATA_COMPRESSION, true);
means that current client support compression.
+ *
+ */
+ // put ability here, which you want current server supports
+ }
+
+ /**.
+ * get static ability current server supports
+ *
+ * @return static ability
+ */
+ public static Map getStaticAbilities() {
+ return INSTANCE.getSupportedAbilities();
+ }
+
+}
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 1a2e14424..75c6fa0ca 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 56e94dad2..3409728f5 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 class ConnectionSetupRequest extends InternalRequest {
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 82eba58db..c633f8934 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 000000000..cecdaa825
--- /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 fd3981cd1..2b8e9fea8 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 class ServerCheckResponse extends Response {
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 000000000..ce4abcb94
--- /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/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 d838e65ea..5e9552afd 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/remote/request/ConnectionSetupRequestTest.java b/api/src/test/java/com/alibaba/nacos/api/remote/request/ConnectionSetupRequestTest.java
index e05860af9..03424d50a 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 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\""));
}
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 80c2ac9ea..c010f0d99 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,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\""));
}
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 000000000..32af5ad2b
--- /dev/null
+++ b/api/src/test/java/com/alibaba/nacos/api/utils/AbilityKeyTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.HashMap;
+import java.util.Map;
+
+/**.
+ * @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);
+ Assert.assertEquals(0, stringBooleanMap.size());
+
+ enumMap.put(AbilityKey.SERVER_TEST_1, true);
+ enumMap.put(AbilityKey.SERVER_TEST_2, false);
+ stringBooleanMap = AbilityKey.mapStr(enumMap);
+ Assert.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);
+ Assert.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 testMapEnum() {
+ Map mapStr = new HashMap<>();
+ mapStr.put("test-no-existed", true);
+ Map enumMap = AbilityKey.mapEnum(AbilityMode.SERVER, mapStr);
+ Assert.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));
+
+ }
+
+}
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 000000000..05d8fef47
--- /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/impl/ClientWorker.java b/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java
index eb8c2d679..86dd81d46 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;
@@ -37,6 +36,8 @@ import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.remote.RemoteConstants;
import com.alibaba.nacos.api.remote.request.Request;
import com.alibaba.nacos.api.remote.response.Response;
+import com.alibaba.nacos.common.remote.client.Connection;
+import com.alibaba.nacos.plugin.auth.api.RequestResource;
import com.alibaba.nacos.client.config.common.GroupKey;
import com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager;
import com.alibaba.nacos.client.config.filter.impl.ConfigResponse;
@@ -65,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;
@@ -122,7 +122,7 @@ public class ClientWorker implements Closeable {
private final AtomicReference