Skip to content

Commit

Permalink
[Improve] flink env check improvement (#3469)
Browse files Browse the repository at this point in the history
* [Improve] flink env check improvement

* minor improve

* [Improve] check flink env improvement

* Update FlinkEnvCheckEnum.java

---------

Co-authored-by: benjobs <[email protected]>
  • Loading branch information
wolfboys and benjobs authored Jan 9, 2024
1 parent 3cc2583 commit bff3876
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

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;
import org.apache.streampark.console.core.enums.FlinkEnvCheckEnum;
import org.apache.streampark.console.core.service.FlinkEnvService;

import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -53,7 +53,7 @@ public RestResponse list() {
@Operation(summary = "Verify flink environment")
@PostMapping("check")
public RestResponse check(FlinkEnv version) {
FlinkEnvStatus checkResp = flinkEnvService.check(version);
FlinkEnvCheckEnum checkResp = flinkEnvService.check(version);
return RestResponse.success(checkResp.getCode());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,33 @@
* limitations under the License.
*/

package org.apache.streampark.common.enums;
package org.apache.streampark.console.core.enums;

import lombok.Getter;

/* the flink environment status */
public enum FlinkEnvStatus {
@Getter
public enum FlinkEnvCheckEnum {

/* FLINK_HOME path invalid */
INVALID(-1),
INVALID_PATH(-1),

/* this add/update operation are feasible */
FEASIBLE(0),
/* this add/update operation ok */
OK(0),

/* defined flink name repeated */
/* flink name repeated */
NAME_REPEATED(1),

/* dist Jar more than one */
FLINK_DIST_REPEATED(2);
/* FLINK_DIST file not found */

FLINK_DIST_NOT_FOUND(2),

/* defined flink name repeated */
FLINK_DIST_REPEATED(3);

private final int code;

FlinkEnvStatus(int code) {
FlinkEnvCheckEnum(int code) {
this.code = code;
}

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

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

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

import com.baomidou.mybatisplus.extension.service.IService;

Expand All @@ -32,7 +32,7 @@ public interface FlinkEnvService extends IService<FlinkEnv> {
* @param version The version of Flink to check.
* @return Returns enum value indicating the existence of the specified version.
*/
FlinkEnvStatus check(FlinkEnv version);
FlinkEnvCheckEnum check(FlinkEnv version);

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

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.enums.FlinkEnvCheckEnum;
import org.apache.streampark.console.core.mapper.FlinkEnvMapper;
import org.apache.streampark.console.core.service.FlinkClusterService;
import org.apache.streampark.console.core.service.FlinkEnvService;
Expand Down Expand Up @@ -52,29 +52,35 @@ public class FlinkEnvServiceImpl extends ServiceImpl<FlinkEnvMapper, FlinkEnv>
* 2) flink-dist repeated <br>
*/
@Override
public FlinkEnvStatus check(FlinkEnv version) {
public FlinkEnvCheckEnum 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;
return FlinkEnvCheckEnum.NAME_REPEATED;
}

// 2) check dist_jar
String lib = version.getFlinkHome().concat("/lib");
File flinkLib = new File(lib);
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;
}
} else {
return FlinkEnvStatus.INVALID;
// 2) flink/lib path exists and is a directory
if (!flinkLib.exists() || !flinkLib.isDirectory()) {
return FlinkEnvCheckEnum.INVALID_PATH;
}
return FlinkEnvStatus.FEASIBLE;

// 3) check flink-dist
File[] files = flinkLib.listFiles(f -> f.getName().matches("flink-dist.*\\.jar"));
if (files == null || files.length == 0) {
return FlinkEnvCheckEnum.FLINK_DIST_NOT_FOUND;
}

if (files.length > 1) {
return FlinkEnvCheckEnum.FLINK_DIST_REPEATED;
}

return FlinkEnvCheckEnum.OK;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@
height: 18px;
background-color: #fff;
border-radius: 50%;
transition:
transform 0.5s,
background-color 0.5s;
transition: transform 0.5s, background-color 0.5s;
will-change: transform;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@
background-color: @component-background;
border: 1px solid rgb(0 0 0 / 8%);
border-radius: 0.25rem;
box-shadow:
0 2px 2px 0 rgb(0 0 0 / 14%),
0 3px 1px -2px rgb(0 0 0 / 10%),
box-shadow: 0 2px 2px 0 rgb(0 0 0 / 14%), 0 3px 1px -2px rgb(0 0 0 / 10%),
0 1px 5px 0 rgb(0 0 0 / 6%);
background-clip: padding-box;
user-select: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
});
const getBindValue = computed(
() => ({ ...attrs, ...props, ...unref(getProps) }) as Recordable,
() => ({ ...attrs, ...props, ...unref(getProps) } as Recordable),
);
const getSchema = computed((): FormSchema[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@
return slot
? getSlot(slots, slot, unref(getValues))
: render
? render(unref(getValues))
: renderComponent();
? render(unref(getValues))
: renderComponent();
};
const showSuffix = !!suffix;
Expand Down Expand Up @@ -382,8 +382,8 @@
return colSlot
? getSlot(slots, colSlot, values)
: renderColContent
? renderColContent(values)
: renderItem();
? renderColContent(values)
: renderItem();
};
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@
realHeightRef.value = props.height
? props.height
: realHeight > maxHeight
? maxHeight
: realHeight;
? maxHeight
: realHeight;
}
emit('height-change', unref(realHeightRef));
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
line-height: 44px;
background-color: @component-background;
border-top: 1px solid @border-color-base;
box-shadow:
0 -6px 16px -8px rgb(0 0 0 / 8%),
0 -9px 28px 0 rgb(0 0 0 / 5%),
box-shadow: 0 -6px 16px -8px rgb(0 0 0 / 8%), 0 -9px 28px 0 rgb(0 0 0 / 5%),
0 -12px 48px 16px rgb(0 0 0 / 3%);
transition: width 0.2s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
props: {
column: {
type: Object as PropType<BasicColumn>,
default: () => ({}) as BasicColumn,
default: () => ({} as BasicColumn),
},
},
setup(props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,10 @@ export enum AppExistsEnum {
INVALID = 4,
}

export enum FlinkEvnEnum {
INVALID = -1,
FEASIBLE = 0,
export enum FlinkEnvCheckEnum {
INVALID_PATH = -1,
OK = 0,
NAME_REPEATED = 1,
FLINK_DIST_REPEATED = 2,
FLINK_DIST_NOT_FOUND = 2,
FLINK_DIST_REPEATED = 3,
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,18 @@ export function useMenuSetting() {
return siderHidden
? 0
: collapsedShowTitle
? SIDE_BAR_SHOW_TIT_MINI_WIDTH
: SIDE_BAR_MINI_WIDTH;
? SIDE_BAR_SHOW_TIT_MINI_WIDTH
: SIDE_BAR_MINI_WIDTH;
});

const getCalcContentWidth = computed(() => {
const width =
unref(getIsTopMenu) || !unref(getShowMenu) || (unref(getSplit) && unref(getMenuHidden))
? 0
: unref(getIsMixSidebar)
? (unref(getCollapsed) ? SIDE_BAR_MINI_WIDTH : SIDE_BAR_SHOW_TIT_MINI_WIDTH) +
(unref(getMixSideFixed) && unref(mixSideHasChildren) ? unref(getRealWidth) : 0)
: unref(getRealWidth);
? (unref(getCollapsed) ? SIDE_BAR_MINI_WIDTH : SIDE_BAR_SHOW_TIT_MINI_WIDTH) +
(unref(getMixSideFixed) && unref(mixSideHasChildren) ? unref(getRealWidth) : 0)
: unref(getRealWidth);

return `calc(100% - ${unref(width)}px)`;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ export function useLockPage() {
}
clear();

timeId = setTimeout(
() => {
lockPage();
},
lockTime * 60 * 1000,
);
timeId = setTimeout(() => {
lockPage();
}, lockTime * 60 * 1000);
}

function lockPage(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ export default {
descriptionPlaceholder: 'Please enter description',
operateMessage: {
flinkNameTips: 'the flink name, e.g: flink-1.12',
flinkNameIsUnique: 'flink name is already exists',
flinkNameIsRepeated: 'flink name is already exists',
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.',
flinkHomePathIsInvalid: 'flink home path is invalid',
flinkDistNotFound: 'can no found flink-dist in FLINK_HOME/lib',
flinkDistIsRepeated: 'found multiple flink-dist in FLINK_HOME/lib, Must be only one',
createFlinkHomeSuccessful: ' create successful!',
updateFlinkHomeSuccessful: ' update successful!',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ export default {
flinkNameIsRepeated: 'Flink名称已存在',
flinkNameIsRequired: 'Flink名称必填',
flinkHomeTips: 'Flink所在服务器的绝对路径,举例: /usr/local/flink',
flinkHomeIsRequired: 'Flink安装路径必填',
flinkDistIsRepeated: 'flink/lib 路径下有且只能有一个flink-dist jar文件,当前未找到或找到多个,请检查!',
flinkHomeIsRequired: 'Flink Home必填',
flinkHomePathIsInvalid: 'Flink Home路径无效',
flinkDistNotFound: 'flink/lib 路径下未找到 flink-dist jar文件',
flinkDistIsRepeated: 'flink/lib 路径下存在多个flink-dist jar文件, 必须只能有一个!',
createFlinkHomeSuccessful: ' 创建成功!',
updateFlinkHomeSuccessful: ' 更新成功!',
},
Expand Down
48 changes: 24 additions & 24 deletions streampark-console/streampark-console-webapp/src/utils/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ export type BuildPropOption<T, D extends BuildPropType<T, V, C>, R, V, C> = {
default?: R extends true
? never
: D extends Record<string, unknown> | Array<any>
? () => D
: (() => D) | D;
? () => D
: (() => D) | D;
validator?: ((val: any) => val is C) | ((val: any) => boolean);
};

type _BuildPropType<T, V, C> =
| (T extends PropWrapper<unknown>
? T[typeof wrapperKey]
: [V] extends [never]
? ResolvePropTypeWithReadonly<T>
: never)
? ResolvePropTypeWithReadonly<T>
: never)
| V
| C;
export type BuildPropType<T, V, C> = _BuildPropType<
Expand All @@ -53,8 +53,8 @@ type _BuildPropDefault<T, D> = [T] extends [
]
? D
: D extends () => T
? ReturnType<D>
: D;
? ReturnType<D>
: D;

export type BuildPropDefault<T, D, R> = R extends true
? { readonly default?: undefined }
Expand Down Expand Up @@ -146,12 +146,12 @@ export const buildProps = <
[K in keyof O]: O[K] extends BuildPropReturn<any, any, any, any, any>
? O[K]
: [O[K]] extends NativePropType
? O[K]
: O[K] extends BuildPropOption<infer T, infer D, infer R, infer V, infer C>
? D extends BuildPropType<T, V, C>
? BuildPropOption<T, D, R, V, C>
: never
: never;
? O[K]
: O[K] extends BuildPropOption<infer T, infer D, infer R, infer V, infer C>
? D extends BuildPropType<T, V, C>
? BuildPropOption<T, D, R, V, C>
: never
: never;
},
>(
props: O,
Expand All @@ -162,20 +162,20 @@ export const buildProps = <
[K in keyof O]: O[K] extends { [propKey]: boolean }
? O[K]
: [O[K]] extends NativePropType
? O[K]
: O[K] extends BuildPropOption<
infer T,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
infer _D,
infer R,
infer V,
infer C
>
? BuildPropReturn<T, O[K]['default'], R, V, C>
: never;
? O[K]
: O[K] extends BuildPropOption<
infer T,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
infer _D,
infer R,
infer V,
infer C
>
? BuildPropReturn<T, O[K]['default'], R, V, C>
: never;
};

export const definePropType = <T>(val: any) => ({ [wrapperKey]: val }) as PropWrapper<T>;
export const definePropType = <T>(val: any) => ({ [wrapperKey]: val } as PropWrapper<T>);

export const keyOf = <T extends Object>(arr: T) => Object.keys(arr) as Array<keyof T>;
export const mutable = <T extends readonly any[] | Record<string, unknown>>(val: T) =>
Expand Down
Loading

0 comments on commit bff3876

Please sign in to comment.