parent
5395237062
commit
e0a9ecb976
@ -45,6 +45,12 @@ public class CapacityController {
|
|||||||
|
|
||||||
private final CapacityService capacityService;
|
private final CapacityService capacityService;
|
||||||
|
|
||||||
|
private static final int STATUS200 = 200;
|
||||||
|
|
||||||
|
private static final int STATUS400 = 400;
|
||||||
|
|
||||||
|
private static final int STATUS500 = 500;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public CapacityController(CapacityService capacityService) {
|
public CapacityController(CapacityService capacityService) {
|
||||||
this.capacityService = capacityService;
|
this.capacityService = capacityService;
|
||||||
@ -55,25 +61,25 @@ public class CapacityController {
|
|||||||
@RequestParam(required = false) String tenant) {
|
@RequestParam(required = false) String tenant) {
|
||||||
if (group == null && tenant == null) {
|
if (group == null && tenant == null) {
|
||||||
RestResult<Capacity> restResult = new RestResult<Capacity>();
|
RestResult<Capacity> restResult = new RestResult<Capacity>();
|
||||||
response.setStatus(400);
|
response.setStatus(STATUS400);
|
||||||
restResult.setCode(400);
|
restResult.setCode(STATUS400);
|
||||||
restResult.setMessage("参数group和tenant不能同时为空");
|
restResult.setMessage("The parameter group and tenant cannot be empty at the same time");
|
||||||
return restResult;
|
return restResult;
|
||||||
}
|
}
|
||||||
if (group == null && StringUtils.isBlank(tenant)) {
|
if (group == null && StringUtils.isBlank(tenant)) {
|
||||||
RestResult<Capacity> restResult = new RestResult<Capacity>();
|
RestResult<Capacity> restResult = new RestResult<Capacity>();
|
||||||
response.setStatus(400);
|
response.setStatus(STATUS400);
|
||||||
restResult.setCode(400);
|
restResult.setCode(STATUS400);
|
||||||
restResult.setMessage("tenant不能为空字符串");
|
restResult.setMessage("tenant cannot be an empty string");
|
||||||
return restResult;
|
return restResult;
|
||||||
}
|
}
|
||||||
RestResult<Capacity> restResult = new RestResult<Capacity>();
|
RestResult<Capacity> restResult = new RestResult<Capacity>();
|
||||||
try {
|
try {
|
||||||
response.setStatus(200);
|
response.setStatus(STATUS200);
|
||||||
restResult.setCode(200);
|
restResult.setCode(STATUS200);
|
||||||
Capacity capacity = capacityService.getCapacityWithDefault(group, tenant);
|
Capacity capacity = capacityService.getCapacityWithDefault(group, tenant);
|
||||||
if (capacity == null) {
|
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);
|
capacityService.initCapacity(group, tenant);
|
||||||
capacity = capacityService.getCapacityWithDefault(group, tenant);
|
capacity = capacityService.getCapacityWithDefault(group, tenant);
|
||||||
}
|
}
|
||||||
@ -82,8 +88,8 @@ public class CapacityController {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("[getCapacity] ", e);
|
LOGGER.error("[getCapacity] ", e);
|
||||||
response.setStatus(500);
|
response.setStatus(STATUS500);
|
||||||
restResult.setCode(500);
|
restResult.setCode(STATUS500);
|
||||||
restResult.setMessage(e.getMessage());
|
restResult.setMessage(e.getMessage());
|
||||||
}
|
}
|
||||||
return restResult;
|
return restResult;
|
||||||
@ -100,14 +106,15 @@ public class CapacityController {
|
|||||||
if (StringUtils.isBlank(group) && StringUtils.isBlank(tenant)) {
|
if (StringUtils.isBlank(group) && StringUtils.isBlank(tenant)) {
|
||||||
capacityService.initAllCapacity();
|
capacityService.initAllCapacity();
|
||||||
RestResult<Boolean> restResult = new RestResult<Boolean>();
|
RestResult<Boolean> restResult = new RestResult<Boolean>();
|
||||||
setFailResult(response, restResult, 400);
|
setFailResult(response, restResult, STATUS400);
|
||||||
restResult.setMessage("参数group和tenant不能同时为空");
|
restResult.setMessage("The parameter group and tenant cannot be empty at the same time");
|
||||||
return restResult;
|
return restResult;
|
||||||
}
|
}
|
||||||
if (quota == null && maxSize == null && maxAggrCount == null && maxAggrSize == null) {
|
if (quota == null && maxSize == null && maxAggrCount == null && maxAggrSize == null) {
|
||||||
RestResult<Boolean> restResult = new RestResult<Boolean>();
|
RestResult<Boolean> restResult = new RestResult<Boolean>();
|
||||||
setFailResult(response, restResult, 400);
|
setFailResult(response, restResult, STATUS400);
|
||||||
restResult.setMessage("参数quota、maxSize、maxAggrCount、maxAggrSize不能同时为空");
|
restResult.setMessage(
|
||||||
|
"The parameters quota, maxSize, maxAggrCount, maxAggrSize cannot be empty at the same time");
|
||||||
return restResult;
|
return restResult;
|
||||||
}
|
}
|
||||||
String targetFieldName;
|
String targetFieldName;
|
||||||
@ -121,8 +128,8 @@ public class CapacityController {
|
|||||||
}
|
}
|
||||||
RestResult<Boolean> restResult = new RestResult<Boolean>();
|
RestResult<Boolean> restResult = new RestResult<Boolean>();
|
||||||
if (StringUtils.isBlank(targetFieldValue)) {
|
if (StringUtils.isBlank(targetFieldValue)) {
|
||||||
setFailResult(response, restResult, 400);
|
setFailResult(response, restResult, STATUS400);
|
||||||
restResult.setMessage(String.format("参数%s为空", targetFieldName));
|
restResult.setMessage(String.format("parameter %s is empty.", targetFieldName));
|
||||||
return restResult;
|
return restResult;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -130,15 +137,19 @@ public class CapacityController {
|
|||||||
.insertOrUpdateCapacity(group, tenant, quota, maxSize, maxAggrCount, maxAggrSize);
|
.insertOrUpdateCapacity(group, tenant, quota, maxSize, maxAggrCount, maxAggrSize);
|
||||||
if (insertOrUpdateResult) {
|
if (insertOrUpdateResult) {
|
||||||
setSuccessResult(response, restResult);
|
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;
|
return restResult;
|
||||||
}
|
}
|
||||||
setFailResult(response, restResult, 500);
|
setFailResult(response, restResult, STATUS500);
|
||||||
restResult.setMessage(String.format("%s为%s的容量信息配置更新失败", targetFieldName, targetFieldValue));
|
restResult.setMessage(
|
||||||
|
String.format("failed updated the capacity information configuration of %s to %s", targetFieldName,
|
||||||
|
targetFieldValue));
|
||||||
return restResult;
|
return restResult;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("[updateCapacity] ", e);
|
LOGGER.error("[updateCapacity] ", e);
|
||||||
setFailResult(response, restResult, 500);
|
setFailResult(response, restResult, STATUS500);
|
||||||
restResult.setMessage(e.getMessage());
|
restResult.setMessage(e.getMessage());
|
||||||
return restResult;
|
return restResult;
|
||||||
}
|
}
|
||||||
@ -151,8 +162,8 @@ public class CapacityController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setSuccessResult(HttpServletResponse response, RestResult<Boolean> restResult) {
|
private void setSuccessResult(HttpServletResponse response, RestResult<Boolean> restResult) {
|
||||||
response.setStatus(200);
|
response.setStatus(STATUS200);
|
||||||
restResult.setCode(200);
|
restResult.setCode(STATUS200);
|
||||||
restResult.setData(true);
|
restResult.setData(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user