Search in sources :

Example 1 with ParamFlowRuleEntity

use of com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity in project Sentinel by alibaba.

the class ParamFlowRuleController method apiDeleteRule.

@DeleteMapping("/rule/{id}")
@AuthAction(PrivilegeType.DELETE_RULE)
public Result<Long> apiDeleteRule(@PathVariable("id") Long id) {
    if (id == null) {
        return Result.ofFail(-1, "id cannot be null");
    }
    ParamFlowRuleEntity oldEntity = repository.findById(id);
    if (oldEntity == null) {
        return Result.ofSuccess(null);
    }
    try {
        repository.delete(id);
        publishRules(oldEntity.getApp(), oldEntity.getIp(), oldEntity.getPort()).get();
        return Result.ofSuccess(id);
    } catch (ExecutionException ex) {
        logger.error("Error when deleting parameter flow rules", ex.getCause());
        if (isNotSupported(ex.getCause())) {
            return unsupportedVersion();
        } else {
            return Result.ofThrowable(-1, ex.getCause());
        }
    } catch (Throwable throwable) {
        logger.error("Error when deleting parameter flow rules", throwable);
        return Result.ofFail(-1, throwable.getMessage());
    }
}
Also used : ParamFlowRuleEntity(com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity) ExecutionException(java.util.concurrent.ExecutionException) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) AuthAction(com.alibaba.csp.sentinel.dashboard.auth.AuthAction)

Example 2 with ParamFlowRuleEntity

use of com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity in project Sentinel by alibaba.

the class ParamFlowRuleController method apiAddParamFlowRule.

@PostMapping("/rule")
@AuthAction(AuthService.PrivilegeType.WRITE_RULE)
public Result<ParamFlowRuleEntity> apiAddParamFlowRule(@RequestBody ParamFlowRuleEntity entity) {
    Result<ParamFlowRuleEntity> checkResult = checkEntityInternal(entity);
    if (checkResult != null) {
        return checkResult;
    }
    if (!checkIfSupported(entity.getApp(), entity.getIp(), entity.getPort())) {
        return unsupportedVersion();
    }
    entity.setId(null);
    entity.getRule().setResource(entity.getResource().trim());
    Date date = new Date();
    entity.setGmtCreate(date);
    entity.setGmtModified(date);
    try {
        entity = repository.save(entity);
        publishRules(entity.getApp(), entity.getIp(), entity.getPort()).get();
        return Result.ofSuccess(entity);
    } catch (ExecutionException ex) {
        logger.error("Error when adding new parameter flow rules", ex.getCause());
        if (isNotSupported(ex.getCause())) {
            return unsupportedVersion();
        } else {
            return Result.ofThrowable(-1, ex.getCause());
        }
    } catch (Throwable throwable) {
        logger.error("Error when adding new parameter flow rules", throwable);
        return Result.ofFail(-1, throwable.getMessage());
    }
}
Also used : ParamFlowRuleEntity(com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity) ExecutionException(java.util.concurrent.ExecutionException) Date(java.util.Date) PostMapping(org.springframework.web.bind.annotation.PostMapping) AuthAction(com.alibaba.csp.sentinel.dashboard.auth.AuthAction)

Example 3 with ParamFlowRuleEntity

use of com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity in project pig by pig-mesh.

the class ParamFlowRuleController method apiAddParamFlowRule.

@PostMapping("/rule")
@AuthAction(PrivilegeType.WRITE_RULE)
public Result<ParamFlowRuleEntity> apiAddParamFlowRule(@RequestBody ParamFlowRuleEntity entity) {
    Result<ParamFlowRuleEntity> checkResult = checkEntityInternal(entity);
    if (checkResult != null) {
        return checkResult;
    }
    if (!checkIfSupported(entity.getApp(), entity.getIp(), entity.getPort())) {
        return unsupportedVersion();
    }
    entity.setId(null);
    entity.getRule().setResource(entity.getResource().trim());
    Date date = new Date();
    entity.setGmtCreate(date);
    entity.setGmtModified(date);
    try {
        entity = repository.save(entity);
        publishRules(entity.getApp(), entity.getIp(), entity.getPort()).get();
        return Result.ofSuccess(entity);
    } catch (ExecutionException ex) {
        logger.error("Error when adding new parameter flow rules", ex.getCause());
        if (isNotSupported(ex.getCause())) {
            return unsupportedVersion();
        } else {
            return Result.ofThrowable(-1, ex.getCause());
        }
    } catch (Throwable throwable) {
        logger.error("Error when adding new parameter flow rules", throwable);
        return Result.ofFail(-1, throwable.getMessage());
    }
}
Also used : ParamFlowRuleEntity(com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity) ExecutionException(java.util.concurrent.ExecutionException) Date(java.util.Date) PostMapping(org.springframework.web.bind.annotation.PostMapping) AuthAction(com.alibaba.csp.sentinel.dashboard.auth.AuthAction)

Example 4 with ParamFlowRuleEntity

use of com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity in project pig by pig-mesh.

the class ParamFlowRuleController method apiDeleteRule.

@DeleteMapping("/rule/{id}")
@AuthAction(PrivilegeType.DELETE_RULE)
public Result<Long> apiDeleteRule(@PathVariable("id") Long id) {
    if (id == null) {
        return Result.ofFail(-1, "id cannot be null");
    }
    ParamFlowRuleEntity oldEntity = repository.findById(id);
    if (oldEntity == null) {
        return Result.ofSuccess(null);
    }
    try {
        repository.delete(id);
        publishRules(oldEntity.getApp(), oldEntity.getIp(), oldEntity.getPort()).get();
        return Result.ofSuccess(id);
    } catch (ExecutionException ex) {
        logger.error("Error when deleting parameter flow rules", ex.getCause());
        if (isNotSupported(ex.getCause())) {
            return unsupportedVersion();
        } else {
            return Result.ofThrowable(-1, ex.getCause());
        }
    } catch (Throwable throwable) {
        logger.error("Error when deleting parameter flow rules", throwable);
        return Result.ofFail(-1, throwable.getMessage());
    }
}
Also used : ParamFlowRuleEntity(com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity) ExecutionException(java.util.concurrent.ExecutionException) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) AuthAction(com.alibaba.csp.sentinel.dashboard.auth.AuthAction)

Example 5 with ParamFlowRuleEntity

use of com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity in project spring-boot-student by wyh-spring-ecosystem-student.

the class ParamFlowRuleController method apiAddParamFlowRule.

@PostMapping("/rule")
@AuthAction(PrivilegeType.WRITE_RULE)
public Result<ParamFlowRuleEntity> apiAddParamFlowRule(@RequestBody ParamFlowRuleEntity entity) {
    Result<ParamFlowRuleEntity> checkResult = checkEntityInternal(entity);
    if (checkResult != null) {
        return checkResult;
    }
    if (!checkIfSupported(entity.getApp(), entity.getIp(), entity.getPort())) {
        return unsupportedVersion();
    }
    entity.setId(null);
    entity.getRule().setResource(entity.getResource().trim());
    Date date = new Date();
    entity.setGmtCreate(date);
    entity.setGmtModified(date);
    try {
        entity = repository.save(entity);
        publishRules(entity.getApp(), entity.getIp(), entity.getPort()).get();
        return Result.ofSuccess(entity);
    } catch (ExecutionException ex) {
        logger.error("Error when adding new parameter flow rules", ex.getCause());
        if (isNotSupported(ex.getCause())) {
            return unsupportedVersion();
        } else {
            return Result.ofThrowable(-1, ex.getCause());
        }
    } catch (Throwable throwable) {
        logger.error("Error when adding new parameter flow rules", throwable);
        return Result.ofFail(-1, throwable.getMessage());
    }
}
Also used : ParamFlowRuleEntity(com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity) ExecutionException(java.util.concurrent.ExecutionException) Date(java.util.Date) PostMapping(org.springframework.web.bind.annotation.PostMapping) AuthAction(com.alibaba.csp.sentinel.dashboard.auth.AuthAction)

Aggregations

ParamFlowRuleEntity (com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity)17 AuthAction (com.alibaba.csp.sentinel.dashboard.auth.AuthAction)15 ExecutionException (java.util.concurrent.ExecutionException)15 Date (java.util.Date)10 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)4 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 PutMapping (org.springframework.web.bind.annotation.PutMapping)4 ParamFlowClusterConfig (com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowClusterConfig)2 ParamFlowRule (com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule)2 Test (org.junit.Test)2