Skip to content

Commit

Permalink
Fixed wrong pointer copy in backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
michelvocks committed Jul 4, 2018
1 parent 8efacb3 commit af4c8de
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
24 changes: 17 additions & 7 deletions handlers/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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)
}
}

Expand Down
17 changes: 12 additions & 5 deletions pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -112,7 +118,7 @@ func (ap *ActivePipelines) Replace(p gaia.Pipeline) bool {
}

// We got it?
if i != -1 {
if i == -1 {
return false
}

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit af4c8de

Please sign in to comment.