赞
踩
按照 (一)部署完成之后
1. 在网关项目pom文件中新增 持久化依赖
- <!-- Sentinel 持久化配置,支持多种持久化数据源:file、nacos、zookeeper、apollo、redis、consul 非必须,按需选择,这里使用的是 nacos-->
- <dependency>
- <groupId>com.alibaba.csp</groupId>
- <artifactId>sentinel-datasource-nacos</artifactId>
- </dependency>
2. 修改网关yaml配置
新增spring.cloud.sentinel.datasource
其中api代表的为数据源名字,可自主起名,server-addr 为 nacos主机连接ip与端口,可通过${spring.cloud.nacos.config.server-addr} 从注册中心获取
rule-type的配置项对应RuleType 枚举类。
public enum RuleType {
FLOW("flow", FlowRule.class),
DEGRADE("degrade", DegradeRule.class),
PARAM_FLOW("param-flow", ParamFlowRule.class),
SYSTEM("system", SystemRule.class),
AUTHORITY("authority", AuthorityRule.class),
GW_FLOW("gw-flow", "com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule"),
GW_API_GROUP("gw-api-group", "com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition");
}
- spring:
- cloud:
- sentinel:
- enable: true
- filter:
- enabled: false
- eager: true #立即加载
- transport:
- port: 9010
- dashboard: 127.0.0.1:8080
- # dashboard: 172.16.10.233:9010
- scg:
- # 限流后的相应配置
- fallback:
- content-type: application/json
- # 模式: response / redirect
- mode: response
- # 相应状态码
- response-status: 200
- # 相应消息体
- response-body: '{"code":0,"message":"服务忙请稍后再试...","data":null}'
- # Sentinel 流控规则持久化
- datasource:
- api:
- nacos:
- server-addr: 127.0.0.1:8848
- namespace: ****************
- # 组名 默认 DEFAULT_GROUP
- group-id: 'SENTINEL_GROUP'
- # Nacos 中配置的Id
- data-id: ${spring.application.name}-api-rules
- # RuleType
- rule-type: gw-api-group
- # 默认就是Json
- data-type: 'json'
- # 自定义命名
- flow:
- # 支持多种持久化数据源:file、nacos、zookeeper、apollo、redis、consul
- nacos:
- # 配置类com.alibaba.cloud.sentinel.datasource.config.NacosDataSourceProperties
- # 连接地址
- server-addr: 127.0.0.1:8848
- namespace: ****************
- # 组名 默认 DEFAULT_GROUP
- group-id: 'SENTINEL_GROUP'
- # Nacos 中配置的Id
- data-id: ${spring.application.name}-flow-rules
- # RuleType
- rule-type: gw-flow
- # 默认就是Json
- data-type: 'json'

二、改造sentinel-dashboard
1.修改pom
改
- <!-- for Nacos rule publisher sample -->
- <dependency>
- <groupId>com.alibaba.csp</groupId>
- <artifactId>sentinel-datasource-nacos</artifactId>
- <scope>test</scope>
- </dependency>
为
- <!-- for Nacos rule publisher sample -->
- <dependency>
- <groupId>com.alibaba.csp</groupId>
- <artifactId>sentinel-datasource-nacos</artifactId>
- </dependency>
2.修改 application.properties 新增
- # local
- spring.cloud.sentinel.datasource.ds.nacos.serverAddr = 127.0.0.1 #nacos地址
- spring.cloud.sentinel.datasource.ds.nacos.groupId=SENTINEL_GROUP
- spring.cloud.sentinel.datasource.ds.nacos.namespace=***** #nacos对应的 namespace
3. 修改代码
1) 将test文件夹下
com.alibaba.csp.sentinel.dashboard.rule.nacos 拷贝到com.alibaba.csp.sentinel.dashboard.controller.gateway下
并修改 NacosConfig
- @Configuration
- public class NacosConfig {
-
- @Value("${spring.cloud.sentinel.datasource.ds.nacos.serverAddr}")
- private String serverAddr;
-
- @Value("${spring.cloud.sentinel.datasource.ds.nacos.namespace}")
- private String namespace;
-
- @Bean
- public Converter<List<FlowRuleEntity>, String> flowRuleEntityEncoder() {
- return JSON::toJSONString;
- }
-
- @Bean
- public Converter<String, List<FlowRuleEntity>> flowRuleEntityDecoder() {
- return s -> JSON.parseArray(s, FlowRuleEntity.class);
- }
-
-
- @Bean
- public ConfigService nacosConfigService() throws Exception {
- Properties properties = new Properties();
- properties.setProperty(PropertyKeyConst.SERVER_ADDR,serverAddr);
- properties.setProperty(PropertyKeyConst.NAMESPACE,namespace);
- return ConfigFactory.createConfigService(properties);
- }
-
- @Bean
- public Converter<List<GatewayFlowRuleEntity>, String> gatewayFlowRuleEntityEncoder() {
- return JSON::toJSONString;
- }
-
- @Bean
- public Converter<String, List<GatewayFlowRuleEntity>> gatewayFlowRuleEntityDecoder() {
- return s -> JSON.parseArray(s, GatewayFlowRuleEntity.class);
- }
-
- @Bean
- public Converter<List<ApiDefinitionEntity>, String> gatewayApiEntityEncoder() {
- return JSON::toJSONString;
- }
-
- @Bean
- public Converter<String, List<ApiDefinitionEntity>> gatewayApiEntityDecoder() {
- return s -> JSON.parseArray(s, ApiDefinitionEntity.class);
- }
- }

2) 新增 nacos api的数据提供类 用于在nacos 发布 和 获取规则
GatewayFlowRuleNacosProvider
- @Component("gatewayFlowRuleNacosProvider")
- public class GatewayFlowRuleNacosProvider implements DynamicRuleProvider<List<GatewayFlowRuleEntity>> {
- @Autowired
- private ConfigService configService;
- // 规则对象的转换器,获取到的数据根据使用的数据类型的不同,需要用不同的转换器转化后使用
- @Autowired
- private Converter<String, List<GatewayFlowRuleEntity>> converter;
- @Override
- public List<GatewayFlowRuleEntity> getRules(String appName) throws Exception {
- String rules = configService.getConfig(appName + NacosConfigUtil.FLOW_DATA_ID_POSTFIX,
- NacosConfigUtil.GROUP_ID, 3000);
- if (StringUtil.isEmpty(rules)) {
- return new ArrayList<>(0);
- }
- return converter.convert(rules);
- }
- }

GatewayFlowRuleNacosPublisher
- @Component("gatewayFlowRuleNacosPublisher")
- public class GatewayFlowRuleNacosPublisher implements DynamicRulePublisher<List<GatewayFlowRuleEntity>> {
- // 数据源的配置服务
- @Autowired
- private ConfigService configService;
- /**
- * <p>数据通信的转换器。
- * <p>在config包下的NacosConfig类中声明的Spring Bean对象。
- * <p>负责将实体对象转换为json格式的字符串</p>
- */
- @Autowired
- private Converter<List<GatewayFlowRuleEntity>, String> converter;
-
- @Override
- public void publish(String app, List<GatewayFlowRuleEntity> rules) throws Exception {
- AssertUtil.notEmpty(app, "app name cannot be empty");
- if (rules == null) {
- return;
- }
- /*
- * 将规则发布到动态数据源作持久化,第一个参数是app+后缀,此处用的是-flow-rules的后缀;
- * 第二个参数是nacos分组id,这个用默认提供的sentinel预留项即可;最后一个参数是数据转换
- * 器,要将对象转换成统一的格式后,网络传输到nacos。
- */
- configService.publishConfig(app + NacosConfigUtil.FLOW_DATA_ID_POSTFIX,
- NacosConfigUtil.GROUP_ID, converter.convert(rules));
- }
- }

3.) 对照着 GatewayFlowRuleController 新增 GatewayFlowRuleControllerV2
并 修改数据的获取方式 原先为通过 sentinelApiClient 获取 修改为通过 上面创建的 发布和获取类获取
- @RestController
- @RequestMapping(value = "/v2/gateway/flow")
- public class GatewayFlowRuleControllerV2 {
-
- private final Logger logger = LoggerFactory.getLogger(GatewayFlowRuleController.class);
-
- @Autowired
- private InMemGatewayFlowRuleStore repository;
-
- @Autowired
- @Qualifier("gatewayFlowRuleNacosProvider")
- private DynamicRuleProvider<List<GatewayFlowRuleEntity>> ruleProvider;
- @Autowired
- @Qualifier("gatewayFlowRuleNacosPublisher")
- private DynamicRulePublisher<List<GatewayFlowRuleEntity>> rulePublisher;
-
- @Autowired
- private AuthService<HttpServletRequest> authService;
-
- @GetMapping("/list.json")
- public Result<List<GatewayFlowRuleEntity>> queryFlowRules(HttpServletRequest request, String app, String ip, Integer port) {
- AuthService.AuthUser authUser = authService.getAuthUser(request);
- authUser.authTarget(app, AuthService.PrivilegeType.READ_RULE);
-
- if (StringUtil.isEmpty(app)) {
- return Result.ofFail(-1, "app can't be null or empty");
- }
- if (StringUtil.isEmpty(ip)) {
- return Result.ofFail(-1, "ip can't be null or empty");
- }
- if (port == null) {
- return Result.ofFail(-1, "port can't be null");
- }
-
- try {
- List<GatewayFlowRuleEntity> rules = ruleProvider.getRules(app);
- repository.saveAll(rules);
- return Result.ofSuccess(rules);
- } catch (Throwable throwable) {
- logger.error("query gateway flow rules error:", throwable);
- return Result.ofThrowable(-1, throwable);
- }
- }
-
- @PostMapping("/new.json")
- public Result<GatewayFlowRuleEntity> addFlowRule(HttpServletRequest request, @RequestBody AddFlowRuleReqVo reqVo) {
- AuthService.AuthUser authUser = authService.getAuthUser(request);
-
- String app = reqVo.getApp();
- if (StringUtil.isBlank(app)) {
- return Result.ofFail(-1, "app can't be null or empty");
- }
-
- authUser.authTarget(app, AuthService.PrivilegeType.WRITE_RULE);
-
- GatewayFlowRuleEntity entity = new GatewayFlowRuleEntity();
- entity.setApp(app.trim());
-
- String ip = reqVo.getIp();
- if (StringUtil.isBlank(ip)) {
- return Result.ofFail(-1, "ip can't be null or empty");
- }
- entity.setIp(ip.trim());
-
- Integer port = reqVo.getPort();
- if (port == null) {
- return Result.ofFail(-1, "port can't be null");
- }
- entity.setPort(port);
-
- // API类型, Route ID或API分组
- Integer resourceMode = reqVo.getResourceMode();
- if (resourceMode == null) {
- return Result.ofFail(-1, "resourceMode can't be null");
- }
- if (!Arrays.asList(RESOURCE_MODE_ROUTE_ID, RESOURCE_MODE_CUSTOM_API_NAME).contains(resourceMode)) {
- return Result.ofFail(-1, "invalid resourceMode: " + resourceMode);
- }
- entity.setResourceMode(resourceMode);
-
- // API名称
- String resource = reqVo.getResource();
- if (StringUtil.isBlank(resource)) {
- return Result.ofFail(-1, "resource can't be null or empty");
- }
- entity.setResource(resource.trim());
-
- // 针对请求属性
- GatewayParamFlowItemVo paramItem = reqVo.getParamItem();
- if (paramItem != null) {
- GatewayParamFlowItemEntity itemEntity = new GatewayParamFlowItemEntity();
- entity.setParamItem(itemEntity);
-
- // 参数属性 0-ClientIP 1-Remote Host 2-Header 3-URL参数 4-Cookie
- Integer parseStrategy = paramItem.getParseStrategy();
- if (!Arrays.asList(PARAM_PARSE_STRATEGY_CLIENT_IP, PARAM_PARSE_STRATEGY_HOST, PARAM_PARSE_STRATEGY_HEADER
- , PARAM_PARSE_STRATEGY_URL_PARAM, PARAM_PARSE_STRATEGY_COOKIE).contains(parseStrategy)) {
- return Result.ofFail(-1, "invalid parseStrategy: " + parseStrategy);
- }
- itemEntity.setParseStrategy(paramItem.getParseStrategy());
-
- // 当参数属性为2-Header 3-URL参数 4-Cookie时,参数名称必填
- if (Arrays.asList(PARAM_PARSE_STRATEGY_HEADER, PARAM_PARSE_STRATEGY_URL_PARAM, PARAM_PARSE_STRATEGY_COOKIE).contains(parseStrategy)) {
- // 参数名称
- String fieldName = paramItem.getFieldName();
- if (StringUtil.isBlank(fieldName)) {
- return Result.ofFail(-1, "fieldName can't be null or empty");
- }
- itemEntity.setFieldName(paramItem.getFieldName());
-
- String pattern = paramItem.getPattern();
- // 如果匹配串不为空,验证匹配模式
- if (StringUtil.isNotEmpty(pattern)) {
- itemEntity.setPattern(pattern);
-
- Integer matchStrategy = paramItem.getMatchStrategy();
- if (!Arrays.asList(PARAM_MATCH_STRATEGY_EXACT, PARAM_MATCH_STRATEGY_CONTAINS, PARAM_MATCH_STRATEGY_REGEX).contains(matchStrategy)) {
- return Result.ofFail(-1, "invalid matchStrategy: " + matchStrategy);
- }
- itemEntity.setMatchStrategy(matchStrategy);
- }
- }
- }
-
- // 阈值类型 0-线程数 1-QPS
- Integer grade = reqVo.getGrade();
- if (grade == null) {
- return Result.ofFail(-1, "grade can't be null");
- }
- if (!Arrays.asList(FLOW_GRADE_THREAD, FLOW_GRADE_QPS).contains(grade)) {
- return Result.ofFail(-1, "invalid grade: " + grade);
- }
- entity.setGrade(grade);
-
- // QPS阈值
- Double count = reqVo.getCount();
- if (count == null) {
- return Result.ofFail(-1, "count can't be null");
- }
- if (count < 0) {
- return Result.ofFail(-1, "count should be at lease zero");
- }
- entity.setCount(count);
-
- // 间隔
- Long interval = reqVo.getInterval();
- if (interval == null) {
- return Result.ofFail(-1, "interval can't be null");
- }
- if (interval <= 0) {
- return Result.ofFail(-1, "interval should be greater than zero");
- }
- entity.setInterval(interval);
-
- // 间隔单位
- Integer intervalUnit = reqVo.getIntervalUnit();
- if (intervalUnit == null) {
- return Result.ofFail(-1, "intervalUnit can't be null");
- }
- if (!Arrays.asList(INTERVAL_UNIT_SECOND, INTERVAL_UNIT_MINUTE, INTERVAL_UNIT_HOUR, INTERVAL_UNIT_DAY).contains(intervalUnit)) {
- return Result.ofFail(-1, "Invalid intervalUnit: " + intervalUnit);
- }
- entity.setIntervalUnit(intervalUnit);
-
- // 流控方式 0-快速失败 2-匀速排队
- Integer controlBehavior = reqVo.getControlBehavior();
- if (controlBehavior == null) {
- return Result.ofFail(-1, "controlBehavior can't be null");
- }
- if (!Arrays.asList(CONTROL_BEHAVIOR_DEFAULT, CONTROL_BEHAVIOR_RATE_LIMITER).contains(controlBehavior)) {
- return Result.ofFail(-1, "invalid controlBehavior: " + controlBehavior);
- }
- entity.setControlBehavior(controlBehavior);
-
- if (CONTROL_BEHAVIOR_DEFAULT == controlBehavior) {
- // 0-快速失败, 则Burst size必填
- Integer burst = reqVo.getBurst();
- if (burst == null) {
- return Result.ofFail(-1, "burst can't be null");
- }
- if (burst < 0) {
- return Result.ofFail(-1, "invalid burst: " + burst);
- }
- entity.setBurst(burst);
- } else if (CONTROL_BEHAVIOR_RATE_LIMITER == controlBehavior) {
- // 1-匀速排队, 则超时时间必填
- Integer maxQueueingTimeoutMs = reqVo.getMaxQueueingTimeoutMs();
- if (maxQueueingTimeoutMs == null) {
- return Result.ofFail(-1, "maxQueueingTimeoutMs can't be null");
- }
- if (maxQueueingTimeoutMs < 0) {
- return Result.ofFail(-1, "invalid maxQueueingTimeoutMs: " + maxQueueingTimeoutMs);
- }
- entity.setMaxQueueingTimeoutMs(maxQueueingTimeoutMs);
- }
-
- Date date = new Date();
- entity.setGmtCreate(date);
- entity.setGmtModified(date);
-
- try {
- entity = repository.save(entity);
- publishRules(entity.getApp(), entity.getIp(), entity.getPort());
- } catch (Throwable throwable) {
- logger.error("add gateway flow rule error:", throwable);
- return Result.ofThrowable(-1, throwable);
- }
-
- return Result.ofSuccess(entity);
- }
-
- @PostMapping("/save.json")
- public Result<GatewayFlowRuleEntity> updateFlowRule(HttpServletRequest request, @RequestBody UpdateFlowRuleReqVo reqVo) {
- AuthService.AuthUser authUser = authService.getAuthUser(request);
-
- String app = reqVo.getApp();
- if (StringUtil.isBlank(app)) {
- return Result.ofFail(-1, "app can't be null or empty");
- }
-
- authUser.authTarget(app, AuthService.PrivilegeType.WRITE_RULE);
-
- Long id = reqVo.getId();
- if (id == null) {
- return Result.ofFail(-1, "id can't be null");
- }
-
- GatewayFlowRuleEntity entity = repository.findById(id);
- if (entity == null) {
- return Result.ofFail(-1, "gateway flow rule does not exist, id=" + id);
- }
-
- // 针对请求属性
- GatewayParamFlowItemVo paramItem = reqVo.getParamItem();
- if (paramItem != null) {
- GatewayParamFlowItemEntity itemEntity = new GatewayParamFlowItemEntity();
- entity.setParamItem(itemEntity);
-
- // 参数属性 0-ClientIP 1-Remote Host 2-Header 3-URL参数 4-Cookie
- Integer parseStrategy = paramItem.getParseStrategy();
- if (!Arrays.asList(PARAM_PARSE_STRATEGY_CLIENT_IP, PARAM_PARSE_STRATEGY_HOST, PARAM_PARSE_STRATEGY_HEADER
- , PARAM_PARSE_STRATEGY_URL_PARAM, PARAM_PARSE_STRATEGY_COOKIE).contains(parseStrategy)) {
- return Result.ofFail(-1, "invalid parseStrategy: " + parseStrategy);
- }
- itemEntity.setParseStrategy(paramItem.getParseStrategy());
-
- // 当参数属性为2-Header 3-URL参数 4-Cookie时,参数名称必填
- if (Arrays.asList(PARAM_PARSE_STRATEGY_HEADER, PARAM_PARSE_STRATEGY_URL_PARAM, PARAM_PARSE_STRATEGY_COOKIE).contains(parseStrategy)) {
- // 参数名称
- String fieldName = paramItem.getFieldName();
- if (StringUtil.isBlank(fieldName)) {
- return Result.ofFail(-1, "fieldName can't be null or empty");
- }
- itemEntity.setFieldName(paramItem.getFieldName());
-
- String pattern = paramItem.getPattern();
- // 如果匹配串不为空,验证匹配模式
- if (StringUtil.isNotEmpty(pattern)) {
- itemEntity.setPattern(pattern);
-
- Integer matchStrategy = paramItem.getMatchStrategy();
- if (!Arrays.asList(PARAM_MATCH_STRATEGY_EXACT, PARAM_MATCH_STRATEGY_CONTAINS, PARAM_MATCH_STRATEGY_REGEX).contains(matchStrategy)) {
- return Result.ofFail(-1, "invalid matchStrategy: " + matchStrategy);
- }
- itemEntity.setMatchStrategy(matchStrategy);
- }
- }
- } else {
- entity.setParamItem(null);
- }
-
- // 阈值类型 0-线程数 1-QPS
- Integer grade = reqVo.getGrade();
- if (grade == null) {
- return Result.ofFail(-1, "grade can't be null");
- }
- if (!Arrays.asList(FLOW_GRADE_THREAD, FLOW_GRADE_QPS).contains(grade)) {
- return Result.ofFail(-1, "invalid grade: " + grade);
- }
- entity.setGrade(grade);
-
- // QPS阈值
- Double count = reqVo.getCount();
- if (count == null) {
- return Result.ofFail(-1, "count can't be null");
- }
- if (count < 0) {
- return Result.ofFail(-1, "count should be at lease zero");
- }
- entity.setCount(count);
-
- // 间隔
- Long interval = reqVo.getInterval();
- if (interval == null) {
- return Result.ofFail(-1, "interval can't be null");
- }
- if (interval <= 0) {
- return Result.ofFail(-1, "interval should be greater than zero");
- }
- entity.setInterval(interval);
-
- // 间隔单位
- Integer intervalUnit = reqVo.getIntervalUnit();
- if (intervalUnit == null) {
- return Result.ofFail(-1, "intervalUnit can't be null");
- }
- if (!Arrays.asList(INTERVAL_UNIT_SECOND, INTERVAL_UNIT_MINUTE, INTERVAL_UNIT_HOUR, INTERVAL_UNIT_DAY).contains(intervalUnit)) {
- return Result.ofFail(-1, "Invalid intervalUnit: " + intervalUnit);
- }
- entity.setIntervalUnit(intervalUnit);
-
- // 流控方式 0-快速失败 2-匀速排队
- Integer controlBehavior = reqVo.getControlBehavior();
- if (controlBehavior == null) {
- return Result.ofFail(-1, "controlBehavior can't be null");
- }
- if (!Arrays.asList(CONTROL_BEHAVIOR_DEFAULT, CONTROL_BEHAVIOR_RATE_LIMITER).contains(controlBehavior)) {
- return Result.ofFail(-1, "invalid controlBehavior: " + controlBehavior);
- }
- entity.setControlBehavior(controlBehavior);
-
- if (CONTROL_BEHAVIOR_DEFAULT == controlBehavior) {
- // 0-快速失败, 则Burst size必填
- Integer burst = reqVo.getBurst();
- if (burst == null) {
- return Result.ofFail(-1, "burst can't be null");
- }
- if (burst < 0) {
- return Result.ofFail(-1, "invalid burst: " + burst);
- }
- entity.setBurst(burst);
- } else if (CONTROL_BEHAVIOR_RATE_LIMITER == controlBehavior) {
- // 2-匀速排队, 则超时时间必填
- Integer maxQueueingTimeoutMs = reqVo.getMaxQueueingTimeoutMs();
- if (maxQueueingTimeoutMs == null) {
- return Result.ofFail(-1, "maxQueueingTimeoutMs can't be null");
- }
- if (maxQueueingTimeoutMs < 0) {
- return Result.ofFail(-1, "invalid maxQueueingTimeoutMs: " + maxQueueingTimeoutMs);
- }
- entity.setMaxQueueingTimeoutMs(maxQueueingTimeoutMs);
- }
-
- Date date = new Date();
- entity.setGmtModified(date);
-
- try {
- entity = repository.save(entity);
- publishRules(entity.getApp(), entity.getIp(), entity.getPort());
- } catch (Throwable throwable) {
- logger.error("update gateway flow rule error:", throwable);
- return Result.ofThrowable(-1, throwable);
- }
-
- return Result.ofSuccess(entity);
- }
-
-
- @PostMapping("/delete.json")
- public Result<Long> deleteFlowRule(HttpServletRequest request, Long id) {
- AuthService.AuthUser authUser = authService.getAuthUser(request);
-
- if (id == null) {
- return Result.ofFail(-1, "id can't be null");
- }
-
- GatewayFlowRuleEntity oldEntity = repository.findById(id);
- if (oldEntity == null) {
- return Result.ofSuccess(null);
- }
-
- authUser.authTarget(oldEntity.getApp(), AuthService.PrivilegeType.DELETE_RULE);
-
- try {
- repository.delete(id);
- publishRules(oldEntity.getApp(), oldEntity.getIp(), oldEntity.getPort());
- } catch (Throwable throwable) {
- logger.error("delete gateway flow rule error:", throwable);
- return Result.ofThrowable(-1, throwable);
- }
-
- return Result.ofSuccess(id);
- }
-
- /**
- * <h3>发布规则统一逻辑</h3>
- *
- * <p>规则都是存在本地内存中的,先从内存中获取所有当前要发布规则应用的规则,是一个List</p>
- * <p>将全量的规则以一定的格式发布到数据源中,进行统一更新</p>
- *
- * @param app 应用名称
- * @param ip 应用IP
- * @param port 应用端口
- * @throws Exception 远程发布,会发生异常,要进行异常处理
- */
- private void publishRules(String app, String ip, Integer port) throws Exception {
- List<GatewayFlowRuleEntity> rules = repository.findAllByMachine(MachineInfo.of(app, ip, port));
- rulePublisher.publish(app, rules);
- }
- }

GatewayApiController 同理。
4) 修改前端代码
复制 resources.app.scripts.controllers.gateway.flow.js
-> resources.app.scripts.controllers.gateway.flow_v2.js
并修改
GatewayFlowService -> GatewayFlowServiceV2
复制 resources.app.views.gateway.flow.html
-> resources.app.views.gateway.flow_v2.html
复制 resources/app/scripts/services/gateway/flow_service.js
-> resources/app/scripts/services/gateway/flow_service_v2.js
修改 GatewayFlowService -> GatewayFlowServiceV2 并 修改下面的url 加/v
修改 resources/app/scripts/app.js 为
// .state("dashboard.gatewayFlow", { // templateUrl: "app/views/gateway/flow.html", // url: "/gateway/flow/:app", // controller: "GatewayFlowCtl", // resolve: { // loadMyFiles: ["$ocLazyLoad", function (e) { // return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/gateway/flow.js"]}) // }] // } // }) .state('dashboard.gatewayFlowV2', { templateUrl: 'app/views/gateway/flow_v2.html', url: '/v2/gateway/flow/:app', controller: 'GatewayFlowCtlV2', resolve: { loadMyFiles: ['$ocLazyLoad', function ($ocLazyLoad) { return $ocLazyLoad.load({ name: 'sentinelDashboardApp', files: [ 'app/scripts/controllers/gateway/flow_v2.js', ] }); }] } })
打包启动 发布规则后 在nacos 可查看到 发布的规则
注:
但我本地不适用这个 可以参考修改 resources/dist/js/app.js
resources/dist/js/app.js 修改后的代码为
- "use strict";
- var app;
- angular.module("sentinelDashboardApp", ["oc.lazyLoad", "ui.router", "ui.bootstrap", "angular-loading-bar", "ngDialog", "ui.bootstrap.datetimepicker", "ui-notification", "rzTable", "angular-clipboard", "selectize", "angularUtils.directives.dirPagination"]).factory("AuthInterceptor", ["$window", "$state", function (t, r) {
- return {
- responseError: function (e) {
- return 401 === e.status && (t.localStorage.removeItem("session_sentinel_admin"), r.go("login")), e
- }, response: function (e) {
- return e
- }, request: function (e) {
- return e
- }, requestError: function (e) {
- return e
- }
- }
- }]).config(["$stateProvider", "$urlRouterProvider", "$ocLazyLoadProvider", "$httpProvider", function (e, t, r, a) {
- a.interceptors.push("AuthInterceptor"), r.config({
- debug: !1,
- events: !0
- }), t.otherwise("/dashboard/home"), e.state("login", {
- url: "/login",
- templateUrl: "app/views/login.html",
- controller: "LoginCtl",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/login.js"]})
- }]
- }
- }).state("dashboard", {
- url: "/dashboard",
- templateUrl: "app/views/dashboard/main.html",
- resolve: {
- loadMyDirectives: ["$ocLazyLoad", function (e) {
- return e.load({
- name: "sentinelDashboardApp",
- files: ["app/scripts/directives/header/header.js", "app/scripts/directives/sidebar/sidebar.js", "app/scripts/directives/sidebar/sidebar-search/sidebar-search.js"]
- })
- }]
- }
- }).state("dashboard.home", {
- url: "/home",
- templateUrl: "app/views/dashboard/home.html",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/main.js"]})
- }]
- }
- }).state("dashboard.flowV1", {
- templateUrl: "app/views/flow_v1.html",
- url: "/flow/:app",
- controller: "FlowControllerV1",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/flow_v1.js"]})
- }]
- }
- }).state("dashboard.flow", {
- templateUrl: "app/views/flow_v2.html",
- url: "/v2/flow/:app",
- controller: "FlowControllerV2",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/flow_v2.js"]})
- }]
- }
- }).state("dashboard.paramFlow", {
- templateUrl: "app/views/param_flow.html",
- url: "/paramFlow/:app",
- controller: "ParamFlowController",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/param_flow.js"]})
- }]
- }
- }).state("dashboard.clusterAppAssignManage", {
- templateUrl: "app/views/cluster_app_assign_manage.html",
- url: "/cluster/assign_manage/:app",
- controller: "SentinelClusterAppAssignManageController",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({
- name: "sentinelDashboardApp",
- files: ["app/scripts/controllers/cluster_app_assign_manage.js"]
- })
- }]
- }
- }).state("dashboard.clusterAppServerList", {
- templateUrl: "app/views/cluster_app_server_list.html",
- url: "/cluster/server/:app",
- controller: "SentinelClusterAppServerListController",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({
- name: "sentinelDashboardApp",
- files: ["app/scripts/controllers/cluster_app_server_list.js"]
- })
- }]
- }
- }).state("dashboard.clusterAppClientList", {
- templateUrl: "app/views/cluster_app_client_list.html",
- url: "/cluster/client/:app",
- controller: "SentinelClusterAppTokenClientListController",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({
- name: "sentinelDashboardApp",
- files: ["app/scripts/controllers/cluster_app_token_client_list.js"]
- })
- }]
- }
- }).state("dashboard.clusterSingle", {
- templateUrl: "app/views/cluster_single_config.html",
- url: "/cluster/single/:app",
- controller: "SentinelClusterSingleController",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/cluster_single.js"]})
- }]
- }
- }).state("dashboard.authority", {
- templateUrl: "app/views/authority.html",
- url: "/authority/:app",
- controller: "AuthorityRuleController",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/authority.js"]})
- }]
- }
- }).state("dashboard.degrade", {
- templateUrl: "app/views/degrade.html",
- url: "/degrade/:app",
- controller: "DegradeCtl",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/degrade.js"]})
- }]
- }
- }).state("dashboard.system", {
- templateUrl: "app/views/system.html",
- url: "/system/:app",
- controller: "SystemCtl",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/system.js"]})
- }]
- }
- }).state("dashboard.machine", {
- templateUrl: "app/views/machine.html",
- url: "/app/:app",
- controller: "MachineCtl",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/machine.js"]})
- }]
- }
- }).state("dashboard.identity", {
- templateUrl: "app/views/identity.html",
- url: "/identity/:app",
- controller: "IdentityCtl",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/identity.js"]})
- }]
- }
- }).state("dashboard.gatewayIdentity", {
- templateUrl: "app/views/gateway/identity.html",
- url: "/gateway/identity/:app",
- controller: "GatewayIdentityCtl",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/gateway/identity.js"]})
- }]
- }
- }).state("dashboard.metric", {
- templateUrl: "app/views/metric.html",
- url: "/metric/:app",
- controller: "MetricCtl",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/metric.js"]})
- }]
- }
- }).state("dashboard.gatewayApi", {
- templateUrl: "app/views/gateway/api.html",
- url: "/gateway/api/:app",
- controller: "GatewayApiCtl",
- resolve: {
- loadMyFiles: ["$ocLazyLoad", function (e) {
- return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/gateway/api.js"]})
- }]
- }
- })
- // .state("dashboard.gatewayFlow", {
- // templateUrl: "app/views/gateway/flow.html",
- // url: "/gateway/flow/:app",
- // controller: "GatewayFlowCtl",
- // resolve: {
- // loadMyFiles: ["$ocLazyLoad", function (e) {
- // return e.load({name: "sentinelDashboardApp", files: ["app/scripts/controllers/gateway/flow.js"]})
- // }]
- // }
- // })
- .state('dashboard.gatewayFlowV2', {
- templateUrl: 'app/views/gateway/flow_v2.html',
- url: '/v2/gateway/flow/:app',
- controller: 'GatewayFlowCtlV2',
- resolve: {
- loadMyFiles: ['$ocLazyLoad', function ($ocLazyLoad) {
- return $ocLazyLoad.load({
- name: 'sentinelDashboardApp',
- files: [
- 'app/scripts/controllers/gateway/flow_v2.js',
- ]
- });
- }]
- }
- })
- }]), (app = angular.module("sentinelDashboardApp")).filter("range", [function () {
- return function (e, t) {
- if (isNaN(t) || t <= 0) return [];
- e = [];
- for (var r = 1; r <= t; r++) e.push(r);
- return e
- }
- }]), (app = angular.module("sentinelDashboardApp")).service("AuthService", ["$http", function (t) {
- this.login = function (e) {
- return t({url: "/auth/login", params: e, method: "POST"})
- }, this.logout = function () {
- return t({url: "/auth/logout", method: "POST"})
- }
- }]), (app = angular.module("sentinelDashboardApp")).service("AppService", ["$http", function (e) {
- this.getApps = function () {
- return e({url: "app/briefinfos.json", method: "GET"})
- }
- }]), (app = angular.module("sentinelDashboardApp")).service("FlowServiceV1", ["$http", function (a) {
- function t(e) {
- return void 0 === e || "" === e || isNaN(e) || e <= 0
- }
-
- this.queryMachineRules = function (e, t, r) {
- return a({url: "/v1/flow/rules", params: {app: e, ip: t, port: r}, method: "GET"})
- }, this.newRule = function (e) {
- e.resource, e.limitApp, e.grade, e.count, e.strategy, e.refResource, e.controlBehavior, e.warmUpPeriodSec, e.maxQueueingTimeMs, e.app, e.ip, e.port;
- return a({url: "/v1/flow/rule", data: e, method: "POST"})
- }, this.saveRule = function (e) {
- var t = {
- id: e.id,
- resource: e.resource,
- limitApp: e.limitApp,
- grade: e.grade,
- count: e.count,
- strategy: e.strategy,
- refResource: e.refResource,
- controlBehavior: e.controlBehavior,
- warmUpPeriodSec: e.warmUpPeriodSec,
- maxQueueingTimeMs: e.maxQueueingTimeMs
- };
- return a({url: "/v1/flow/save.json", params: t, method: "PUT"})
- }, this.deleteRule = function (e) {
- var t = {id: e.id, app: e.app};
- return a({url: "/v1/flow/delete.json", params: t, method: "DELETE"})
- }, this.checkRuleValid = function (e) {
- return void 0 === e.resource || "" === e.resource ? (alert("资源名称不能为空"), !1) : void 0 === e.count || e.count < 0 ? (alert("限流阈值必须大于等于 0"), !1) : void 0 === e.strategy || e.strategy < 0 ? (alert("无效的流控模式"), !1) : 1 != e.strategy && 2 != e.strategy || void 0 !== e.refResource && "" != e.refResource ? void 0 === e.controlBehavior || e.controlBehavior < 0 ? (alert("无效的流控整形方式"), !1) : 1 == e.controlBehavior && t(e.warmUpPeriodSec) ? (alert("预热时长必须大于 0"), !1) : 2 == e.controlBehavior && t(e.maxQueueingTimeMs) ? (alert("排队超时时间必须大于 0"), !1) : !e.clusterMode || void 0 !== e.clusterConfig && void 0 !== e.clusterConfig.thresholdType || (alert("集群限流配置不正确"), !1) : (alert("请填写关联资源或入口"), !1)
- }
- }]), (app = angular.module("sentinelDashboardApp")).service("FlowServiceV2", ["$http", function (a) {
- function t(e) {
- return void 0 === e || "" === e || isNaN(e) || e <= 0
- }
-
- this.queryMachineRules = function (e, t, r) {
- return a({url: "/v2/flow/rules", params: {app: e, ip: t, port: r}, method: "GET"})
- }, this.newRule = function (e) {
- return a({url: "/v2/flow/rule", data: e, method: "POST"})
- }, this.saveRule = function (e) {
- return a({url: "/v2/flow/rule/" + e.id, data: e, method: "PUT"})
- }, this.deleteRule = function (e) {
- return a({url: "/v2/flow/rule/" + e.id, method: "DELETE"})
- }, this.checkRuleValid = function (e) {
- return void 0 === e.resource || "" === e.resource ? (alert("资源名称不能为空"), !1) : void 0 === e.count || e.count < 0 ? (alert("限流阈值必须大于等于 0"), !1) : void 0 === e.strategy || e.strategy < 0 ? (alert("无效的流控模式"), !1) : 1 != e.strategy && 2 != e.strategy || void 0 !== e.refResource && "" != e.refResource ? void 0 === e.controlBehavior || e.controlBehavior < 0 ? (alert("无效的流控整形方式"), !1) : 1 == e.controlBehavior && t(e.warmUpPeriodSec) ? (alert("预热时长必须大于 0"), !1) : 2 == e.controlBehavior && t(e.maxQueueingTimeMs) ? (alert("排队超时时间必须大于 0"), !1) : !e.clusterMode || void 0 !== e.clusterConfig && void 0 !== e.clusterConfig.thresholdType || (alert("集群限流配置不正确"), !1) : (alert("请填写关联资源或入口"), !1)
- }
- }]), (app = angular.module("sentinelDashboardApp")).service("DegradeService", ["$http", function (a) {
- this.queryMachineRules = function (e, t, r) {
- return a({url: "degrade/rules.json", params: {app: e, ip: t, port: r}, method: "GET"})
- }, this.newRule = function (e) {
- var t = {
- id: e.id,
- resource: e.resource,
- limitApp: e.limitApp,
- count: e.count,
- timeWindow: e.timeWindow,
- grade: e.grade,
- app: e.app,
- ip: e.ip,
- port: e.port
- };
- return a({url: "/degrade/new.json", params: t, method: "GET"})
- }, this.saveRule = function (e) {
- var t = {
- id: e.id,
- resource: e.resource,
- limitApp: e.limitApp,
- grade: e.grade,
- count: e.count,
- timeWindow: e.timeWindow
- };
- return a({url: "/degrade/save.json", params: t, method: "GET"})
- }, this.deleteRule = function (e) {
- var t = {id: e.id, app: e.app};
- return a({url: "/degrade/delete.json", params: t, method: "GET"})
- }, this.checkRuleValid = function (e) {
- return void 0 === e.resource || "" === e.resource ? (alert("资源名称不能为空"), !1) : void 0 === e.grade || e.grade < 0 ? (alert("未知的降级策略"), !1) : void 0 === e.count || "" === e.count || e.count < 0 ? (alert("降级阈值不能为空或小于 0"), !1) : void 0 === e.timeWindow || "" === e.timeWindow || e.timeWindow <= 0 ? (alert("降级时间窗口必须大于 0"), !1) : !(1 == e.grade && 1 < e.count) || (alert("异常比率超出范围:[0.0 - 1.0]"), !1)
- }
- }]), (app = angular.module("sentinelDashboardApp")).service("SystemService", ["$http", function (a) {
- this.queryMachineRules = function (e, t, r) {
- return a({url: "system/rules.json", params: {app: e, ip: t, port: r}, method: "GET"})
- }, this.newRule = function (e) {
- var t = {app: e.app, ip: e.ip, port: e.port};
- return 0 == e.grade ? t.avgLoad = e.avgLoad : 1 == e.grade ? t.avgRt = e.avgRt : 2 == e.grade ? t.maxThread = e.maxThread : 3 == e.grade && (t.qps = e.qps), a({
- url: "/system/new.json",
- params: t,
- method: "GET"
- })
- }, this.saveRule = function (e) {
- var t = {id: e.id};
- return 0 == e.grade ? t.avgLoad = e.avgLoad : 1 == e.grade ? t.avgRt = e.avgRt : 2 == e.grade ? t.maxThread = e.maxThread : 3 == e.grade && (t.qps = e.qps), a({
- url: "/system/save.json",
- params: t,
- method: "GET"
- })
- }, this.deleteRule = function (e) {
- var t = {id: e.id, app: e.app};
- return a({url: "/system/delete.json", params: t, method: "GET"})
- }
- }]), (app = angular.module("sentinelDashboardApp")).service("MachineService", ["$http", "$httpParamSerializerJQLike", function (a, o) {
- this.getAppMachines = function (e) {
- return a({url: "app/" + e + "/machines.json", method: "GET"})
- }, this.removeAppMachine = function (e, t, r) {
- return a({
- url: "app/" + e + "/machine/remove.json",
- method: "POST",
- headers: {"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"},
- data: o({ip: t, port: r})
- })
- }
- }]), (app = angular.module("sentinelDashboardApp")).service("IdentityService", ["$http", function (a) {
- this.fetchIdentityOfMachine = function (e, t, r) {
- return a({url: "resource/machineResource.json", params: {ip: e, port: t, searchKey: r}, method: "GET"})
- }, this.fetchClusterNodeOfMachine = function (e, t, r) {
- return a({
- url: "resource/machineResource.json",
- params: {ip: e, port: t, type: "cluster", searchKey: r},
- method: "GET"
- })
- }
- }]), (app = angular.module("sentinelDashboardApp")).service("MetricService", ["$http", function (i) {
- this.queryAppSortedIdentities = function (e) {
- return i({url: "/metric/queryTopResourceMetric.json", params: e, method: "GET"})
- }, this.queryByAppAndIdentity = function (e) {
- return i({url: "/metric/queryByAppAndResource.json", params: e, method: "GET"})
- }, this.queryByMachineAndIdentity = function (e, t, r, a, o) {
- var l = {ip: e, port: t, identity: r, startTime: a.getTime(), endTime: o.getTime()};
- return i({url: "/metric/queryByAppAndResource.json", params: l, method: "GET"})
- }
- }]), angular.module("sentinelDashboardApp").service("ParamFlowService", ["$http", function (a) {
- function o(e) {
- return !("int" !== (r = e.classType) && "double" !== r && "float" !== r && "long" !== r && "short" !== r || void 0 !== (t = e.object) && "" !== t && !isNaN(t)) || (!!("byte" === e.classType && (a = e.object, o = -128, l = 127, void 0 === a || "" === a || isNaN(a) || a < o || l < a)) || (void 0 === e.object || void 0 === e.classType || (void 0 === (i = e.count) || "" === i || isNaN(i) || i < 0)));
- var t, r, a, o, l, i
- }
-
- this.queryMachineRules = function (e, t, r) {
- return a({url: "/paramFlow/rules", params: {app: e, ip: t, port: r}, method: "GET"})
- }, this.addNewRule = function (e) {
- return a({url: "/paramFlow/rule", data: e, method: "POST"})
- }, this.saveRule = function (e) {
- return a({url: "/paramFlow/rule/" + e.id, data: e, method: "PUT"})
- }, this.deleteRule = function (e) {
- return a({url: "/paramFlow/rule/" + e.id, method: "DELETE"})
- }, this.checkRuleValid = function (e) {
- if (!e.resource || "" === e.resource) return alert("资源名称不能为空"), !1;
- if (1 != e.grade) return alert("未知的限流模式"), !1;
- if (e.count < 0) return alert("限流阈值必须大于等于 0"), !1;
- if (void 0 === e.paramIdx || "" === e.paramIdx || isNaN(e.paramIdx) || e.paramIdx < 0) return alert("热点参数索引必须大于等于 0"), !1;
- if (void 0 !== e.paramFlowItemList) for (var t = 0; t < e.paramFlowItemList.length; t++) {
- var r = e.paramFlowItemList[t];
- if (o(r)) return alert("热点参数例外项不合法,请检查值和类型是否正确:参数为 " + r.object + ", 类型为 " + r.classType + ", 限流阈值为 " + r.count), !1
- }
- return !0
- }
- }]), angular.module("sentinelDashboardApp").service("AuthorityRuleService", ["$http", function (a) {
- this.queryMachineRules = function (e, t, r) {
- return a({url: "/authority/rules", params: {app: e, ip: t, port: r}, method: "GET"})
- }, this.addNewRule = function (e) {
- return a({url: "/authority/rule", data: e, method: "POST"})
- }, this.saveRule = function (e) {
- return a({url: "/authority/rule/" + e.id, data: e, method: "PUT"})
- }, this.deleteRule = function (e) {
- return a({url: "/authority/rule/" + e.id, method: "DELETE"})
- }, this.checkRuleValid = function (e) {
- return void 0 === e.resource || "" === e.resource ? (alert("资源名称不能为空"), !1) : void 0 === e.limitApp || "" === e.limitApp ? (alert("流控针对应用不能为空"), !1) : void 0 !== e.strategy || (alert("必须选择黑白名单模式"), !1)
- }
- }]), angular.module("sentinelDashboardApp").service("ClusterStateService", ["$http", function (a) {
- this.fetchClusterUniversalStateSingle = function (e, t, r) {
- return a({url: "/cluster/state_single", params: {app: e, ip: t, port: r}, method: "GET"})
- }, this.fetchClusterUniversalStateOfApp = function (e) {
- return a({url: "/cluster/state/" + e, method: "GET"})
- }, this.fetchClusterServerStateOfApp = function (e) {
- return a({url: "/cluster/server_state/" + e, method: "GET"})
- }, this.fetchClusterClientStateOfApp = function (e) {
- return a({url: "/cluster/client_state/" + e, method: "GET"})
- }, this.modifyClusterConfig = function (e) {
- return a({url: "/cluster/config/modify_single", data: e, method: "POST"})
- }, this.applyClusterFullAssignOfApp = function (e, t) {
- return a({url: "/cluster/assign/all_server/" + e, data: t, method: "POST"})
- }, this.applyClusterSingleServerAssignOfApp = function (e, t) {
- return a({url: "/cluster/assign/single_server/" + e, data: t, method: "POST"})
- }, this.applyClusterServerBatchUnbind = function (e, t) {
- return a({url: "/cluster/assign/unbind_server/" + e, data: t, method: "POST"})
- }
- }]), (app = angular.module("sentinelDashboardApp")).service("GatewayApiService", ["$http", function (a) {
- this.queryApis = function (e, t, r) {
- return a({url: "/gateway/api/list.json", params: {app: e, ip: t, port: r}, method: "GET"})
- }, this.newApi = function (e) {
- return a({url: "/gateway/api/new.json", data: e, method: "POST"})
- }, this.saveApi = function (e) {
- return a({url: "/gateway/api/save.json", data: e, method: "POST"})
- }, this.deleteApi = function (e) {
- var t = {id: e.id, app: e.app};
- return a({url: "/gateway/api/delete.json", params: t, method: "POST"})
- }, this.checkApiValid = function (e, t) {
- if (void 0 === e.apiName || "" === e.apiName) return alert("API名称不能为空"), !1;
- if (null == e.predicateItems || 0 === e.predicateItems.length) return alert("至少有一个匹配规则"), !1;
- for (var r = 0; r < e.predicateItems.length; r++) {
- var a = e.predicateItems[r].pattern;
- if (void 0 === a || "" === a) return alert("匹配串不能为空,请检查"), !1
- }
- return -1 === t.indexOf(e.apiName) || (alert("API名称(" + e.apiName + ")已存在"), !1)
- }
- }]), (app = angular.module("sentinelDashboardApp")).service("GatewayFlowService", ["$http", function (a) {
- this.queryRules = function (e, t, r) {
- return a({url: "/gateway/flow/list.json", params: {app: e, ip: t, port: r}, method: "GET"})
- }, this.newRule = function (e) {
- return a({url: "/gateway/flow/new.json", data: e, method: "POST"})
- }, this.saveRule = function (e) {
- return a({url: "/gateway/flow/save.json", data: e, method: "POST"})
- }, this.deleteRule = function (e) {
- var t = {id: e.id, app: e.app};
- return a({url: "/gateway/flow/delete.json", params: t, method: "POST"})
- }, this.checkRuleValid = function (e) {
- if (void 0 === e.resource || "" === e.resource) return alert("API名称不能为空"), !1;
- if (null != e.paramItem && (2 == e.paramItem.parseStrategy || 3 == e.paramItem.parseStrategy || 4 == e.paramItem.parseStrategy)) {
- if (void 0 === e.paramItem.fieldName || "" === e.paramItem.fieldName) return alert("当参数属性为Header、URL参数、Cookie时,参数名称不能为空"), !1;
- if ("" === e.paramItem.pattern) return alert("匹配串不能为空"), !1
- }
- return !(void 0 === e.count || e.count < 0) || (alert((1 === e.grade ? "QPS阈值" : "线程数") + "必须大于等于 0"), !1)
- }
- }]), (app = angular.module("sentinelDashboardApp")).service("GatewayFlowServiceV2", ["$http", function (a) {
- this.queryRules = function (e, t, r) {
- return a({url: "/v2/gateway/flow/list.json", params: {app: e, ip: t, port: r}, method: "GET"})
- }, this.newRule = function (e) {
- return a({url: "/v2/gateway/flow/new.json", data: e, method: "POST"})
- }, this.saveRule = function (e) {
- return a({url: "/v2/gateway/flow/save.json", data: e, method: "POST"})
- }, this.deleteRule = function (e) {
- var t = {id: e.id, app: e.app};
- return a({url: "/v2/gateway/flow/delete.json", params: t, method: "POST"})
- }, this.checkRuleValid = function (e) {
- if (void 0 === e.resource || "" === e.resource) return alert("API名称不能为空"), !1;
- if (null != e.paramItem && (2 == e.paramItem.parseStrategy || 3 == e.paramItem.parseStrategy || 4 == e.paramItem.parseStrategy)) {
- if (void 0 === e.paramItem.fieldName || "" === e.paramItem.fieldName) return alert("当参数属性为Header、URL参数、Cookie时,参数名称不能为空"), !1;
- if ("" === e.paramItem.pattern) return alert("匹配串不能为空"), !1
- }
- return !(void 0 === e.count || e.count < 0) || (alert((1 === e.grade ? "QPS阈值" : "线程数") + "必须大于等于 0"), !1)
- }
- }]);

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。