From 22cbb3fd244ce3f95be04601bce331e788522baf Mon Sep 17 00:00:00 2001 From: zzzk1 Date: Sun, 7 Jan 2024 16:12:43 +0800 Subject: [PATCH] improve front end hard code and back end check method --- .../common/enums/FlinkEnvStatus.java | 19 ++++++++++--------- .../core/controller/FlinkEnvController.java | 2 +- .../console/core/service/FlinkEnvService.java | 6 ++---- .../service/impl/FlinkEnvServiceImpl.java | 10 +++++----- .../src/views/flink/home/components/Modal.vue | 10 +++++----- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/streampark-common/src/main/java/org/apache/streampark/common/enums/FlinkEnvStatus.java b/streampark-common/src/main/java/org/apache/streampark/common/enums/FlinkEnvStatus.java index 411dae3f2e..58087529bc 100644 --- a/streampark-common/src/main/java/org/apache/streampark/common/enums/FlinkEnvStatus.java +++ b/streampark-common/src/main/java/org/apache/streampark/common/enums/FlinkEnvStatus.java @@ -20,21 +20,22 @@ /* the flink environment status */ public enum FlinkEnvStatus { /* FLINK_HOME path invalid */ - INVALID(-1), + INVALID("path invalid"), /* this add/update operation are feasible */ - FEASIBLE(0), + FEASIBLE("ok"), /* defined flink name repeated */ - NAME_REPEATED(1), + NAME_REPEATED("name repeated"), /* dist Jar more than one */ - FLINK_DIST_REPEATED(2); - private final int code; + FLINK_DIST_REPEATED("dist repeated"); - FlinkEnvStatus(int code) { - this.code = code; + private final String msg; + + FlinkEnvStatus(String msg) { + this.msg = msg; } - public int getCode() { - return code; + public String getMsg() { + return this.msg; } } diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/FlinkEnvController.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/FlinkEnvController.java index 1c0e794686..9d6a54e7fe 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/FlinkEnvController.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/FlinkEnvController.java @@ -52,7 +52,7 @@ public RestResponse list() { @Operation(summary = "Verify flink environment") @PostMapping("check") public RestResponse check(FlinkEnv version) { - Integer checkResp = flinkEnvService.check(version); + String checkResp = flinkEnvService.check(version); return RestResponse.success(checkResp); } diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/FlinkEnvService.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/FlinkEnvService.java index 4a0b9bdd27..8a63b1422b 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/FlinkEnvService.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/FlinkEnvService.java @@ -29,11 +29,9 @@ public interface FlinkEnvService extends IService { * Checks if a specific version of Flink exists. * * @param version The version of Flink to check. - * @return Returns an Integer value indicating the existence of the specified version: - 0 if the - * version exists - 1 if the version does not exist - null if the version is invalid or an - * error occurred during the check + * @return Returns an String value indicating the existence of the specified version. */ - Integer check(FlinkEnv version); + String check(FlinkEnv version); /** * Create a new instance. diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkEnvServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkEnvServiceImpl.java index 89e4ecd4be..9695444d40 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkEnvServiceImpl.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/FlinkEnvServiceImpl.java @@ -54,7 +54,7 @@ public class FlinkEnvServiceImpl extends ServiceImpl * 0) ok
*/ @Override - public Integer check(FlinkEnv version) { + public String check(FlinkEnv version) { // 1) check name LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper().eq(FlinkEnv::getFlinkName, version.getFlinkName()); @@ -62,7 +62,7 @@ public Integer check(FlinkEnv version) { queryWrapper.ne(FlinkEnv::getId, version.getId()); } if (this.count(queryWrapper) > 0) { - return FlinkEnvStatus.NAME_REPEATED.getCode(); + return FlinkEnvStatus.NAME_REPEATED.getMsg(); } // 2) check dist_jar @@ -71,14 +71,14 @@ public Integer check(FlinkEnv version) { if (flinkLib.exists() && flinkLib.isDirectory()) { int distSize = flinkLib.listFiles(f -> f.getName().matches("flink-dist.*\\.jar")).length; if (distSize > 1) { - return FlinkEnvStatus.FLINK_DIST_REPEATED.getCode(); + return FlinkEnvStatus.FLINK_DIST_REPEATED.getMsg(); } } else { - return FlinkEnvStatus.INVALID.getCode(); + return FlinkEnvStatus.INVALID.getMsg(); } - return FlinkEnvStatus.FEASIBLE.getCode(); + return FlinkEnvStatus.FEASIBLE.getMsg(); } @Override diff --git a/streampark-console/streampark-console-webapp/src/views/flink/home/components/Modal.vue b/streampark-console/streampark-console-webapp/src/views/flink/home/components/Modal.vue index 6f047906f1..5bb7a85418 100644 --- a/streampark-console/streampark-console-webapp/src/views/flink/home/components/Modal.vue +++ b/streampark-console/streampark-console-webapp/src/views/flink/home/components/Modal.vue @@ -99,14 +99,14 @@ flinkName: formValue.flinkName, flinkHome: formValue.flinkHome, }); - const checkResp = parseInt(resp.data); - if (checkResp != 0) { + const checkResp = resp.data; + if (checkResp != 'ok') { // Environment detection is successful - if (checkResp == -1) { + if (checkResp == 'path invalid') { Swal.fire('Failed', 'FLINK_HOME invalid path.', 'error'); - } else if (checkResp == 1) { + } else if (checkResp == 'name repeated') { Swal.fire('Failed', t('setting.flinkHome.operateMessage.flinkNameIsUnique'), 'error'); - } else if (checkResp == 2) { + } else if (checkResp == 'dist repeated') { Swal.fire( 'Failed', 'can no found flink-dist or found multiple flink-dist, FLINK_HOME error.',