Browse Source

依赖编辑

Leo 1 năm trước cách đây
mục cha
commit
87c45ef2f3

+ 13 - 3
packages/yili-dag/src/Dag.tsx

@@ -269,6 +269,16 @@ export default class Dag extends React.Component<any, any> {
     this.setState({ scriptInputNodes: input_nodes });
     this.setState({ scriptInputNodes: input_nodes });
   };
   };
 
 
+  saveData = () => {
+    const text = this.props.context.current;
+    text.ready.then(() => {
+      const dagJson: any = text.model.toJSON();
+      this.props.saveGraph(
+        DagToData(this.state.dagGraph, this.state.dagId, dagJson.requirements)
+      );
+    });
+  };
+
   executeDagData = async (script_nodes: any, script_edges: any) => {
   executeDagData = async (script_nodes: any, script_edges: any) => {
     const dag_script = JSON.stringify({
     const dag_script = JSON.stringify({
       sub_nodes: script_nodes,
       sub_nodes: script_nodes,
@@ -280,7 +290,7 @@ export default class Dag extends React.Component<any, any> {
     };
     };
     // 执行时间长,先变更状态再处理
     // 执行时间长,先变更状态再处理
     this.formatNodeStatus(script_nodes);
     this.formatNodeStatus(script_nodes);
-    this.props.saveGraph(DagToData(this.state.dagGraph, this.state.dagId));
+    this.saveData();
     const { data } = await executeDag(params);
     const { data } = await executeDag(params);
     if (data.code === 200) {
     if (data.code === 200) {
       setTimeout(() => {
       setTimeout(() => {
@@ -295,7 +305,7 @@ export default class Dag extends React.Component<any, any> {
           item.setData({ ...data, status: 'undone' });
           item.setData({ ...data, status: 'undone' });
         }
         }
       });
       });
-      this.props.saveGraph(DagToData(this.state.dagGraph, this.state.dagId));
+      this.saveData();
     }
     }
   };
   };
 
 
@@ -811,7 +821,7 @@ export default class Dag extends React.Component<any, any> {
         }
         }
       }
       }
     }
     }
-    this.props.saveGraph(DagToData(this.state.dagGraph, this.state.dagId));
+    this.saveData();
   };
   };
 
 
   // 容器
   // 容器

+ 68 - 39
packages/yili-dag/src/ToolBar.tsx

@@ -15,7 +15,7 @@ import {
 } from '@ant-design/icons';
 } from '@ant-design/icons';
 import { DagToData } from './utils';
 import { DagToData } from './utils';
 // import MediateDataTable from './MediateDataTable';
 // import MediateDataTable from './MediateDataTable';
-import { uploadFile } from './request';
+import { uploadFile, postRequirements, getRequirementsStatus } from './request';
 
 
 const Item = Toolbar.Item; // eslint-disable-line
 const Item = Toolbar.Item; // eslint-disable-line
 const Group = Toolbar.Group; // eslint-disable-line
 const Group = Toolbar.Group; // eslint-disable-line
@@ -25,7 +25,8 @@ export default class ToolBar extends React.Component<any, any> {
     super(props);
     super(props);
     this.state = {
     this.state = {
       modalVisible: false,
       modalVisible: false,
-      packageData: ''
+      packageData: '',
+      status: ''
     };
     };
   }
   }
 
 
@@ -33,18 +34,33 @@ export default class ToolBar extends React.Component<any, any> {
     this.setState({ modalVisible: true });
     this.setState({ modalVisible: true });
   };
   };
 
 
-  submitEdit = () => {
-    const node = this.props.graph.getSelectedCells()[0];
-    node.data.packageData = this.state.packageData;
-    this.setState({ modalVisible: false });
+  submitEdit = async () => {
+    const { data } = await postRequirements({
+      requirements: this.state.packageData,
+      dag_uuid: this.props.dagId
+    });
+    if (data.code === 200) {
+      this.props.saveGraph(
+        DagToData(this.props.graph, this.props.dagId, this.state.packageData)
+      );
+      this.setState({ modalVisible: false });
+      message.success('添加成功');
+    } else {
+      message.success(data.msg);
+    }
   };
   };
 
 
   onClick = (name: string) => {
   onClick = (name: string) => {
-    // const zoomNumber = this.props.graph.zoom()
     switch (name) {
     switch (name) {
       case 'save':
       case 'save':
-        this.props.saveGraph(DagToData(this.props.graph, this.props.dagId));
-        message.success('保存成功!');
+        const text = this.props.context.current;
+        text.ready.then(() => {
+          const dagJson: any = text.model.toJSON();
+          this.props.saveGraph(
+            DagToData(this.props.graph, this.props.dagId, dagJson.requirements)
+          );
+          message.success('保存成功!');
+        });
         break;
         break;
       case 'zoomOut':
       case 'zoomOut':
         this.props.graph.zoom(-0.1, {
         this.props.graph.zoom(-0.1, {
@@ -60,26 +76,46 @@ export default class ToolBar extends React.Component<any, any> {
     }
     }
   };
   };
 
 
-  async uploadDagFile() {
+  uploadDagFile() {
     const text = this.props.context.current;
     const text = this.props.context.current;
     const filename = text.path.split('/').pop();
     const filename = text.path.split('/').pop();
-    const content = JSON.stringify(
-      DagToData(this.props.graph, this.props.dagId)
-    );
-    let blob = new Blob([content], { type: 'text/plain;charset=utf-8' });
-    let file = new File([blob], filename, {
-      lastModified: Date.now()
+    text.ready.then(async () => {
+      const dagJson: any = text.model.toJSON();
+      const content = JSON.stringify(
+        DagToData(this.props.graph, this.props.dagId, dagJson.requirements)
+      );
+      let blob = new Blob([content], { type: 'text/plain;charset=utf-8' });
+      let file = new File([blob], filename, {
+        lastModified: Date.now()
+      });
+      const dagfile = new FormData();
+      dagfile.append('file', file);
+      dagfile.append('project_id', 'test');
+      dagfile.append('file_type', 'dag');
+      const { data } = await uploadFile(dagfile);
+      if (data.code === 200) {
+        message.success('上传成功');
+      } else {
+        message.error(data.msg);
+      }
+    });
+  }
+
+  openRequirements() {
+    const text = this.props.context.current;
+    text.ready.then(async () => {
+      const dagJson: any = text.model.toJSON();
+      const { data } = await getRequirementsStatus(this.props.dagId);
+      if (data.code === 200) {
+        this.setState({
+          modalVisible: true,
+          packageData: dagJson.requirements,
+          status: data.data
+        });
+      } else {
+        message.success(data.msg);
+      }
     });
     });
-    const dagfile = new FormData();
-    dagfile.append('file', file);
-    dagfile.append('project_id', 'test');
-    dagfile.append('file_type', 'dag');
-    const { data } = await uploadFile(dagfile);
-    if (data.code === 200) {
-      message.success('上传成功');
-    } else {
-      message.error(data.msg);
-    }
   }
   }
 
 
   DropDown(toolType: string) {
   DropDown(toolType: string) {
@@ -113,19 +149,7 @@ export default class ToolBar extends React.Component<any, any> {
             <MenuItem
             <MenuItem
               name="packageEdit"
               name="packageEdit"
               onClick={() => {
               onClick={() => {
-                const selected = this.props.graph.getSelectedCells();
-                if (
-                  selected.length === 1 &&
-                  selected[0].data &&
-                  selected[0].data.type === 'script'
-                ) {
-                  this.setState({
-                    modalVisible: true,
-                    packageData: selected[0].data.packageData
-                  });
-                } else {
-                  message.warning('请选择单个脚本节点');
-                }
+                this.openRequirements();
               }}
               }}
             >
             >
               依赖编辑
               依赖编辑
@@ -188,6 +212,8 @@ export default class ToolBar extends React.Component<any, any> {
           }}
           }}
         >
         >
           <Form
           <Form
+            labelCol={{ span: 4 }}
+            wrapperCol={{ span: 18 }}
             initialValues={{
             initialValues={{
               packageData: this.state.packageData
               packageData: this.state.packageData
             }}
             }}
@@ -201,6 +227,9 @@ export default class ToolBar extends React.Component<any, any> {
                 }}
                 }}
               />
               />
             </Form.Item>
             </Form.Item>
+            <Form.Item label="状态" name="status">
+              <span>{this.state.status}</span>
+            </Form.Item>
           </Form>
           </Form>
         </Modal>
         </Modal>
       </div>
       </div>

+ 1 - 17
packages/yili-dag/src/index.ts

@@ -122,23 +122,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
             const dagJson = {
             const dagJson = {
               id: 'uuid1',
               id: 'uuid1',
               requirements: '',
               requirements: '',
-              user_name: 'xxx',
-              user_id: 1,
-              project_name: 'dfs',
-              project_id: 123,
-              nodes: [
-                {
-                  id: 'node-uuid',
-                  op: 'python/sql/spark/datasource',
-                  data: {
-                    input: ['input1', 'input2'],
-                    output: ['output1', 'o2'],
-                    itermidate_data: ['hdfs://host:port/uri'],
-                    script: ''
-                  },
-                  datasource_table: 'uri'
-                }
-              ],
+              nodes: [],
               edges: []
               edges: []
             };
             };
             const newWidget = await app.commands.execute(
             const newWidget = await app.commands.execute(

+ 13 - 0
packages/yili-dag/src/request.ts

@@ -120,3 +120,16 @@ export const getSqlDsTable = (table_name: string) =>
     url: `/jpt/datamanagement/table_content?table_name=${table_name}&page=${1}&size=${100}`,
     url: `/jpt/datamanagement/table_content?table_name=${table_name}&page=${1}&size=${100}`,
     method: 'get'
     method: 'get'
   });
   });
+
+export const postRequirements = (params: any) =>
+  request({
+    url: `/jpt/dag/install_requirements`,
+    method: 'post',
+    data: params
+  });
+
+export const getRequirementsStatus = (id: string) =>
+  request({
+    url: `/jpt/dag/requirements_status?dag_uuid=${id}`,
+    method: 'get'
+  });

+ 2 - 1
packages/yili-dag/src/utils.ts

@@ -1,10 +1,11 @@
 // 数据转化
 // 数据转化
-export const DagToData = (graph: any, dagId: any) => {
+export const DagToData = (graph: any, dagId: any, requirements: any) => {
   const dagData = graph.toJSON();
   const dagData = graph.toJSON();
   const { edges, nodes } = getEdgesAndNodes(graph);
   const { edges, nodes } = getEdgesAndNodes(graph);
   // const { script_nodes, script_edges } = getScriptEdgesAndNodes(graph);
   // const { script_nodes, script_edges } = getScriptEdgesAndNodes(graph);
   return {
   return {
     dag_id: dagId,
     dag_id: dagId,
+    requirements,
     user_name: 'XXX',
     user_name: 'XXX',
     user_id: 1,
     user_id: 1,
     nodes_task_name: 'dfs',
     nodes_task_name: 'dfs',

+ 1 - 0
untitled1.dag

@@ -0,0 +1 @@
+{"dag_id":"b4IOpUcybv9s7z3T2T7pX","requirements":"132131212313","user_name":"XXX","user_id":1,"nodes_task_name":"dfs","nodes_task_id":123,"itermidate_data":["hdfs://host:port/uri"],"nodes":[],"edges":[],"graph":{"cells":[]}}