FEATURE: Added sub-workflow trigger

This commit is contained in:
frikky
2021-01-03 16:54:31 +01:00
parent a7e0b2706b
commit faae62e1ab
12 changed files with 495 additions and 66 deletions
+105
View File
@@ -788,3 +788,108 @@ func hookTest() {
log.Printf("Success! - %s", returnHook.Id)
}
}
//https://stackoverflow.com/questions/23935141/how-to-copy-docker-images-from-one-host-to-another-without-using-a-repository
func getDockerImage(resp http.ResponseWriter, request *http.Request) {
cors := handleCors(resp, request)
if cors {
return
}
// Just here to verify that the user is logged in
_, err := handleApiAuthentication(resp, request)
if err != nil {
log.Printf("Api authentication failed in validate swagger: %s", err)
resp.WriteHeader(401)
resp.Write([]byte(`{"success": false}`))
return
}
body, err := ioutil.ReadAll(request.Body)
if err != nil {
resp.WriteHeader(401)
resp.Write([]byte(`{"success": false, "reason": "Failed reading body"}`))
return
}
type requestCheck struct {
Name string `datastore:"name" json:"name" yaml:"name"`
}
//body = []byte(`swagger: "2.0"`)
//body = []byte(`swagger: '1.0'`)
//newbody := string(body)
//newbody = strings.TrimSpace(newbody)
//body = []byte(newbody)
//log.Println(string(body))
//tmpbody, err := yaml.YAMLToJSON(body)
//log.Println(err)
//log.Println(string(tmpbody))
// This has to be done in a weird way because Datastore doesn't
// support map[string]interface and similar (openapi3.Swagger)
var version requestCheck
err = json.Unmarshal(body, &version)
if err != nil {
resp.WriteHeader(422)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Failed JSON marshalling: %s"}`, err)))
return
}
log.Printf("Image to load: %s", version.Name)
//cli, err := client.NewEnvClient()
//if err != nil {
// log.Println("Unable to create docker client")
// return err
//}
dockercli, err := client.NewEnvClient()
if err != nil {
log.Printf("Unable to create docker client: %s", err)
resp.WriteHeader(422)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Failed JSON marshalling: %s"}`, err)))
return
}
ctx := context.Background()
images, err := dockercli.ImageList(ctx, types.ImageListOptions{
All: true,
})
img := types.ImageSummary{}
tagFound := ""
for _, image := range images {
for _, tag := range image.RepoTags {
log.Printf("Image: %s", tag)
if strings.ToLower(tag) == strings.ToLower(version.Name) {
img = image
tagFound = tag
break
}
}
}
if len(img.ID) == 0 {
resp.WriteHeader(401)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "message": "Couldn't find image %s"}`, version.Name)))
return
}
_ = tagFound
/*
log.Printf("IMg: %#v", img)
pullOptions := types.ImagePullOptions{}
log.Printf("[INFO] Pulling image %s", image)
reader, err := dockercli.ImagePull(ctx, tag, pullOptions)
if err != nil {
log.Printf("[ERROR] Failed getting image %s: %s", image, err)
}
io.Copy(os.Stdout, r)
*/
resp.WriteHeader(200)
resp.Write([]byte(fmt.Sprintf(`{"success": true, "message": "Downloading image %s"}`, version.Name)))
}
+3
View File
@@ -8214,6 +8214,9 @@ func initHandlers() {
r.HandleFunc("/api/v1/orgs/{orgId}", handleEditOrg).Methods("POST", "OPTIONS")
//r.HandleFunc("/api/v1/orgs/{orgId}", handleEditOrg).Methods("POST", "OPTIONS")
// Docker orborus specific
//r.HandleFunc("/api/v1/get_docker_image", getDockerImage).Methods("POST", "OPTIONS")
// Important for email, IDS etc. Create this by:
// PS: For cloud, this has to use cloud storage.
// https://developer.box.com/reference/get-files-id-content/
+21 -2
View File
@@ -1244,12 +1244,16 @@ func runWorkflowExecutionTransaction(ctx context.Context, attempts int64, workfl
if result.Action.Name == "User Input" && result.Action.AppName == "User Input" {
log.Printf("Found User Input node - prepare cloud?")
extraInputs += 1
} else if result.Action.Name == "run_subflow" && result.Action.AppName == "shuffle-subflow" {
log.Printf("[INFO] Found Shuffle Workflow node")
extraInputs += 1
}
}
//log.Printf("LENGTH: %d - %d", len(workflowExecution.Results), len(workflowExecution.Workflow.Actions))
if len(workflowExecution.Results) == len(workflowExecution.Workflow.Actions)+extraInputs {
log.Printf("\nIN HERE WITH RESULTS %d vs %d\n", len(workflowExecution.Results), len(workflowExecution.Workflow.Actions)+extraInputs)
finished := true
lastResult := ""
@@ -2065,6 +2069,8 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
} else if schedule.Id == "" {
trigger.Status = "stopped"
}
} else if trigger.TriggerType == "SUBFLOW" {
//log.Printf("Found subflow: %#v", trigger.Parameters)
} else if trigger.TriggerType == "WEBHOOK" && trigger.Status != "uninitialized" {
hook, err := getHook(ctx, trigger.ID)
if err != nil {
@@ -2718,7 +2724,7 @@ func handleExecution(id string, workflow Workflow, request *http.Request) (Workf
var execution ExecutionRequest
err = json.Unmarshal(body, &execution)
if err != nil {
log.Printf("Failed execution POST unmarshaling - continuing anyway: %s", err)
log.Printf("[WARNING] Failed execution POST unmarshaling - continuing anyway: %s", err)
//return WorkflowExecution{}, "", err
}
@@ -4689,9 +4695,10 @@ func getWorkflowApps(resp http.ResponseWriter, request *http.Request) {
//log.Printf("Length: %d", len(workflowapps))
// FIXME - this is really garbage, but is here to protect again null values etc.
skipApps := []string{"Shuffle Subflow"}
newapps := []WorkflowApp{}
baseApps := []WorkflowApp{}
for _, workflowapp := range workflowapps {
if !workflowapp.Activated && workflowapp.Generated {
continue
@@ -4701,6 +4708,18 @@ func getWorkflowApps(resp http.ResponseWriter, request *http.Request) {
continue
}
continueOuter := false
for _, skip := range skipApps {
if workflowapp.Name == skip {
continueOuter = true
break
}
}
if continueOuter {
continue
}
//workflowapp.Environment = "cloud"
newactions := []WorkflowAppAction{}
for _, action := range workflowapp.Actions {