mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-05-06 20:11:27 +08:00
工作流
This commit is contained in:
62
pkg/flow_engine/manifest/manifest.go
Normal file
62
pkg/flow_engine/manifest/manifest.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package manifest
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Node struct {
|
||||
Type string `json:"type" yaml:"type"`
|
||||
Id string `json:"id" yaml:"id"`
|
||||
Properties map[string]interface{} `json:"properties" yaml:"properties"` //debugMode
|
||||
}
|
||||
|
||||
type Edge struct {
|
||||
SourceNodeId string `json:"sourceNodeId" yaml:"sourceNodeId"`
|
||||
TargetNodeId string `json:"targetNodeId" yaml:"targetNodeId"`
|
||||
Type string `json:"type" yaml:"type"` //success or fail
|
||||
Properties map[string]interface{} `json:"properties" yaml:"properties"` //debugMode
|
||||
}
|
||||
|
||||
type Manifest struct {
|
||||
FirstRuleNodeId string `json:"firstRuleNodeId" yaml:"firstRuleNodeId"`
|
||||
Nodes []Node `json:"nodes" yaml:"nodes"`
|
||||
Edges []Edge `json:"edges" yaml:"edges"`
|
||||
}
|
||||
|
||||
func New(data []byte) (*Manifest, error) {
|
||||
firstRuleNodeId := ""
|
||||
manifest := make(map[string]interface{})
|
||||
if err := json.Unmarshal(data, &manifest); err != nil {
|
||||
logrus.WithError(err).Errorf("invalid node chain manifest file")
|
||||
return nil, err
|
||||
}
|
||||
nodes := make([]Node, 0)
|
||||
for _, mn := range manifest["nodes"].([]interface{}) {
|
||||
node := mn.(map[string]interface{})
|
||||
if node["type"].(string) == "InputNode" {
|
||||
firstRuleNodeId = node["id"].(string)
|
||||
}
|
||||
nodes = append(nodes, Node{
|
||||
Id: node["id"].(string),
|
||||
Type: node["type"].(string),
|
||||
Properties: node["properties"].(map[string]interface{}),
|
||||
})
|
||||
}
|
||||
edges := make([]Edge, 0)
|
||||
for _, en := range manifest["edges"].([]interface{}) {
|
||||
edge := en.(map[string]interface{})
|
||||
edges = append(edges, Edge{
|
||||
Type: edge["type"].(string),
|
||||
Properties: edge["properties"].(map[string]interface{}),
|
||||
SourceNodeId: edge["sourceNodeId"].(string),
|
||||
TargetNodeId: edge["targetNodeId"].(string),
|
||||
})
|
||||
}
|
||||
m := &Manifest{
|
||||
FirstRuleNodeId: firstRuleNodeId,
|
||||
Nodes: nodes,
|
||||
Edges: edges,
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
127
pkg/flow_engine/manifest/manifest_sample.json
Normal file
127
pkg/flow_engine/manifest/manifest_sample.json
Normal file
@@ -0,0 +1,127 @@
|
||||
{
|
||||
"nodes": [
|
||||
{
|
||||
"id": "3b6b8df4-445f-4e70-9674-f7aa486b3d81",
|
||||
"type": "InputNode",
|
||||
"x": 280,
|
||||
"y": 280,
|
||||
"properties": {
|
||||
"icon": "/src/assets/icon_module/svg/start.svg",
|
||||
"debugMode": false
|
||||
},
|
||||
"zIndex": 1002,
|
||||
"text": {
|
||||
"x": 290,
|
||||
"y": 280,
|
||||
"value": "输入"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "45afb241-1977-4cbf-8af3-c12844d5666b",
|
||||
"type": "DelayNode",
|
||||
"x": 600,
|
||||
"y": 160,
|
||||
"properties": {
|
||||
"icon": "/src/assets/icon_module/svg/function.svg",
|
||||
"debugMode": false
|
||||
},
|
||||
"zIndex": 1004,
|
||||
"text": {
|
||||
"x": 610,
|
||||
"y": 160,
|
||||
"value": "延迟"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "95047b03-e966-4685-b625-3cea27415706",
|
||||
"type": "SwitchNode",
|
||||
"x": 600,
|
||||
"y": 460,
|
||||
"properties": {
|
||||
"icon": "/src/assets/icon_module/svg/switch.svg",
|
||||
"debugMode": false,
|
||||
"scripts": "return {\n msg: msg,\n metadata: metadata,\n msgType: msgType\n};"
|
||||
},
|
||||
"zIndex": 1006,
|
||||
"text": {
|
||||
"x": 610,
|
||||
"y": 460,
|
||||
"value": "分流"
|
||||
}
|
||||
}
|
||||
],
|
||||
"edges": [
|
||||
{
|
||||
"id": "fde7f2de-cc0f-467d-a614-4505f058dc2a",
|
||||
"type": "bezier-link",
|
||||
"sourceNodeId": "3b6b8df4-445f-4e70-9674-f7aa486b3d81",
|
||||
"targetNodeId": "45afb241-1977-4cbf-8af3-c12844d5666b",
|
||||
"startPoint": {
|
||||
"x": 340,
|
||||
"y": 280
|
||||
},
|
||||
"endPoint": {
|
||||
"x": 540,
|
||||
"y": 160
|
||||
},
|
||||
"properties": {
|
||||
"type": "Success"
|
||||
},
|
||||
"zIndex": 1007,
|
||||
"pointsList": [
|
||||
{
|
||||
"x": 340,
|
||||
"y": 280
|
||||
},
|
||||
{
|
||||
"x": 440,
|
||||
"y": 280
|
||||
},
|
||||
{
|
||||
"x": 440,
|
||||
"y": 160
|
||||
},
|
||||
{
|
||||
"x": 540,
|
||||
"y": 160
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "986878cc-a9be-42b5-afc0-6c0a169c4e4d",
|
||||
"type": "bezier-link",
|
||||
"sourceNodeId": "3b6b8df4-445f-4e70-9674-f7aa486b3d81",
|
||||
"targetNodeId": "95047b03-e966-4685-b625-3cea27415706",
|
||||
"startPoint": {
|
||||
"x": 340,
|
||||
"y": 280
|
||||
},
|
||||
"endPoint": {
|
||||
"x": 540,
|
||||
"y": 460
|
||||
},
|
||||
"properties": {
|
||||
"type": "Failure"
|
||||
},
|
||||
"zIndex": 1008,
|
||||
"pointsList": [
|
||||
{
|
||||
"x": 340,
|
||||
"y": 280
|
||||
},
|
||||
{
|
||||
"x": 440,
|
||||
"y": 280
|
||||
},
|
||||
{
|
||||
"x": 440,
|
||||
"y": 460
|
||||
},
|
||||
{
|
||||
"x": 540,
|
||||
"y": 460
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user