From 5b90bdf563770bb85f157c01763b9fb3f4624d06 Mon Sep 17 00:00:00 2001 From: zzzk1 Date: Sun, 7 Jan 2024 18:18:08 +0800 Subject: [PATCH] improve front end hard code and back end check method --- .../apache/streampark/common/enums/FlinkEnvStatus.java | 4 ++++ .../console/core/service/impl/FlinkEnvServiceImpl.java | 4 ---- .../streampark-console-webapp/src/enums/flinkEnum.ts | 7 +++++++ .../src/views/flink/home/components/Modal.vue | 10 +++++----- 4 files changed, 16 insertions(+), 9 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..8e47123e31 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 @@ -19,15 +19,19 @@ /* the flink environment status */ public enum FlinkEnvStatus { + /* FLINK_HOME path invalid */ INVALID(-1), + /* this add/update operation are feasible */ FEASIBLE(0), + /* defined flink name repeated */ NAME_REPEATED(1), /* dist Jar more than one */ FLINK_DIST_REPEATED(2); + private final int code; FlinkEnvStatus(int code) { 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..72edf15a5f 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 @@ -50,8 +50,6 @@ public class FlinkEnvServiceImpl extends ServiceImpl * two places will be checked:
* 1) name repeated
* 2) flink-dist repeated
- * -1) invalid path
- * 0) ok
*/ @Override public Integer check(FlinkEnv version) { @@ -74,10 +72,8 @@ public Integer check(FlinkEnv version) { return FlinkEnvStatus.FLINK_DIST_REPEATED.getCode(); } } else { - return FlinkEnvStatus.INVALID.getCode(); } - return FlinkEnvStatus.FEASIBLE.getCode(); } diff --git a/streampark-console/streampark-console-webapp/src/enums/flinkEnum.ts b/streampark-console/streampark-console-webapp/src/enums/flinkEnum.ts index b0b2f83ed1..7a2359c427 100644 --- a/streampark-console/streampark-console-webapp/src/enums/flinkEnum.ts +++ b/streampark-console/streampark-console-webapp/src/enums/flinkEnum.ts @@ -234,3 +234,10 @@ export enum AppExistsEnum { IN_KUBERNETES = 3, INVALID = 4, } + +export enum FlinkEvnEnum { + INVALID = -1, + FEASIBLE = 0, + NAME_REPEATED = 1, + FLINK_DIST_REPEATED = 2, +} 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..f08567c865 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 @@ -29,7 +29,7 @@ import { BasicModal, useModalInner } from '/@/components/Modal'; import { useMessage } from '/@/hooks/web/useMessage'; import { fetchCheckEnv, fetchFlinkCreate, fetchFlinkUpdate } from '/@/api/flink/flinkEnv'; - + import { FlinkEvnEnum } from '/@/enums/flinkEnum'; const emit = defineEmits(['reload', 'register']); const versionId = ref(null); const { t } = useI18n(); @@ -100,13 +100,13 @@ flinkHome: formValue.flinkHome, }); const checkResp = parseInt(resp.data); - if (checkResp != 0) { + if (checkResp !== FlinkEvnEnum.FEASIBLE) { // Environment detection is successful - if (checkResp == -1) { + if (checkResp === FlinkEvnEnum.INVALID) { Swal.fire('Failed', 'FLINK_HOME invalid path.', 'error'); - } else if (checkResp == 1) { + } else if (checkResp === FlinkEvnEnum.NAME_REPEATED) { Swal.fire('Failed', t('setting.flinkHome.operateMessage.flinkNameIsUnique'), 'error'); - } else if (checkResp == 2) { + } else if (checkResp === FlinkEvnEnum.FLINK_DIST_REPEATED) { Swal.fire( 'Failed', 'can no found flink-dist or found multiple flink-dist, FLINK_HOME error.',