parent
5395237062
commit
e0a9ecb976
@ -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<Capacity> restResult = new RestResult<Capacity>();
|
||||
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<Capacity> restResult = new RestResult<Capacity>();
|
||||
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<Capacity> restResult = new RestResult<Capacity>();
|
||||
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<Boolean> restResult = new RestResult<Boolean>();
|
||||
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<Boolean> restResult = new RestResult<Boolean>();
|
||||
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<Boolean> restResult = new RestResult<Boolean>();
|
||||
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<Boolean> restResult) {
|
||||
response.setStatus(200);
|
||||
restResult.setCode(200);
|
||||
response.setStatus(STATUS200);
|
||||
restResult.setCode(STATUS200);
|
||||
restResult.setData(true);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user