Skip to content
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

Merged
merged 11 commits into from
Jul 25, 2018

Conversation

bidhan-a
Copy link
Contributor

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!

@codecov-io
Copy link

codecov-io commented Jul 22, 2018

Codecov Report

Merging #52 into master will increase coverage by 1.09%.
The diff coverage is 68.29%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
pipeline/pipeline.go 90.52% <100%> (+3.38%) ⬆️
handlers/handler.go 83.58% <100%> (+0.5%) ⬆️
store/pipeline.go 75.96% <30%> (-2.9%) ⬇️
handlers/pipeline.go 26.77% <57.77%> (+17.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 17b7873...d08125e. Read the comment docs.

@michelvocks
Copy link
Member

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?

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! 🤗

Copy link
Member

@Skarlso Skarlso left a 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. :)

}

// Look up pipeline for the given id
var foundPipeline *gaia.Pipeline
Copy link
Member

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.

Copy link
Contributor Author

@bidhan-a bidhan-a Jul 22, 2018

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 ?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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. 😅

for pipeline := range pipeline.GlobalActivePipelines.Iter() {
if pipeline.ID == pipelineID {
foundPipeline = &pipeline
deletedPipelineIndex = index
Copy link
Member

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.

Copy link
Contributor Author

@bidhan-a bidhan-a Jul 22, 2018

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

Copy link
Member

@Skarlso Skarlso Jul 22, 2018

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 :-).

// 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")
Copy link
Member

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.

Copy link
Contributor Author

@bidhan-a bidhan-a Jul 22, 2018

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. 😄

}

if foundPipeline == nil {
return c.String(http.StatusNotFound, err.Error())
Copy link
Member

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.

// Delete pipeline binary
err = pipeline.DeleteBinary(*foundPipeline)
if err != nil {
return c.String(http.StatusInternalServerError, err.Error())
Copy link
Member

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?

// Delete pipeline from store
err = storeService.PipelineDelete(pipelineID)
if err != nil {
return c.String(http.StatusNotFound, err.Error())
Copy link
Member

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.

@bidhan-a
Copy link
Contributor Author

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!

if err != nil {
return c.String(http.StatusInternalServerError, errPipelineRename.Error())
}

// Update pipeline in store
err = storeService.PipelinePut(&p)
Copy link
Member

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.

}

// Update active pipelines
pipeline.GlobalActivePipelines.ReplaceByName(foundPipeline.Name, p)
Copy link
Member

@michelvocks michelvocks Jul 23, 2018

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 😃

@michelvocks
Copy link
Member

Looks really good now. Good job @bidhan-a 🤗 ❤️
Let me know when you are ready with your tests.

Copy link
Member

@Skarlso Skarlso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! :-)

@bidhan-a
Copy link
Contributor Author

bidhan-a commented Jul 24, 2018

Thanks @michelvocks and @Skarlso . Will let you know once tests are added. 😃

@bidhan-a
Copy link
Contributor Author

Hey @michelvocks I've added test cases for all the newly added functions. Let me know if I've missed anything!

Copy link
Member

@michelvocks michelvocks left a 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 ❤️

@michelvocks michelvocks merged commit d6a51f1 into gaia-pipeline:master Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants