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) { @RequestParam(value = "alertInstanceName") String alertInstanceName) {
boolean exist = alertPluginInstanceService.checkExistPluginInstanceName(alertInstanceName); boolean exist = alertPluginInstanceService.checkExistPluginInstanceName(alertInstanceName);
Result result = new Result();
if (exist) { if (exist) {
logger.error("alert plugin instance {} has exist, can't create again.", alertInstanceName); logger.error("alert plugin instance {} has exist, can't create again.", alertInstanceName);
result.setCode(Status.PLUGIN_INSTANCE_ALREADY_EXIT.getCode()); return Result.error(Status.PLUGIN_INSTANCE_ALREADY_EXIT);
result.setMsg(Status.PLUGIN_INSTANCE_ALREADY_EXIT.getMsg());
} else { } else {
result.setCode(Status.SUCCESS.getCode()); return Result.success();
result.setMsg(Status.SUCCESS.getMsg());
} }
return result;
} }
/** /**

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

@ -50,11 +50,6 @@ public class Result<T> {
this.msg = msg; this.msg = msg;
} }
private Result(T data) {
this.code = 0;
this.data = data;
}
private Result(Status status) { private Result(Status status) {
if (status != null) { if (status != null) {
this.code = status.getCode(); this.code = status.getCode();
@ -62,6 +57,12 @@ public class Result<T> {
} }
} }
public Result(Integer code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
/** /**
* Call this function if there is success * Call this function if there is success
* *
@ -70,7 +71,11 @@ public class Result<T> {
* @return resule * @return resule
*/ */
public static <T> Result<T> success(T data) { 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() { public boolean isSuccess() {

Loading…
Cancel
Save