From a5e95b7b24d8e92fcd7a5e7ddbf87c1cc6aa9858 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Mon, 14 Jan 2019 14:16:58 +0800 Subject: [PATCH] Update cluster demo README and remove unused demo Signed-off-by: Eric Zhao --- .../sentinel-demo-cluster-embedded/README.md | 6 ++ .../demo/cluster/ClusterClientDemo.java | 62 ------------------- 2 files changed, 6 insertions(+), 62 deletions(-) create mode 100644 sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/README.md delete mode 100644 sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/ClusterClientDemo.java diff --git a/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/README.md b/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/README.md new file mode 100644 index 00000000..95d93c07 --- /dev/null +++ b/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/README.md @@ -0,0 +1,6 @@ +# Sentinel Cluster Embedded Mode Demo + +This demo demonstrates how to configure data source for cluster rules and configuration +in **embedded mode**. You can start multiple `ClusterDemoApplication` instances and do cluster assignment in Sentinel dashboard or via dynamic data source. + +See [DemoClusterInitFunc](https://github.com/alibaba/Sentinel/blob/master/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/init/DemoClusterInitFunc.java) for a sample of dynamic configuration. \ No newline at end of file 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 deleted file mode 100644 index cf0af2e9..00000000 --- a/sentinel-demo/sentinel-demo-cluster/sentinel-demo-cluster-embedded/src/main/java/com/alibaba/csp/sentinel/demo/cluster/ClusterClientDemo.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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(); - } - } - } -}