Skip to content

Commit 39d6cba

Browse files
author
Mohammed Diaa
authored
Merge pull request #64 from trickest/fix/execute-edgecase
Fix execute command's config and duplicated versions
2 parents a1b6a13 + 09ff69b commit 39d6cba

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

cmd/execute/execute.go

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,7 @@ func prepareForExec(objectPath string) *types.WorkflowVersionDetailed {
12521252
if update {
12531253
uploadFilesIfNeeded(newPrimitiveNodes)
12541254
wfVersion = createNewVersion(updatedWfVersion)
1255+
return wfVersion
12551256
}
12561257
}
12571258
} else {
@@ -1359,6 +1360,7 @@ func prepareForExec(objectPath string) *types.WorkflowVersionDetailed {
13591360
return wfVersion
13601361
}
13611362

1363+
wfVersion = createNewVersion(wfVersion)
13621364
return wfVersion
13631365
}
13641366

@@ -1547,7 +1549,7 @@ func readConfigInputs(config *map[string]interface{}, wfVersion *types.WorkflowV
15471549
isSplitter := strings.HasPrefix(node.Name, "file-splitter") || strings.HasPrefix(node.Name, "split-to-string")
15481550
if node.Script == nil && !isSplitter {
15491551
oldParam, paramExists := node.Inputs[paramName]
1550-
paramExists = paramExists && oldParam.Value != nil
1552+
// paramExists = paramExists && oldParam.Value != nil
15511553
if !paramExists {
15521554
fmt.Println("Parameter " + paramName + " doesn't exist for node " + nodeName)
15531555
os.Exit(0)
@@ -1783,9 +1785,9 @@ func addPrimitiveNodeFromConfig(wfVersion *types.WorkflowVersionDetailed, newPri
17831785
connectionFound = true
17841786
primitiveNodeName := getNodeNameFromConnectionID(connection.Source.ID)
17851787
if strings.HasSuffix(connection.Destination.ID, node.Name+"/"+paramName) && newPNode.Name != primitiveNodeName {
1786-
delete(wfVersion.Data.PrimitiveNodes, newPNode.Name)
1788+
// delete(wfVersion.Data.PrimitiveNodes, newPNode.Name)
17871789
newPNode.Name = primitiveNodeName
1788-
wfVersion.Data.PrimitiveNodes[newPNode.Name] = &newPNode
1790+
wfVersion.Data.PrimitiveNodes[primitiveNodeName] = &newPNode
17891791
}
17901792
var primitiveNode *types.PrimitiveNode
17911793
primitiveNode, pNodeExists = wfVersion.Data.PrimitiveNodes[primitiveNodeName]
@@ -1841,9 +1843,28 @@ func addPrimitiveNodeFromConfig(wfVersion *types.WorkflowVersionDetailed, newPri
18411843
wfVersion.Name = nil
18421844
updateNeeded = true
18431845
}
1846+
wfVersion.Data.PrimitiveNodes[primitiveNodeName] = &newPNode
18441847
break
18451848
}
18461849
}
1850+
1851+
if !pNodeExists {
1852+
id := getAvailablePrimitiveNodeID(strings.ToLower(newPNode.Type), wfVersion.Data.Connections)
1853+
nodeID := newPNode.Type + "-input-" + fmt.Sprint(id)
1854+
nodeID = strings.ToLower(nodeID)
1855+
1856+
pNode := createNewPrimitiveNode(newPNode.Type, newPNode.Value, id)
1857+
1858+
wfVersion.Data.PrimitiveNodes[nodeID] = &pNode
1859+
1860+
connection := createPrimitiveNodeConnection(nodeID, node.Name, paramName)
1861+
wfVersion.Data.Connections = append(wfVersion.Data.Connections, connection)
1862+
1863+
wfVersion.Data.Nodes[node.Name].Inputs[paramName].Value = newPNode.Value
1864+
connectionFound = true
1865+
pNodeExists = true
1866+
}
1867+
18471868
if !connectionFound {
18481869
fmt.Println(node.Name + " is not connected to any input!")
18491870
os.Exit(0)
@@ -1854,6 +1875,41 @@ func addPrimitiveNodeFromConfig(wfVersion *types.WorkflowVersionDetailed, newPri
18541875
return updateNeeded
18551876
}
18561877

1878+
func createNewPrimitiveNode(nodeType string, value interface{}, id int) types.PrimitiveNode {
1879+
var node types.PrimitiveNode
1880+
1881+
node.Name = strings.ToLower(nodeType) + "-input-" + fmt.Sprint(id)
1882+
node.Value = value
1883+
node.Label = value.(string)
1884+
node.Type = nodeType
1885+
node.TypeName = nodeType
1886+
1887+
return node
1888+
}
1889+
1890+
func getAvailablePrimitiveNodeID(nodeType string, connections []types.Connection) int {
1891+
availableID := 1
1892+
for _, connection := range connections {
1893+
if strings.HasPrefix(connection.Source.ID, "output/"+nodeType+"-input-") {
1894+
nodeID := strings.Split(connection.Source.ID, "/")[1]
1895+
numericID, _ := strconv.Atoi(strings.Split(nodeID, "-")[2])
1896+
if numericID >= availableID {
1897+
availableID = numericID + 1
1898+
}
1899+
}
1900+
}
1901+
return availableID
1902+
}
1903+
1904+
func createPrimitiveNodeConnection(source, destinationNode, destinationInput string) types.Connection {
1905+
var c types.Connection
1906+
1907+
c.Source.ID = "output/" + source + "/output"
1908+
c.Destination.ID = "input/" + destinationNode + "/" + destinationInput
1909+
1910+
return c
1911+
}
1912+
18571913
func readConfigOutputs(config *map[string]interface{}) map[string]output.NodeInfo {
18581914
downloadNodes := make(map[string]output.NodeInfo)
18591915
if outputs, exists := (*config)["outputs"]; exists && outputs != nil {

0 commit comments

Comments
 (0)