Skip to content

Commit

Permalink
improve front end hard code and back end check method
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzk1 committed Jan 7, 2024
1 parent f2cd7f4 commit 22cbb3f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,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 an String value indicating the existence of the specified version.
*/
Integer check(FlinkEnv version);
String check(FlinkEnv version);

/**
* Create a new instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public class FlinkEnvServiceImpl extends ServiceImpl<FlinkEnvMapper, FlinkEnv>
* 0) ok <br>
*/
@Override
public Integer check(FlinkEnv version) {
public String 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 FlinkEnvStatus.NAME_REPEATED.getCode();
return FlinkEnvStatus.NAME_REPEATED.getMsg();
}

// 2) check dist_jar
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down

0 comments on commit 22cbb3f

Please sign in to comment.