use of com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPathPredicateItem in project Sentinel by alibaba.
the class GatewayConfiguration 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("/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);
}
use of com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPathPredicateItem in project Sentinel by alibaba.
the class UpdateGatewayApiDefinitionGroupCommandHandler method parseJson.
/**
* Parse json data to set of {@link ApiDefinition}.
*
* Since the predicateItems of {@link ApiDefinition} is set of interface,
* here we parse predicateItems to {@link ApiPathPredicateItem} temporarily.
*/
private Set<ApiDefinition> parseJson(String data) {
Set<ApiDefinition> apiDefinitions = new HashSet<>();
JSONArray array = JSON.parseArray(data);
for (Object obj : array) {
JSONObject o = (JSONObject) obj;
ApiDefinition apiDefinition = new ApiDefinition((o.getString("apiName")));
Set<ApiPredicateItem> predicateItems = new HashSet<>();
JSONArray itemArray = o.getJSONArray("predicateItems");
if (itemArray != null) {
predicateItems.addAll(itemArray.toJavaList(ApiPathPredicateItem.class));
}
apiDefinition.setPredicateItems(predicateItems);
apiDefinitions.add(apiDefinition);
}
return apiDefinitions;
}
use of com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPathPredicateItem in project matecloud by matevip.
the class SentinelConfig method initCustomizedApis.
/**
* 样例,可以扩展使用
* 文档参见:https://github.com/alibaba/Sentinel/wiki/%E7%BD%91%E5%85%B3%E9%99%90%E6%B5%81
*/
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("/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);
}
use of com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPathPredicateItem in project pig by pig-mesh.
the class ApiDefinitionEntity method fromApiDefinition.
public static ApiDefinitionEntity fromApiDefinition(String app, String ip, Integer port, ApiDefinition apiDefinition) {
ApiDefinitionEntity entity = new ApiDefinitionEntity();
entity.setApp(app);
entity.setIp(ip);
entity.setPort(port);
entity.setApiName(apiDefinition.getApiName());
Set<ApiPredicateItemEntity> predicateItems = new LinkedHashSet<>();
entity.setPredicateItems(predicateItems);
Set<ApiPredicateItem> apiPredicateItems = apiDefinition.getPredicateItems();
if (apiPredicateItems != null) {
for (ApiPredicateItem apiPredicateItem : apiPredicateItems) {
ApiPredicateItemEntity itemEntity = new ApiPredicateItemEntity();
predicateItems.add(itemEntity);
ApiPathPredicateItem pathPredicateItem = (ApiPathPredicateItem) apiPredicateItem;
itemEntity.setPattern(pathPredicateItem.getPattern());
itemEntity.setMatchStrategy(pathPredicateItem.getMatchStrategy());
}
}
return entity;
}
use of com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPathPredicateItem in project spring-boot-student by wyh-spring-ecosystem-student.
the class ApiDefinitionEntity method fromApiDefinition.
public static ApiDefinitionEntity fromApiDefinition(String app, String ip, Integer port, ApiDefinition apiDefinition) {
ApiDefinitionEntity entity = new ApiDefinitionEntity();
entity.setApp(app);
entity.setIp(ip);
entity.setPort(port);
entity.setApiName(apiDefinition.getApiName());
Set<ApiPredicateItemEntity> predicateItems = new LinkedHashSet<>();
entity.setPredicateItems(predicateItems);
Set<ApiPredicateItem> apiPredicateItems = apiDefinition.getPredicateItems();
if (apiPredicateItems != null) {
for (ApiPredicateItem apiPredicateItem : apiPredicateItems) {
ApiPredicateItemEntity itemEntity = new ApiPredicateItemEntity();
predicateItems.add(itemEntity);
ApiPathPredicateItem pathPredicateItem = (ApiPathPredicateItem) apiPredicateItem;
itemEntity.setPattern(pathPredicateItem.getPattern());
itemEntity.setMatchStrategy(pathPredicateItem.getMatchStrategy());
}
}
return entity;
}
Aggregations