Skip to content

Commit

Permalink
Optimize some judgment logic and alert rule logic (DataLinkDC#3591)
Browse files Browse the repository at this point in the history
Signed-off-by: Zzm0809 <[email protected]>
Co-authored-by: Zzm0809 <[email protected]>
  • Loading branch information
Zzm0809 and Zzm0809 authored Jun 13, 2024
1 parent 1166b33 commit d33d97f
Show file tree
Hide file tree
Showing 17 changed files with 380 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public Result<Boolean> saveOrUpdateAlertRule(@RequestBody AlertRule alertRule) {
boolean saved = alertRuleService.saveOrUpdate(alertRule);
if (saved) {
JobAlertHandler.getInstance().refreshRulesData();
return Result.succeed(Status.MODIFY_SUCCESS);
return Result.succeed(Status.SAVE_SUCCESS);
}
return Result.failed(Status.MODIFY_FAILED);
return Result.failed(Status.SAVE_FAILED);
}

@DeleteMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@

package org.dinky.data.model.alert;

import org.dinky.data.typehandler.ListTypeHandler;
import org.dinky.mybatis.model.SuperEntity;

import java.util.List;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;

import io.swagger.annotations.ApiModel;
Expand All @@ -38,8 +42,9 @@
@ApiModel(value = "AlertRule", description = "AlertRule")
public class AlertRule extends SuperEntity<AlertRule> {

@ApiModelProperty(value = "rule", required = true, dataType = "String", example = "rule")
String rule;
@ApiModelProperty(value = "rule", required = true, dataType = "List<AlertTriggerRule>", example = "rule")
@TableField(typeHandler = ListTypeHandler.class)
List<AlertTriggerRule> rule;

@ApiModelProperty(value = "templateId", required = true, dataType = "int", example = "1")
int templateId;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
*
* 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.dinky.data.model.alert;

import lombok.Data;

/**
* alert triggering rules
*/
@Data
public class AlertTriggerRule {
private String ruleKey;
private String ruleOperator;
private String ruleValue;
private Integer rulePriority;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import {
assert,
getCurrentData,
getCurrentTab,
isDataStudioTabsItemType,
Expand Down Expand Up @@ -135,7 +136,7 @@ const Result = (props: any) => {
} else if (consoleData.results && !isRefresh) {
setDataList(consoleData.results);
} else {
if (current?.dialect && current?.dialect?.toLowerCase() == DIALECT.FLINK_SQL) {
if (assert(current?.dialect, [DIALECT.FLINK_SQL], true, 'includes')) {
// flink sql
// to do: get job data by history id list, not flink jid
if (current?.id) {
Expand Down
20 changes: 14 additions & 6 deletions dinky-web/src/pages/DataStudio/HeaderContainer/function.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { TabsPageType, TaskDataType } from '@/pages/DataStudio/model';
import { JOB_LIFE_CYCLE } from '@/pages/DevOps/constants';
import { DIALECT } from '@/services/constants';
import { assert } from '@/pages/DataStudio/function';

/**
* @description: 生成面包屑
Expand All @@ -46,15 +47,22 @@ export const isOnline = (data: TaskDataType | undefined) => {
export const isCanPushDolphin = (data: TaskDataType | undefined) => {
return data
? JOB_LIFE_CYCLE.PUBLISH === data.step &&
data?.dialect?.toLowerCase() !== DIALECT.FLINKSQLENV &&
data?.dialect?.toLowerCase() !== DIALECT.SCALA &&
data?.dialect?.toLowerCase() !== DIALECT.JAVA &&
data?.dialect?.toLowerCase() !== DIALECT.PYTHON_LONG
assert(
data?.dialect,
[DIALECT.FLINKSQLENV, DIALECT.SCALA, DIALECT.JAVA, DIALECT.PYTHON_LONG],
true,
'notIncludes'
)
: false;
};

export const isSql = (dialect: string, includedFlinkSQL: boolean = false) => {
if (!dialect) {
/**
* @description: 判断是否为 SQL 方言 | assert is sql dialect
* @param dialect
* @param includedFlinkSQL
*/
export const isSql = (dialect: string = '', includedFlinkSQL: boolean = false) => {
if (!dialect || dialect === '') {
return false;
}
switch (dialect.toLowerCase()) {
Expand Down
49 changes: 29 additions & 20 deletions dinky-web/src/pages/DataStudio/HeaderContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import { PushpinIcon } from '@/components/Icons/CustomIcons';
import { FlexCenterDiv } from '@/components/StyledComponents';
import { LeftBottomKey } from '@/pages/DataStudio/data.d';
import {
assert,
getCurrentData,
getCurrentTab,
isNotEmpty,
lockTask,
mapDispatchToProps
} from '@/pages/DataStudio/function';
Expand Down Expand Up @@ -373,9 +375,8 @@ const HeaderContainer = (props: connect) => {
icon: <ApartmentOutlined />,
title: l('button.graph'),
isShow:
(projectCommonShow(currentTab?.type) &&
currentTab?.subType?.toLowerCase() === DIALECT.FLINK_SQL) ||
currentTab?.subType?.toLowerCase() === DIALECT.FLINKJAR,
projectCommonShow(currentTab?.type) &&
assert(currentTab?.subType, [DIALECT.FLINK_SQL, DIALECT.FLINKJAR], true, 'includes'),
click: async () => showDagGraph(),
props: {
disabled: isLockTask
Expand All @@ -391,9 +392,13 @@ const HeaderContainer = (props: connect) => {
click: () => showExplain(),
isShow:
projectCommonShow(currentTab?.type) &&
currentTab?.subType?.toLowerCase() !== DIALECT.JAVA &&
currentTab?.subType?.toLowerCase() !== DIALECT.SCALA &&
currentTab?.subType?.toLowerCase() !== DIALECT.PYTHON_LONG,
assert(
currentTab?.subType,
[DIALECT.JAVA, DIALECT.SCALA, DIALECT.PYTHON_LONG],
true,
'notIncludes'
) &&
!isSql(currentTab?.subType),
props: {
disabled: isLockTask
}
Expand All @@ -414,7 +419,7 @@ const HeaderContainer = (props: connect) => {
// 发布按钮
icon: isOnline(currentData) ? <MergeCellsOutlined /> : <FundOutlined />,
title: isOnline(currentData) ? l('button.offline') : l('button.publish'),
isShow: currentTab?.type == TabsPageType.project,
isShow: assert(currentTab?.type, TabsPageType.project, true, 'equal'),
click: () => handleChangeJobLife(),
props: {
disabled: isLockTask
Expand All @@ -425,10 +430,10 @@ const HeaderContainer = (props: connect) => {
icon: <RotateRightOutlined />,
title: l('pages.datastudio.to.jobDetail'),
isShow:
currentTab?.type == TabsPageType.project &&
currentData?.jobInstanceId &&
(currentTab?.subType?.toLowerCase() == DIALECT.FLINK_SQL ||
currentTab?.subType?.toLowerCase() == DIALECT.FLINKJAR),
isNotEmpty(currentData?.jobInstanceId) &&
!isSql(currentTab?.subType) &&
assert(currentTab?.subType, [DIALECT.FLINK_SQL, DIALECT.FLINKJAR], true, 'includes') &&
assert(currentTab?.type, TabsPageType.project, true, 'equal'),
props: {
onClick: async () => {
const dataByParams = await queryDataByParams<Jobs.JobInstance>(
Expand All @@ -451,12 +456,14 @@ const HeaderContainer = (props: connect) => {
hotKey: (e: KeyboardEvent) => e.shiftKey && e.key === 'F10',
hotKeyDesc: 'Shift+F10',
isShow:
currentTab?.type == TabsPageType.project &&
assert(currentTab?.type, TabsPageType.project, true, 'equal') &&
isStatusDone(currentData?.status) &&
currentTab?.subType?.toLowerCase() !== DIALECT.JAVA &&
currentTab?.subType?.toLowerCase() !== DIALECT.SCALA &&
currentTab?.subType?.toLowerCase() !== DIALECT.PYTHON_LONG &&
currentTab?.subType?.toLowerCase() !== DIALECT.FLINKSQLENV,
assert(
currentTab?.subType,
[DIALECT.JAVA, DIALECT.SCALA, DIALECT.PYTHON_LONG, DIALECT.FLINKSQLENV],
true,
'notIncludes'
),
props: {
style: { background: '#52c41a' },
type: 'primary',
Expand All @@ -471,10 +478,10 @@ const HeaderContainer = (props: connect) => {
hotKey: (e: KeyboardEvent) => e.shiftKey && e.key === 'F9',
hotKeyDesc: 'Shift+F9',
isShow:
currentTab?.type == TabsPageType.project &&
assert(currentTab?.type, TabsPageType.project, true, 'equal') &&
isStatusDone(currentData?.status) &&
(currentTab?.subType?.toLowerCase() === DIALECT.FLINK_SQL ||
isSql(currentTab?.subType?.toLowerCase() ?? '')),
!isSql(currentTab?.subType) &&
assert(currentTab?.subType, [DIALECT.FLINK_SQL], true, 'includes'),
props: {
style: { background: '#52c41a' },
type: 'primary',
Expand All @@ -486,7 +493,9 @@ const HeaderContainer = (props: connect) => {
icon: <PauseOutlined />,
title: l('pages.datastudio.editor.stop'),
click: handlerStop,
isShow: currentTab?.type == TabsPageType.project && !isStatusDone(currentData?.status),
isShow:
assert(currentTab?.type, TabsPageType.project, true, 'equal') &&
!isStatusDone(currentData?.status),
hotKey: (e: KeyboardEvent) => e.shiftKey && e.key === 'F10',
hotKeyDesc: 'Shift+F10',
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { LeftBottomKey, RightMenuKey } from '@/pages/DataStudio/data.d';
import { lockTask, showAllOwners } from '@/pages/DataStudio/function';
import { assert, lockTask, showAllOwners } from '@/pages/DataStudio/function';
import { isSql } from '@/pages/DataStudio/HeaderContainer/function';
import { getTabIcon } from '@/pages/DataStudio/MiddleContainer/function';
import { DIALECT } from '@/services/constants';
Expand Down Expand Up @@ -323,15 +323,11 @@ export const buildProjectTree = (
: [];

export const isUDF = (jobType: string): boolean => {
return (
jobType.toLowerCase() === DIALECT.SCALA ||
jobType.toLowerCase() === DIALECT.PYTHON_LONG ||
jobType.toLowerCase() === DIALECT.JAVA
);
return assert(jobType, [DIALECT.SCALA, DIALECT.PYTHON_LONG, DIALECT.JAVA], true, 'includes');
};

export const isFlinkJob = (jobType: string): boolean => {
return jobType.toLowerCase() === DIALECT.FLINK_SQL || jobType.toLowerCase() === DIALECT.FLINKJAR;
return assert(jobType, [DIALECT.FLINK_SQL, DIALECT.FLINKJAR], true, 'includes');
};

export function getRightSelectKeyFromNodeClickJobType(jobType: string): string {
Expand Down
16 changes: 13 additions & 3 deletions dinky-web/src/pages/DataStudio/LeftContainer/Project/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
*/

import RightContextMenu from '@/components/RightContextMenu';
import { getTabByTaskId } from '@/pages/DataStudio/function';
import { assert, getTabByTaskId } from '@/pages/DataStudio/function';
import { useTasksDispatch } from '@/pages/DataStudio/LeftContainer/BtnContext';
import {
FOLDER_RIGHT_MENU,
JOB_RIGHT_MENU
} from '@/pages/DataStudio/LeftContainer/Project/constants';
import FolderModal from '@/pages/DataStudio/LeftContainer/Project/FolderModal';
import { getRightSelectKeyFromNodeClickJobType } from '@/pages/DataStudio/LeftContainer/Project/function';
import {
getRightSelectKeyFromNodeClickJobType,
isUDF
} from '@/pages/DataStudio/LeftContainer/Project/function';
import JobModal from '@/pages/DataStudio/LeftContainer/Project/JobModal';
import JobTree from '@/pages/DataStudio/LeftContainer/Project/JobTree';
import {
Expand Down Expand Up @@ -146,6 +149,13 @@ const Project: React.FC = (props: connect) => {
type: STUDIO_MODEL.updateSelectRightKey,
payload: getRightSelectKeyFromNodeClickJobType(type)
});
// 如果是 udf 或者 是env 则需要更新 bottom key 为空|| if is udf or is env then update bottom key to empty
if (isUDF(type) || assert(type, [DIALECT.FLINKSQLENV], true, 'includes')) {
dispatch({
type: STUDIO_MODEL.updateSelectBottomKey,
payload: ''
});
}
}

dispatch({
Expand Down Expand Up @@ -213,7 +223,7 @@ const Project: React.FC = (props: connect) => {
() => {},
() => {
dispatch({ type: STUDIO_MODEL_ASYNC.queryProject, payload: selectCatalogueSortTypeData });
if (values.type && values.type.toLowerCase() === DIALECT.FLINKSQLENV) {
if (assert(values.type, [DIALECT.FLINKSQLENV], true, 'includes')) {
dispatch({ type: STUDIO_MODEL_ASYNC.queryEnv });
}
if (projectState.isEdit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import FlinkOptionsSelect from '@/components/Flink/OptionsSelect';
import { SAVE_POINT_TYPE } from '@/pages/DataStudio/constants';
import {
assert,
getCurrentData,
getCurrentTab,
isDataStudioTabsItemType,
Expand Down Expand Up @@ -121,10 +122,12 @@ const JobConfig = (props: any) => {
Object.keys(change).forEach((key) => {
if (key === 'configJson') {
if (!pane.params.taskData.configJson) {
// @ts-ignore
pane.params.taskData.configJson = {};
}

Object.keys(change[key]).forEach((k) => {
// @ts-ignore
pane.params.taskData[key][k] = all[key][k];
});
} else {
Expand Down Expand Up @@ -315,7 +318,7 @@ const JobConfig = (props: any) => {
</>
)}

{current?.dialect && current?.dialect?.toLowerCase() === DIALECT.FLINK_SQL && (
{assert(current?.dialect, [DIALECT.FLINK_SQL], true, 'includes') && (
<ProFormSelect
name='envId'
label={l('pages.datastudio.label.jobConfig.flinksql.env')}
Expand Down
Loading

0 comments on commit d33d97f

Please sign in to comment.