> apiGetClusterStateOfApp(@PathVariable String app) {
+ if (StringUtil.isEmpty(app)) {
+ return Result.ofFail(-1, "app cannot be null or empty");
+ }
+ try {
+ return clusterConfigService.getClusterUniversalState(app)
+ .thenApply(Result::ofSuccess)
+ .get();
+ } catch (ExecutionException ex) {
+ logger.error("Error when fetching cluster state of app: " + app, ex.getCause());
+ return errorResponse(ex);
+ } catch (Throwable throwable) {
+ logger.error("Error when fetching cluster state of app: " + app, throwable);
+ return Result.ofFail(-1, throwable.getMessage());
+ }
+ }
+
private boolean isNotSupported(Throwable ex) {
return ex instanceof CommandNotFoundException;
}
diff --git a/sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/NacosConfigUtil.java b/sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/NacosConfigUtil.java
index d17d2475..312d63fd 100644
--- a/sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/NacosConfigUtil.java
+++ b/sentinel-dashboard/src/test/java/com/taobao/csp/sentinel/dashboard/rule/nacos/NacosConfigUtil.java
@@ -25,6 +25,7 @@ public final class NacosConfigUtil {
public static final String FLOW_DATA_ID_POSTFIX = "-flow-rules";
public static final String PARAM_FLOW_DATA_ID_POSTFIX = "-param-rules";
+ public static final String CLUSTER_MAP_DATA_ID_POSTFIX = "-cluster-map";
/**
* cc for `cluster-client`
diff --git a/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/ClusterClientDemo.java b/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/ClusterClientDemo.java
new file mode 100644
index 00000000..cf0af2e9
--- /dev/null
+++ b/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/ClusterClientDemo.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 1999-2018 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.csp.sentinel.demo.cluster;
+
+import com.alibaba.csp.sentinel.Entry;
+import com.alibaba.csp.sentinel.EntryType;
+import com.alibaba.csp.sentinel.SphU;
+import com.alibaba.csp.sentinel.cluster.ClusterStateManager;
+import com.alibaba.csp.sentinel.init.InitExecutor;
+import com.alibaba.csp.sentinel.slots.block.BlockException;
+
+/**
+ * Run this demo with the following args: -Dproject.name=appA
+ * You need a token server running already.
+ *
+ * @author Eric Zhao
+ */
+public class ClusterClientDemo {
+
+ public static void main(String[] args) {
+ InitExecutor.doInit();
+
+ // Manually schedule the cluster mode to client.
+ // In common, we need a scheduling system to modify the cluster mode automatically.
+ // Command HTTP API: http://:/setClusterMode?mode=
+ ClusterStateManager.setToClient();
+
+ String resourceName = "cluster-demo-entry";
+
+ // Assume we have a cluster flow rule for `demo-resource`: QPS = 5 in AVG_LOCAL mode.
+ for (int i = 0; i < 10; i++) {
+ tryEntry(resourceName);
+ }
+ }
+
+ private static void tryEntry(String res) {
+ Entry entry = null;
+ try {
+ entry = SphU.entry(res, EntryType.IN, 1, "abc", "def");
+ System.out.println("Passed");
+ } catch (BlockException ex) {
+ ex.printStackTrace();
+ } finally {
+ if (entry != null) {
+ entry.exit();
+ }
+ }
+ }
+}