-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Modify, Delete Pipeline feature (#30) #52
Conversation
Codecov Report
@@ Coverage Diff @@
## master #52 +/- ##
==========================================
+ Coverage 52.5% 53.59% +1.09%
==========================================
Files 14 14
Lines 1118 1196 +78
==========================================
+ Hits 587 641 +54
- Misses 472 491 +19
- Partials 59 64 +5
Continue to review full report at Codecov.
|
Yes, I think that's enough for now. I was also thinking about changing the source git repository but then you also have to update credentials etc. So for now renaming should be fine! 🤗 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had some nits about the Go part of this PR. :)
handlers/pipeline.go
Outdated
} | ||
|
||
// Look up pipeline for the given id | ||
var foundPipeline *gaia.Pipeline |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for this to be a reference since you are passing in a copy anyways. Let's keep this on the stack with removing the pointer and the address passing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to a reference type as per @michelvocks suggestion.
You can make foundPipeline a pointer. Then you can check here: if foundPipeline == nil
Thoughts @Skarlso ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can check if it is initialized by comparing it to an empty struct of the same type. Rather than a pointer which might be stored on the heap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it doesn't matter much but avoids a nil pointer expedition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bidhan-a Sorry. My mistake here. You implementation was actually right. 😅
handlers/pipeline.go
Outdated
for pipeline := range pipeline.GlobalActivePipelines.Iter() { | ||
if pipeline.ID == pipelineID { | ||
foundPipeline = &pipeline | ||
deletedPipelineIndex = index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add break here once the pipeline you are looking for is found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Skarlso I tried adding break inside Iter()
but after doing so the process just freezes. I assume this is why break
isn't used here either? https://github.com/gaia-pipeline/gaia/blob/master/pipeline/pipeline.go#L102
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh beasue iter is a channel. Never mind then. Carry on :-).
handlers/pipeline.go
Outdated
// PipelineDelete accepts a pipeline id and deletes it from the | ||
// store. It also removes the binary inside the pipeline folder. | ||
func PipelineDelete(c echo.Context) error { | ||
pipelineIDStr := c.Param("pipelineid") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for this variable to exist. c.Param
will return an empty string if the parameter is not found making Atoi fail gracefully. So this can be removed and inlined into Atoi.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought so too initially but after seeing this pattern being used in other handler functions, I decided to stick with it. 😄
handlers/pipeline.go
Outdated
} | ||
|
||
if foundPipeline == nil { | ||
return c.String(http.StatusNotFound, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a errPipelineNotFound
error.
handlers/pipeline.go
Outdated
// Delete pipeline binary | ||
err = pipeline.DeleteBinary(*foundPipeline) | ||
if err != nil { | ||
return c.String(http.StatusInternalServerError, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of an internal server error I suggest creating an errPipelineDelete
error. Something like, oops sorry, I couldn't delete the binary, maybe permissions are incorrect? Please fix permissions and try again or delete it by hand.
. Thoughts?
handlers/pipeline.go
Outdated
// Delete pipeline from store | ||
err = storeService.PipelineDelete(pipelineID) | ||
if err != nil { | ||
return c.String(http.StatusNotFound, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be a StatusNotFound
not? Rather an internal error since it's a db operation.
Hey guys @michelvocks @Skarlso So I've added the implementation for renaming pipelines. Both renaming & deletion seem to be working properly. Please feel free to critique the code and let me know if I should add/remove anything. If all seems to be okay, I'll start writing test cases for the methods which I've added. Thanks! |
handlers/pipeline.go
Outdated
if err != nil { | ||
return c.String(http.StatusInternalServerError, errPipelineRename.Error()) | ||
} | ||
|
||
// Update pipeline in store | ||
err = storeService.PipelinePut(&p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to update the name in foundPipeline
and store this object instead of p
which we got from the client. For example, a hacker could potentially change something else than the name in the struct and that will be saved too.
handlers/pipeline.go
Outdated
} | ||
|
||
// Update active pipelines | ||
pipeline.GlobalActivePipelines.ReplaceByName(foundPipeline.Name, p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. I think we should stick to the old object 😃
Looks really good now. Good job @bidhan-a 🤗 ❤️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! :-)
Thanks @michelvocks and @Skarlso . Will let you know once tests are added. 😃 |
Hey @michelvocks I've added test cases for all the newly added functions. Let me know if I've missed anything! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🤗 Thanks a lot @bidhan-a ❤️
Hey @michelvocks
I have started working on this.
I've added a new tab pane in the Settings page for managing pipelines. In the backend, I've also added a delete handler which basically does the following: (a) Remove binary, (b) Remove from store, and (c) Remove from the active pipelines list. Is this good enough?
Also, how should we handle the modify/rename thing? Would renaming the binary in the pipelines folder and updating the pipeline in the store & the active pipelines list suffice? Or did you have something else in mind?
Please let me know.
Thanks!