From af4c8dedc2c278c97063b030be2f4919dcd6797f Mon Sep 17 00:00:00 2001 From: Michel Vocks Date: Wed, 4 Jul 2018 11:18:03 +0200 Subject: [PATCH] Fixed wrong pointer copy in backend. --- handlers/pipeline.go | 24 +++++++++++++++++------- pipeline/pipeline.go | 17 ++++++++++++----- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/handlers/pipeline.go b/handlers/pipeline.go index b094853f..cd29a0e8 100644 --- a/handlers/pipeline.go +++ b/handlers/pipeline.go @@ -121,12 +121,17 @@ func PipelineGet(c echo.Context) error { } // Look up pipeline for the given id + var foundPipeline gaia.Pipeline for pipeline := range pipeline.GlobalActivePipelines.Iter() { if pipeline.ID == pipelineID { - return c.JSON(http.StatusOK, pipeline) + foundPipeline = pipeline } } + if foundPipeline.Name != "" { + return c.JSON(http.StatusOK, foundPipeline) + } + // Pipeline not found return c.String(http.StatusNotFound, errPipelineNotFound.Error()) } @@ -143,14 +148,19 @@ func PipelineStart(c echo.Context) error { } // Look up pipeline for the given id + var foundPipeline gaia.Pipeline for pipeline := range pipeline.GlobalActivePipelines.Iter() { if pipeline.ID == pipelineID { - pipelineRun, err := schedulerService.SchedulePipeline(&pipeline) - if err != nil { - return c.String(http.StatusBadRequest, err.Error()) - } else if pipelineRun != nil { - return c.JSON(http.StatusCreated, pipelineRun) - } + foundPipeline = pipeline + } + } + + if foundPipeline.Name != "" { + pipelineRun, err := schedulerService.SchedulePipeline(&foundPipeline) + if err != nil { + return c.String(http.StatusBadRequest, err.Error()) + } else if pipelineRun != nil { + return c.JSON(http.StatusCreated, pipelineRun) } } diff --git a/pipeline/pipeline.go b/pipeline/pipeline.go index d22ba76d..895b330e 100644 --- a/pipeline/pipeline.go +++ b/pipeline/pipeline.go @@ -89,12 +89,18 @@ func (ap *ActivePipelines) Append(p gaia.Pipeline) { // GetByName looks up the pipeline by the given name. func (ap *ActivePipelines) GetByName(n string) *gaia.Pipeline { + var foundPipeline gaia.Pipeline for pipeline := range ap.Iter() { if pipeline.Name == n { - return &pipeline + foundPipeline = pipeline } } - return nil + + if foundPipeline.Name == "" { + return nil + } + + return &foundPipeline } // Replace takes the given pipeline and replaces it in the ActivePipelines @@ -112,7 +118,7 @@ func (ap *ActivePipelines) Replace(p gaia.Pipeline) bool { } // We got it? - if i != -1 { + if i == -1 { return false } @@ -140,13 +146,14 @@ func (ap *ActivePipelines) Iter() <-chan gaia.Pipeline { // Contains checks if the given pipeline name has been already appended // to the given ActivePipelines instance. func (ap *ActivePipelines) Contains(n string) bool { + var foundPipeline bool for pipeline := range ap.Iter() { if pipeline.Name == n { - return true + foundPipeline = true } } - return false + return foundPipeline } // appendTypeToName appends the type to the output binary name.