Skip to content

Commit

Permalink
[Improve]Improve flink env check method (#3461)
Browse files Browse the repository at this point in the history
* [Improve] improve hard code in FlinkEnvServiceImpl

* improve front end hard code and back end check method

* improve check method return type

* improve front end check method logic

* improve message support i18n

* improve i18n error message

---------

Co-authored-by: benjobs <[email protected]>
  • Loading branch information
zzzk1 and wolfboys authored Jan 8, 2024
1 parent 203c751 commit 3cc2583
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.streampark.common.enums;

/* 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) {
this.code = code;
}

public int getCode() {
return code;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.streampark.console.core.controller;

import org.apache.streampark.common.enums.FlinkEnvStatus;
import org.apache.streampark.console.base.domain.RestResponse;
import org.apache.streampark.console.base.exception.ApiDetailException;
import org.apache.streampark.console.core.entity.FlinkEnv;
Expand Down Expand Up @@ -52,8 +53,8 @@ public RestResponse list() {
@Operation(summary = "Verify flink environment")
@PostMapping("check")
public RestResponse check(FlinkEnv version) {
Integer checkResp = flinkEnvService.check(version);
return RestResponse.success(checkResp);
FlinkEnvStatus checkResp = flinkEnvService.check(version);
return RestResponse.success(checkResp.getCode());
}

@Operation(summary = "Create flink environment")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.streampark.console.core.service;

import org.apache.streampark.common.enums.FlinkEnvStatus;
import org.apache.streampark.console.core.entity.FlinkEnv;

import com.baomidou.mybatisplus.extension.service.IService;
Expand All @@ -29,11 +30,9 @@ public interface FlinkEnvService extends IService<FlinkEnv> {
* 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 enum value indicating the existence of the specified version.
*/
Integer check(FlinkEnv version);
FlinkEnvStatus check(FlinkEnv version);

/**
* Create a new instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.streampark.console.core.service.impl;

import org.apache.streampark.common.enums.FlinkEnvStatus;
import org.apache.streampark.console.base.exception.ApiAlertException;
import org.apache.streampark.console.core.entity.FlinkEnv;
import org.apache.streampark.console.core.mapper.FlinkEnvMapper;
Expand Down Expand Up @@ -49,19 +50,17 @@ public class FlinkEnvServiceImpl extends ServiceImpl<FlinkEnvMapper, FlinkEnv>
* two places will be checked: <br>
* 1) name repeated <br>
* 2) flink-dist repeated <br>
* -1) invalid path <br>
* 0) ok <br>
*/
@Override
public Integer check(FlinkEnv version) {
public FlinkEnvStatus check(FlinkEnv version) {
// 1) check name
LambdaQueryWrapper<FlinkEnv> queryWrapper =
new LambdaQueryWrapper<FlinkEnv>().eq(FlinkEnv::getFlinkName, version.getFlinkName());
if (version.getId() != null) {
queryWrapper.ne(FlinkEnv::getId, version.getId());
}
if (this.count(queryWrapper) > 0) {
return 1;
return FlinkEnvStatus.NAME_REPEATED;
}

// 2) check dist_jar
Expand All @@ -70,12 +69,12 @@ 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 2;
return FlinkEnvStatus.FLINK_DIST_REPEATED;
}
} else {
return -1;
return FlinkEnvStatus.INVALID;
}
return 0;
return FlinkEnvStatus.FEASIBLE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default {
flinkNameIsRequired: 'flink name is required',
flinkHomeTips: 'The absolute path of the FLINK_HOME',
flinkHomeIsRequired: 'flink home is required',
flinkDistIsRepeated: 'FLINK_HOME error: can no found flink-dist or found multiple flink-dist.',
createFlinkHomeSuccessful: ' create successful!',
updateFlinkHomeSuccessful: ' update successful!',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ export default {
descriptionPlaceholder: 'Flink描述',
operateMessage: {
flinkNameTips: 'Flink别名,举例: Flink-1.12',
flinkNameIsUnique: 'Flink名称已存在',
flinkNameIsRepeated: 'Flink名称已存在',
flinkNameIsRequired: 'Flink名称必填',
flinkHomeTips: 'Flink所在服务器的绝对路径,举例: /usr/local/flink',
flinkHomeIsRequired: 'Flink安装路径必填',
flinkDistIsRepeated: 'flink/lib 路径下有且只能有一个flink-dist jar文件,当前未找到或找到多个,请检查!',
createFlinkHomeSuccessful: ' 创建成功!',
updateFlinkHomeSuccessful: ' 更新成功!',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | null>(null);
const { t } = useI18n();
Expand Down Expand Up @@ -100,18 +100,16 @@
flinkHome: formValue.flinkHome,
});
const checkResp = parseInt(resp.data);
if (checkResp != 0) {
// Environment detection is successful
if (checkResp == -1) {
Swal.fire('Failed', 'FLINK_HOME invalid path.', 'error');
} else if (checkResp == 1) {
Swal.fire('Failed', t('setting.flinkHome.operateMessage.flinkNameIsUnique'), 'error');
} else if (checkResp == 2) {
Swal.fire(
'Failed',
'can no found flink-dist or found multiple flink-dist, FLINK_HOME error.',
'error',
);
if (checkResp !== FlinkEvnEnum.FEASIBLE) {
switch (checkResp) {
case FlinkEvnEnum.INVALID:
Swal.fire('Failed', t('setting.flinkHome.operateMessage.flinkHomePathIsInvalid'), 'error');
break;
case FlinkEvnEnum.NAME_REPEATED:
Swal.fire('Failed', t('setting.flinkHome.operateMessage.flinkNameIsRepeated'), 'error');
break;
case FlinkEvnEnum.FLINK_DIST_REPEATED:
Swal.fire('Failed', t('setting.flinkHome.operateMessage.flinkDistIsRepeated'), 'error');
}
changeOkLoading(false);
return;
Expand Down

0 comments on commit 3cc2583

Please sign in to comment.