mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
优化portId,提高兼容性
This commit is contained in:
@@ -22,6 +22,8 @@ type IInnerExecNode interface {
|
|||||||
|
|
||||||
GetInPort(index int) IPort
|
GetInPort(index int) IPort
|
||||||
GetOutPort(index int) IPort
|
GetOutPort(index int) IPort
|
||||||
|
|
||||||
|
GetOutPortParamStartIndex() int
|
||||||
}
|
}
|
||||||
|
|
||||||
type IExecNode interface {
|
type IExecNode interface {
|
||||||
@@ -40,8 +42,10 @@ type innerExecNode struct {
|
|||||||
Package string
|
Package string
|
||||||
Description string
|
Description string
|
||||||
|
|
||||||
inPort []IPort
|
inPort []IPort // 下标即为portId
|
||||||
outPort []IPort
|
outPort []IPort // 下标即为portId
|
||||||
|
|
||||||
|
outPortParamStartIndex int // 输出参数的起始索引,用于排除执行出口
|
||||||
|
|
||||||
IExecNode
|
IExecNode
|
||||||
}
|
}
|
||||||
@@ -139,21 +143,27 @@ func (em *innerExecNode) SetOutPortById(id int, port IPort) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
em.outPort[id] = port
|
em.outPort[id] = port
|
||||||
|
|
||||||
|
// 分析执行的
|
||||||
|
em.outPortParamStartIndex = -1
|
||||||
|
for i := range em.outPort {
|
||||||
|
if em.outPort[i] == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 遇到非Exec结点,即为输出参数开始位置
|
||||||
|
if !em.outPort[i].IsPortExec() {
|
||||||
|
em.outPortParamStartIndex = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
func (em *innerExecNode) GetOutPortParamStartIndex() int {
|
||||||
//func (em *innerExecNode) AppendOutPort(port ...IPort) {
|
return em.outPortParamStartIndex
|
||||||
// if len(em.outPort) == 0 {
|
}
|
||||||
// em.outPortParamStartIndex = -1
|
|
||||||
// }
|
|
||||||
// for i := 0; i < len(port); i++ {
|
|
||||||
// if !port[i].IsPortExec() && em.outPortParamStartIndex < 0 {
|
|
||||||
// em.outPortParamStartIndex = len(em.outPort)
|
|
||||||
// }
|
|
||||||
// em.outPort = append(em.outPort, port[i])
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
func (em *innerExecNode) GetName() string {
|
func (em *innerExecNode) GetName() string {
|
||||||
return em.Name
|
return em.Name
|
||||||
@@ -166,6 +176,10 @@ func (em *innerExecNode) SetExec(exec IExecNode) {
|
|||||||
func (em *innerExecNode) CloneInOutPort() ([]IPort, []IPort) {
|
func (em *innerExecNode) CloneInOutPort() ([]IPort, []IPort) {
|
||||||
inPorts := make([]IPort, 0, 2)
|
inPorts := make([]IPort, 0, 2)
|
||||||
for _, port := range em.inPort {
|
for _, port := range em.inPort {
|
||||||
|
if port == nil {
|
||||||
|
inPorts = append(inPorts, nil)
|
||||||
|
}
|
||||||
|
|
||||||
if port.IsPortExec() {
|
if port.IsPortExec() {
|
||||||
// 执行入口, 不需要克隆,占位处理
|
// 执行入口, 不需要克隆,占位处理
|
||||||
inPorts = append(inPorts, nil)
|
inPorts = append(inPorts, nil)
|
||||||
@@ -177,6 +191,10 @@ func (em *innerExecNode) CloneInOutPort() ([]IPort, []IPort) {
|
|||||||
outPorts := make([]IPort, 0, 2)
|
outPorts := make([]IPort, 0, 2)
|
||||||
|
|
||||||
for _, port := range em.outPort {
|
for _, port := range em.outPort {
|
||||||
|
if port == nil {
|
||||||
|
outPorts = append(outPorts, nil)
|
||||||
|
}
|
||||||
|
|
||||||
if port.IsPortExec() {
|
if port.IsPortExec() {
|
||||||
outPorts = append(outPorts, nil)
|
outPorts = append(outPorts, nil)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 格式说明Entrance_ID
|
// 格式说明Entrance_ID
|
||||||
@@ -83,6 +84,15 @@ func (em *ExecPool) processJSONFile(filePath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i := range baseExecConfig {
|
for i := range baseExecConfig {
|
||||||
|
// 排序
|
||||||
|
sort.Slice(baseExecConfig[i].Inputs, func(left, right int) bool {
|
||||||
|
return baseExecConfig[i].Inputs[left].PortId < baseExecConfig[i].Inputs[right].PortId
|
||||||
|
})
|
||||||
|
|
||||||
|
sort.Slice(baseExecConfig[i].Outputs, func(left, right int) bool {
|
||||||
|
return baseExecConfig[i].Outputs[left].PortId < baseExecConfig[i].Outputs[right].PortId
|
||||||
|
})
|
||||||
|
|
||||||
exec, err := em.createExecFromJSON(baseExecConfig[i])
|
exec, err := em.createExecFromJSON(baseExecConfig[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ func (gp *GraphPool) findPreInPortNode(mapNodes map[string]*execNode, nodeExec *
|
|||||||
|
|
||||||
var preNode prePortNode
|
var preNode prePortNode
|
||||||
preNode.node = srcNode
|
preNode.node = srcNode
|
||||||
preNode.outPortIndex = edge.SourcePortId
|
preNode.outPortId = edge.SourcePortId
|
||||||
|
|
||||||
return &preNode
|
return &preNode
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
type prePortNode struct {
|
type prePortNode struct {
|
||||||
node *execNode // 上个结点
|
node *execNode // 上个结点
|
||||||
outPortIndex int // 对应上一个结点的OutPort索引
|
outPortId int // 对应上一个结点的OutPortId
|
||||||
}
|
}
|
||||||
|
|
||||||
type execNode struct {
|
type execNode struct {
|
||||||
@@ -142,9 +142,9 @@ func (en *execNode) doSetInPort(gr *Graph, index int, inPort IPort) error {
|
|||||||
|
|
||||||
// 判断上一个结点是否已经执行过
|
// 判断上一个结点是否已经执行过
|
||||||
if _, ok := gr.context[preNode.node.Id]; ok {
|
if _, ok := gr.context[preNode.node.Id]; ok {
|
||||||
outPort := gr.GetNodeOutPortValue(preNode.node.Id, preNode.outPortIndex)
|
outPort := gr.GetNodeOutPortValue(preNode.node.Id, preNode.outPortId)
|
||||||
if outPort == nil {
|
if outPort == nil {
|
||||||
return fmt.Errorf("pre node %s out port index %d not found", preNode.node.Id, preNode.outPortIndex)
|
return fmt.Errorf("pre node %s out port index %d not found", preNode.node.Id, preNode.outPortId)
|
||||||
}
|
}
|
||||||
|
|
||||||
inPort.SetValue(outPort)
|
inPort.SetValue(outPort)
|
||||||
@@ -175,12 +175,12 @@ func (en *execNode) Do(gr *Graph, outPortArgs ...any) error {
|
|||||||
|
|
||||||
// 处理InPort结点值
|
// 处理InPort结点值
|
||||||
var err error
|
var err error
|
||||||
for index := range inPorts {
|
for portId := range inPorts {
|
||||||
if en.execNode.IsInPortExec(index) {
|
if en.execNode.IsInPortExec(portId) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err = en.doSetInPort(gr, index, inPorts[index])
|
err = en.doSetInPort(gr, portId, inPorts[portId])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user