diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/HttpHelper.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/client/SentinelApiClient.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/HttpHelper.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/client/SentinelApiClient.java index bde4ebfb..3854fa83 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/HttpHelper.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/client/SentinelApiClient.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.inmem; +package com.taobao.csp.sentinel.dashboard.client; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -53,31 +53,31 @@ import org.springframework.stereotype.Component; * @author leyou */ @Component -public class HttpHelper { +public class SentinelApiClient { - private static Logger logger = LoggerFactory.getLogger(HttpHelper.class); + private static Logger logger = LoggerFactory.getLogger(SentinelApiClient.class); private static final Charset defaultCharset = Charset.forName(SentinelConfig.charset()); - private CloseableHttpAsyncClient httpclient; + private CloseableHttpAsyncClient httpClient; + private final String resourceUrlPath = "jsonTree"; private final String clusterNodePath = "clusterNode"; - private final String getRulesPath = "getRules"; private final String setRulesPath = "setRules"; private final String flowRuleType = "flow"; private final String degradeRuleType = "degrade"; private final String systemRuleType = "system"; - public HttpHelper() { + public SentinelApiClient() { IOReactorConfig ioConfig = IOReactorConfig.custom().setConnectTimeout(3000).setSoTimeout(3000) .setIoThreadCount(Runtime.getRuntime().availableProcessors() * 2).build(); - httpclient = HttpAsyncClients.custom().setRedirectStrategy(new DefaultRedirectStrategy() { + httpClient = HttpAsyncClients.custom().setRedirectStrategy(new DefaultRedirectStrategy() { @Override protected boolean isRedirectable(final String method) { return false; } }).setMaxConnTotal(4000).setMaxConnPerRoute(1000).setDefaultIOReactorConfig(ioConfig).build(); - httpclient.start(); + httpClient.start(); } public List fetchResourceOfMachine(String ip, int port, String type) { @@ -282,7 +282,7 @@ public class HttpHelper { final HttpGet httpGet = new HttpGet(url); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference reference = new AtomicReference<>(); - httpclient.execute(httpGet, new FutureCallback() { + httpClient.execute(httpGet, new FutureCallback() { @Override public void completed(final HttpResponse response) { try { @@ -324,4 +324,7 @@ public class HttpHelper { return EntityUtils.toString(response.getEntity(), charset != null ? charset : defaultCharset); } + public void close() throws Exception { + httpClient.close(); + } } diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/InMemDegradeRuleStore.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemDegradeRuleStore.java similarity index 86% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/InMemDegradeRuleStore.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemDegradeRuleStore.java index 549c47ae..17d3481e 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/InMemDegradeRuleStore.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemDegradeRuleStore.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.inmem; +package com.taobao.csp.sentinel.dashboard.repository.rule; import java.util.concurrent.atomic.AtomicLong; @@ -24,7 +24,7 @@ import org.springframework.stereotype.Component; * @author leyou */ @Component -public class InMemDegradeRuleStore extends InMemRepositoryAdapter { +public class InMemDegradeRuleStore extends InMemoryRuleRepositoryAdapter { private static AtomicLong ids = new AtomicLong(0); diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/InMemFlowRuleStore.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemFlowRuleStore.java similarity index 87% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/InMemFlowRuleStore.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemFlowRuleStore.java index 220d64ef..1e1c5ec2 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/InMemFlowRuleStore.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemFlowRuleStore.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.inmem; +package com.taobao.csp.sentinel.dashboard.repository.rule; import java.util.concurrent.atomic.AtomicLong; @@ -26,7 +26,7 @@ import org.springframework.stereotype.Component; * @author leyou */ @Component -public class InMemFlowRuleStore extends InMemRepositoryAdapter { +public class InMemFlowRuleStore extends InMemoryRuleRepositoryAdapter { private static AtomicLong ids = new AtomicLong(0); @Override diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/InMemSystemRuleStore.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemSystemRuleStore.java similarity index 86% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/InMemSystemRuleStore.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemSystemRuleStore.java index 1ed00bf3..eed207cf 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/InMemSystemRuleStore.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemSystemRuleStore.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.inmem; +package com.taobao.csp.sentinel.dashboard.repository.rule; import java.util.concurrent.atomic.AtomicLong; @@ -24,7 +24,7 @@ import org.springframework.stereotype.Component; * @author leyou */ @Component -public class InMemSystemRuleStore extends InMemRepositoryAdapter { +public class InMemSystemRuleStore extends InMemoryRuleRepositoryAdapter { private static AtomicLong ids = new AtomicLong(0); diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/InMemRepositoryAdapter.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemoryRuleRepositoryAdapter.java similarity index 94% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/InMemRepositoryAdapter.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemoryRuleRepositoryAdapter.java index bd43bea8..ce9f143a 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/InMemRepositoryAdapter.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/InMemoryRuleRepositoryAdapter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.inmem; +package com.taobao.csp.sentinel.dashboard.repository.rule; import java.util.ArrayList; import java.util.List; @@ -27,7 +27,7 @@ import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; /** * @author leyou */ -public abstract class InMemRepositoryAdapter implements RuleRepository { +public abstract class InMemoryRuleRepositoryAdapter implements RuleRepository { /** * {@code >} */ diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/RuleRepository.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/RuleRepository.java similarity index 96% rename from sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/RuleRepository.java rename to sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/RuleRepository.java index 65892087..cb50669f 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/inmem/RuleRepository.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/repository/rule/RuleRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.taobao.csp.sentinel.dashboard.inmem; +package com.taobao.csp.sentinel.dashboard.repository.rule; import java.util.List; diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/DegradeController.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/DegradeController.java index 2b526702..058fe0f9 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/DegradeController.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/DegradeController.java @@ -22,8 +22,8 @@ import com.alibaba.csp.sentinel.util.StringUtil; import com.taobao.csp.sentinel.dashboard.datasource.entity.DegradeRuleEntity; import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; -import com.taobao.csp.sentinel.dashboard.inmem.HttpHelper; -import com.taobao.csp.sentinel.dashboard.inmem.InMemDegradeRuleStore; +import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; +import com.taobao.csp.sentinel.dashboard.repository.rule.InMemDegradeRuleStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -42,7 +42,7 @@ public class DegradeController { @Autowired InMemDegradeRuleStore repository; @Autowired - private HttpHelper httpHelper; + private SentinelApiClient sentinelApiClient; @ResponseBody @RequestMapping("/rules.json") @@ -57,7 +57,7 @@ public class DegradeController { return Result.ofFail(-1, "port can't be null"); } try { - List rules = httpHelper.fetchDegradeRuleOfMachine(app, ip, port); + List rules = sentinelApiClient.fetchDegradeRuleOfMachine(app, ip, port); rules = repository.saveAll(rules); return Result.ofSuccess(rules); } catch (Throwable throwable) { @@ -195,6 +195,6 @@ public class DegradeController { private boolean publishRules(String app, String ip, Integer port) { List rules = repository.findAllByMachine(MachineInfo.of(app, ip, port)); - return httpHelper.setDegradeRuleOfMachine(app, ip, port, rules); + return sentinelApiClient.setDegradeRuleOfMachine(app, ip, port, rules); } } diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/FlowController.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/FlowController.java index 6aeaf305..cd761872 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/FlowController.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/FlowController.java @@ -22,8 +22,8 @@ import com.alibaba.csp.sentinel.util.StringUtil; import com.taobao.csp.sentinel.dashboard.datasource.entity.FlowRuleEntity; import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; -import com.taobao.csp.sentinel.dashboard.inmem.HttpHelper; -import com.taobao.csp.sentinel.dashboard.inmem.InMemFlowRuleStore; +import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; +import com.taobao.csp.sentinel.dashboard.repository.rule.InMemFlowRuleStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -45,7 +45,7 @@ public class FlowController { private InMemFlowRuleStore repository; @Autowired - private HttpHelper httpHelper; + private SentinelApiClient sentinelApiClient; @ResponseBody @RequestMapping("/rules.json") @@ -60,7 +60,7 @@ public class FlowController { return Result.ofFail(-1, "port can't be null"); } try { - List rules = httpHelper.fetchFlowRuleOfMachine(app, ip, port); + List rules = sentinelApiClient.fetchFlowRuleOfMachine(app, ip, port); rules = repository.saveAll(rules); return Result.ofSuccess(rules); } catch (Throwable throwable) { @@ -244,6 +244,6 @@ public class FlowController { private boolean publishRules(String app, String ip, Integer port) { List rules = repository.findAllByMachine(MachineInfo.of(app, ip, port)); - return httpHelper.setFlowRuleOfMachine(app, ip, port, rules); + return sentinelApiClient.setFlowRuleOfMachine(app, ip, port, rules); } } diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/ResourceController.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/ResourceController.java index 44932775..a6e16cae 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/ResourceController.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/ResourceController.java @@ -22,7 +22,7 @@ import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.command.vo.NodeVo; import com.taobao.csp.sentinel.dashboard.domain.ResourceTreeNode; -import com.taobao.csp.sentinel.dashboard.inmem.HttpHelper; +import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; import com.taobao.csp.sentinel.dashboard.view.vo.ResourceVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,7 +41,7 @@ public class ResourceController { private static Logger logger = LoggerFactory.getLogger(ResourceController.class); @Autowired - HttpHelper httpFetcher; + SentinelApiClient httpFetcher; /** * Fetch real time statistics info of the machine. diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/SystemController.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/SystemController.java index d195fe00..20449a1d 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/SystemController.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/view/SystemController.java @@ -22,8 +22,8 @@ import com.alibaba.csp.sentinel.util.StringUtil; import com.taobao.csp.sentinel.dashboard.datasource.entity.SystemRuleEntity; import com.taobao.csp.sentinel.dashboard.discovery.MachineInfo; -import com.taobao.csp.sentinel.dashboard.inmem.HttpHelper; -import com.taobao.csp.sentinel.dashboard.inmem.InMemSystemRuleStore; +import com.taobao.csp.sentinel.dashboard.client.SentinelApiClient; +import com.taobao.csp.sentinel.dashboard.repository.rule.InMemSystemRuleStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -43,7 +43,7 @@ public class SystemController { @Autowired private InMemSystemRuleStore repository; @Autowired - private HttpHelper httpHelper; + private SentinelApiClient sentinelApiClient; @ResponseBody @RequestMapping("/rules.json") @@ -58,7 +58,7 @@ public class SystemController { return Result.ofFail(-1, "port can't be null"); } try { - List rules = httpHelper.fetchSystemRuleOfMachine(app, ip, port); + List rules = sentinelApiClient.fetchSystemRuleOfMachine(app, ip, port); rules = repository.saveAll(rules); return Result.ofSuccess(rules); } catch (Throwable throwable) { @@ -209,6 +209,6 @@ public class SystemController { private boolean publishRules(String app, String ip, Integer port) { List rules = repository.findAllByMachine(MachineInfo.of(app, ip, port)); - return httpHelper.setSystemRuleOfMachine(app, ip, port, rules); + return sentinelApiClient.setSystemRuleOfMachine(app, ip, port, rules); } }