Unverified Commit 89c35c9e authored by ZackYoung's avatar ZackYoung Committed by GitHub

optimize_table_data (#2674)

parent 9b4bd242
...@@ -247,7 +247,7 @@ public class SystemInit implements ApplicationRunner { ...@@ -247,7 +247,7 @@ public class SystemInit implements ApplicationRunner {
} }
try { try {
project = projectClient.getDinkyProject(); project = projectClient.getDinkyProject();
if (Asserts.isNull(project)) { if (project == null) {
project = projectClient.createDinkyProject(); project = projectClient.createDinkyProject();
} }
} catch (Exception e) { } catch (Exception e) {
......
...@@ -160,6 +160,7 @@ public class JobInstanceServiceImpl extends SuperServiceImpl<JobInstanceMapper, ...@@ -160,6 +160,7 @@ public class JobInstanceServiceImpl extends SuperServiceImpl<JobInstanceMapper,
jobInfoDetail.setClusterInstance(clusterInstance); jobInfoDetail.setClusterInstance(clusterInstance);
History history = historyService.getById(jobInstance.getHistoryId()); History history = historyService.getById(jobInstance.getHistoryId());
if (history != null) {
history.setConfigJson(history.getConfigJson()); history.setConfigJson(history.getConfigJson());
jobInfoDetail.setHistory(history); jobInfoDetail.setHistory(history);
if (Asserts.isNotNull(history.getClusterConfigurationId())) { if (Asserts.isNotNull(history.getClusterConfigurationId())) {
...@@ -167,6 +168,7 @@ public class JobInstanceServiceImpl extends SuperServiceImpl<JobInstanceMapper, ...@@ -167,6 +168,7 @@ public class JobInstanceServiceImpl extends SuperServiceImpl<JobInstanceMapper,
clusterConfigurationService.getClusterConfigById(history.getClusterConfigurationId()); clusterConfigurationService.getClusterConfigById(history.getClusterConfigurationId());
jobInfoDetail.setClusterConfiguration(ClusterConfigurationDTO.fromBean(clusterConfig)); jobInfoDetail.setClusterConfiguration(ClusterConfigurationDTO.fromBean(clusterConfig));
} }
}
JobDataDto jobDataDto = jobHistoryService.getJobHistoryDto(jobInstance.getId()); JobDataDto jobDataDto = jobHistoryService.getJobHistoryDto(jobInstance.getId());
jobInfoDetail.setJobDataDto(jobDataDto); jobInfoDetail.setJobDataDto(jobDataDto);
......
...@@ -39,6 +39,7 @@ public class RunTimeUtil { ...@@ -39,6 +39,7 @@ public class RunTimeUtil {
obj = null; obj = null;
System.gc(); System.gc();
} }
/** /**
* 处理命令,多行命令原样返回,单行命令拆分处理 * 处理命令,多行命令原样返回,单行命令拆分处理
* *
...@@ -47,14 +48,14 @@ public class RunTimeUtil { ...@@ -47,14 +48,14 @@ public class RunTimeUtil {
*/ */
public static String[] handleCmds(String... cmds) { public static String[] handleCmds(String... cmds) {
if (ArrayUtil.isEmpty(cmds)) { if (ArrayUtil.isEmpty(cmds)) {
throw new NullPointerException("Command is empty !"); return new String[] {};
} }
// 单条命令的情况 // 单条命令的情况
if (1 == cmds.length) { if (1 == cmds.length) {
final String cmd = cmds[0]; final String cmd = cmds[0];
if (StrUtil.isBlank(cmd)) { if (StrUtil.isBlank(cmd)) {
throw new NullPointerException("Command is blank !"); return new String[] {};
} }
cmds = cmdSplit(cmd); cmds = cmdSplit(cmd);
} }
......
...@@ -35,8 +35,11 @@ import org.springframework.stereotype.Component; ...@@ -35,8 +35,11 @@ import org.springframework.stereotype.Component;
import cn.hutool.core.lang.TypeReference; import cn.hutool.core.lang.TypeReference;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
/** 项目 */ /**
* 项目
*/
@Component @Component
public class ProjectClient { public class ProjectClient {
...@@ -55,8 +58,7 @@ public class ProjectClient { ...@@ -55,8 +58,7 @@ public class ProjectClient {
.getDolphinschedulerProjectName() .getDolphinschedulerProjectName()
.getValue()); .getValue());
map.put("description", "自动创建"); map.put("description", "自动创建");
HttpResponse httpResponse = HttpRequest.post(SystemConfiguration.getInstances()
String content = HttpRequest.post(SystemConfiguration.getInstances()
.getDolphinschedulerUrl() .getDolphinschedulerUrl()
.getValue() .getValue()
+ "/projects") + "/projects")
...@@ -67,8 +69,13 @@ public class ProjectClient { ...@@ -67,8 +69,13 @@ public class ProjectClient {
.getValue()) .getValue())
.form(map) .form(map)
.timeout(5000) .timeout(5000)
.execute() .execute();
.body(); if (httpResponse.getStatus() != 200) {
SystemConfiguration.getInstances().getDolphinschedulerEnable().setValue(false);
logger.error("DolphInScheduler connection failed, Reason: {}", httpResponse.getStatus());
return null;
}
String content = httpResponse.body();
return MyJSONUtil.verifyResult(MyJSONUtil.toBean(content, new TypeReference<Result<Project>>() {})); return MyJSONUtil.verifyResult(MyJSONUtil.toBean(content, new TypeReference<Result<Project>>() {}));
} }
...@@ -79,7 +86,7 @@ public class ProjectClient { ...@@ -79,7 +86,7 @@ public class ProjectClient {
*/ */
public Project getDinkyProject() { public Project getDinkyProject() {
String content = HttpRequest.get(SystemConfiguration.getInstances() HttpResponse httpResponse = HttpRequest.get(SystemConfiguration.getInstances()
.getDolphinschedulerUrl() .getDolphinschedulerUrl()
.getValue() .getValue()
+ "/projects") + "/projects")
...@@ -92,9 +99,14 @@ public class ProjectClient { ...@@ -92,9 +99,14 @@ public class ProjectClient {
.getDolphinschedulerProjectName() .getDolphinschedulerProjectName()
.getValue())) .getValue()))
.timeout(5000) .timeout(5000)
.execute() .execute();
.body();
if (httpResponse.getStatus() != 200) {
SystemConfiguration.getInstances().getDolphinschedulerEnable().setValue(false);
logger.error("DolphInScheduler connection failed, Reason: {}", httpResponse.getStatus());
return null;
}
String content = httpResponse.body();
try { try {
return MyJSONUtil.toPageBeanAndFindByName( return MyJSONUtil.toPageBeanAndFindByName(
content, content,
......
...@@ -17,9 +17,10 @@ ...@@ -17,9 +17,10 @@
* *
*/ */
import { TabsItemType } from '@/pages/DataStudio/model'; import {TabsItemType, TaskDataType} from '@/pages/DataStudio/model';
import { Button } from 'antd'; import {Button} from 'antd';
import React from 'react'; import React from 'react';
import {Tab} from '@/pages/DataStudio/route';
export type CircleButtonProps = { export type CircleButtonProps = {
icon: React.ReactNode; icon: React.ReactNode;
...@@ -28,16 +29,24 @@ export type CircleButtonProps = { ...@@ -28,16 +29,24 @@ export type CircleButtonProps = {
title?: string; title?: string;
key?: string; key?: string;
}; };
export type CircleBottomButtonProps = {
icon: React.ReactNode;
loading?: boolean;
onClick?: (tabs: Tab[], key: string, data: TaskDataType | undefined,refresh:any) => Promise<void>;
title?: string;
key?: string;
};
export type CircleDataStudioButtonProps = { export type CircleDataStudioButtonProps = {
icon: React.ReactNode; icon: React.ReactNode;
loading?: boolean; loading?: boolean;
onClick?: (panes: TabsItemType[], activeKey: string) => void; onClick?: (panes: TabsItemType[], activeKey: string) => void;
title?: string; title?: string;
key?: string; key?: string;
isShow?: boolean;
}; };
export const CircleBtn: React.FC<CircleButtonProps> = (props) => { export const CircleBtn: React.FC<CircleButtonProps> = (props) => {
const { onClick, title, icon, loading } = props; const {onClick, title, icon, loading} = props;
return ( return (
<Button <Button
......
...@@ -17,36 +17,32 @@ ...@@ -17,36 +17,32 @@
* *
*/ */
import { SseData } from '@/models/Sse'; import {SseData} from '@/models/Sse';
import { getCurrentData } from '@/pages/DataStudio/function'; import {TaskDataType} from '@/pages/DataStudio/model';
import { StateType } from '@/pages/DataStudio/model'; import {SSE_TOPIC} from '@/pages/DevOps/constants';
import { SSE_TOPIC } from '@/pages/DevOps/constants'; import {postAll} from '@/services/api';
import { getData, postAll } from '@/services/api'; import {l} from '@/utils/intl';
import { l } from '@/utils/intl'; import {useModel} from '@@/exports';
import { connect, useModel } from '@@/exports'; import {Modal, Select} from 'antd';
import { Modal, Select, Tabs } from 'antd';
import TextArea from 'antd/es/input/TextArea'; import TextArea from 'antd/es/input/TextArea';
import { Tab } from 'rc-tabs/lib/interface.d'; import {Tab} from 'rc-tabs/lib/interface.d';
import * as React from 'react'; import * as React from 'react';
import { useEffect, useState } from 'react'; import {useEffect, useState} from 'react';
export async function getPrintTables(statement: string) { export async function getPrintTables(statement: string) {
return postAll('api/printTable/getPrintTables', { statement }); return postAll('api/printTable/getPrintTables', {statement});
} }
/*--- Clear Console ---*/ /*--- Clear Console ---*/
export function clearConsole() {
return getData('api/process/clearConsole', {});
}
export type PrintTable = { export type PrintTable = {
tableName: string; tableName: string;
fullTableName: string; fullTableName: string;
}; };
const DataPage = (props: any) => { export const DataPage = (props: any) => {
const { style, title } = props; const {style, title} = props;
const [consoleInfo, setConsoleInfo] = useState<string>(''); const [consoleInfo, setConsoleInfo] = useState<string>('');
const { subscribeTopic } = useModel('Sse', (model: any) => ({ const {subscribeTopic} = useModel('Sse', (model: any) => ({
subscribeTopic: model.subscribeTopic subscribeTopic: model.subscribeTopic
})); }));
const [tableName, setTableName] = useState<string>(''); const [tableName, setTableName] = useState<string>('');
...@@ -61,28 +57,16 @@ const DataPage = (props: any) => { ...@@ -61,28 +57,16 @@ const DataPage = (props: any) => {
} }
}, []); }, []);
return <TextArea value={consoleInfo} style={{ width: style.width, height: style.height }} />; return <TextArea value={consoleInfo} style={{width: style.width, height: style.height}}/>;
}; };
const TableData = (props: any) => { export const onAdd = async (tabs: Tab[], key: string, data: TaskDataType | undefined, refresh: any) => {
const { statement, height } = props; const statement = data?.statement;
const [panes, setPanes] = useState<Tab[]>([]);
function onOk(title: PrintTable) {
const activeKey = `${panes.length + 1}`;
const newPanes = [...panes];
newPanes.push({
label: title.tableName,
children: <DataPage title={title} style={{ width: '100%', height: height - 63 }} />,
key: activeKey
});
setPanes(newPanes);
}
const addTab = async () => {
if (!statement) return; if (!statement) return;
const tabNames = tabs.map((tab) => tab.label);
const result = await getPrintTables(statement); const result = await getPrintTables(statement);
const tables: PrintTable[] = result.data; const tables: PrintTable[] = result.data.filter((table: PrintTable) => !tabNames.includes(table.tableName));
let selectTable: PrintTable; let selectTable: PrintTable;
Modal.confirm({ Modal.confirm({
...@@ -90,39 +74,22 @@ const TableData = (props: any) => { ...@@ -90,39 +74,22 @@ const TableData = (props: any) => {
content: ( content: (
<Select <Select
defaultValue='' defaultValue=''
style={{ width: '90%' }} style={{width: '90%'}}
onChange={(e, t: any) => { onChange={(e, t: any) => {
selectTable = { tableName: t.label, fullTableName: t.value }; selectTable = {tableName: t.label, fullTableName: t.value};
}} }}
options={tables.map((table) => ({ label: table.tableName, value: table.fullTableName }))} options={tables.map((table) => ({label: table.tableName, value: table.fullTableName}))}
/> />
), ),
onOk() { onOk() {
onOk(selectTable); tabs.push({
key: key + "/" + selectTable.tableName,
label: selectTable.tableName,
children: <DataPage title={selectTable} style={{width: '100%', height: '100%'}}/>
});
refresh()
// onOk(selectTable);
}, },
zIndex: 1000 zIndex: 1000
}); });
}; }
\ No newline at end of file
const onEdit = (
targetKey: React.MouseEvent | React.KeyboardEvent | string,
action: 'add' | 'remove'
) => {
switch (action) {
case 'add':
addTab();
break;
case 'remove':
const newPanes = panes.filter((pane) => pane.key !== targetKey);
setPanes(newPanes);
break;
}
};
return <Tabs type='editable-card' onEdit={onEdit} items={panes} />;
};
export default connect(({ Studio }: { Studio: StateType }) => ({
height: Studio.bottomContainer.height,
statement: getCurrentData(Studio.tabs.panes, Studio.tabs.activeKey)?.statement
}))(TableData);
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* *
*/ */
import { CircleBtn } from '@/components/CallBackButton/CircleBtn'; import {CircleBtn} from '@/components/CallBackButton/CircleBtn';
import Title from '@/components/Front/Title'; import Title from '@/components/Front/Title';
import ContentScroll from '@/components/Scroll/ContentScroll'; import ContentScroll from '@/components/Scroll/ContentScroll';
import MovableSidebar from '@/components/Sidebar/MovableSidebar'; import MovableSidebar from '@/components/Sidebar/MovableSidebar';
...@@ -28,25 +28,44 @@ import { ...@@ -28,25 +28,44 @@ import {
TabsPageType, TabsPageType,
VIEW VIEW
} from '@/pages/DataStudio/model'; } from '@/pages/DataStudio/model';
import { LeftBottomMoreTabs, LeftBottomSide } from '@/pages/DataStudio/route'; import {BottomBtnRoute, LeftBottomMoreTabs, LeftBottomSide, Tab} from '@/pages/DataStudio/route';
import { l } from '@/utils/intl'; import {l} from '@/utils/intl';
import { connect } from '@@/exports'; import {connect} from '@@/exports';
import { PlusOutlined } from '@ant-design/icons'; import {ConfigProvider, Space, Tabs} from 'antd';
import { ConfigProvider, Space, Tabs } from 'antd'; import React, {useEffect, useState} from 'react';
import React from 'react'; import {getCurrentData} from "@/pages/DataStudio/function";
import {BottomTabRoute} from "@/pages/DataStudio/TabRoute";
export type BottomContainerProps = { export type BottomContainerProps = {
size: number; size: number;
height: number | string; height: number | string;
}; };
const BottomContainer: React.FC<BottomContainerProps> = (props: any) => { const BottomContainer: React.FC<BottomContainerProps> = (props: any) => {
const { const {
dispatch, dispatch,
size, size,
bottomContainer, bottomContainer,
height, height,
tabs: { activeKey, panes } tabs: {activeKey, panes}
} = props; } = props;
const currentData = getCurrentData(panes, activeKey);
const taskId = currentData?.id ?? 0;
const [tabState, setTabState] = useState<Record<string, Tab[]>>(Object.keys(BottomTabRoute).map(x => ({[x]: []})).reduce((a, b) => ({...a, ...b}), {}));
const tabItems = (LeftBottomMoreTabs[bottomContainer.selectKey] ?? []).map((item: any) => {
return {
key: bottomContainer.selectKey + '/' + item.key,
label: (<span>{item.icon}{item.label}</span>)
};
})
useEffect(() => {
setTabState({...tabState, [bottomContainer.selectKey]: []});
},[taskId,bottomContainer.selectKey])
const refresh = () => {
const tabs = tabState?.[bottomContainer.selectKey] ?? [];
setTabState({...tabState, [bottomContainer.selectKey]: [...tabs]})
}
const width = document.documentElement.clientWidth - VIEW.sideWidth * 2; const width = document.documentElement.clientWidth - VIEW.sideWidth * 2;
/** /**
...@@ -110,7 +129,7 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => { ...@@ -110,7 +129,7 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => {
return Object.values( return Object.values(
Object.keys(LeftBottomMoreTabs).map((x) => Object.keys(LeftBottomMoreTabs).map((x) =>
LeftBottomMoreTabs[x].map((y) => { LeftBottomMoreTabs[x].map((y) => {
return { ...y, key: x + '/' + y.key }; return {...y, key: x + '/' + y.key};
}) })
) )
).flatMap((x) => x); ).flatMap((x) => x);
...@@ -142,24 +161,28 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => { ...@@ -142,24 +161,28 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => {
}; };
const renderTabPane = () => { const renderTabPane = () => {
// @ts-ignore const onChange = (activeKey: string) => {
const leftBottomMoreTab = LeftBottomMoreTabs[bottomContainer.selectKey]; updateSelectBottomSubKey(activeKey.split('/')[1]);
if (leftBottomMoreTab) { }
const items = leftBottomMoreTab.map((item: any) => { const onEdit = async (
return { targetKey: React.MouseEvent | React.KeyboardEvent | string,
key: bottomContainer.selectKey + '/' + item.key, action: 'add' | 'remove'
label: ( ) => {
<span> switch (action) {
{item.icon} case 'add':
{item.label} await BottomTabRoute[bottomContainer.selectKey].onAdd(tabState?.[bottomContainer.selectKey] ?? [], bottomContainer.selectKey, currentData, refresh);
</span> break;
) case 'remove':
const newPanes = tabState?.[bottomContainer.selectKey].filter(pane => pane.key !== targetKey);
setTabState({...tabState, [bottomContainer.selectKey]: newPanes});
break;
}
}; };
});
return ( return (
<>
<Tabs <Tabs
style={{ height: '32px', display: '-webkit-box' }} style={{height: '32px', display: '-webkit-box'}}
items={items} items={tabItems}
type='card' type='card'
onChange={(key: string) => { onChange={(key: string) => {
updateSelectBottomSubKey(key.split('/')[1]); updateSelectBottomSubKey(key.split('/')[1]);
...@@ -172,9 +195,24 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => { ...@@ -172,9 +195,24 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => {
size='small' size='small'
tabPosition='top' tabPosition='top'
/> />
); {BottomTabRoute[bottomContainer.selectKey] &&
<Tabs
style={{height: '32px', display: '-webkit-box'}}
items={tabState?.[bottomContainer.selectKey].map(x => ({key: x.key, label: x.label}))}
onEdit={onEdit}
activeKey={
bottomContainer.selectKey +
'/' +
bottomContainer.selectSubKey[bottomContainer.selectKey]
} }
return <></>; onChange={onChange}
type='editable-card'
size='small'
tabPosition='top'
/>
}
</>
);
}; };
const renderItems = () => { const renderItems = () => {
return [ return [
...@@ -204,9 +242,9 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => { ...@@ -204,9 +242,9 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => {
// } // }
return show; return show;
}).map((x) => { }).map((x) => {
return { ...x, key: x.key + '/' }; return {...x, key: x.key + '/'};
}), }),
...getSubTabs() ...getSubTabs(), ...tabState?.[bottomContainer.selectKey] ?? []
].map((item) => { ].map((item) => {
return { return {
...item, ...item,
...@@ -246,7 +284,7 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => { ...@@ -246,7 +284,7 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => {
position: 'fixed', position: 'fixed',
bottom: VIEW.footerHeight bottom: VIEW.footerHeight
}} }}
defaultSize={{ width: '100%', height: height }} defaultSize={{width: '100%', height: height}}
minHeight={VIEW.midMargin} minHeight={VIEW.midMargin}
maxHeight={size.contentHeight - 40} maxHeight={size.contentHeight - 40}
onResize={( onResize={(
...@@ -256,8 +294,14 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => { ...@@ -256,8 +294,14 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => {
offsetHeight: any; offsetHeight: any;
} }
) => resizeCallback(event, direction, elementRef)} ) => resizeCallback(event, direction, elementRef)}
btnGroup={[<CircleBtn key={'max'} icon={<PlusOutlined />} />]} btnGroup={BottomBtnRoute[bottomContainer.selectKey]?.map(x => <CircleBtn key={x.key} icon={x.icon}
enable={{ top: true }} onClick={async () => {
const tabs = tabState?.[bottomContainer.selectKey] ?? [];
await x.onClick?.(tabs, bottomContainer.selectKey, currentData, refresh);
refresh()
}}
/>)}
enable={{top: true}}
handlerMinimize={handleMinimize} handlerMinimize={handleMinimize}
maxWidth={width} maxWidth={width}
> >
...@@ -270,13 +314,13 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => { ...@@ -270,13 +314,13 @@ const BottomContainer: React.FC<BottomContainerProps> = (props: any) => {
: '') : '')
} }
items={renderItems()} items={renderItems()}
tabBarStyle={{ display: 'none' }} tabBarStyle={{display: 'none'}}
/> />
</MovableSidebar> </MovableSidebar>
); );
}; };
export default connect(({ Studio }: { Studio: StateType }) => ({ export default connect(({Studio}: { Studio: StateType }) => ({
bottomContainer: Studio.bottomContainer, bottomContainer: Studio.bottomContainer,
tabs: Studio.tabs tabs: Studio.tabs
}))(BottomContainer); }))(BottomContainer);
/*
*
* 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.
*
*/
import React from "react";
import {Tab} from "@/pages/DataStudio/route";
import {TaskDataType} from "@/pages/DataStudio/model";
import {LeftBottomKey} from "@/pages/DataStudio/data.d";
import {onAdd} from "@/pages/DataStudio/BottomContainer/TableData";
export type BottomTabProps = {
icon?: React.ReactNode;
onAdd: (tabs: Tab[], key: string, data: TaskDataType | undefined, operator: any) => Promise<void>;
onRemove?: (tabs: Tab[], key: string, data: TaskDataType | undefined, tabKey: string, refresh: any) => Promise<void>;
key: string;
};
export const BottomTabRoute: { [c: string]: BottomTabProps } = {
[LeftBottomKey.TABLE_DATA_KEY]:
{
key: 'add table data',
onAdd: async (tabs, key, data, operator) => {
await onAdd(tabs, key, data, operator);
}
}
}
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment