Added button for choosing to validate subflows

This commit is contained in:
frikky
2021-05-19 10:11:42 +02:00
parent 1edca6c5b6
commit 892fc768eb
2 changed files with 125 additions and 80 deletions
+81 -62
View File
@@ -1024,7 +1024,7 @@ func handleWorkflowQueue(resp http.ResponseWriter, request *http.Request) {
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Workflowexecution is aborted because of %s with result %s and status %s"}`, workflowExecution.LastNode, workflowExecution.Result, workflowExecution.Status))) resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Workflowexecution is aborted because of %s with result %s and status %s"}`, workflowExecution.LastNode, workflowExecution.Result, workflowExecution.Status)))
return return
} else { } else {
log.Printf("Continuing even though it's aborted.") log.Printf("[WARNING] Continuing workflow even though it's aborted (ExitOnError config)")
} }
} }
@@ -1936,6 +1936,7 @@ func handleExecution(id string, workflow shuffle.Workflow, request *http.Request
} }
} }
removeTriggers := []string{}
for triggerIndex, trigger := range workflowExecution.Workflow.Triggers { for triggerIndex, trigger := range workflowExecution.Workflow.Triggers {
//log.Printf("[INFO] ID: %s vs %s", trigger.ID, workflowExecution.Start) //log.Printf("[INFO] ID: %s vs %s", trigger.ID, workflowExecution.Start)
if trigger.ID == workflowExecution.Start { if trigger.ID == workflowExecution.Start {
@@ -1976,81 +1977,99 @@ func handleExecution(id string, workflow shuffle.Workflow, request *http.Request
}) })
} else { } else {
// Replaces trigger with the subflow // Replaces trigger with the subflow
if trigger.AppName == "Shuffle Workflow" { //if trigger.AppName == "Shuffle Workflow" {
replaceActions := false // replaceActions := false
workflowAction := "" // workflowAction := ""
for _, param := range trigger.Parameters { // for _, param := range trigger.Parameters {
if param.Name == "argument" && !strings.Contains(param.Value, ".#") { // if param.Name == "argument" && !strings.Contains(param.Value, ".#") {
replaceActions = true // replaceActions = true
} // }
if param.Name == "startnode" { // if param.Name == "startnode" {
workflowAction = param.Value // workflowAction = param.Value
} // }
} // }
if replaceActions { // if replaceActions {
replacementNodes, newBranches, lastnode := shuffle.GetReplacementNodes(ctx, workflowExecution, trigger) // replacementNodes, newBranches, lastnode := shuffle.GetReplacementNodes(ctx, workflowExecution, trigger, trigger.Label)
log.Printf("REPLACEMENTS: %d, %d", len(replacementNodes), len(newBranches)) // log.Printf("REPLACEMENTS: %d, %d", len(replacementNodes), len(newBranches))
if len(replacementNodes) > 0 { // if len(replacementNodes) > 0 {
//workflowExecution.Workflow.Actions = append(workflowExecution.Workflow.Actions, action) // for _, action := range replacementNodes {
// found := false
//lastnode = replacementNodes[0] // for subActionIndex, subaction := range newActions {
// Have to validate in case it's the same workflow and such // if subaction.ID == action.ID {
for _, action := range replacementNodes { // found = true
found := false // //newActions[subActionIndex].Name = action.Name
for subActionIndex, subaction := range newActions { // newActions[subActionIndex].Label = action.Label
if subaction.ID == action.ID { // break
found = true // }
//newActions[subActionIndex].Name = action.Name // }
newActions[subActionIndex].Label = action.Label
break
}
}
if !found { // if !found {
newActions = append(newActions, action) // action.SubAction = true
} // newActions = append(newActions, action)
// }
// Check if it's already set to have a value // // Check if it's already set to have a value
for resultIndex, result := range defaultResults { // for resultIndex, result := range defaultResults {
if result.Action.ID == action.ID { // if result.Action.ID == action.ID {
defaultResults = append(defaultResults[:resultIndex], defaultResults[resultIndex+1:]...) // defaultResults = append(defaultResults[:resultIndex], defaultResults[resultIndex+1:]...)
break // break
} // }
} // }
} // }
for _, branch := range newBranches { // for _, branch := range newBranches {
workflowExecution.Workflow.Branches = append(workflowExecution.Workflow.Branches, branch) // workflowExecution.Workflow.Branches = append(workflowExecution.Workflow.Branches, branch)
} // }
// Append branches: // // Append branches:
// parent -> new inner node (FIRST one) // // parent -> new inner node (FIRST one)
for branchIndex, branch := range workflowExecution.Workflow.Branches { // for branchIndex, branch := range workflowExecution.Workflow.Branches {
if branch.DestinationID == trigger.ID { // if branch.DestinationID == trigger.ID {
log.Printf("REPLACE DESTINATION WITH %s!!", workflowAction) // log.Printf("REPLACE DESTINATION WITH %s!!", workflowAction)
workflowExecution.Workflow.Branches[branchIndex].DestinationID = workflowAction // workflowExecution.Workflow.Branches[branchIndex].DestinationID = workflowAction
} // }
if branch.SourceID == trigger.ID { // if branch.SourceID == trigger.ID {
log.Printf("REPLACE SOURCE WITH LASTNODE %s!!", lastnode) // log.Printf("REPLACE SOURCE WITH LASTNODE %s!!", lastnode)
workflowExecution.Workflow.Branches[branchIndex].SourceID = lastnode // workflowExecution.Workflow.Branches[branchIndex].SourceID = lastnode
} // }
} // }
// Remove the trigger // // Remove the trigger
workflowExecution.Workflow.Triggers = append(workflowExecution.Workflow.Triggers[:triggerIndex], workflowExecution.Workflow.Triggers[triggerIndex+1:]...) // removeTriggers = append(removeTriggers, workflowExecution.Workflow.Triggers[triggerIndex].ID)
workflow.Triggers = append(workflow.Triggers[:triggerIndex], workflow.Triggers[triggerIndex+1:]...) // }
}
log.Printf("NEW ACTION LENGTH %d, RESULT: %d, Triggers: %d", len(newActions), len(defaultResults), len(workflowExecution.Workflow.Triggers)) // log.Printf("NEW ACTION LENGTH %d, RESULT: %d, Triggers: %d, BRANCHES: %d", len(newActions), len(defaultResults), len(workflowExecution.Workflow.Triggers), len(workflowExecution.Workflow.Branches))
} // }
} //}
_ = triggerIndex
} }
} }
} }
//newTriggers := []shuffle.Trigger{}
//for _, trigger := range workflowExecution.Workflow.Triggers {
// found := false
// for _, triggerId := range removeTriggers {
// if trigger.ID == triggerId {
// found = true
// break
// }
// }
// if found {
// log.Printf("[WARNING] Removed trigger %s during execution", trigger.ID)
// continue
// }
// newTriggers = append(newTriggers, trigger)
//}
//workflowExecution.Workflow.Triggers = newTriggers
_ = removeTriggers
if !startFound { if !startFound {
if len(workflowExecution.Start) == 0 && len(workflowExecution.Workflow.Start) > 0 { if len(workflowExecution.Start) == 0 && len(workflowExecution.Workflow.Start) > 0 {
workflowExecution.Start = workflow.Start workflowExecution.Start = workflow.Start
+43 -17
View File
@@ -554,9 +554,9 @@ const AngularWorkflow = (props) => {
if (executionData.execution_id === undefined || (responseJson.execution_id === executionData.execution_id && responseJson.results !== undefined && responseJson.results !== null)) { if (executionData.execution_id === undefined || (responseJson.execution_id === executionData.execution_id && responseJson.results !== undefined && responseJson.results !== null)) {
if (executionData.status !== responseJson.status || executionData.result !== responseJson.result || executionData.results.length !== responseJson.results.length) { if (executionData.status !== responseJson.status || executionData.result !== responseJson.result || executionData.results.length !== responseJson.results.length) {
console.log("Updated state with this data:") //console.log("Updated state with this data:")
console.log(responseJson) //console.log(responseJson)
console.log(executionData) //console.log(executionData)
setExecutionData(responseJson) setExecutionData(responseJson)
} else { } else {
console.log("NOT updating state.") console.log("NOT updating state.")
@@ -1731,6 +1731,7 @@ const AngularWorkflow = (props) => {
console.log(tmpapp) console.log(tmpapp)
console.log(curaction) console.log(curaction)
setSelectedApp(tmpapp) setSelectedApp(tmpapp)
//setSelectedAction(JSON.parse(JSON.stringify(curaction)))
setSelectedAction(curaction) setSelectedAction(curaction)
//return //return
} else { } else {
@@ -1779,6 +1780,7 @@ const AngularWorkflow = (props) => {
curaction.selectedAuthentication = {} curaction.selectedAuthentication = {}
} }
//setSelectedAction(JSON.parse(JSON.stringify(curaction)))
setSelectedApp(curapp) setSelectedApp(curapp)
setSelectedAction(curaction) setSelectedAction(curaction)
@@ -3365,7 +3367,7 @@ const AngularWorkflow = (props) => {
if (data.name !== "User Input" && data.name !== "Shuffle Workflow") { if (data.name !== "User Input" && data.name !== "Shuffle Workflow") {
//workflow.branches.push(newbranch) //workflow.branches.push(newbranch)
//cy.add(edgeToBeAdded) cy.add(edgeToBeAdded)
} }
setWorkflow(workflow) setWorkflow(workflow)
@@ -3865,7 +3867,7 @@ const AngularWorkflow = (props) => {
} }
if (currentnode.data() === undefined) { if (currentnode.data() === undefined) {
console.log("Node doesn't have any data (getParents)! Probably a trigger.") //console.log("Node doesn't have any data (getParents)! Probably a trigger.")
handled.push(allkeys[key]) handled.push(allkeys[key])
results.push({"id": allkeys[key], "type": "TRIGGER"}) results.push({"id": allkeys[key], "type": "TRIGGER"})
} else { } else {
@@ -5037,7 +5039,7 @@ const AngularWorkflow = (props) => {
} }
console.log("ACTIONS: ", actionlist) //console.log("ACTIONS: ", actionlist)
setActionlist(actionlist) setActionlist(actionlist)
} }
@@ -5260,6 +5262,7 @@ const AngularWorkflow = (props) => {
workflow.triggers[selectedTriggerIndex].parameters[1] = {"name": "argument", "value": ""} workflow.triggers[selectedTriggerIndex].parameters[1] = {"name": "argument", "value": ""}
workflow.triggers[selectedTriggerIndex].parameters[2] = {"name": "user_apikey", "value": ""} workflow.triggers[selectedTriggerIndex].parameters[2] = {"name": "user_apikey", "value": ""}
workflow.triggers[selectedTriggerIndex].parameters[3] = {"name": "startnode", "value": ""} workflow.triggers[selectedTriggerIndex].parameters[3] = {"name": "startnode", "value": ""}
workflow.triggers[selectedTriggerIndex].parameters[4] = {"name": "check_result", "value": "true"}
console.log("SETTINGS: ", userSettings) console.log("SETTINGS: ", userSettings)
if (userSettings !== undefined && userSettings !== null && userSettings.apikey !== null && userSettings.apikey !== undefined && userSettings.apikey.length > 0) { if (userSettings !== undefined && userSettings !== null && userSettings.apikey !== null && userSettings.apikey !== undefined && userSettings.apikey.length > 0) {
@@ -5295,6 +5298,27 @@ const AngularWorkflow = (props) => {
placeholder={selectedTrigger.label} placeholder={selectedTrigger.label}
onChange={selectedTriggerChange} onChange={selectedTriggerChange}
/> />
<FormControlLabel
control={
<Checkbox
checked={workflow.triggers[selectedTriggerIndex].parameters[4] !== undefined && workflow.triggers[selectedTriggerIndex].parameters[4].value === "true"}
onChange={() => {
const newvalue = workflow.triggers[selectedTriggerIndex].parameters[4] === undefined || workflow.triggers[selectedTriggerIndex].parameters[4].value === "false" ? "true" : "false"
workflow.triggers[selectedTriggerIndex].parameters[4] = {
"name": "check_result",
"value": newvalue,
}
setWorkflow(workflow)
setUpdate(Math.random())
}}
color="primary"
value="Wait for results"
/>
}
style={{marginTop: 10}}
label={<div style={{color: "white"}}>Wait for results</div>}
/>
<Divider style={{marginTop: "20px", height: "1px", width: "100%", backgroundColor: "rgb(91, 96, 100)"}}/> <Divider style={{marginTop: "20px", height: "1px", width: "100%", backgroundColor: "rgb(91, 96, 100)"}}/>
<div style={{flex: "6", marginTop: "20px"}}> <div style={{flex: "6", marginTop: "20px"}}>
<div> <div>
@@ -5384,7 +5408,7 @@ const AngularWorkflow = (props) => {
fullWidth fullWidth
onChange={(e) => { onChange={(e) => {
setSubworkflowStartnode(e.target.value) setSubworkflowStartnode(e.target.value)
console.log("WF: ", workflow) //console.log("WF: ", workflow)
const branchId = uuid.v4() const branchId = uuid.v4()
const newbranch = { const newbranch = {
@@ -5418,15 +5442,17 @@ const AngularWorkflow = (props) => {
} }
} }
const cybranch = { if (workflow.id == subworkflow.id) {
group: "edges", const cybranch = {
source: newbranch.source_id, group: "edges",
target: newbranch.destination_id, source: newbranch.source_id,
id: branchId, target: newbranch.destination_id,
data: newbranch, id: branchId,
} data: newbranch,
}
cy.add(cybranch) cy.add(cybranch)
}
try { try {
workflow.triggers[selectedTriggerIndex].parameters[3].value = e.target.value.id workflow.triggers[selectedTriggerIndex].parameters[3].value = e.target.value.id
@@ -7017,7 +7043,7 @@ const AngularWorkflow = (props) => {
{executionData.status !== undefined && executionData.status.length > 0 ? {executionData.status !== undefined && executionData.status.length > 0 ?
<div style={{display: "flex"}}> <div style={{display: "flex"}}>
<Typography variant="body1"> <Typography variant="body1">
<b>Status &nbsp;</b> <b>Status &nbsp;&nbsp;</b>
</Typography> </Typography>
<Typography variant="body1" color="textSecondary"> <Typography variant="body1" color="textSecondary">
{executionData.status} {executionData.status}
@@ -7144,7 +7170,7 @@ const AngularWorkflow = (props) => {
} }
return ( return (
<div key={index} style={{marginBottom: 40,}} onMouseOver={() => { <div key={index} style={{marginBottom: 40, border: data.action.sub_action === true ? "1px solid rgba(255,255,255,0.3)" : null, borderRadius: theme.palette.borderRadius,}} onMouseOver={() => {
var currentnode = cy.getElementById(data.action.id) var currentnode = cy.getElementById(data.action.id)
if (currentnode.length !== 0) { if (currentnode.length !== 0) {
currentnode.addClass('shuffle-hover-highlight') currentnode.addClass('shuffle-hover-highlight')