!221 up sentinel 1.8.4

Merge pull request !221 from fxz/dev
This commit is contained in:
lbw 2022-04-15 06:44:22 +00:00 committed by Gitee
commit cab40f4b41
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
129 changed files with 834 additions and 461 deletions

View File

@ -33,6 +33,7 @@
<oss.version>1.0.4</oss.version> <oss.version>1.0.4</oss.version>
<sms.version>2.0.2</sms.version> <sms.version>2.0.2</sms.version>
<jaxb.version>2.3.5</jaxb.version> <jaxb.version>2.3.5</jaxb.version>
<sentinel.version>1.8.4</sentinel.version>
</properties> </properties>
<!-- 定义全局jar版本,模块使用需要再次引入但不用写版本号--> <!-- 定义全局jar版本,模块使用需要再次引入但不用写版本号-->
@ -197,6 +198,41 @@
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-core</artifactId>
<version>${sentinel.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-web-servlet</artifactId>
<version>${sentinel.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-transport-simple-http</artifactId>
<version>${sentinel.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-parameter-flow-control</artifactId>
<version>${sentinel.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-api-gateway-adapter-common</artifactId>
<version>${sentinel.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

View File

@ -16,6 +16,7 @@
package com.alibaba.csp.sentinel.dashboard; package com.alibaba.csp.sentinel.dashboard;
import com.alibaba.csp.sentinel.init.InitExecutor; import com.alibaba.csp.sentinel.init.InitExecutor;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -33,7 +34,7 @@ public class PigSentinelApplication {
} }
private static void triggerSentinelInit() { private static void triggerSentinelInit() {
new Thread(InitExecutor::doInit).start(); new Thread(() -> InitExecutor.doInit()).start();
} }
} }

View File

@ -15,10 +15,14 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.auth; package com.alibaba.csp.sentinel.dashboard.auth;
import java.lang.annotation.*; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/** /**
* @author lkxiaolou * @author lkxiaolou 无改动
* @since 1.7.1 * @since 1.7.1
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

View File

@ -16,7 +16,7 @@
package com.alibaba.csp.sentinel.dashboard.auth; package com.alibaba.csp.sentinel.dashboard.auth;
/** /**
* Interface for authentication and authorization. * Interface for authentication and authorization. 不需要改
* *
* @author Carpenter Lee * @author Carpenter Lee
* @since 1.5.0 * @since 1.5.0

View File

@ -15,59 +15,15 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.auth; package com.alibaba.csp.sentinel.dashboard.auth;
import com.alibaba.csp.sentinel.dashboard.domain.Result;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;
/** /**
* The web interceptor for privilege-based authorization. * The web interceptor for privilege-based authorization. 不需要改
* *
* @author lkxiaolou * @author lkxiaolou
* @author wxq
* @since 1.7.1 * @since 1.7.1
*/ */
@Component public interface AuthorizationInterceptor extends HandlerInterceptor {
public class AuthorizationInterceptor implements HandlerInterceptor {
@Autowired
private AuthService<HttpServletRequest> authService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
if (handler.getClass().isAssignableFrom(HandlerMethod.class)) {
Method method = ((HandlerMethod) handler).getMethod();
AuthAction authAction = method.getAnnotation(AuthAction.class);
if (authAction != null) {
AuthService.AuthUser authUser = authService.getAuthUser(request);
if (authUser == null) {
responseNoPrivilegeMsg(response, authAction.message());
return false;
}
String target = request.getParameter(authAction.targetName());
if (!authUser.authTarget(target, authAction.value())) {
responseNoPrivilegeMsg(response, authAction.message());
return false;
}
}
}
return true;
}
private void responseNoPrivilegeMsg(HttpServletResponse response, String message) throws IOException {
Result result = Result.ofFail(-1, message);
response.addHeader("Content-Type", "application/json;charset=UTF-8");
response.getOutputStream().write(JSON.toJSONBytes(result));
}
} }

View File

@ -0,0 +1,75 @@
/*
* 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.dashboard.auth;
import com.alibaba.csp.sentinel.dashboard.domain.Result;
import com.alibaba.fastjson.JSON;
import org.springframework.web.method.HandlerMethod;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;
/**
* The web interceptor for privilege-based authorization. 不需要
* <p>
* move from old {@link AuthorizationInterceptor}.
*
* @author lkxiaolou
* @author wxq
* @since 1.7.1
*/
public class DefaultAuthorizationInterceptor implements AuthorizationInterceptor {
private final AuthService<HttpServletRequest> authService;
public DefaultAuthorizationInterceptor(AuthService<HttpServletRequest> authService) {
this.authService = authService;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
if (handler.getClass().isAssignableFrom(HandlerMethod.class)) {
Method method = ((HandlerMethod) handler).getMethod();
AuthAction authAction = method.getAnnotation(AuthAction.class);
if (authAction != null) {
AuthService.AuthUser authUser = authService.getAuthUser(request);
if (authUser == null) {
responseNoPrivilegeMsg(response, authAction.message());
return false;
}
String target = request.getParameter(authAction.targetName());
if (!authUser.authTarget(target, authAction.value())) {
responseNoPrivilegeMsg(response, authAction.message());
return false;
}
}
}
return true;
}
private void responseNoPrivilegeMsg(HttpServletResponse response, String message) throws IOException {
Result result = Result.ofFail(-1, message);
response.addHeader("Content-Type", "application/json;charset=UTF-8");
response.getOutputStream().write(JSON.toJSONBytes(result));
}
}

View File

@ -0,0 +1,132 @@
/*
* 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.dashboard.auth;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.util.AntPathMatcher;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* <p>
* The Servlet filter for authentication.
* </p>
*
* <p>
* Note: some urls are excluded as they needn't auth, such as:
* </p>
* <ul>
* <li>index url: {@code /}</li>
* <li>authentication request url: {@code /login}, {@code /logout}</li>
* <li>machine registry: {@code /registry/machine}</li>
* <li>static resources</li>
* </ul>
* <p>
* The excluded urls and urlSuffixes could be configured in {@code application.properties}
* file.
*
* @author cdfive 不需要
* @since 1.6.0
*/
public class DefaultLoginAuthenticationFilter implements LoginAuthenticationFilter {
private static final AntPathMatcher PATH_MATCHER = new AntPathMatcher();
private static final String URL_SUFFIX_DOT = ".";
/**
* 忽略鉴权的url
*/
@Value("#{'${auth.filter.exclude-urls}'.split(',')}")
private List<String> authFilterExcludeUrls;
/**
* 根据后缀不需要鉴权的url
*/
@Value("#{'${auth.filter.exclude-url-suffixes}'.split(',')}")
private List<String> authFilterExcludeUrlSuffixes;
/**
* Authentication using AuthService interface.
*/
private final AuthService<HttpServletRequest> authService;
public DefaultLoginAuthenticationFilter(AuthService<HttpServletRequest> authService) {
this.authService = authService;
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String servletPath = httpRequest.getServletPath();
// Exclude the urls which needn't auth
boolean authFilterExcludeMatch = authFilterExcludeUrls.stream()
.anyMatch(authFilterExcludeUrl -> PATH_MATCHER.match(authFilterExcludeUrl, servletPath));
if (authFilterExcludeMatch) {
chain.doFilter(request, response);
return;
}
// Exclude the urls with suffixes which needn't auth
for (String authFilterExcludeUrlSuffix : authFilterExcludeUrlSuffixes) {
if (StringUtils.isBlank(authFilterExcludeUrlSuffix)) {
continue;
}
// Add . for url suffix so that we needn't add . in property file
if (!authFilterExcludeUrlSuffix.startsWith(URL_SUFFIX_DOT)) {
authFilterExcludeUrlSuffix = URL_SUFFIX_DOT + authFilterExcludeUrlSuffix;
}
if (servletPath.endsWith(authFilterExcludeUrlSuffix)) {
chain.doFilter(request, response);
return;
}
}
AuthService.AuthUser authUser = authService.getAuthUser(httpRequest);
HttpServletResponse httpResponse = (HttpServletResponse) response;
if (authUser == null) {
// If auth fail, set response status code to 401
httpResponse.setStatus(HttpStatus.UNAUTHORIZED.value());
}
else {
chain.doFilter(request, response);
}
}
@Override
public void destroy() {
}
}

View File

@ -15,7 +15,8 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.auth; package com.alibaba.csp.sentinel.dashboard.auth;
import org.springframework.stereotype.Component; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -25,9 +26,14 @@ import javax.servlet.http.HttpServletRequest;
* @author Carpenter Lee * @author Carpenter Lee
* @since 1.5.0 * @since 1.5.0
*/ */
@Component
public class FakeAuthServiceImpl implements AuthService<HttpServletRequest> { public class FakeAuthServiceImpl implements AuthService<HttpServletRequest> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public FakeAuthServiceImpl() {
this.logger.warn("there is no auth, use {} by implementation {}", AuthService.class, this.getClass());
}
@Override @Override
public AuthUser getAuthUser(HttpServletRequest request) { public AuthUser getAuthUser(HttpServletRequest request) {
return new AuthUserImpl(); return new AuthUserImpl();

View File

@ -15,18 +15,7 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.auth; package com.alibaba.csp.sentinel.dashboard.auth;
import org.apache.commons.lang.StringUtils; import javax.servlet.Filter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/** /**
* <p> * <p>
@ -42,92 +31,14 @@ import java.util.List;
* <li>machine registry: {@code /registry/machine}</li> * <li>machine registry: {@code /registry/machine}</li>
* <li>static resources</li> * <li>static resources</li>
* </ul> * </ul>
* * <p>
* The excluded urls and urlSuffixes could be configured in {@code application.properties} * The excluded urls and urlSuffixes could be configured in {@code application.properties}
* file. * file.
* *
* @author cdfive * @author cdfive 不需要
* @author wxq
* @since 1.6.0 * @since 1.6.0
*/ */
@Component public interface LoginAuthenticationFilter extends Filter {
public class LoginAuthenticationFilter implements Filter {
private static final String URL_SUFFIX_DOT = ".";
private static final AntPathMatcher PATH_MATCHER = new AntPathMatcher();
/**
* Some urls which needn't auth, such as /auth/login, /registry/machine and so on.
*/
@Value("#{'${auth.filter.exclude-urls}'.split(',')}")
private List<String> authFilterExcludeUrls;
/**
* Some urls with suffixes which needn't auth, such as htm, html, js and so on.
*/
@Value("#{'${auth.filter.exclude-url-suffixes}'.split(',')}")
private List<String> authFilterExcludeUrlSuffixes;
/**
* Authentication using AuthService interface.
*/
@Autowired
private AuthService<HttpServletRequest> authService;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String servletPath = httpRequest.getServletPath();
// Exclude the urls which needn't auth
if (authFilterExcludeUrls.stream().anyMatch(s -> PATH_MATCHER.match(s, servletPath))) {
chain.doFilter(request, response);
return;
}
if (authFilterExcludeUrls.contains(servletPath)) {
chain.doFilter(request, response);
return;
}
// Exclude the urls with suffixes which needn't auth
for (String authFilterExcludeUrlSuffix : authFilterExcludeUrlSuffixes) {
if (StringUtils.isBlank(authFilterExcludeUrlSuffix)) {
continue;
}
// Add . for url suffix so that we needn't add . in property file
if (!authFilterExcludeUrlSuffix.startsWith(URL_SUFFIX_DOT)) {
authFilterExcludeUrlSuffix = URL_SUFFIX_DOT + authFilterExcludeUrlSuffix;
}
if (servletPath.endsWith(authFilterExcludeUrlSuffix)) {
chain.doFilter(request, response);
return;
}
}
AuthService.AuthUser authUser = authService.getAuthUser(httpRequest);
HttpServletResponse httpResponse = (HttpServletResponse) response;
if (authUser == null) {
// If auth fail, set response status code to 401
httpResponse.setStatus(HttpStatus.UNAUTHORIZED.value());
}
else {
chain.doFilter(request, response);
}
}
@Override
public void destroy() {
}
} }

View File

@ -15,20 +15,13 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.auth; package com.alibaba.csp.sentinel.dashboard.auth;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
/** /**
* @author cdfive * @author cdfive 不需要
* @since 1.6.0 * @since 1.6.0
*/ */
@Component
@Primary
@ConditionalOnProperty(name = "auth.enabled", matchIfMissing = true)
public class SimpleWebAuthServiceImpl implements AuthService<HttpServletRequest> { public class SimpleWebAuthServiceImpl implements AuthService<HttpServletRequest> {
public static final String WEB_SESSION_KEY = "session_sentinel_admin"; public static final String WEB_SESSION_KEY = "session_sentinel_admin";

View File

@ -15,23 +15,28 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.client; package com.alibaba.csp.sentinel.dashboard.client;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule; import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
import com.alibaba.csp.sentinel.command.CommandConstants; import com.alibaba.csp.sentinel.command.CommandConstants;
import com.alibaba.csp.sentinel.command.vo.NodeVo;
import com.alibaba.csp.sentinel.config.SentinelConfig; import com.alibaba.csp.sentinel.config.SentinelConfig;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.SentinelVersion; import com.alibaba.csp.sentinel.command.vo.NodeVo;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.ApiDefinitionEntity; import com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.ApiDefinitionEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.GatewayFlowRuleEntity; import com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.GatewayFlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.*;
import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterClientInfoVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterStateSimpleEntity;
import com.alibaba.csp.sentinel.dashboard.util.AsyncUtils; import com.alibaba.csp.sentinel.dashboard.util.AsyncUtils;
import com.alibaba.csp.sentinel.dashboard.util.VersionUtils;
import com.alibaba.csp.sentinel.slots.block.Rule; import com.alibaba.csp.sentinel.slots.block.Rule;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule; import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
@ -41,6 +46,22 @@ import com.alibaba.csp.sentinel.slots.system.SystemRule;
import com.alibaba.csp.sentinel.util.AssertUtil; import com.alibaba.csp.sentinel.util.AssertUtil;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.SentinelVersion;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.RuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity;
import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterClientInfoVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterStateSimpleEntity;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig;
import com.alibaba.csp.sentinel.dashboard.util.VersionUtils;
import org.apache.http.Consts; import org.apache.http.Consts;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
@ -63,15 +84,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
/** /**
* Communicate with Sentinel client. * Communicate with Sentinel client.
* *
@ -171,8 +183,8 @@ public class SentinelApiClient {
} }
/** /**
* Check wheter target instance (identified by tuple of app-ip:port) supports the form * Check whether target instance (identified by tuple of app-ip:port) supports the
* of "xxxxx; xx=xx" in "Content-Type" header. * form of "xxxxx; xx=xx" in "Content-Type" header.
* @param app target app name * @param app target app name
* @param ip target node's address * @param ip target node's address
* @param port target node's port * @param port target node's port
@ -520,7 +532,7 @@ public class SentinelApiClient {
AssertUtil.notEmpty(ip, "Bad machine IP"); AssertUtil.notEmpty(ip, "Bad machine IP");
AssertUtil.isTrue(port > 0, "Bad machine port"); AssertUtil.isTrue(port > 0, "Bad machine port");
return fetchItemsAsync(ip, port, GET_PARAM_RULE_PATH, null, ParamFlowRule.class) return fetchItemsAsync(ip, port, GET_PARAM_RULE_PATH, null, ParamFlowRule.class)
.thenApply(rules -> rules.stream().map(e -> ParamFlowRuleEntity.fromAuthorityRule(app, ip, port, e)) .thenApply(rules -> rules.stream().map(e -> ParamFlowRuleEntity.fromParamFlowRule(app, ip, port, e))
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
catch (Exception e) { catch (Exception e) {

View File

@ -0,0 +1,59 @@
/*
* 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.dashboard.config;
import com.alibaba.csp.sentinel.dashboard.auth.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.http.HttpServletRequest;
@Configuration
@EnableConfigurationProperties(AuthProperties.class)
public class AuthConfiguration {
private final AuthProperties authProperties;
public AuthConfiguration(AuthProperties authProperties) {
this.authProperties = authProperties;
}
@Bean
@ConditionalOnMissingBean
public AuthService<HttpServletRequest> httpServletRequestAuthService() {
if (this.authProperties.isEnabled()) {
return new SimpleWebAuthServiceImpl();
}
return new FakeAuthServiceImpl();
}
@Bean
@ConditionalOnMissingBean
public LoginAuthenticationFilter loginAuthenticationFilter(
AuthService<HttpServletRequest> httpServletRequestAuthService) {
return new DefaultLoginAuthenticationFilter(httpServletRequestAuthService);
}
@Bean
@ConditionalOnMissingBean
public AuthorizationInterceptor authorizationInterceptor(
AuthService<HttpServletRequest> httpServletRequestAuthService) {
return new DefaultAuthorizationInterceptor(httpServletRequestAuthService);
}
}

View File

@ -0,0 +1,33 @@
/*
* 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.dashboard.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "auth")
public class AuthProperties {
private boolean enabled = true;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

View File

@ -15,13 +15,13 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.config; package com.alibaba.csp.sentinel.dashboard.config;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.math.NumberUtils;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/** /**
* <p> * <p>
* Dashboard local config support. * Dashboard local config support.

View File

@ -15,11 +15,16 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.config; package com.alibaba.csp.sentinel.dashboard.config;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter; import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager; import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
import com.alibaba.csp.sentinel.dashboard.auth.AuthorizationInterceptor; import com.alibaba.csp.sentinel.dashboard.auth.AuthorizationInterceptor;
import com.alibaba.csp.sentinel.dashboard.auth.LoginAuthenticationFilter; import com.alibaba.csp.sentinel.dashboard.auth.LoginAuthenticationFilter;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -33,14 +38,11 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.servlet.Filter; import javax.servlet.Filter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/** /**
* @author leyou * @author leyou
*/ */
@Configuration(proxyBeanMethods = false) @Configuration
public class WebConfig implements WebMvcConfigurer { public class WebConfig implements WebMvcConfigurer {
private final Logger logger = LoggerFactory.getLogger(WebConfig.class); private final Logger logger = LoggerFactory.getLogger(WebConfig.class);

View File

@ -15,19 +15,24 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.controller; package com.alibaba.csp.sentinel.dashboard.controller;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.alibaba.csp.sentinel.dashboard.discovery.AppInfo; import com.alibaba.csp.sentinel.dashboard.discovery.AppInfo;
import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement; import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.dashboard.domain.Result; import com.alibaba.csp.sentinel.dashboard.domain.Result;
import com.alibaba.csp.sentinel.dashboard.domain.vo.MachineInfoVo; import com.alibaba.csp.sentinel.dashboard.domain.vo.MachineInfoVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import javax.servlet.http.HttpServletRequest; import org.springframework.web.bind.annotation.RequestMapping;
import java.util.ArrayList; import org.springframework.web.bind.annotation.RequestParam;
import java.util.Collections; import org.springframework.web.bind.annotation.RestController;
import java.util.Comparator;
import java.util.List;
/** /**
* @author Carpenter Lee * @author Carpenter Lee

View File

@ -15,22 +15,32 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.controller; package com.alibaba.csp.sentinel.dashboard.controller;
import java.util.Date;
import java.util.List;
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction; import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.dashboard.domain.Result; import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository;
import com.alibaba.csp.sentinel.slots.block.RuleConstant; import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity;
import com.alibaba.csp.sentinel.dashboard.domain.Result;
import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.Date; import org.springframework.web.bind.annotation.PathVariable;
import java.util.List; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/** /**
* @author Eric Zhao * @author Eric Zhao

View File

@ -15,23 +15,32 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.controller; package com.alibaba.csp.sentinel.dashboard.controller;
import java.util.Date;
import java.util.List;
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction; import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.dashboard.domain.Result; import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository; import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository;
import com.alibaba.csp.sentinel.slots.block.RuleConstant; import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.degrade.circuitbreaker.CircuitBreakerStrategy; import com.alibaba.csp.sentinel.slots.block.degrade.circuitbreaker.CircuitBreakerStrategy;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity;
import com.alibaba.csp.sentinel.dashboard.domain.Result;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.Date; import org.springframework.web.bind.annotation.PathVariable;
import java.util.List; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/** /**
* Controller regarding APIs of degrade rules. Refactored since 1.8.0. * Controller regarding APIs of degrade rules. Refactored since 1.8.0.

View File

@ -15,11 +15,9 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.controller; package com.alibaba.csp.sentinel.dashboard.controller;
import com.alibaba.csp.sentinel.Entry; import java.util.Random;
import com.alibaba.csp.sentinel.EntryType; import java.util.concurrent.TimeUnit;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.context.ContextUtil;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
@ -27,8 +25,11 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Random; import com.alibaba.csp.sentinel.Entry;
import java.util.concurrent.TimeUnit; import com.alibaba.csp.sentinel.EntryType;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.context.ContextUtil;
import com.alibaba.csp.sentinel.slots.block.BlockException;
@Controller @Controller
@RequestMapping(value = "/demo", produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/demo", produces = MediaType.APPLICATION_JSON_VALUE)

View File

@ -15,25 +15,34 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.controller; package com.alibaba.csp.sentinel.dashboard.controller;
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.dashboard.domain.Result;
import com.alibaba.csp.sentinel.dashboard.repository.rule.InMemoryRuleRepositoryAdapter;
import com.alibaba.csp.sentinel.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.dashboard.domain.Result;
import com.alibaba.csp.sentinel.dashboard.repository.rule.InMemoryRuleRepositoryAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/** /**
* Flow rule controller. * Flow rule controller.
* *

View File

@ -16,10 +16,11 @@
package com.alibaba.csp.sentinel.dashboard.controller; package com.alibaba.csp.sentinel.dashboard.controller;
import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement; import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineDiscovery; import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.dashboard.domain.Result; import com.alibaba.csp.sentinel.dashboard.domain.Result;
import com.alibaba.csp.sentinel.util.StringUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -28,6 +29,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import sun.net.util.IPAddressUtil;
@Controller @Controller
@RequestMapping(value = "/registry", produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/registry", produces = MediaType.APPLICATION_JSON_VALUE)
@ -43,20 +45,27 @@ public class MachineRegistryController {
public Result<?> receiveHeartBeat(String app, public Result<?> receiveHeartBeat(String app,
@RequestParam(value = "app_type", required = false, defaultValue = "0") Integer appType, Long version, @RequestParam(value = "app_type", required = false, defaultValue = "0") Integer appType, Long version,
String v, String hostname, String ip, Integer port) { String v, String hostname, String ip, Integer port) {
if (app == null) { if (StringUtil.isBlank(app) || app.length() > 256) {
app = MachineDiscovery.UNKNOWN_APP_NAME; return Result.ofFail(-1, "invalid appName");
} }
if (ip == null) { if (StringUtil.isBlank(ip) || ip.length() > 128) {
return Result.ofFail(-1, "ip can't be null"); return Result.ofFail(-1, "invalid ip: " + ip);
} }
if (port == null) { if (!IPAddressUtil.isIPv4LiteralAddress(ip) && !IPAddressUtil.isIPv6LiteralAddress(ip)) {
return Result.ofFail(-1, "port can't be null"); return Result.ofFail(-1, "invalid ip: " + ip);
}
if (port == null || port < -1) {
return Result.ofFail(-1, "invalid port");
}
if (hostname != null && hostname.length() > 256) {
return Result.ofFail(-1, "hostname too long");
} }
if (port == -1) { if (port == -1) {
logger.info("Receive heartbeat from " + ip + " but port not set yet"); logger.warn("Receive heartbeat from " + ip + " but port not set yet");
return Result.ofFail(-1, "your port not set yet"); return Result.ofFail(-1, "your port not set yet");
} }
String sentinelVersion = StringUtil.isEmpty(v) ? "unknown" : v; String sentinelVersion = StringUtil.isBlank(v) ? "unknown" : v;
version = version == null ? System.currentTimeMillis() : version; version = version == null ? System.currentTimeMillis() : version;
try { try {
MachineInfo machineInfo = new MachineInfo(); MachineInfo machineInfo = new MachineInfo();

View File

@ -15,11 +15,17 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.controller; package com.alibaba.csp.sentinel.dashboard.controller;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import com.alibaba.csp.sentinel.dashboard.domain.Result; import com.alibaba.csp.sentinel.dashboard.domain.Result;
import com.alibaba.csp.sentinel.dashboard.domain.vo.MetricVo;
import com.alibaba.csp.sentinel.dashboard.repository.metric.MetricsRepository; import com.alibaba.csp.sentinel.dashboard.repository.metric.MetricsRepository;
import com.alibaba.csp.sentinel.util.StringUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -28,8 +34,10 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*; import com.alibaba.csp.sentinel.util.StringUtil;
import java.util.concurrent.ConcurrentHashMap;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity;
import com.alibaba.csp.sentinel.dashboard.domain.vo.MetricVo;
/** /**
* @author leyou * @author leyou

View File

@ -15,31 +15,40 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.controller; package com.alibaba.csp.sentinel.dashboard.controller;
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
import com.alibaba.csp.sentinel.dashboard.auth.AuthService;
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
import com.alibaba.csp.sentinel.dashboard.client.CommandNotFoundException;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.SentinelVersion;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.dashboard.domain.Result;
import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository;
import com.alibaba.csp.sentinel.dashboard.util.VersionUtils;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
import com.alibaba.csp.sentinel.dashboard.client.CommandNotFoundException;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.dashboard.auth.AuthService;
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.SentinelVersion;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.domain.Result;
import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository;
import com.alibaba.csp.sentinel.dashboard.util.VersionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/** /**
* @author Eric Zhao * @author Eric Zhao
* @since 0.2.1 * @since 0.2.1
@ -111,7 +120,7 @@ public class ParamFlowRuleController {
} }
@PostMapping("/rule") @PostMapping("/rule")
@AuthAction(AuthService.PrivilegeType.WRITE_RULE) @AuthAction(PrivilegeType.WRITE_RULE)
public Result<ParamFlowRuleEntity> apiAddParamFlowRule(@RequestBody ParamFlowRuleEntity entity) { public Result<ParamFlowRuleEntity> apiAddParamFlowRule(@RequestBody ParamFlowRuleEntity entity) {
Result<ParamFlowRuleEntity> checkResult = checkEntityInternal(entity); Result<ParamFlowRuleEntity> checkResult = checkEntityInternal(entity);
if (checkResult != null) { if (checkResult != null) {
@ -183,7 +192,7 @@ public class ParamFlowRuleController {
} }
@PutMapping("/rule/{id}") @PutMapping("/rule/{id}")
@AuthAction(AuthService.PrivilegeType.WRITE_RULE) @AuthAction(PrivilegeType.WRITE_RULE)
public Result<ParamFlowRuleEntity> apiUpdateParamFlowRule(@PathVariable("id") Long id, public Result<ParamFlowRuleEntity> apiUpdateParamFlowRule(@PathVariable("id") Long id,
@RequestBody ParamFlowRuleEntity entity) { @RequestBody ParamFlowRuleEntity entity) {
if (id == null || id <= 0) { if (id == null || id <= 0) {

View File

@ -15,12 +15,17 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.controller; package com.alibaba.csp.sentinel.dashboard.controller;
import java.util.List;
import java.util.stream.Collectors;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.command.vo.NodeVo; import com.alibaba.csp.sentinel.command.vo.NodeVo;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.domain.ResourceTreeNode; import com.alibaba.csp.sentinel.dashboard.domain.ResourceTreeNode;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.domain.Result; import com.alibaba.csp.sentinel.dashboard.domain.Result;
import com.alibaba.csp.sentinel.dashboard.domain.vo.ResourceVo; import com.alibaba.csp.sentinel.dashboard.domain.vo.ResourceVo;
import com.alibaba.csp.sentinel.util.StringUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -28,9 +33,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author Carpenter Lee * @author Carpenter Lee
*/ */

View File

@ -15,14 +15,19 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.controller; package com.alibaba.csp.sentinel.dashboard.controller;
import java.util.Date;
import java.util.List;
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction; import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType; import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.dashboard.domain.Result;
import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository; import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.domain.Result;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -30,9 +35,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;
/** /**
* @author leyou(lihao) * @author leyou(lihao)
*/ */

View File

@ -17,6 +17,7 @@ package com.alibaba.csp.sentinel.dashboard.controller;
import com.alibaba.csp.sentinel.dashboard.domain.Result; import com.alibaba.csp.sentinel.dashboard.domain.Result;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;

View File

@ -15,19 +15,24 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.controller.cluster; package com.alibaba.csp.sentinel.dashboard.controller.cluster;
import com.alibaba.csp.sentinel.dashboard.domain.Result; import java.util.Collections;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO; import java.util.Set;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppFullAssignRequest; import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppFullAssignRequest;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppSingleServerAssignRequest; import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppSingleServerAssignRequest;
import com.alibaba.csp.sentinel.dashboard.service.ClusterAssignService; import com.alibaba.csp.sentinel.dashboard.service.ClusterAssignService;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.dashboard.domain.Result;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import java.util.Collections; import org.springframework.web.bind.annotation.RequestBody;
import java.util.Set; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/** /**
* @author Eric Zhao * @author Eric Zhao

View File

@ -15,11 +15,18 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.controller.cluster; package com.alibaba.csp.sentinel.dashboard.controller.cluster;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import com.alibaba.csp.sentinel.cluster.ClusterStateManager; import com.alibaba.csp.sentinel.cluster.ClusterStateManager;
import com.alibaba.csp.sentinel.dashboard.client.CommandNotFoundException; import com.alibaba.csp.sentinel.dashboard.client.CommandNotFoundException;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.SentinelVersion;
import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement; import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement;
import com.alibaba.csp.sentinel.dashboard.domain.Result; import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.SentinelVersion;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest; import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterModifyRequest; import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterModifyRequest;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest; import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest;
@ -30,17 +37,17 @@ import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalS
import com.alibaba.csp.sentinel.dashboard.service.ClusterConfigService; import com.alibaba.csp.sentinel.dashboard.service.ClusterConfigService;
import com.alibaba.csp.sentinel.dashboard.util.ClusterEntityUtils; import com.alibaba.csp.sentinel.dashboard.util.ClusterEntityUtils;
import com.alibaba.csp.sentinel.dashboard.util.VersionUtils; import com.alibaba.csp.sentinel.dashboard.util.VersionUtils;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.dashboard.domain.Result;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.List; import org.springframework.web.bind.annotation.PostMapping;
import java.util.Optional; import org.springframework.web.bind.annotation.RequestBody;
import java.util.concurrent.ExecutionException; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/** /**
* @author Eric Zhao * @author Eric Zhao

View File

@ -36,9 +36,9 @@ import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import static com.alibaba.csp.sentinel.slots.block.RuleConstant.*;
import static com.alibaba.csp.sentinel.adapter.gateway.common.SentinelGatewayConstants.*; import static com.alibaba.csp.sentinel.adapter.gateway.common.SentinelGatewayConstants.*;
import static com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.GatewayFlowRuleEntity.*; import static com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.GatewayFlowRuleEntity.*;
import static com.alibaba.csp.sentinel.slots.block.RuleConstant.*;
/** /**
* Gateway flow rule Controller for manage gateway flow rules. * Gateway flow rule Controller for manage gateway flow rules.

View File

@ -15,23 +15,33 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.controller.v2; package com.alibaba.csp.sentinel.dashboard.controller.v2;
import java.util.Date;
import java.util.List;
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction; import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
import com.alibaba.csp.sentinel.dashboard.auth.AuthService; import com.alibaba.csp.sentinel.dashboard.auth.AuthService;
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType; import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.domain.Result;
import com.alibaba.csp.sentinel.dashboard.repository.rule.InMemoryRuleRepositoryAdapter; import com.alibaba.csp.sentinel.dashboard.repository.rule.InMemoryRuleRepositoryAdapter;
import com.alibaba.csp.sentinel.dashboard.rule.DynamicRuleProvider; import com.alibaba.csp.sentinel.dashboard.rule.DynamicRuleProvider;
import com.alibaba.csp.sentinel.dashboard.rule.DynamicRulePublisher; import com.alibaba.csp.sentinel.dashboard.rule.DynamicRulePublisher;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.dashboard.domain.Result;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.Date; import org.springframework.web.bind.annotation.PathVariable;
import java.util.List; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/** /**
* Flow rule controller (v2). * Flow rule controller (v2).
@ -127,7 +137,7 @@ public class FlowControllerV2 {
} }
@PostMapping("/rule") @PostMapping("/rule")
@AuthAction(value = AuthService.PrivilegeType.WRITE_RULE) @AuthAction(value = PrivilegeType.WRITE_RULE)
public Result<FlowRuleEntity> apiAddFlowRule(@RequestBody FlowRuleEntity entity) { public Result<FlowRuleEntity> apiAddFlowRule(@RequestBody FlowRuleEntity entity) {
Result<FlowRuleEntity> checkResult = checkEntityInternal(entity); Result<FlowRuleEntity> checkResult = checkEntityInternal(entity);
@ -152,7 +162,7 @@ public class FlowControllerV2 {
} }
@PutMapping("/rule/{id}") @PutMapping("/rule/{id}")
@AuthAction(AuthService.PrivilegeType.WRITE_RULE) @AuthAction(PrivilegeType.WRITE_RULE)
public Result<FlowRuleEntity> apiUpdateFlowRule(@PathVariable("id") Long id, @RequestBody FlowRuleEntity entity) { public Result<FlowRuleEntity> apiUpdateFlowRule(@PathVariable("id") Long id, @RequestBody FlowRuleEntity entity) {
if (id == null || id <= 0) { if (id == null || id <= 0) {

View File

@ -15,10 +15,10 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.datasource.entity; package com.alibaba.csp.sentinel.dashboard.datasource.entity;
import com.alibaba.csp.sentinel.dashboard.discovery.AppInfo;
import java.util.Date; import java.util.Date;
import com.alibaba.csp.sentinel.dashboard.discovery.AppInfo;
/** /**
* @author leyou * @author leyou
*/ */

View File

@ -15,10 +15,10 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.datasource.entity; package com.alibaba.csp.sentinel.dashboard.datasource.entity;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import java.util.Date; import java.util.Date;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
/** /**
* @author leyou * @author leyou
*/ */

View File

@ -15,10 +15,11 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule; package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule;
import com.alibaba.csp.sentinel.slots.block.AbstractRule;
import java.util.Date; import java.util.Date;
import com.alibaba.csp.sentinel.slots.block.AbstractRule;
import com.alibaba.csp.sentinel.slots.block.Rule;
/** /**
* @author Eric Zhao * @author Eric Zhao
* @since 0.2.1 * @since 0.2.1

View File

@ -15,10 +15,10 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule; package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import java.util.Date; import java.util.Date;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
/** /**
* @author leyou * @author leyou
*/ */

View File

@ -15,11 +15,11 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule; package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule;
import java.util.Date;
import com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig; import com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import java.util.Date;
/** /**
* @author leyou * @author leyou
*/ */

View File

@ -38,7 +38,7 @@ public class ParamFlowRuleEntity extends AbstractRuleEntity<ParamFlowRule> {
this.rule = rule; this.rule = rule;
} }
public static ParamFlowRuleEntity fromAuthorityRule(String app, String ip, Integer port, ParamFlowRule rule) { public static ParamFlowRuleEntity fromParamFlowRule(String app, String ip, Integer port, ParamFlowRule rule) {
ParamFlowRuleEntity entity = new ParamFlowRuleEntity(rule); ParamFlowRuleEntity entity = new ParamFlowRuleEntity(rule);
entity.setApp(app); entity.setApp(app);
entity.setIp(ip); entity.setIp(ip);

View File

@ -15,10 +15,10 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule; package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule;
import com.alibaba.csp.sentinel.slots.block.Rule;
import java.util.Date; import java.util.Date;
import com.alibaba.csp.sentinel.slots.block.Rule;
/** /**
* @author leyou * @author leyou
*/ */

View File

@ -15,11 +15,15 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.discovery; package com.alibaba.csp.sentinel.dashboard.discovery;
import com.alibaba.csp.sentinel.dashboard.config.DashboardConfig; import java.util.Comparator;
import java.util.HashSet;
import java.util.*; import java.util.Optional;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import com.alibaba.csp.sentinel.dashboard.config.DashboardConfig;
public class AppInfo { public class AppInfo {
private String app = ""; private String app = "";

View File

@ -15,14 +15,15 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.discovery; package com.alibaba.csp.sentinel.dashboard.discovery;
import java.util.List;
import java.util.Set;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Set;
@Component @Component
public class AppManagement implements MachineDiscovery { public class AppManagement implements MachineDiscovery {

View File

@ -15,11 +15,11 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.discovery; package com.alibaba.csp.sentinel.dashboard.discovery;
import java.util.Objects;
import com.alibaba.csp.sentinel.dashboard.config.DashboardConfig; import com.alibaba.csp.sentinel.dashboard.config.DashboardConfig;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;
import java.util.Objects;
public class MachineInfo implements Comparable<MachineInfo> { public class MachineInfo implements Comparable<MachineInfo> {
private String app = ""; private String app = "";

View File

@ -15,9 +15,6 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.discovery; package com.alibaba.csp.sentinel.dashboard.discovery;
import com.alibaba.csp.sentinel.util.AssertUtil;
import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -25,6 +22,10 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import com.alibaba.csp.sentinel.util.AssertUtil;
import org.springframework.stereotype.Component;
/** /**
* @author leyou * @author leyou
*/ */

View File

@ -15,13 +15,13 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.domain; package com.alibaba.csp.sentinel.dashboard.domain;
import com.alibaba.csp.sentinel.command.vo.NodeVo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.alibaba.csp.sentinel.command.vo.NodeVo;
/** /**
* @author leyou * @author leyou
*/ */

View File

@ -15,11 +15,11 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.domain.cluster; package com.alibaba.csp.sentinel.dashboard.domain.cluster;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap;
/** /**
* @author Eric Zhao * @author Eric Zhao
* @since 1.4.1 * @since 1.4.1

View File

@ -15,10 +15,10 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.domain.cluster; package com.alibaba.csp.sentinel.dashboard.domain.cluster;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap;
import java.util.Set; import java.util.Set;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap;
/** /**
* @author Eric Zhao * @author Eric Zhao
* @since 1.4.1 * @since 1.4.1

View File

@ -15,11 +15,11 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.domain.cluster.request; package com.alibaba.csp.sentinel.dashboard.domain.cluster.request;
import java.util.Set;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig; import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig; import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig;
import java.util.Set;
/** /**
* @author Eric Zhao * @author Eric Zhao
* @since 1.4.0 * @since 1.4.0

View File

@ -15,13 +15,13 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.domain.cluster.state; package com.alibaba.csp.sentinel.dashboard.domain.cluster.state;
import java.util.List;
import java.util.Set;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ConnectionGroupVO; import com.alibaba.csp.sentinel.dashboard.domain.cluster.ConnectionGroupVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig; import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig; import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig;
import java.util.List;
import java.util.Set;
/** /**
* @author Eric Zhao * @author Eric Zhao
* @since 1.4.0 * @since 1.4.0

View File

@ -15,11 +15,11 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.domain.vo; package com.alibaba.csp.sentinel.dashboard.domain.vo;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
/** /**
* @author leyou * @author leyou
*/ */

View File

@ -15,12 +15,12 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.domain.vo; package com.alibaba.csp.sentinel.dashboard.domain.vo;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity;
/** /**
* @author leyou * @author leyou
*/ */

View File

@ -15,12 +15,13 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.domain.vo; package com.alibaba.csp.sentinel.dashboard.domain.vo;
import com.alibaba.csp.sentinel.command.vo.NodeVo;
import com.alibaba.csp.sentinel.dashboard.domain.ResourceTreeNode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.alibaba.csp.sentinel.command.vo.NodeVo;
import com.alibaba.csp.sentinel.dashboard.domain.ResourceTreeNode;
/** /**
* @author leyou * @author leyou
*/ */

View File

@ -23,8 +23,21 @@ package com.alibaba.csp.sentinel.dashboard.domain.vo.gateway.api;
*/ */
public class ApiPredicateItemVo { public class ApiPredicateItemVo {
/**
* The pattern for matching url.
*/
private String pattern; private String pattern;
/**
* The matching Strategy in url. Constants are defined in class
* SentinelGatewayConstants.\
*
* <ul>
* <li>0(URL_MATCH_STRATEGY_EXACT): exact match mode</li>
* <li>1(URL_MATCH_STRATEGY_PREFIX): prefix match mode</li>
* <li>2(URL_MATCH_STRATEGY_REGEX): regex match mode</li>
* </ul>
*/
private Integer matchStrategy; private Integer matchStrategy;
public String getPattern() { public String getPattern() {

View File

@ -15,6 +15,26 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.metric; package com.alibaba.csp.sentinel.dashboard.metric;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor.DiscardPolicy;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import com.alibaba.csp.sentinel.Constants; import com.alibaba.csp.sentinel.Constants;
import com.alibaba.csp.sentinel.concurrent.NamedThreadFactory; import com.alibaba.csp.sentinel.concurrent.NamedThreadFactory;
import com.alibaba.csp.sentinel.config.SentinelConfig; import com.alibaba.csp.sentinel.config.SentinelConfig;
@ -22,9 +42,10 @@ import com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity;
import com.alibaba.csp.sentinel.dashboard.discovery.AppInfo; import com.alibaba.csp.sentinel.dashboard.discovery.AppInfo;
import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement; import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.dashboard.repository.metric.MetricsRepository;
import com.alibaba.csp.sentinel.node.metric.MetricNode; import com.alibaba.csp.sentinel.node.metric.MetricNode;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.dashboard.repository.metric.MetricsRepository;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.concurrent.FutureCallback; import org.apache.http.concurrent.FutureCallback;
@ -40,14 +61,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.nio.charset.Charset;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.ThreadPoolExecutor.DiscardPolicy;
import java.util.concurrent.atomic.AtomicLong;
/** /**
* Fetch metric of machines. * Fetch metric of machines.
* *
@ -84,7 +97,7 @@ public class MetricFetcher {
@SuppressWarnings("PMD.ThreadPoolCreationRule") @SuppressWarnings("PMD.ThreadPoolCreationRule")
private ScheduledExecutorService fetchScheduleService = Executors.newScheduledThreadPool(1, private ScheduledExecutorService fetchScheduleService = Executors.newScheduledThreadPool(1,
new NamedThreadFactory("sentinel-dashboard-metrics-fetch-task")); new NamedThreadFactory("sentinel-dashboard-metrics-fetch-task", true));
private ExecutorService fetchService; private ExecutorService fetchService;
@ -96,11 +109,11 @@ public class MetricFetcher {
int queueSize = 2048; int queueSize = 2048;
RejectedExecutionHandler handler = new DiscardPolicy(); RejectedExecutionHandler handler = new DiscardPolicy();
fetchService = new ThreadPoolExecutor(cores, cores, keepAliveTime, TimeUnit.MILLISECONDS, fetchService = new ThreadPoolExecutor(cores, cores, keepAliveTime, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<>(queueSize), new NamedThreadFactory("sentinel-dashboard-metrics-fetchService"), new ArrayBlockingQueue<>(queueSize),
handler); new NamedThreadFactory("sentinel-dashboard-metrics-fetchService", true), handler);
fetchWorker = new ThreadPoolExecutor(cores, cores, keepAliveTime, TimeUnit.MILLISECONDS, fetchWorker = new ThreadPoolExecutor(cores, cores, keepAliveTime, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<>(queueSize), new NamedThreadFactory("sentinel-dashboard-metrics-fetchWorker"), new ArrayBlockingQueue<>(queueSize),
handler); new NamedThreadFactory("sentinel-dashboard-metrics-fetchWorker", true), handler);
IOReactorConfig ioConfig = IOReactorConfig.custom().setConnectTimeout(3000).setSoTimeout(3000) IOReactorConfig ioConfig = IOReactorConfig.custom().setConnectTimeout(3000).setSoTimeout(3000)
.setIoThreadCount(Runtime.getRuntime().availableProcessors() * 2).build(); .setIoThreadCount(Runtime.getRuntime().availableProcessors() * 2).build();
@ -249,7 +262,7 @@ public class MetricFetcher {
catch (Exception e) { catch (Exception e) {
logger.info(msg + " metric, wait http client error:", e); logger.info(msg + " metric, wait http client error:", e);
} }
long cost = System.currentTimeMillis() - start; // long cost = System.currentTimeMillis() - start;
// logger.info("finished " + msg + " metric for " + app + ", time intervalMs [" + // logger.info("finished " + msg + " metric for " + app + ", time intervalMs [" +
// startTime + ", " + endTime // startTime + ", " + endTime
// + "], total machines=" + machines.size() + ", dead=" + dead + ", fetch // + "], total machines=" + machines.size() + ", dead=" + dead + ", fetch
@ -268,7 +281,7 @@ public class MetricFetcher {
lastFetchMs = lastFetchMs / 1000 * 1000; lastFetchMs = lastFetchMs / 1000 * 1000;
long endTime = lastFetchMs + FETCH_INTERVAL_SECOND * 1000; long endTime = lastFetchMs + FETCH_INTERVAL_SECOND * 1000;
if (endTime > now - 1000 * 2) { if (endTime > now - 1000 * 2) {
// to near // too near
return; return;
} }
// update last_fetch in advance. // update last_fetch in advance.
@ -336,26 +349,24 @@ public class MetricFetcher {
* aggregation metrics by app_resource_timeSecond, ignore ip and port. * aggregation metrics by app_resource_timeSecond, ignore ip and port.
*/ */
String key = buildMetricKey(machine.getApp(), node.getResource(), node.getTimestamp()); String key = buildMetricKey(machine.getApp(), node.getResource(), node.getTimestamp());
MetricEntity entity = map.get(key);
if (entity != null) { MetricEntity metricEntity = map.computeIfAbsent(key, s -> {
entity.addPassQps(node.getPassQps()); MetricEntity initMetricEntity = new MetricEntity();
entity.addBlockQps(node.getBlockQps()); initMetricEntity.setApp(machine.getApp());
entity.addRtAndSuccessQps(node.getRt(), node.getSuccessQps()); initMetricEntity.setTimestamp(new Date(node.getTimestamp()));
entity.addExceptionQps(node.getExceptionQps()); initMetricEntity.setPassQps(0L);
entity.addCount(1); initMetricEntity.setBlockQps(0L);
} initMetricEntity.setRtAndSuccessQps(0, 0L);
else { initMetricEntity.setExceptionQps(0L);
entity = new MetricEntity(); initMetricEntity.setCount(0);
entity.setApp(machine.getApp()); initMetricEntity.setResource(node.getResource());
entity.setTimestamp(new Date(node.getTimestamp())); return initMetricEntity;
entity.setPassQps(node.getPassQps()); });
entity.setBlockQps(node.getBlockQps()); metricEntity.addPassQps(node.getPassQps());
entity.setRtAndSuccessQps(node.getRt(), node.getSuccessQps()); metricEntity.addBlockQps(node.getBlockQps());
entity.setExceptionQps(node.getExceptionQps()); metricEntity.addRtAndSuccessQps(node.getRt(), node.getSuccessQps());
entity.setCount(1); metricEntity.addExceptionQps(node.getExceptionQps());
entity.setResource(node.getResource()); metricEntity.addCount(1);
map.put(key, entity);
}
} }
catch (Exception e) { catch (Exception e) {
logger.warn("handleBody line exception, machine: {}, line: {}", machine.toLogString(), line); logger.warn("handleBody line exception, machine: {}, line: {}", machine.toLogString(), line);

View File

@ -20,7 +20,11 @@ import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.util.TimeUtil; import com.alibaba.csp.sentinel.util.TimeUtil;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;

View File

@ -15,11 +15,12 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.repository.rule; package com.alibaba.csp.sentinel.dashboard.repository.rule;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity;
import org.springframework.stereotype.Component;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity;
import org.springframework.stereotype.Component;
/** /**
* In-memory storage for authority rules. * In-memory storage for authority rules.
* *

View File

@ -15,11 +15,12 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.repository.rule; package com.alibaba.csp.sentinel.dashboard.repository.rule;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity;
import org.springframework.stereotype.Component;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity;
import org.springframework.stereotype.Component;
/** /**
* @author leyou * @author leyou
*/ */

View File

@ -15,11 +15,12 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.repository.rule; package com.alibaba.csp.sentinel.dashboard.repository.rule;
import java.util.concurrent.atomic.AtomicLong;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
import com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig; import com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig;
import org.springframework.stereotype.Component;
import java.util.concurrent.atomic.AtomicLong; import org.springframework.stereotype.Component;
/** /**
* Store {@link FlowRuleEntity} in memory. * Store {@link FlowRuleEntity} in memory.

View File

@ -15,11 +15,12 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.repository.rule; package com.alibaba.csp.sentinel.dashboard.repository.rule;
import java.util.concurrent.atomic.AtomicLong;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity; import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowClusterConfig; import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowClusterConfig;
import org.springframework.stereotype.Component;
import java.util.concurrent.atomic.AtomicLong; import org.springframework.stereotype.Component;
/** /**
* @author Eric Zhao * @author Eric Zhao

View File

@ -15,11 +15,12 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.repository.rule; package com.alibaba.csp.sentinel.dashboard.repository.rule;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity;
import org.springframework.stereotype.Component;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity;
import org.springframework.stereotype.Component;
/** /**
* @author leyou * @author leyou
*/ */

View File

@ -15,15 +15,15 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.repository.rule; package com.alibaba.csp.sentinel.dashboard.repository.rule;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.RuleEntity;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.util.AssertUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.RuleEntity;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.util.AssertUtil;
/** /**
* @author leyou * @author leyou
*/ */

View File

@ -15,10 +15,10 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.repository.rule; package com.alibaba.csp.sentinel.dashboard.repository.rule;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import java.util.List; import java.util.List;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
/** /**
* Interface to store and find rules. * Interface to store and find rules.
* *

View File

@ -15,18 +15,20 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.rule; package com.alibaba.csp.sentinel.dashboard.rule;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/** /**
* @author Eric Zhao * @author Eric Zhao
*/ */

View File

@ -15,17 +15,18 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.rule; package com.alibaba.csp.sentinel.dashboard.rule;
import java.util.List;
import java.util.Set;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement; import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement;
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Set;
/** /**
* @author Eric Zhao * @author Eric Zhao
* @since 1.4.0 * @since 1.4.0

View File

@ -15,12 +15,12 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.service; package com.alibaba.csp.sentinel.dashboard.service;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap;
/** /**
* @author Eric Zhao * @author Eric Zhao
* @since 1.4.1 * @since 1.4.1

View File

@ -15,7 +15,21 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.service; package com.alibaba.csp.sentinel.dashboard.service;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import com.alibaba.csp.sentinel.cluster.ClusterStateManager; import com.alibaba.csp.sentinel.cluster.ClusterStateManager;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO;
import com.alibaba.csp.sentinel.util.AssertUtil;
import com.alibaba.csp.sentinel.util.function.Tuple2;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO; import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity; import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity;
@ -23,21 +37,12 @@ import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientCon
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig; import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig; import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap; import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterAppAssignMap;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO;
import com.alibaba.csp.sentinel.dashboard.util.MachineUtils; import com.alibaba.csp.sentinel.dashboard.util.MachineUtils;
import com.alibaba.csp.sentinel.util.AssertUtil;
import com.alibaba.csp.sentinel.util.function.Tuple2;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/** /**
* @author Eric Zhao * @author Eric Zhao
* @since 1.4.1 * @since 1.4.1

View File

@ -15,31 +15,32 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.service; package com.alibaba.csp.sentinel.dashboard.service;
import com.alibaba.csp.sentinel.cluster.ClusterStateManager;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.discovery.AppInfo;
import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO;
import com.alibaba.csp.sentinel.dashboard.util.AsyncUtils;
import com.alibaba.csp.sentinel.dashboard.util.ClusterEntityUtils;
import com.alibaba.csp.sentinel.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.alibaba.csp.sentinel.cluster.ClusterStateManager;
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.discovery.AppInfo;
import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest;
import com.alibaba.csp.sentinel.dashboard.util.AsyncUtils;
import com.alibaba.csp.sentinel.dashboard.util.ClusterEntityUtils;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/** /**
* @author Eric Zhao * @author Eric Zhao
* @since 1.4.0 * @since 1.4.0

View File

@ -15,15 +15,15 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.util; package com.alibaba.csp.sentinel.dashboard.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author Eric Zhao * @author Eric Zhao
* @since 1.4.1 * @since 1.4.1

View File

@ -15,13 +15,23 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.util; package com.alibaba.csp.sentinel.dashboard.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.alibaba.csp.sentinel.cluster.ClusterStateManager; import com.alibaba.csp.sentinel.cluster.ClusterStateManager;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ConnectionGroupVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.*;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;
import java.util.*; import com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.ConnectionGroupVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterClientStateWrapVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterServerStateWrapVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO;
import com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO;
/** /**
* @author Eric Zhao * @author Eric Zhao
@ -107,7 +117,8 @@ public final class ClusterEntityUtils {
if (mode == ClusterStateManager.CLUSTER_SERVER) { if (mode == ClusterStateManager.CLUSTER_SERVER) {
String serverAddress = getIp(ip); String serverAddress = getIp(ip);
int port = stateVO.getState().getServer().getPort(); int port = stateVO.getState().getServer().getPort();
map.computeIfAbsent(serverAddress, v -> new ClusterGroupEntity().setBelongToApp(true) String targetAddress = serverAddress + ":" + port;
map.computeIfAbsent(targetAddress, v -> new ClusterGroupEntity().setBelongToApp(true)
.setMachineId(ip + '@' + stateVO.getCommandPort()).setIp(ip).setPort(port)); .setMachineId(ip + '@' + stateVO.getCommandPort()).setIp(ip).setPort(port));
} }
} }
@ -120,8 +131,8 @@ public final class ClusterEntityUtils {
if (StringUtil.isBlank(targetServer) || targetPort == null || targetPort <= 0) { if (StringUtil.isBlank(targetServer) || targetPort == null || targetPort <= 0) {
continue; continue;
} }
String targetAddress = targetServer + ":" + targetPort;
ClusterGroupEntity group = map.computeIfAbsent(targetServer, v -> new ClusterGroupEntity() ClusterGroupEntity group = map.computeIfAbsent(targetAddress, v -> new ClusterGroupEntity()
.setBelongToApp(true).setMachineId(targetServer).setIp(targetServer).setPort(targetPort)); .setBelongToApp(true).setMachineId(targetServer).setIp(targetServer).setPort(targetPort));
group.getClientSet().add(ip + '@' + stateVO.getCommandPort()); group.getClientSet().add(ip + '@' + stateVO.getCommandPort());
} }

View File

@ -15,11 +15,11 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.util; package com.alibaba.csp.sentinel.dashboard.util;
import java.util.Optional;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.util.function.Tuple2; import com.alibaba.csp.sentinel.util.function.Tuple2;
import java.util.Optional;
/** /**
* @author Eric Zhao * @author Eric Zhao
*/ */

View File

@ -15,10 +15,11 @@
*/ */
package com.alibaba.csp.sentinel.dashboard.util; package com.alibaba.csp.sentinel.dashboard.util;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.SentinelVersion; import java.util.Optional;
import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.util.StringUtil;
import java.util.Optional; import com.alibaba.csp.sentinel.dashboard.datasource.entity.SentinelVersion;
/** /**
* Util class for parsing version. * Util class for parsing version.
@ -30,16 +31,16 @@ public final class VersionUtils {
/** /**
* Parse version of Sentinel from raw string. * Parse version of Sentinel from raw string.
* @param versionFull version string * @param verStr version string
* @return parsed {@link SentinelVersion} if the version is valid; empty if there is * @return parsed {@link SentinelVersion} if the version is valid; empty if there is
* something wrong with the format * something wrong with the format
*/ */
public static Optional<SentinelVersion> parseVersion(String s) { public static Optional<SentinelVersion> parseVersion(String verStr) {
if (StringUtil.isBlank(s)) { if (StringUtil.isBlank(verStr)) {
return Optional.empty(); return Optional.empty();
} }
try { try {
String versionFull = s; String versionFull = verStr;
SentinelVersion version = new SentinelVersion(); SentinelVersion version = new SentinelVersion();
// postfix // postfix

View File

View File

View File

Some files were not shown because too many files have changed in this diff Show More