From c2cf104700bfb8b439922164b960cba7a294220f Mon Sep 17 00:00:00 2001 From: frikky Date: Thu, 24 Dec 2020 07:35:27 +0100 Subject: [PATCH] Feature: Added contains_any_of to conditions --- backend/app_sdk/app_base.py | 16 +++++++++ backend/go-app/walkoff.go | 14 ++++---- docker-compose.yml | 2 +- frontend/src/components/OrgHeader.js | 2 +- frontend/src/views/AngularWorkflow.jsx | 5 +++ functions/onprem/orborus/orborus.go | 2 +- functions/onprem/worker/worker.go | 45 +++++++++++++++++++++----- 7 files changed, 69 insertions(+), 17 deletions(-) diff --git a/backend/app_sdk/app_base.py b/backend/app_sdk/app_base.py index e226eefd..98f62feb 100644 --- a/backend/app_sdk/app_base.py +++ b/backend/app_sdk/app_base.py @@ -1127,6 +1127,22 @@ class AppBase: elif check.lower() == "contains": if destinationvalue.lower() in sourcevalue.lower(): return True + elif check.lower() == "contains_any_of": + newvalue = [destinationvalue.lower()] + if "," in destinationvalue: + newvalue = destinationvalue.split(",") + elif ", " in destinationvalue: + newvalue = destinationvalue.split(", ") + + for item in new_value: + if not item: + continue + + if item.trim() in sourcevalue: + print("[INFO] Found %s in %s" % (item, sourcevalue)) + return True + + return False elif check.lower() == "larger than": try: if sourcevalue.isdigit() and destinationvalue.isdigit(): diff --git a/backend/go-app/walkoff.go b/backend/go-app/walkoff.go index d2d99d56..85796a74 100644 --- a/backend/go-app/walkoff.go +++ b/backend/go-app/walkoff.go @@ -785,7 +785,7 @@ func handleGetStreamResults(resp http.ResponseWriter, request *http.Request) { ctx := context.Background() workflowExecution, err := getWorkflowExecution(ctx, actionResult.ExecutionId) if err != nil { - log.Printf("Failed getting execution (streamresult) %s: %s", actionResult.ExecutionId, err) + //log.Printf("Failed getting execution (streamresult) %s: %s", actionResult.ExecutionId, err) resp.WriteHeader(401) resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Bad authorization key or execution_id might not exist."}`))) return @@ -1004,7 +1004,7 @@ func runWorkflowExecutionTransaction(ctx context.Context, attempts int64, workfl } if actionResult.Status == "ABORTED" || actionResult.Status == "FAILURE" { - log.Printf("Actionresult is %s. Should set workflowExecution and exit all running functions", actionResult.Status) + log.Printf("[WARNING] Actionresult is %s. Should set workflowExecution and exit all running functions", actionResult.Status) newResults := []ActionResult{} childNodes := []string{} @@ -1016,7 +1016,7 @@ func runWorkflowExecutionTransaction(ctx context.Context, attempts int64, workfl // Finds ALL childnodes to set them to SKIPPED childNodes = findChildNodes(*workflowExecution, actionResult.Action.ID) // Remove duplicates - log.Printf("CHILD NODES: %d", len(childNodes)) + //log.Printf("CHILD NODES: %d", len(childNodes)) for _, nodeId := range childNodes { if nodeId == actionResult.Action.ID { continue @@ -1290,7 +1290,7 @@ func runWorkflowExecutionTransaction(ctx context.Context, attempts int64, workfl } if _, err = tx.Commit(); err != nil { - if attempts >= 5 { + if attempts >= 7 { log.Printf("[ERROR] QUITTING: tx.Commit %d: %v", attempts, err) tx.Rollback() workflowExecution.Status = "ABORTED" @@ -1301,7 +1301,9 @@ func runWorkflowExecutionTransaction(ctx context.Context, attempts int64, workfl return } - log.Printf("[WARNING] tx.Commit %d: %v", attempts, err) + if attempts > 3 { + log.Printf("[WARNING] tx.Commit %d: %v", attempts, err) + } attempts += 1 runWorkflowExecutionTransaction(ctx, attempts, workflowExecutionId, actionResult, resp) @@ -2604,7 +2606,7 @@ func handleExecution(id string, workflow Workflow, request *http.Request) (Workf } // This one doesn't really matter. - log.Printf("Running POST execution with data %s", body) + log.Printf("Running POST execution with body of length %d", len(string(body))) var execution ExecutionRequest err = json.Unmarshal(body, &execution) if err != nil { diff --git a/docker-compose.yml b/docker-compose.yml index 7a356dff..c575474a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3' services: frontend: #build: ./frontend - image: ghcr.io/frikky/shuffle-frontend:0.8.42 + image: ghcr.io/frikky/shuffle-frontend:0.8.43 container_name: shuffle-frontend hostname: shuffle-frontend ports: diff --git a/frontend/src/components/OrgHeader.js b/frontend/src/components/OrgHeader.js index 7f21cdce..da6cf847 100644 --- a/frontend/src/components/OrgHeader.js +++ b/frontend/src/components/OrgHeader.js @@ -130,7 +130,7 @@ const OrgHeader = (props) => { return (
- +
0 ? null : "1px solid #f85a3e", cursor: "pointer", backgroundColor: imageData !== undefined && imageData.length > 0 ? null : theme.palette.inputColor, maxWidth: 174, maxHeight: 174}} onClick={() => {upload.click()}}> upload = ref} onChange={editHeaderImage} /> {imageInfo} diff --git a/frontend/src/views/AngularWorkflow.jsx b/frontend/src/views/AngularWorkflow.jsx index e9f2f1ef..77451c91 100644 --- a/frontend/src/views/AngularWorkflow.jsx +++ b/frontend/src/views/AngularWorkflow.jsx @@ -4366,6 +4366,11 @@ const AngularWorkflow = (props) => { setConditionValue(conditionValue) setVariableAnchorEl(null) }} key={"contains"}>contains + { + conditionValue.value = "contains_any_of" + setConditionValue(conditionValue) + setVariableAnchorEl(null) + }} key={"contains_any_of"}>contains { conditionValue.value = "matches regex" setConditionValue(conditionValue) diff --git a/functions/onprem/orborus/orborus.go b/functions/onprem/orborus/orborus.go index 06a938ff..cf6a8b1a 100644 --- a/functions/onprem/orborus/orborus.go +++ b/functions/onprem/orborus/orborus.go @@ -106,7 +106,7 @@ func getThisContainerId() { // cgroup error. Hardcoding this. // https://github.com/moby/moby/issues/7015 - log.Printf("Checking if %s is in %s", ".scope", string(out)) + //log.Printf("Checking if %s is in %s", ".scope", string(out)) if strings.Contains(string(out), ".scope") { containerId = "shuffle-orborus" //docker-76c537e9a4b7c7233011f5d70e6b7f2d600b6413ac58a96519b8dca7a3f7117a.scope diff --git a/functions/onprem/worker/worker.go b/functions/onprem/worker/worker.go index 067cdbe4..d0267d14 100644 --- a/functions/onprem/worker/worker.go +++ b/functions/onprem/worker/worker.go @@ -6,7 +6,7 @@ import ( "encoding/json" "errors" "fmt" - //"io" + "io" "io/ioutil" "log" "net/http" @@ -37,7 +37,7 @@ func getThisContainerId() string { if err == nil { id = strings.TrimSpace(string(out)) - log.Printf("Checking if %s is in %s", ".scope", string(out)) + //log.Printf("Checking if %s is in %s", ".scope", string(out)) if strings.Contains(string(out), ".scope") { id = fallbackName } @@ -1370,7 +1370,12 @@ func handleExecution(client *http.Client, req *http.Request, workflowExecution W log.Printf("Skipping FULL_EXECUTION because size is larger than %d", maxSize) } - // Try original -> Go to lowercase + // Uses a few ways of getting / checking if an app is available + // 1. Try original + // 2. Go to lowercase + // 3. Add remote repo location + // 4. Actually download last repo + err = deployApp(dockercli, image, identifier, env) if err != nil { // Trying to replace with lowercase to deploy again. This seems to work with Dockerhub well. @@ -1389,13 +1394,37 @@ func handleExecution(client *http.Client, req *http.Request, workflowExecution W err = deployApp(dockercli, image, identifier, env) if err != nil { - - log.Printf("[ERROR] Failed deploying image THRICE. Aborting if the image doesn't exist") - if strings.Contains(err.Error(), "No such image") { - //log.Printf("[WARNING] Failed deploying %s from image %s: %s", identifier, image, err) - log.Printf("[ERROR] Image doesn't exist. Shutting down") + log.Printf("[WARNING] Failed deploying image THRICE. Attempting to download the latter as last resort.") + reader, err := dockercli.ImagePull(context.Background(), image, pullOptions) + if err != nil { + log.Printf("[ERROR] Failed getting %s. The couldn't be find locally, AND is missing.", image) shutdown(workflowExecution.ExecutionId, workflowExecution.Workflow.ID) } + + buildBuf := new(strings.Builder) + _, err = io.Copy(buildBuf, reader) + if err != nil { + log.Printf("[ERROR] Error in IO copy: %s", err) + shutdown(workflowExecution.ExecutionId, workflowExecution.Workflow.ID) + } else { + if strings.Contains(buildBuf.String(), "errorDetail") { + log.Printf("[ERROR] Docker build:\n%s\nERROR ABOVE: Trying to pull tags from: %s", buildBuf.String(), image) + shutdown(workflowExecution.ExecutionId, workflowExecution.Workflow.ID) + } + + log.Printf("[INFO] Successfully downloaded %s", image) + } + + err = deployApp(dockercli, image, identifier, env) + if err != nil { + + log.Printf("[ERROR] Failed deploying image for the FOURTH time. Aborting if the image doesn't exist") + if strings.Contains(err.Error(), "No such image") { + //log.Printf("[WARNING] Failed deploying %s from image %s: %s", identifier, image, err) + log.Printf("[ERROR] Image doesn't exist. Shutting down") + shutdown(workflowExecution.ExecutionId, workflowExecution.Workflow.ID) + } + } } } }