Skip to content

Commit 89c35c9

Browse files
authored
optimize_table_data (#2674)
1 parent 9b4bd24 commit 89c35c9

File tree

9 files changed

+715
-612
lines changed

9 files changed

+715
-612
lines changed

dinky-admin/src/main/java/org/dinky/init/SystemInit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ private void aboutDolphinSchedulerInitOperation(Object v) {
247247
}
248248
try {
249249
project = projectClient.getDinkyProject();
250-
if (Asserts.isNull(project)) {
250+
if (project == null) {
251251
project = projectClient.createDinkyProject();
252252
}
253253
} catch (Exception e) {

dinky-admin/src/main/java/org/dinky/service/impl/JobInstanceServiceImpl.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,14 @@ public JobInfoDetail getJobInfoDetailInfo(JobInstance jobInstance) {
160160
jobInfoDetail.setClusterInstance(clusterInstance);
161161

162162
History history = historyService.getById(jobInstance.getHistoryId());
163-
history.setConfigJson(history.getConfigJson());
164-
jobInfoDetail.setHistory(history);
165-
if (Asserts.isNotNull(history.getClusterConfigurationId())) {
166-
ClusterConfiguration clusterConfig =
167-
clusterConfigurationService.getClusterConfigById(history.getClusterConfigurationId());
168-
jobInfoDetail.setClusterConfiguration(ClusterConfigurationDTO.fromBean(clusterConfig));
163+
if (history != null) {
164+
history.setConfigJson(history.getConfigJson());
165+
jobInfoDetail.setHistory(history);
166+
if (Asserts.isNotNull(history.getClusterConfigurationId())) {
167+
ClusterConfiguration clusterConfig =
168+
clusterConfigurationService.getClusterConfigById(history.getClusterConfigurationId());
169+
jobInfoDetail.setClusterConfiguration(ClusterConfigurationDTO.fromBean(clusterConfig));
170+
}
169171
}
170172

171173
JobDataDto jobDataDto = jobHistoryService.getJobHistoryDto(jobInstance.getId());

dinky-common/src/main/java/org/dinky/utils/RunTimeUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static void recovery(Object obj) {
3939
obj = null;
4040
System.gc();
4141
}
42+
4243
/**
4344
* 处理命令,多行命令原样返回,单行命令拆分处理
4445
*
@@ -47,14 +48,14 @@ public static void recovery(Object obj) {
4748
*/
4849
public static String[] handleCmds(String... cmds) {
4950
if (ArrayUtil.isEmpty(cmds)) {
50-
throw new NullPointerException("Command is empty !");
51+
return new String[] {};
5152
}
5253

5354
// 单条命令的情况
5455
if (1 == cmds.length) {
5556
final String cmd = cmds[0];
5657
if (StrUtil.isBlank(cmd)) {
57-
throw new NullPointerException("Command is blank !");
58+
return new String[] {};
5859
}
5960
cmds = cmdSplit(cmd);
6061
}

dinky-scheduler/src/main/java/org/dinky/scheduler/client/ProjectClient.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@
3535

3636
import cn.hutool.core.lang.TypeReference;
3737
import cn.hutool.http.HttpRequest;
38+
import cn.hutool.http.HttpResponse;
3839

39-
/** 项目 */
40+
/**
41+
* 项目
42+
*/
4043
@Component
4144
public class ProjectClient {
4245

@@ -55,8 +58,7 @@ public Project createDinkyProject() {
5558
.getDolphinschedulerProjectName()
5659
.getValue());
5760
map.put("description", "自动创建");
58-
59-
String content = HttpRequest.post(SystemConfiguration.getInstances()
61+
HttpResponse httpResponse = HttpRequest.post(SystemConfiguration.getInstances()
6062
.getDolphinschedulerUrl()
6163
.getValue()
6264
+ "/projects")
@@ -67,8 +69,13 @@ public Project createDinkyProject() {
6769
.getValue())
6870
.form(map)
6971
.timeout(5000)
70-
.execute()
71-
.body();
72+
.execute();
73+
if (httpResponse.getStatus() != 200) {
74+
SystemConfiguration.getInstances().getDolphinschedulerEnable().setValue(false);
75+
logger.error("DolphInScheduler connection failed, Reason: {}", httpResponse.getStatus());
76+
return null;
77+
}
78+
String content = httpResponse.body();
7279
return MyJSONUtil.verifyResult(MyJSONUtil.toBean(content, new TypeReference<Result<Project>>() {}));
7380
}
7481

@@ -79,7 +86,7 @@ public Project createDinkyProject() {
7986
*/
8087
public Project getDinkyProject() {
8188

82-
String content = HttpRequest.get(SystemConfiguration.getInstances()
89+
HttpResponse httpResponse = HttpRequest.get(SystemConfiguration.getInstances()
8390
.getDolphinschedulerUrl()
8491
.getValue()
8592
+ "/projects")
@@ -92,9 +99,14 @@ public Project getDinkyProject() {
9299
.getDolphinschedulerProjectName()
93100
.getValue()))
94101
.timeout(5000)
95-
.execute()
96-
.body();
102+
.execute();
97103

104+
if (httpResponse.getStatus() != 200) {
105+
SystemConfiguration.getInstances().getDolphinschedulerEnable().setValue(false);
106+
logger.error("DolphInScheduler connection failed, Reason: {}", httpResponse.getStatus());
107+
return null;
108+
}
109+
String content = httpResponse.body();
98110
try {
99111
return MyJSONUtil.toPageBeanAndFindByName(
100112
content,

dinky-web/src/components/CallBackButton/CircleBtn.tsx

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,46 @@
1717
*
1818
*/
1919

20-
import { TabsItemType } from '@/pages/DataStudio/model';
21-
import { Button } from 'antd';
20+
import {TabsItemType, TaskDataType} from '@/pages/DataStudio/model';
21+
import {Button} from 'antd';
2222
import React from 'react';
23+
import {Tab} from '@/pages/DataStudio/route';
2324

2425
export type CircleButtonProps = {
25-
icon: React.ReactNode;
26-
loading?: boolean;
27-
onClick?: () => void;
28-
title?: string;
29-
key?: string;
26+
icon: React.ReactNode;
27+
loading?: boolean;
28+
onClick?: () => void;
29+
title?: string;
30+
key?: string;
31+
};
32+
export type CircleBottomButtonProps = {
33+
icon: React.ReactNode;
34+
loading?: boolean;
35+
onClick?: (tabs: Tab[], key: string, data: TaskDataType | undefined,refresh:any) => Promise<void>;
36+
title?: string;
37+
key?: string;
3038
};
3139
export type CircleDataStudioButtonProps = {
32-
icon: React.ReactNode;
33-
loading?: boolean;
34-
onClick?: (panes: TabsItemType[], activeKey: string) => void;
35-
title?: string;
36-
key?: string;
40+
icon: React.ReactNode;
41+
loading?: boolean;
42+
onClick?: (panes: TabsItemType[], activeKey: string) => void;
43+
title?: string;
44+
key?: string;
45+
isShow?: boolean;
3746
};
3847

3948
export const CircleBtn: React.FC<CircleButtonProps> = (props) => {
40-
const { onClick, title, icon, loading } = props;
49+
const {onClick, title, icon, loading} = props;
4150

42-
return (
43-
<Button
44-
title={title}
45-
loading={loading}
46-
icon={icon}
47-
block
48-
type={'text'}
49-
shape={'circle'}
50-
onClick={onClick}
51-
/>
52-
);
51+
return (
52+
<Button
53+
title={title}
54+
loading={loading}
55+
icon={icon}
56+
block
57+
type={'text'}
58+
shape={'circle'}
59+
onClick={onClick}
60+
/>
61+
);
5362
};

dinky-web/src/pages/DataStudio/BottomContainer/TableData/index.tsx

Lines changed: 55 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -17,112 +17,79 @@
1717
*
1818
*/
1919

20-
import { SseData } from '@/models/Sse';
21-
import { getCurrentData } from '@/pages/DataStudio/function';
22-
import { StateType } from '@/pages/DataStudio/model';
23-
import { SSE_TOPIC } from '@/pages/DevOps/constants';
24-
import { getData, postAll } from '@/services/api';
25-
import { l } from '@/utils/intl';
26-
import { connect, useModel } from '@@/exports';
27-
import { Modal, Select, Tabs } from 'antd';
20+
import {SseData} from '@/models/Sse';
21+
import {TaskDataType} from '@/pages/DataStudio/model';
22+
import {SSE_TOPIC} from '@/pages/DevOps/constants';
23+
import {postAll} from '@/services/api';
24+
import {l} from '@/utils/intl';
25+
import {useModel} from '@@/exports';
26+
import {Modal, Select} from 'antd';
2827
import TextArea from 'antd/es/input/TextArea';
29-
import { Tab } from 'rc-tabs/lib/interface.d';
28+
import {Tab} from 'rc-tabs/lib/interface.d';
3029
import * as React from 'react';
31-
import { useEffect, useState } from 'react';
30+
import {useEffect, useState} from 'react';
3231

3332
export async function getPrintTables(statement: string) {
34-
return postAll('api/printTable/getPrintTables', { statement });
33+
return postAll('api/printTable/getPrintTables', {statement});
3534
}
3635

3736
/*--- Clear Console ---*/
38-
export function clearConsole() {
39-
return getData('api/process/clearConsole', {});
40-
}
4137
export type PrintTable = {
42-
tableName: string;
43-
fullTableName: string;
38+
tableName: string;
39+
fullTableName: string;
4440
};
4541

46-
const DataPage = (props: any) => {
47-
const { style, title } = props;
48-
const [consoleInfo, setConsoleInfo] = useState<string>('');
49-
const { subscribeTopic } = useModel('Sse', (model: any) => ({
50-
subscribeTopic: model.subscribeTopic
51-
}));
52-
const [tableName, setTableName] = useState<string>('');
42+
export const DataPage = (props: any) => {
43+
const {style, title} = props;
44+
const [consoleInfo, setConsoleInfo] = useState<string>('');
45+
const {subscribeTopic} = useModel('Sse', (model: any) => ({
46+
subscribeTopic: model.subscribeTopic
47+
}));
48+
const [tableName, setTableName] = useState<string>('');
5349

54-
useEffect(() => {
55-
if (title) {
56-
setTableName(title.tableName);
57-
const topic = `${SSE_TOPIC.PRINT_TABLE}/${title.fullTableName}`;
58-
return subscribeTopic([topic], (data: SseData) => {
59-
setConsoleInfo((preConsoleInfo) => preConsoleInfo + '\n' + data.data);
60-
});
61-
}
62-
}, []);
50+
useEffect(() => {
51+
if (title) {
52+
setTableName(title.tableName);
53+
const topic = `${SSE_TOPIC.PRINT_TABLE}/${title.fullTableName}`;
54+
return subscribeTopic([topic], (data: SseData) => {
55+
setConsoleInfo((preConsoleInfo) => preConsoleInfo + '\n' + data.data);
56+
});
57+
}
58+
}, []);
6359

64-
return <TextArea value={consoleInfo} style={{ width: style.width, height: style.height }} />;
60+
return <TextArea value={consoleInfo} style={{width: style.width, height: style.height}}/>;
6561
};
6662

67-
const TableData = (props: any) => {
68-
const { statement, height } = props;
69-
const [panes, setPanes] = useState<Tab[]>([]);
70-
71-
function onOk(title: PrintTable) {
72-
const activeKey = `${panes.length + 1}`;
73-
const newPanes = [...panes];
74-
newPanes.push({
75-
label: title.tableName,
76-
children: <DataPage title={title} style={{ width: '100%', height: height - 63 }} />,
77-
key: activeKey
78-
});
79-
setPanes(newPanes);
80-
}
63+
export const onAdd = async (tabs: Tab[], key: string, data: TaskDataType | undefined, refresh: any) => {
64+
const statement = data?.statement;
8165

82-
const addTab = async () => {
8366
if (!statement) return;
67+
const tabNames = tabs.map((tab) => tab.label);
8468
const result = await getPrintTables(statement);
85-
const tables: PrintTable[] = result.data;
69+
const tables: PrintTable[] = result.data.filter((table: PrintTable) => !tabNames.includes(table.tableName));
8670

8771
let selectTable: PrintTable;
8872
Modal.confirm({
89-
title: l('pages.datastudio.print.table.inputTableName'),
90-
content: (
91-
<Select
92-
defaultValue=''
93-
style={{ width: '90%' }}
94-
onChange={(e, t: any) => {
95-
selectTable = { tableName: t.label, fullTableName: t.value };
96-
}}
97-
options={tables.map((table) => ({ label: table.tableName, value: table.fullTableName }))}
98-
/>
99-
),
100-
onOk() {
101-
onOk(selectTable);
102-
},
103-
zIndex: 1000
73+
title: l('pages.datastudio.print.table.inputTableName'),
74+
content: (
75+
<Select
76+
defaultValue=''
77+
style={{width: '90%'}}
78+
onChange={(e, t: any) => {
79+
selectTable = {tableName: t.label, fullTableName: t.value};
80+
}}
81+
options={tables.map((table) => ({label: table.tableName, value: table.fullTableName}))}
82+
/>
83+
),
84+
onOk() {
85+
tabs.push({
86+
key: key + "/" + selectTable.tableName,
87+
label: selectTable.tableName,
88+
children: <DataPage title={selectTable} style={{width: '100%', height: '100%'}}/>
89+
});
90+
refresh()
91+
// onOk(selectTable);
92+
},
93+
zIndex: 1000
10494
});
105-
};
106-
107-
const onEdit = (
108-
targetKey: React.MouseEvent | React.KeyboardEvent | string,
109-
action: 'add' | 'remove'
110-
) => {
111-
switch (action) {
112-
case 'add':
113-
addTab();
114-
break;
115-
case 'remove':
116-
const newPanes = panes.filter((pane) => pane.key !== targetKey);
117-
setPanes(newPanes);
118-
break;
119-
}
120-
};
121-
122-
return <Tabs type='editable-card' onEdit={onEdit} items={panes} />;
123-
};
124-
125-
export default connect(({ Studio }: { Studio: StateType }) => ({
126-
height: Studio.bottomContainer.height,
127-
statement: getCurrentData(Studio.tabs.panes, Studio.tabs.activeKey)?.statement
128-
}))(TableData);
95+
}

0 commit comments

Comments
 (0)