Search in sources :

Example 1 with ClusterClientModifyRequest

use of com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest in project Sentinel by alibaba.

the class ClusterConfigController method apiModifyClusterConfig.

@PostMapping("/config/modify_single")
public Result<Boolean> apiModifyClusterConfig(@RequestBody String payload) {
    if (StringUtil.isBlank(payload)) {
        return Result.ofFail(-1, "empty request body");
    }
    try {
        JSONObject body = JSON.parseObject(payload);
        if (body.containsKey(KEY_MODE)) {
            int mode = body.getInteger(KEY_MODE);
            switch(mode) {
                case ClusterStateManager.CLUSTER_CLIENT:
                    ClusterClientModifyRequest data = JSON.parseObject(payload, ClusterClientModifyRequest.class);
                    Result<Boolean> res = checkValidRequest(data);
                    if (res != null) {
                        return res;
                    }
                    clusterConfigService.modifyClusterClientConfig(data).get();
                    return Result.ofSuccess(true);
                case ClusterStateManager.CLUSTER_SERVER:
                    ClusterServerModifyRequest d = JSON.parseObject(payload, ClusterServerModifyRequest.class);
                    Result<Boolean> r = checkValidRequest(d);
                    if (r != null) {
                        return r;
                    }
                    // TODO: bad design here, should refactor!
                    clusterConfigService.modifyClusterServerConfig(d).get();
                    return Result.ofSuccess(true);
                default:
                    return Result.ofFail(-1, "invalid mode");
            }
        }
        return Result.ofFail(-1, "invalid parameter");
    } catch (ExecutionException ex) {
        logger.error("Error when modifying cluster config", ex.getCause());
        return errorResponse(ex);
    } catch (Throwable ex) {
        logger.error("Error when modifying cluster config", ex);
        return Result.ofFail(-1, ex.getMessage());
    }
}
Also used : ClusterClientModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest) JSONObject(com.alibaba.fastjson.JSONObject) ClusterServerModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest) ExecutionException(java.util.concurrent.ExecutionException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with ClusterClientModifyRequest

use of com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest in project pig by pig-mesh.

the class ClusterConfigController method apiModifyClusterConfig.

@PostMapping("/config/modify_single")
public Result<Boolean> apiModifyClusterConfig(@RequestBody String payload) {
    if (StringUtil.isBlank(payload)) {
        return Result.ofFail(-1, "empty request body");
    }
    try {
        JSONObject body = JSON.parseObject(payload);
        if (body.containsKey(KEY_MODE)) {
            int mode = body.getInteger(KEY_MODE);
            switch(mode) {
                case ClusterStateManager.CLUSTER_CLIENT:
                    ClusterClientModifyRequest data = JSON.parseObject(payload, ClusterClientModifyRequest.class);
                    Result<Boolean> res = checkValidRequest(data);
                    if (res != null) {
                        return res;
                    }
                    clusterConfigService.modifyClusterClientConfig(data).get();
                    return Result.ofSuccess(true);
                case ClusterStateManager.CLUSTER_SERVER:
                    ClusterServerModifyRequest d = JSON.parseObject(payload, ClusterServerModifyRequest.class);
                    Result<Boolean> r = checkValidRequest(d);
                    if (r != null) {
                        return r;
                    }
                    // TODO: bad design here, should refactor!
                    clusterConfigService.modifyClusterServerConfig(d).get();
                    return Result.ofSuccess(true);
                default:
                    return Result.ofFail(-1, "invalid mode");
            }
        }
        return Result.ofFail(-1, "invalid parameter");
    } catch (ExecutionException ex) {
        logger.error("Error when modifying cluster config", ex.getCause());
        return errorResponse(ex);
    } catch (Throwable ex) {
        logger.error("Error when modifying cluster config", ex);
        return Result.ofFail(-1, ex.getMessage());
    }
}
Also used : ClusterClientModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest) JSONObject(com.alibaba.fastjson.JSONObject) ClusterServerModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest) ExecutionException(java.util.concurrent.ExecutionException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with ClusterClientModifyRequest

use of com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest in project spring-boot-student by wyh-spring-ecosystem-student.

the class ClusterConfigController method apiModifyClusterConfig.

@PostMapping("/config/modify_single")
public Result<Boolean> apiModifyClusterConfig(@RequestBody String payload) {
    if (StringUtil.isBlank(payload)) {
        return Result.ofFail(-1, "empty request body");
    }
    try {
        JSONObject body = JSON.parseObject(payload);
        if (body.containsKey(KEY_MODE)) {
            int mode = body.getInteger(KEY_MODE);
            switch(mode) {
                case ClusterStateManager.CLUSTER_CLIENT:
                    ClusterClientModifyRequest data = JSON.parseObject(payload, ClusterClientModifyRequest.class);
                    Result<Boolean> res = checkValidRequest(data);
                    if (res != null) {
                        return res;
                    }
                    clusterConfigService.modifyClusterClientConfig(data).get();
                    return Result.ofSuccess(true);
                case ClusterStateManager.CLUSTER_SERVER:
                    ClusterServerModifyRequest d = JSON.parseObject(payload, ClusterServerModifyRequest.class);
                    Result<Boolean> r = checkValidRequest(d);
                    if (r != null) {
                        return r;
                    }
                    // TODO: bad design here, should refactor!
                    clusterConfigService.modifyClusterServerConfig(d).get();
                    return Result.ofSuccess(true);
                default:
                    return Result.ofFail(-1, "invalid mode");
            }
        }
        return Result.ofFail(-1, "invalid parameter");
    } catch (ExecutionException ex) {
        logger.error("Error when modifying cluster config", ex.getCause());
        return errorResponse(ex);
    } catch (Throwable ex) {
        logger.error("Error when modifying cluster config", ex);
        return Result.ofFail(-1, ex.getMessage());
    }
}
Also used : ClusterClientModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest) JSONObject(com.alibaba.fastjson.JSONObject) ClusterServerModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest) ExecutionException(java.util.concurrent.ExecutionException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 4 with ClusterClientModifyRequest

use of com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest in project XHuiCloud by sindaZeng.

the class ClusterConfigController method apiModifyClusterConfig.

@PostMapping("/config/modify_single")
public Result<Boolean> apiModifyClusterConfig(@RequestBody String payload) {
    if (StringUtil.isBlank(payload)) {
        return Result.ofFail(-1, "empty request body");
    }
    try {
        JSONObject body = JSON.parseObject(payload);
        if (body.containsKey(KEY_MODE)) {
            int mode = body.getInteger(KEY_MODE);
            switch(mode) {
                case ClusterStateManager.CLUSTER_CLIENT:
                    ClusterClientModifyRequest data = JSON.parseObject(payload, ClusterClientModifyRequest.class);
                    Result<Boolean> res = checkValidRequest(data);
                    if (res != null) {
                        return res;
                    }
                    clusterConfigService.modifyClusterClientConfig(data).get();
                    return Result.ofSuccess(true);
                case ClusterStateManager.CLUSTER_SERVER:
                    ClusterServerModifyRequest d = JSON.parseObject(payload, ClusterServerModifyRequest.class);
                    Result<Boolean> r = checkValidRequest(d);
                    if (r != null) {
                        return r;
                    }
                    // TODO: bad design here, should refactor!
                    clusterConfigService.modifyClusterServerConfig(d).get();
                    return Result.ofSuccess(true);
                default:
                    return Result.ofFail(-1, "invalid mode");
            }
        }
        return Result.ofFail(-1, "invalid parameter");
    } catch (ExecutionException ex) {
        logger.error("Error when modifying cluster config", ex.getCause());
        return errorResponse(ex);
    } catch (Throwable ex) {
        logger.error("Error when modifying cluster config", ex);
        return Result.ofFail(-1, ex.getMessage());
    }
}
Also used : ClusterClientModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest) JSONObject(com.alibaba.fastjson.JSONObject) ClusterServerModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest) ExecutionException(java.util.concurrent.ExecutionException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 5 with ClusterClientModifyRequest

use of com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest in project RuoYi-Cloud-Plus by JavaLionLi.

the class ClusterConfigController method apiModifyClusterConfig.

@PostMapping("/config/modify_single")
public Result<Boolean> apiModifyClusterConfig(@RequestBody String payload) {
    if (StringUtil.isBlank(payload)) {
        return Result.ofFail(-1, "empty request body");
    }
    try {
        JSONObject body = JSON.parseObject(payload);
        if (body.containsKey(KEY_MODE)) {
            int mode = body.getInteger(KEY_MODE);
            switch(mode) {
                case ClusterStateManager.CLUSTER_CLIENT:
                    ClusterClientModifyRequest data = JSON.parseObject(payload, ClusterClientModifyRequest.class);
                    Result<Boolean> res = checkValidRequest(data);
                    if (res != null) {
                        return res;
                    }
                    clusterConfigService.modifyClusterClientConfig(data).get();
                    return Result.ofSuccess(true);
                case ClusterStateManager.CLUSTER_SERVER:
                    ClusterServerModifyRequest d = JSON.parseObject(payload, ClusterServerModifyRequest.class);
                    Result<Boolean> r = checkValidRequest(d);
                    if (r != null) {
                        return r;
                    }
                    // TODO: bad design here, should refactor!
                    clusterConfigService.modifyClusterServerConfig(d).get();
                    return Result.ofSuccess(true);
                default:
                    return Result.ofFail(-1, "invalid mode");
            }
        }
        return Result.ofFail(-1, "invalid parameter");
    } catch (ExecutionException ex) {
        logger.error("Error when modifying cluster config", ex.getCause());
        return errorResponse(ex);
    } catch (Throwable ex) {
        logger.error("Error when modifying cluster config", ex);
        return Result.ofFail(-1, ex.getMessage());
    }
}
Also used : ClusterClientModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest) JSONObject(com.alibaba.fastjson.JSONObject) ClusterServerModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest) ExecutionException(java.util.concurrent.ExecutionException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

ClusterClientModifyRequest (com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest)5 ClusterServerModifyRequest (com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest)5 JSONObject (com.alibaba.fastjson.JSONObject)5 ExecutionException (java.util.concurrent.ExecutionException)5 PostMapping (org.springframework.web.bind.annotation.PostMapping)5