Browse Source

AlertPluginInstanceController verifyGroupName method code optimizatio… (#8920)

* AlertPluginInstanceController verifyGroupName method code optimization #8863
Co-authored-by: Kerwin <37063904+zhuangchong@users.noreply.github.com>
3.0.0/version-upgrade
yangyunxi 3 years ago committed by GitHub
parent
commit
b7cf8b49c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java
  2. 17
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/Result.java

8
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java

@ -198,16 +198,12 @@ public class AlertPluginInstanceController extends BaseController {
@RequestParam(value = "alertInstanceName") String alertInstanceName) {
boolean exist = alertPluginInstanceService.checkExistPluginInstanceName(alertInstanceName);
Result result = new Result();
if (exist) {
logger.error("alert plugin instance {} has exist, can't create again.", alertInstanceName);
result.setCode(Status.PLUGIN_INSTANCE_ALREADY_EXIT.getCode());
result.setMsg(Status.PLUGIN_INSTANCE_ALREADY_EXIT.getMsg());
return Result.error(Status.PLUGIN_INSTANCE_ALREADY_EXIT);
} else {
result.setCode(Status.SUCCESS.getCode());
result.setMsg(Status.SUCCESS.getMsg());
return Result.success();
}
return result;
}
/**

17
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/Result.java

@ -50,17 +50,18 @@ public class Result<T> {
this.msg = msg;
}
private Result(T data) {
this.code = 0;
this.data = data;
}
private Result(Status status) {
if (status != null) {
this.code = status.getCode();
this.msg = status.getMsg();
}
}
public Result(Integer code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
/**
* Call this function if there is success
@ -70,7 +71,11 @@ public class Result<T> {
* @return resule
*/
public static <T> Result<T> success(T data) {
return new Result<>(data);
return new Result<>(Status.SUCCESS.getCode(), Status.SUCCESS.getMsg(), data);
}
public static Result success() {
return success(null);
}
public boolean isSuccess() {

Loading…
Cancel
Save