From 6bce3bda7be450c5ea793f5e11d35b75aeb3fba6 Mon Sep 17 00:00:00 2001
From: Daydreamer-ia <2296032269@qq.com>
Date: Mon, 25 Sep 2023 14:44:47 +0800
Subject: [PATCH] add AbilityPostProcessor param to know abilities init detail,
sdk client, server or cluster client
---
.../api/ability/initializer/AbilityPostProcessor.java | 4 +++-
.../client/ability/ClientAbilityControlManager.java | 8 +++++++-
.../common/ability/AbstractAbilityControlManager.java | 11 ++++++++++-
.../ability/control/ServerAbilityControlManager.java | 8 +++++++-
4 files changed, 27 insertions(+), 4 deletions(-)
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
index bec04d6e4..078671ac2 100644
--- 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
@@ -1,6 +1,7 @@
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;
@@ -15,8 +16,9 @@ public interface AbilityPostProcessor {
/**
* process before loading by Ability Controller
.
*
+ * @param mode mode: sdk client, server or cluster client
* @param abilities abilities
*/
- void process(Map abilities);
+ void process(AbilityMode mode, Map abilities);
}
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
index f1cb6cf7d..a47b9b87e 100644
--- a/client/src/main/java/com/alibaba/nacos/client/ability/ClientAbilityControlManager.java
+++ b/client/src/main/java/com/alibaba/nacos/client/ability/ClientAbilityControlManager.java
@@ -17,6 +17,7 @@
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.ClientAbilities;
import com.alibaba.nacos.common.ability.AbstractAbilityControlManager;
@@ -36,7 +37,12 @@ public class ClientAbilityControlManager extends AbstractAbilityControlManager {
protected Map initCurrentNodeAbilities() {
return ClientAbilities.getStaticAbilities();
}
-
+
+ @Override
+ protected AbilityMode initializeMode() {
+ return AbilityMode.SDK_CLIENT;
+ }
+
@Override
public int getPriority() {
// if server ability manager exist, you should choose the server one
diff --git a/common/src/main/java/com/alibaba/nacos/common/ability/AbstractAbilityControlManager.java b/common/src/main/java/com/alibaba/nacos/common/ability/AbstractAbilityControlManager.java
index ed346525f..447d214ef 100644
--- a/common/src/main/java/com/alibaba/nacos/common/ability/AbstractAbilityControlManager.java
+++ b/common/src/main/java/com/alibaba/nacos/common/ability/AbstractAbilityControlManager.java
@@ -17,6 +17,7 @@
package com.alibaba.nacos.common.ability;
import com.alibaba.nacos.api.ability.constant.AbilityKey;
+import com.alibaba.nacos.api.ability.constant.AbilityMode;
import com.alibaba.nacos.api.ability.initializer.AbilityPostProcessor;
import com.alibaba.nacos.common.notify.Event;
import com.alibaba.nacos.common.notify.NotifyCenter;
@@ -60,9 +61,10 @@ public abstract class AbstractAbilityControlManager {
// get processors
Collection processors = NacosServiceLoader.load(AbilityPostProcessor.class);
Map abilities = initCurrentNodeAbilities();
+ AbilityMode mode = initializeMode();
// get abilities
for (AbilityPostProcessor processor : processors) {
- processor.process(abilities);
+ processor.process(mode, abilities);
}
return AbilityKey.mapStr(abilities);
}
@@ -111,6 +113,13 @@ public abstract class AbstractAbilityControlManager {
* @return current node abilities
*/
protected abstract Map initCurrentNodeAbilities();
+
+ /**
+ * initialize mode.
+ *
+ * @return mode.
+ */
+ protected abstract AbilityMode initializeMode();
/**.
* Return the abilities current node
diff --git a/core/src/main/java/com/alibaba/nacos/core/ability/control/ServerAbilityControlManager.java b/core/src/main/java/com/alibaba/nacos/core/ability/control/ServerAbilityControlManager.java
index 67845d821..99e3fbb12 100644
--- a/core/src/main/java/com/alibaba/nacos/core/ability/control/ServerAbilityControlManager.java
+++ b/core/src/main/java/com/alibaba/nacos/core/ability/control/ServerAbilityControlManager.java
@@ -17,6 +17,7 @@
package com.alibaba.nacos.core.ability.control;
import com.alibaba.nacos.api.ability.constant.AbilityKey;
+import com.alibaba.nacos.api.ability.constant.AbilityMode;
import com.alibaba.nacos.api.ability.register.impl.ServerAbilities;
import com.alibaba.nacos.common.ability.AbstractAbilityControlManager;
import com.alibaba.nacos.core.ability.config.AbilityConfigs;
@@ -65,7 +66,12 @@ public class ServerAbilityControlManager extends AbstractAbilityControlManager {
unIncludedInConfig.forEach(abilityKey -> abilityTable.put(abilityKey, staticAbilities.get(abilityKey)));
return abilityTable;
}
-
+
+ @Override
+ protected AbilityMode initializeMode() {
+ return AbilityMode.SERVER;
+ }
+
@Override
public int getPriority() {
return 1;