Unverified Commit bb8b272d authored by gaoyan's avatar gaoyan Committed by GitHub

[Feature][Web]Add flink dag (#2337)

* fix k8s submit bug * formate code * add flink dag * formate code * formate code
parent 8ce42006
......@@ -43,6 +43,9 @@
"@ant-design/pro-layout": "^7.13.3",
"@ant-design/pro-table": "^3.6.9",
"@ant-design/use-emotion-css": "^1.0.4",
"@antv/x6": "^2.15.1",
"@antv/x6-plugin-selection": "^2.2.1",
"@antv/x6-react-shape": "^2.2.2",
"@monaco-editor/react": "^4.5.1",
"@umijs/route-utils": "^4.0.1",
"antd": "^5.6.1",
......
/*
*
* 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 StatusTag from '@/components/JobTags/StatusTag';
import { Jobs } from '@/types/DevOps/data';
import { Card, Col, Row, Tag, Typography } from 'antd';
const { Text } = Typography;
const DagNode = (props: any) => {
const { node } = props;
const vertices: Jobs.JobVertices = node?.getData();
return (
<Card
style={{ width: '250px' }}
bordered={false}
size={'small'}
type={'inner'}
hoverable={true}
title={vertices.name}
extra={<Text keyboard>{vertices.parallelism}</Text>}
>
<Row>
<Col span={15}>
<Text type='secondary'>BackPressure:</Text>
<Tag bordered={false} color='success'>
OK
</Tag>
</Col>
<Col span={8}>
<Text type='secondary'>Busy:97%</Text>
</Col>
</Row>
<Row>
<Col span={15}>
<Text type='secondary'>Status:</Text>
<StatusTag status={vertices.status} bordered={false} animation={false} />
</Col>
<Col span={8}>
<Text type='secondary'>Idle:50%</Text>
</Col>
</Row>
</Card>
);
};
export default DagNode;
/*
*
* 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 { DagreLayoutOptions } from '@antv/layout/lib/layout/types';
import { Platform } from '@antv/x6';
import { Options } from '@antv/x6/lib/graph/options';
import Connecting = Options.Connecting;
import Manual = Options.Manual;
export const edgeConfig = {
markup: [
{
tagName: 'path',
selector: 'wrap',
attrs: {
fill: 'none',
cursor: 'pointer',
stroke: 'transparent',
strokeLinecap: 'round'
}
},
{
tagName: 'path',
selector: 'line',
attrs: {
fill: 'none',
pointerEvents: 'none'
}
}
],
connector: { name: 'curveConnector' },
attrs: {
wrap: {
connection: true,
strokeWidth: 1,
strokeLinejoin: 'round'
},
line: {
connection: true,
stroke: '#A2B1C3',
strokeWidth: 1,
targetMarker: {
name: 'classic',
size: 6
}
},
text: {
fontSize: 12
},
rect: {
// fill: 'transparent',
}
}
};
export const portConfig = {
groups: {
in: {
position: 'left',
attrs: {
circle: {
r: 4,
magnet: true,
stroke: 'transparent',
strokeWidth: 1,
fill: 'transparent'
}
}
},
out: {
position: {
name: 'right',
args: {
dx: -32
}
},
attrs: {
circle: {
r: 4,
magnet: true,
stroke: 'transparent',
strokeWidth: 1,
fill: 'transparent'
}
}
}
}
};
export const graphConnectConfig: Partial<Connecting> = {
snap: true,
allowBlank: false,
allowLoop: false,
highlight: true,
sourceAnchor: {
name: 'left',
args: {
dx: Platform.IS_SAFARI ? 4 : 8
}
},
targetAnchor: {
name: 'right',
args: {
dx: Platform.IS_SAFARI ? 4 : -8
}
},
// Connection pile verification
validateConnection({ sourceMagnet, targetMagnet }) {
// Connections can only be created from output link stubs
if (!sourceMagnet || sourceMagnet.getAttribute('port-group') === 'in') {
return false;
}
// You can only connect to input link stubs
return !(!targetMagnet || targetMagnet.getAttribute('port-group') !== 'in');
}
};
export const graphConfig: Partial<Manual> = {
// The canvas can be moved using the mouse
panning: {
enabled: true,
eventTypes: ['leftMouseDown', 'mouseWheel']
},
// Moving nodes beyond the canvas is prohibited
translating: {
restrict: true
},
// Prohibit moving nodes
interacting: {
nodeMovable: false
},
// Control scaling via CTRL
mousewheel: {
enabled: true,
modifiers: 'ctrl',
factor: 1.1,
maxScale: 1.5,
minScale: 0.5
},
connecting: graphConnectConfig
};
export const layoutConfig: DagreLayoutOptions = {
type: 'dagre',
rankdir: 'LR',
align: 'UL',
ranksep: 120,
nodesep: 40,
controlPoints: true
};
/*
*
* 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 { Jobs } from '@/types/DevOps/data';
import { Graph, Path } from '@antv/x6';
export const buildEdge = (job: Jobs.Job) => {
const edges: any = [];
for (let node of job.plan.nodes) {
if (node.inputs) {
const sources = node.inputs;
for (let i = 0; i < sources.length; i++) {
const plan_node = sources[i];
edges.push({
attrs: {
line: {
strokeDasharray: '5',
stroke: '#3471F9',
style: {
animation: 'running-line 30s infinite linear'
}
},
label: {
text: plan_node.ship_strategy
}
},
label: plan_node.ship_strategy,
id: `${plan_node.id}-${i}`,
shape: 'data-processing-curve',
zIndex: -1,
source: {
cell: `${plan_node.id}`,
port: `${plan_node.id}-out`
},
target: {
cell: `${node.id}`,
port: `${node.id}-in`
},
data: node
});
}
}
}
return edges;
};
export const buildNode = (job: Jobs.Job) => {
const nodes: any = {};
for (let vertice of job.vertices) {
nodes[vertice.id] = {
id: vertice.id,
shape: 'data-processing-dag-node',
ports: [
{
id: `${vertice.id}-in`,
group: 'in'
},
{
id: `${vertice.id}-out`,
group: 'out'
}
],
data: vertice
};
}
return nodes;
};
export const buildData = (job: Jobs.Job) => {
const nodes = Object.values(buildNode(job));
return { nodes: nodes, edges: buildEdge(job) };
};
export const updateEdge = (job: Jobs.Job, graph?: Graph) => {
if (graph) {
const nodes = buildNode(job);
graph.getCells().forEach((node) => {
const data = node.getData();
if (nodes[data.id]) {
console.log(nodes[data.id]);
node.setData(nodes[data.id].data);
}
});
graph.getEdges().forEach((edge) => {
const node = edge.getSourceNode()?.getData();
if (node.status == 'RUNNING') {
edge.attr({ line: { stroke: '#3471F9' } });
edge.attr('line/strokeDasharray', 5);
edge.attr('line/strokeWidth', 2);
edge.attr('line/style/animation', 'running-line 30s infinite linear');
} else {
edge.attr('line/strokeDasharray', 0);
edge.attr('line/style/animation', '');
edge.attr('line/strokeWidth', 1);
if (node.status == 'FINISHED') {
edge.attr('line/stroke', '#52c41a');
} else if (node.status == 'CANCELED') {
edge.attr('line/stroke', '#ffe7ba');
} else if (node.status == 'FAILED') {
edge.attr('line/stroke', '#ff4d4f');
} else {
edge.attr('line/stroke', '#bfbfbf');
}
}
});
}
};
export const regConnect = (sourcePoint: any, targetPoint: any) => {
const hgap = Math.abs(targetPoint.x - sourcePoint.x);
const path = new Path();
path.appendSegment(Path.createSegment('M', sourcePoint.x - 4, sourcePoint.y));
path.appendSegment(Path.createSegment('L', sourcePoint.x + 12, sourcePoint.y));
// 水平三阶贝塞尔曲线
path.appendSegment(
Path.createSegment(
'C',
sourcePoint.x < targetPoint.x ? sourcePoint.x + hgap / 2 : sourcePoint.x - hgap / 2,
sourcePoint.y,
sourcePoint.x < targetPoint.x ? targetPoint.x - hgap / 2 : targetPoint.x + hgap / 2,
targetPoint.y,
targetPoint.x - 6,
targetPoint.y
)
);
path.appendSegment(Path.createSegment('L', targetPoint.x + 2, targetPoint.y));
return path.serialize();
};
/*
*
* 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.
*
*/
@keyframes running-line {
to {
stroke-dashoffset: -1000;
}
}
/*
*
* 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 DagNode from '@/components/FlinkDag/component/DagNode';
import { edgeConfig, graphConfig, layoutConfig, portConfig } from '@/components/FlinkDag/config';
import { buildData, regConnect, updateEdge } from '@/components/FlinkDag/functions';
import { Jobs } from '@/types/DevOps/data';
import { DagreLayout } from '@antv/layout';
import { Edge, Graph } from '@antv/x6';
import { register } from '@antv/x6-react-shape';
import { useEffect, useRef, useState } from 'react';
import './index.css';
const FlinkDag = (props: { jobDetail: Jobs.JobInfoDetail }) => {
const container = useRef(null);
const job = props.jobDetail.jobDataDto.job;
const [graph, setGraph] = useState<Graph>();
const [curentJob, setCurentJob] = useState<string>();
const initGraph = (flinkData: any) => {
register({
shape: 'data-processing-dag-node',
width: 212,
height: 48,
component: DagNode,
ports: portConfig
});
Edge.config(edgeConfig);
Graph.registerConnector('curveConnector', regConnect, true);
Graph.registerEdge('data-processing-curve', Edge, true);
const graph: Graph = new Graph({
// @ts-ignore
container: container.current,
...graphConfig
});
// Adaptive layout
const dagreLayout = new DagreLayout(layoutConfig);
const model = dagreLayout.layout(flinkData);
graph.fromJSON(model);
// Automatically zoom to fit
const zoomOptions = {
padding: {
left: 50,
right: 50,
bottom: 100
}
};
graph.zoomToFit(zoomOptions);
graph.centerContent();
return graph;
};
useEffect(() => {
const flinkData = buildData(job);
// Clean up old data
if (graph) {
graph.clearCells();
}
setGraph(initGraph(flinkData));
}, [curentJob]);
useEffect(() => {
updateEdge(job, graph);
if (curentJob != job.jid) {
setCurentJob(job.jid);
}
}, [job]);
return (
<div
style={{
height: '100%',
width: '100%'
}}
ref={container}
/>
);
};
export default FlinkDag;
/*
* 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 { JOB_STATUS } from '@/pages/DevOps/constants';
import {
CheckCircleOutlined,
ClockCircleOutlined,
CloseCircleOutlined,
MinusCircleOutlined,
QuestionCircleOutlined,
SyncOutlined
} from '@ant-design/icons';
import { Tag } from 'antd';
export interface StatusTagProps {
status: string;
animation?: boolean;
bordered?: boolean;
}
const StatusTag = (props: StatusTagProps) => {
const { status, animation = true, bordered = true } = props;
const buildParam = () => {
switch (status) {
case JOB_STATUS.RUNNING:
return {
icon: <SyncOutlined spin />,
color: 'success',
text: 'RUNNING'
};
case JOB_STATUS.FINISHED:
return {
icon: <CheckCircleOutlined />,
color: 'blue',
text: 'FINISHED'
};
case JOB_STATUS.CANCELED:
return {
icon: <MinusCircleOutlined />,
color: 'orange',
text: 'CANCELED'
};
case JOB_STATUS.INITIALIZING:
return {
icon: <ClockCircleOutlined />,
color: 'default',
text: 'INITIALIZING'
};
case JOB_STATUS.RESTARTING:
return {
icon: <ClockCircleOutlined />,
color: 'default',
text: 'RESTARTING'
};
case JOB_STATUS.CREATED:
return {
icon: <ClockCircleOutlined />,
color: 'default',
text: 'CREATED'
};
case JOB_STATUS.UNKNOWN:
return {
icon: <QuestionCircleOutlined />,
color: 'default',
text: 'UNKNOWN'
};
default:
return {
icon: <CloseCircleOutlined />,
color: 'error',
text: 'FAILED'
};
}
};
const param = buildParam();
return (
<Tag icon={animation ? param.icon : undefined} color={param.color} bordered={bordered}>
{param.text}
</Tag>
);
};
export default StatusTag;
......@@ -17,9 +17,11 @@
*
*/
import FlinkDag from '@/components/FlinkDag';
import { JobProps } from '@/pages/DevOps/JobDetail/data';
import FlinkTable from '@/pages/DevOps/JobDetail/JobOverview/components/FlinkTable';
import JobDesc from '@/pages/DevOps/JobDetail/JobOverview/components/JobDesc';
import { ProCard } from '@ant-design/pro-components';
const JobConfigTab = (props: JobProps) => {
const { jobDetail } = props;
......@@ -27,6 +29,15 @@ const JobConfigTab = (props: JobProps) => {
return (
<>
<JobDesc jobDetail={jobDetail} />
<ProCard
style={{
height: '40vh'
}}
>
<FlinkDag jobDetail={jobDetail} />
</ProCard>
<FlinkTable jobDetail={jobDetail} />
</>
);
......
......@@ -17,6 +17,7 @@
*
*/
import Lineage from '@/components/FlinkDag';
import { TagJobLifeCycle } from '@/pages/DevOps/function';
import CheckPoints from '@/pages/DevOps/JobDetail/CheckPointsTab';
import JobLogsTab from '@/pages/DevOps/JobDetail/JobLogs/JobLogsTab';
......@@ -71,7 +72,7 @@ const JobDetail = (props: any) => {
[OperatorEnum.JOB_VERSION]: <JobVersionTab jobDetail={jobInfoDetail} />,
[OperatorEnum.JOB_CHECKPOINTS]: <CheckPoints jobDetail={jobInfoDetail} />,
[OperatorEnum.JOB_METRICS]: <JobMetrics />,
[OperatorEnum.JOB_LINEAGE]: <CheckPoints jobDetail={jobInfoDetail} />,
[OperatorEnum.JOB_LINEAGE]: <Lineage jobDetail={jobInfoDetail} />,
[OperatorEnum.JOB_ALERT]: <CheckPoints jobDetail={jobInfoDetail} />,
[OperatorEnum.JOB_GRAPH]: <JobOperatorGraph jobDetail={jobInfoDetail} />
};
......
......@@ -174,7 +174,7 @@ export default () => {
setClusterConfigState((prevState) => ({
...prevState,
editOpen: true,
value: { ...item}
value: { ...item }
}));
};
......
......@@ -71,10 +71,7 @@ const FlinkK8s = (props: { type: string; value: any } & connect) => {
label: <TagAlignCenter>Default Pod Template</TagAlignCenter>,
children: (
<ProFormItem key='dpe' name={['config', 'kubernetesConfig', 'podTemplate']}>
<CodeEdit
{...CodeEditProps}
code={value.config?.kubernetesConfig?.podTemplate ?? ''}
/>
<CodeEdit {...CodeEditProps} code={value.config?.kubernetesConfig?.podTemplate ?? ''} />
</ProFormItem>
)
},
......@@ -83,10 +80,7 @@ const FlinkK8s = (props: { type: string; value: any } & connect) => {
label: <TagAlignCenter>JM Pod Template</TagAlignCenter>,
children: (
<ProFormItem key='jmdpe' name={['config', 'kubernetesConfig', 'jmPodTemplate']}>
<CodeEdit
{...CodeEditProps}
code={value.config?.kubernetesConfig?.jmPodTemplate ?? ''}
/>
<CodeEdit {...CodeEditProps} code={value.config?.kubernetesConfig?.jmPodTemplate ?? ''} />
</ProFormItem>
)
},
......@@ -95,10 +89,7 @@ const FlinkK8s = (props: { type: string; value: any } & connect) => {
label: <TagAlignCenter>TM Pod Template</TagAlignCenter>,
children: (
<ProFormItem key='tmdpe' name={['config', 'kubernetesConfig', 'tmPodTemplate']}>
<CodeEdit
{...CodeEditProps}
code={value.config?.kubernetesConfig?.tmPodTemplate ?? ''}
/>
<CodeEdit {...CodeEditProps} code={value.config?.kubernetesConfig?.tmPodTemplate ?? ''} />
</ProFormItem>
)
}
......
......@@ -71,6 +71,17 @@ declare namespace Jobs {
clusterName: string;
};
export type VetricsMetrics = {
'read-bytes': number;
'read-bytes-complete': boolean;
'write-bytes': number;
'write-bytes-complete': boolean;
'read-records': number;
'read-records-complete': boolean;
'write-records': number;
'write-records-complete': boolean;
};
export type JobVertices = {
id: string;
name: string;
......@@ -79,7 +90,7 @@ declare namespace Jobs {
status: string;
duration: number;
tasks: any;
metrics: any;
metrics: VetricsMetrics;
};
export type Job = {
......@@ -94,8 +105,8 @@ declare namespace Jobs {
now: number;
timestamps: any;
vertices: JobVertices[];
'status-counts': {};
plan: {};
'status-counts': any;
plan: any;
};
export type JobDataDtoItem = {
id: number;
......
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