From e0a9ecb97687ba8f983ae1f4a76f643221489c62 Mon Sep 17 00:00:00 2001 From: xiaoheng1 <2018154970@qq.com> Date: Mon, 10 May 2021 11:24:16 +0800 Subject: [PATCH] fix #5583 Modify the Chinese log in CapacityController (#5584) --- .../server/controller/CapacityController.java | 57 +++++++++++-------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/config/src/main/java/com/alibaba/nacos/config/server/controller/CapacityController.java b/config/src/main/java/com/alibaba/nacos/config/server/controller/CapacityController.java index 9eecb92a0..0d170fba0 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/controller/CapacityController.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/controller/CapacityController.java @@ -45,6 +45,12 @@ public class CapacityController { private final CapacityService capacityService; + private static final int STATUS200 = 200; + + private static final int STATUS400 = 400; + + private static final int STATUS500 = 500; + @Autowired public CapacityController(CapacityService capacityService) { this.capacityService = capacityService; @@ -55,25 +61,25 @@ public class CapacityController { @RequestParam(required = false) String tenant) { if (group == null && tenant == null) { RestResult restResult = new RestResult(); - response.setStatus(400); - restResult.setCode(400); - restResult.setMessage("参数group和tenant不能同时为空"); + response.setStatus(STATUS400); + restResult.setCode(STATUS400); + restResult.setMessage("The parameter group and tenant cannot be empty at the same time"); return restResult; } if (group == null && StringUtils.isBlank(tenant)) { RestResult restResult = new RestResult(); - response.setStatus(400); - restResult.setCode(400); - restResult.setMessage("tenant不能为空字符串"); + response.setStatus(STATUS400); + restResult.setCode(STATUS400); + restResult.setMessage("tenant cannot be an empty string"); return restResult; } RestResult restResult = new RestResult(); try { - response.setStatus(200); - restResult.setCode(200); + response.setStatus(STATUS200); + restResult.setCode(STATUS200); Capacity capacity = capacityService.getCapacityWithDefault(group, tenant); if (capacity == null) { - LOGGER.warn("[getCapacity] capacity不存在,需初始化 group: {}, tenant: {}", group, tenant); + LOGGER.warn("[getCapacity] capacity not exist,need init group: {}, tenant: {}", group, tenant); capacityService.initCapacity(group, tenant); capacity = capacityService.getCapacityWithDefault(group, tenant); } @@ -82,8 +88,8 @@ public class CapacityController { } } catch (Exception e) { LOGGER.error("[getCapacity] ", e); - response.setStatus(500); - restResult.setCode(500); + response.setStatus(STATUS500); + restResult.setCode(STATUS500); restResult.setMessage(e.getMessage()); } return restResult; @@ -100,14 +106,15 @@ public class CapacityController { if (StringUtils.isBlank(group) && StringUtils.isBlank(tenant)) { capacityService.initAllCapacity(); RestResult restResult = new RestResult(); - setFailResult(response, restResult, 400); - restResult.setMessage("参数group和tenant不能同时为空"); + setFailResult(response, restResult, STATUS400); + restResult.setMessage("The parameter group and tenant cannot be empty at the same time"); return restResult; } if (quota == null && maxSize == null && maxAggrCount == null && maxAggrSize == null) { RestResult restResult = new RestResult(); - setFailResult(response, restResult, 400); - restResult.setMessage("参数quota、maxSize、maxAggrCount、maxAggrSize不能同时为空"); + setFailResult(response, restResult, STATUS400); + restResult.setMessage( + "The parameters quota, maxSize, maxAggrCount, maxAggrSize cannot be empty at the same time"); return restResult; } String targetFieldName; @@ -121,8 +128,8 @@ public class CapacityController { } RestResult restResult = new RestResult(); if (StringUtils.isBlank(targetFieldValue)) { - setFailResult(response, restResult, 400); - restResult.setMessage(String.format("参数%s为空", targetFieldName)); + setFailResult(response, restResult, STATUS400); + restResult.setMessage(String.format("parameter %s is empty.", targetFieldName)); return restResult; } try { @@ -130,15 +137,19 @@ public class CapacityController { .insertOrUpdateCapacity(group, tenant, quota, maxSize, maxAggrCount, maxAggrSize); if (insertOrUpdateResult) { setSuccessResult(response, restResult); - restResult.setMessage(String.format("成功更新%s为%s的容量信息配置", targetFieldName, targetFieldValue)); + restResult.setMessage( + String.format("successfully updated the capacity information configuration of %s to %s", + targetFieldName, targetFieldValue)); return restResult; } - setFailResult(response, restResult, 500); - restResult.setMessage(String.format("%s为%s的容量信息配置更新失败", targetFieldName, targetFieldValue)); + setFailResult(response, restResult, STATUS500); + restResult.setMessage( + String.format("failed updated the capacity information configuration of %s to %s", targetFieldName, + targetFieldValue)); return restResult; } catch (Exception e) { LOGGER.error("[updateCapacity] ", e); - setFailResult(response, restResult, 500); + setFailResult(response, restResult, STATUS500); restResult.setMessage(e.getMessage()); return restResult; } @@ -151,8 +162,8 @@ public class CapacityController { } private void setSuccessResult(HttpServletResponse response, RestResult restResult) { - response.setStatus(200); - restResult.setCode(200); + response.setStatus(STATUS200); + restResult.setCode(STATUS200); restResult.setData(true); } }