Search in sources :

Example 1 with ApiDefinition

use of com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition in project Sentinel by alibaba.

the class GatewayApiMatcherManager method loadApiDefinitions.

static synchronized void loadApiDefinitions(/*@Valid*/
Set<ApiDefinition> definitions) {
    Map<String, WebExchangeApiMatcher> apiMatcherMap = new HashMap<>();
    for (ApiDefinition definition : definitions) {
        apiMatcherMap.put(definition.getApiName(), new WebExchangeApiMatcher(definition));
    }
    API_MATCHER_MAP = apiMatcherMap;
}
Also used : WebExchangeApiMatcher(com.alibaba.csp.sentinel.adapter.gateway.sc.api.matcher.WebExchangeApiMatcher) HashMap(java.util.HashMap) ApiDefinition(com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition)

Example 2 with ApiDefinition

use of com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition in project Sentinel by alibaba.

the class ApiDefinitionEntity method toApiDefinition.

public ApiDefinition toApiDefinition() {
    ApiDefinition apiDefinition = new ApiDefinition();
    apiDefinition.setApiName(apiName);
    Set<ApiPredicateItem> apiPredicateItems = new LinkedHashSet<>();
    apiDefinition.setPredicateItems(apiPredicateItems);
    if (predicateItems != null) {
        for (ApiPredicateItemEntity predicateItem : predicateItems) {
            ApiPathPredicateItem apiPredicateItem = new ApiPathPredicateItem();
            apiPredicateItems.add(apiPredicateItem);
            apiPredicateItem.setMatchStrategy(predicateItem.getMatchStrategy());
            apiPredicateItem.setPattern(predicateItem.getPattern());
        }
    }
    return apiDefinition;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ApiDefinition(com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition) ApiPathPredicateItem(com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPathPredicateItem) ApiPredicateItem(com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPredicateItem)

Example 3 with ApiDefinition

use of com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition in project Sentinel by alibaba.

the class GatewayRuleConfig method initCustomizedApis.

private void initCustomizedApis() {
    Set<ApiDefinition> definitions = new HashSet<>();
    ApiDefinition api1 = new ApiDefinition("some_customized_api").setPredicateItems(new HashSet<ApiPredicateItem>() {

        {
            add(new ApiPathPredicateItem().setPattern("/ahas"));
            add(new ApiPathPredicateItem().setPattern("/aliyun_product/**").setMatchStrategy(SentinelGatewayConstants.URL_MATCH_STRATEGY_PREFIX));
        }
    });
    ApiDefinition api2 = new ApiDefinition("another_customized_api").setPredicateItems(new HashSet<ApiPredicateItem>() {

        {
            add(new ApiPathPredicateItem().setPattern("/**").setMatchStrategy(SentinelGatewayConstants.URL_MATCH_STRATEGY_PREFIX));
        }
    });
    definitions.add(api1);
    definitions.add(api2);
    GatewayApiDefinitionManager.loadApiDefinitions(definitions);
}
Also used : ApiDefinition(com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition) ApiPathPredicateItem(com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPathPredicateItem) ApiPredicateItem(com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPredicateItem) HashSet(java.util.HashSet)

Example 4 with ApiDefinition

use of com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition in project pig by pig-mesh.

the class ApiDefinitionEntity method toApiDefinition.

public ApiDefinition toApiDefinition() {
    ApiDefinition apiDefinition = new ApiDefinition();
    apiDefinition.setApiName(apiName);
    Set<ApiPredicateItem> apiPredicateItems = new LinkedHashSet<>();
    apiDefinition.setPredicateItems(apiPredicateItems);
    if (predicateItems != null) {
        for (ApiPredicateItemEntity predicateItem : predicateItems) {
            ApiPathPredicateItem apiPredicateItem = new ApiPathPredicateItem();
            apiPredicateItems.add(apiPredicateItem);
            apiPredicateItem.setMatchStrategy(predicateItem.getMatchStrategy());
            apiPredicateItem.setPattern(predicateItem.getPattern());
        }
    }
    return apiDefinition;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ApiDefinition(com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition) ApiPathPredicateItem(com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPathPredicateItem) ApiPredicateItem(com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPredicateItem)

Example 5 with ApiDefinition

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

the class ApiDefinitionEntity method toApiDefinition.

public ApiDefinition toApiDefinition() {
    ApiDefinition apiDefinition = new ApiDefinition();
    apiDefinition.setApiName(apiName);
    Set<ApiPredicateItem> apiPredicateItems = new LinkedHashSet<>();
    apiDefinition.setPredicateItems(apiPredicateItems);
    if (predicateItems != null) {
        for (ApiPredicateItemEntity predicateItem : predicateItems) {
            ApiPathPredicateItem apiPredicateItem = new ApiPathPredicateItem();
            apiPredicateItems.add(apiPredicateItem);
            apiPredicateItem.setMatchStrategy(predicateItem.getMatchStrategy());
            apiPredicateItem.setPattern(predicateItem.getPattern());
        }
    }
    return apiDefinition;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ApiDefinition(com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition) ApiPathPredicateItem(com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPathPredicateItem) ApiPredicateItem(com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPredicateItem)

Aggregations

ApiDefinition (com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition)16 ApiPathPredicateItem (com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPathPredicateItem)13 ApiPredicateItem (com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPredicateItem)13 HashSet (java.util.HashSet)6 LinkedHashSet (java.util.LinkedHashSet)5 GatewayFlowRule (com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule)2 DegradeRule (com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)2 WebExchangeApiMatcher (com.alibaba.csp.sentinel.adapter.gateway.sc.api.matcher.WebExchangeApiMatcher)1 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 Listener (com.alibaba.nacos.api.config.listener.Listener)1 DoorGoodConfig (com.hummer.doorgod.service.domain.configuration.DoorGoodConfig)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Test (org.junit.Test)1 RequestPath (org.springframework.http.server.RequestPath)1 ServerHttpRequest (org.springframework.http.server.reactive.ServerHttpRequest)1 ServerWebExchange (org.springframework.web.server.ServerWebExchange)1