Search in sources :

Example 16 with ParamFlowRuleEntity

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

the class ParamFlowRuleController method apiUpdateParamFlowRule.

@PutMapping("/rule/{id}")
@AuthAction(PrivilegeType.WRITE_RULE)
public Result<ParamFlowRuleEntity> apiUpdateParamFlowRule(@PathVariable("id") Long id, @RequestBody ParamFlowRuleEntity entity) {
    if (id == null || id <= 0) {
        return Result.ofFail(-1, "Invalid id");
    }
    ParamFlowRuleEntity oldEntity = repository.findById(id);
    if (oldEntity == null) {
        return Result.ofFail(-1, "id " + id + " does not exist");
    }
    Result<ParamFlowRuleEntity> checkResult = checkEntityInternal(entity);
    if (checkResult != null) {
        return checkResult;
    }
    if (!checkIfSupported(entity.getApp(), entity.getIp(), entity.getPort())) {
        return unsupportedVersion();
    }
    entity.setId(id);
    Date date = new Date();
    entity.setGmtCreate(oldEntity.getGmtCreate());
    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 updating parameter flow rules, id=" + id, ex.getCause());
        if (isNotSupported(ex.getCause())) {
            return unsupportedVersion();
        } else {
            return Result.ofThrowable(-1, ex.getCause());
        }
    } catch (Throwable throwable) {
        logger.error("Error when updating parameter flow rules, id=" + id, 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) PutMapping(org.springframework.web.bind.annotation.PutMapping) AuthAction(com.alibaba.csp.sentinel.dashboard.auth.AuthAction)

Example 17 with ParamFlowRuleEntity

use of com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity in project RuoYi-Cloud-Plus by JavaLionLi.

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) 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