Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improve]Improve flink env check method #3461

Merged
merged 15 commits into from
Jan 8, 2024
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 @@ -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,20 @@
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) {
zzzk1 marked this conversation as resolved.
Show resolved Hide resolved
switch (checkResp) {
case FlinkEvnEnum.INVALID:
Swal.fire('Failed', 'FLINK_HOME invalid path.', 'error');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error msg should use i18n

break;
case FlinkEvnEnum.NAME_REPEATED:
Swal.fire('Failed', t('setting.flinkHome.operateMessage.flinkNameIsUnique'), 'error');
break;
case FlinkEvnEnum.FLINK_DIST_REPEATED:
Swal.fire(
'Failed',
'can no found flink-dist or found multiple flink-dist, FLINK_HOME error.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error msg should use i18n, e.g: t('setting.flinkHome.operateMessage.FLINK_DIST_REPEATED')
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sry I know nothing about the front end

'error',
);
}
changeOkLoading(false);
return;
Expand Down
Loading