WangHan
2024-09-12 d5855a4926926698b740bc6c7ba489de47adb68b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package tech.powerjob.common.model;
 
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.google.common.collect.Lists;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import tech.powerjob.common.enums.WorkflowNodeType;
 
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.Serializable;
import java.util.List;
 
/**
 * Points & edges for DAG, making it easier to describe or transfer.
 *
 * @author tjq
 * @since 2020/5/26
 */
@Data
@NoArgsConstructor
public class PEWorkflowDAG implements Serializable {
 
    /**
     * Nodes of DAG diagram.
     */
    private List<Node> nodes;
    /**
     * Edges of DAG diagram.
     */
    private List<Edge> edges;
 
    /**
     * Point.
     */
    @Data
    @Accessors(chain = true)
    @NoArgsConstructor
    public static class Node implements Serializable {
        /**
         * node id
         *
         * @since 20210128
         */
        private Long nodeId;
        /* Instance running param, which is not required by DAG. */
 
        /**
         * note type
         *
         * @see WorkflowNodeType
         * @since 20210316
         */
        private Integer nodeType;
        /**
         * job id or workflow id (if this Node type is a nested workflow)
         *
         * @see WorkflowNodeType#NESTED_WORKFLOW
         */
        private Long jobId;
        /**
         * node name
         */
        private String nodeName;
 
        @JsonSerialize(using = ToStringSerializer.class)
        private Long instanceId;
        /**
         * for decision node, it is JavaScript code
         */
        private String nodeParams;
 
        private Integer status;
        /**
         * for decision node, it only be can "true" or "false"
         */
        private String result;
        /**
         * instanceId will be null if disable .
         */
        private Boolean enable;
        /**
         * mark node which disable by control node.
         */
        private Boolean disableByControlNode;
 
        private Boolean skipWhenFailed;
 
        private String startTime;
 
        private String finishedTime;
 
        public Node(Long nodeId) {
            this.nodeId = nodeId;
            this.nodeType = WorkflowNodeType.JOB.getCode();
        }
 
        public Node(Long nodeId, Integer nodeType) {
            this.nodeId = nodeId;
            this.nodeType = nodeType;
        }
    }
 
    /**
     * Edge formed by two node ids.
     */
    @Data
    @NoArgsConstructor
    public static class Edge implements Serializable {
 
        private Long from;
 
        private Long to;
        /**
         * property,support for complex flow control
         * for decision node , it can be "true" or "false"
         */
        private String property;
 
        private Boolean enable;
 
        public Edge(long from, long to) {
            this.from = from;
            this.to = to;
        }
 
        public Edge(long from, long to, String property) {
            this.from = from;
            this.to = to;
            this.property = property;
        }
    }
 
    public PEWorkflowDAG(@Nonnull List<Node> nodes, @Nullable List<Edge> edges) {
        this.nodes = nodes;
        this.edges = edges == null ? Lists.newLinkedList() : edges;
    }
}