Search in sources :

Example 16 with GatewayParamFlowItem

use of com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayParamFlowItem in project spring-boot-student by wyh-spring-ecosystem-student.

the class GatewayFlowRuleEntity method toGatewayFlowRule.

public GatewayFlowRule toGatewayFlowRule() {
    GatewayFlowRule rule = new GatewayFlowRule();
    rule.setResource(resource);
    rule.setResourceMode(resourceMode);
    rule.setGrade(grade);
    rule.setCount(count);
    rule.setIntervalSec(calIntervalSec(interval, intervalUnit));
    rule.setControlBehavior(controlBehavior);
    if (burst != null) {
        rule.setBurst(burst);
    }
    if (maxQueueingTimeoutMs != null) {
        rule.setMaxQueueingTimeoutMs(maxQueueingTimeoutMs);
    }
    if (paramItem != null) {
        GatewayParamFlowItem ruleItem = new GatewayParamFlowItem();
        rule.setParamItem(ruleItem);
        ruleItem.setParseStrategy(paramItem.getParseStrategy());
        ruleItem.setFieldName(paramItem.getFieldName());
        ruleItem.setPattern(paramItem.getPattern());
        if (paramItem.getMatchStrategy() != null) {
            ruleItem.setMatchStrategy(paramItem.getMatchStrategy());
        }
    }
    return rule;
}
Also used : GatewayParamFlowItem(com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayParamFlowItem) GatewayFlowRule(com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule)

Example 17 with GatewayParamFlowItem

use of com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayParamFlowItem in project spring-boot-student by wyh-spring-ecosystem-student.

the class GatewayFlowRuleEntity method fromGatewayFlowRule.

public static GatewayFlowRuleEntity fromGatewayFlowRule(String app, String ip, Integer port, GatewayFlowRule rule) {
    GatewayFlowRuleEntity entity = new GatewayFlowRuleEntity();
    entity.setApp(app);
    entity.setIp(ip);
    entity.setPort(port);
    entity.setResource(rule.getResource());
    entity.setResourceMode(rule.getResourceMode());
    entity.setGrade(rule.getGrade());
    entity.setCount(rule.getCount());
    Object[] intervalSecResult = parseIntervalSec(rule.getIntervalSec());
    entity.setInterval((Long) intervalSecResult[0]);
    entity.setIntervalUnit((Integer) intervalSecResult[1]);
    entity.setControlBehavior(rule.getControlBehavior());
    entity.setBurst(rule.getBurst());
    entity.setMaxQueueingTimeoutMs(rule.getMaxQueueingTimeoutMs());
    GatewayParamFlowItem paramItem = rule.getParamItem();
    if (paramItem != null) {
        GatewayParamFlowItemEntity itemEntity = new GatewayParamFlowItemEntity();
        entity.setParamItem(itemEntity);
        itemEntity.setParseStrategy(paramItem.getParseStrategy());
        itemEntity.setFieldName(paramItem.getFieldName());
        itemEntity.setPattern(paramItem.getPattern());
        itemEntity.setMatchStrategy(paramItem.getMatchStrategy());
    }
    return entity;
}
Also used : GatewayParamFlowItem(com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayParamFlowItem)

Example 18 with GatewayParamFlowItem

use of com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayParamFlowItem in project XHuiCloud by sindaZeng.

the class GatewayFlowRuleEntity method toGatewayFlowRule.

public GatewayFlowRule toGatewayFlowRule() {
    GatewayFlowRule rule = new GatewayFlowRule();
    rule.setResource(resource);
    rule.setResourceMode(resourceMode);
    rule.setGrade(grade);
    rule.setCount(count);
    rule.setIntervalSec(calIntervalSec(interval, intervalUnit));
    rule.setControlBehavior(controlBehavior);
    if (burst != null) {
        rule.setBurst(burst);
    }
    if (maxQueueingTimeoutMs != null) {
        rule.setMaxQueueingTimeoutMs(maxQueueingTimeoutMs);
    }
    if (paramItem != null) {
        GatewayParamFlowItem ruleItem = new GatewayParamFlowItem();
        rule.setParamItem(ruleItem);
        ruleItem.setParseStrategy(paramItem.getParseStrategy());
        ruleItem.setFieldName(paramItem.getFieldName());
        ruleItem.setPattern(paramItem.getPattern());
        if (paramItem.getMatchStrategy() != null) {
            ruleItem.setMatchStrategy(paramItem.getMatchStrategy());
        }
    }
    return rule;
}
Also used : GatewayParamFlowItem(com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayParamFlowItem) GatewayFlowRule(com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule)

Example 19 with GatewayParamFlowItem

use of com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayParamFlowItem in project XHuiCloud by sindaZeng.

the class GatewayFlowRuleEntity method fromGatewayFlowRule.

public static GatewayFlowRuleEntity fromGatewayFlowRule(String app, String ip, Integer port, GatewayFlowRule rule) {
    GatewayFlowRuleEntity entity = new GatewayFlowRuleEntity();
    entity.setApp(app);
    entity.setIp(ip);
    entity.setPort(port);
    entity.setResource(rule.getResource());
    entity.setResourceMode(rule.getResourceMode());
    entity.setGrade(rule.getGrade());
    entity.setCount(rule.getCount());
    Object[] intervalSecResult = parseIntervalSec(rule.getIntervalSec());
    entity.setInterval((Long) intervalSecResult[0]);
    entity.setIntervalUnit((Integer) intervalSecResult[1]);
    entity.setControlBehavior(rule.getControlBehavior());
    entity.setBurst(rule.getBurst());
    entity.setMaxQueueingTimeoutMs(rule.getMaxQueueingTimeoutMs());
    GatewayParamFlowItem paramItem = rule.getParamItem();
    if (paramItem != null) {
        GatewayParamFlowItemEntity itemEntity = new GatewayParamFlowItemEntity();
        entity.setParamItem(itemEntity);
        itemEntity.setParseStrategy(paramItem.getParseStrategy());
        itemEntity.setFieldName(paramItem.getFieldName());
        itemEntity.setPattern(paramItem.getPattern());
        itemEntity.setMatchStrategy(paramItem.getMatchStrategy());
    }
    return entity;
}
Also used : GatewayParamFlowItem(com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayParamFlowItem)

Example 20 with GatewayParamFlowItem

use of com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayParamFlowItem in project RuoYi-Cloud-Plus by JavaLionLi.

the class GatewayFlowRuleEntity method fromGatewayFlowRule.

public static GatewayFlowRuleEntity fromGatewayFlowRule(String app, String ip, Integer port, GatewayFlowRule rule) {
    GatewayFlowRuleEntity entity = new GatewayFlowRuleEntity();
    entity.setApp(app);
    entity.setIp(ip);
    entity.setPort(port);
    entity.setResource(rule.getResource());
    entity.setResourceMode(rule.getResourceMode());
    entity.setGrade(rule.getGrade());
    entity.setCount(rule.getCount());
    Object[] intervalSecResult = parseIntervalSec(rule.getIntervalSec());
    entity.setInterval((Long) intervalSecResult[0]);
    entity.setIntervalUnit((Integer) intervalSecResult[1]);
    entity.setControlBehavior(rule.getControlBehavior());
    entity.setBurst(rule.getBurst());
    entity.setMaxQueueingTimeoutMs(rule.getMaxQueueingTimeoutMs());
    GatewayParamFlowItem paramItem = rule.getParamItem();
    if (paramItem != null) {
        GatewayParamFlowItemEntity itemEntity = new GatewayParamFlowItemEntity();
        entity.setParamItem(itemEntity);
        itemEntity.setParseStrategy(paramItem.getParseStrategy());
        itemEntity.setFieldName(paramItem.getFieldName());
        itemEntity.setPattern(paramItem.getPattern());
        itemEntity.setMatchStrategy(paramItem.getMatchStrategy());
    }
    return entity;
}
Also used : GatewayParamFlowItem(com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayParamFlowItem)

Aggregations

GatewayParamFlowItem (com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayParamFlowItem)20 GatewayFlowRule (com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule)15 HashSet (java.util.HashSet)9 Test (org.junit.Test)4 HashMap (java.util.HashMap)2 SentinelGatewayConstants (com.alibaba.csp.sentinel.adapter.gateway.common.SentinelGatewayConstants)1 GatewayApiDefinitionManager (com.alibaba.csp.sentinel.adapter.gateway.common.api.GatewayApiDefinitionManager)1 GatewayParamParser (com.alibaba.csp.sentinel.adapter.gateway.common.param.GatewayParamParser)1 GatewayRuleManager (com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager)1 RuleConstant (com.alibaba.csp.sentinel.slots.block.RuleConstant)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 Map (java.util.Map)1 Set (java.util.Set)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 After (org.junit.After)1 Before (org.junit.Before)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 HttpHeaders (org.springframework.http.HttpHeaders)1