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

Enable cancel operation for service template transformation plan request #17825

Merged
merged 1 commit into from
Sep 13, 2018

Conversation

hsong-rh
Copy link
Contributor

@hsong-rh hsong-rh commented Aug 9, 2018

This PR enable cancellation for V2V request by using the new introduced cancelation_status column in miq_requests table.

cancelation_status has three valid values: cancel_requested, canceling and canceled. After UI gets cancel request, it will mark to cancel_requested. Following checking will change it to canceling, canceled, based on subtasks' states.

https://bugzilla.redhat.com/show_bug.cgi?id=1614864

@hsong-rh
Copy link
Contributor Author

hsong-rh commented Aug 9, 2018

@bzwei @gmcculloug Please review.

false
end

def do_cancel
Copy link
Contributor

Choose a reason for hiding this comment

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

make it a private method

end

def do_cancel
update_attributes(:request_state => "finished", :status => "Error", :message => "Request is canceled by user.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the logic to cancel. Here do_cancel does nothing.

@bzwei
Copy link
Contributor

bzwei commented Aug 9, 2018

@hsong-rh Please change the title to wip.

@hsong-rh hsong-rh changed the title Enable cancel operation for service template transformation plan request [WIP] Enable cancel operation for service template transformation plan request Aug 9, 2018
@miq-bot miq-bot added the wip label Aug 9, 2018
@hsong-rh hsong-rh force-pushed the miq_request_cancel branch 5 times, most recently from d3fd4e6 to 9ac1276 Compare August 13, 2018 21:00
@hsong-rh hsong-rh changed the title [WIP] Enable cancel operation for service template transformation plan request Enable cancel operation for service template transformation plan request Aug 13, 2018
@miq-bot miq-bot removed the wip label Aug 13, 2018
validates_inclusion_of :approval_state, :in => %w(pending_approval approved denied), :message => "should be 'pending_approval', 'approved' or 'denied'"
validates_inclusion_of :status, :in => %w(Ok Warn Error Timeout Denied)
validates_inclusion_of :cancel_state, :in => %w(pending_cancel processing finished), :message => "should be 'pending_cancel', 'processing' or 'finished'"
Copy link
Contributor

Choose a reason for hiding this comment

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

for allowed states, how about %w(cancel_requested canceling canceled)

@bzwei
Copy link
Contributor

bzwei commented Aug 13, 2018

cc @fdupont-redhat @priley86
Automate should check and update task's cancel_state.
UI should check this column to show cancellation status instead of parsing options.

@ghost
Copy link

ghost commented Aug 14, 2018

@bzwei How do I update task's cancel_state ? I can only method to check the cancel state, not to set it. Should I simply do `task.cancel_state = 'canceling' when I have successfully launched the cancellation state machine ?

Alos, this PR has code only for the model, but not for the service model. I guess there will be another PR for that.

@bzwei
Copy link
Contributor

bzwei commented Aug 14, 2018

@fdupont-redhat yes. Another PR for service model is on the way. It will provide methods for automate to change cancel_state.

@JPrause
Copy link
Member

JPrause commented Aug 14, 2018

@miq-bot add_label blocker

@JPrause
Copy link
Member

JPrause commented Aug 14, 2018

@hsong-rh if this can be backported, please add the gaprindashvili/yes label.

Copy link
Member

@gmcculloug gmcculloug left a comment

Choose a reason for hiding this comment

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

Instead of jamming more code into the miq_request.rb and miq_request_task.rb files it would be better to move this logic into new files using include_concern. There seems to be some potential to use a mixin as well as there are common elements in both.

Still need to review this more and it would be good to get together to discuss the columns involved as well as the state values.

@hsong-rh
Copy link
Contributor Author

@bzwei @agrare @gmcculloug Please review.

@hsong-rh hsong-rh force-pushed the miq_request_cancel branch 3 times, most recently from 3e4c30e to 91a7b4b Compare August 29, 2018 19:01
@hsong-rh
Copy link
Contributor Author

@agrare @bzwei @mkanoor @gmcculloug Changed StateMachine into StateMachineMixin and added corresponding spec tests. Please review and decide if need to separate into 2 PRs.

:pending => {'pending' => 'pending'},
:queued => {'pending' => 'queued'},
:active => {'pending' => 'active',
'active' => 'active',
Copy link
Contributor

Choose a reason for hiding this comment

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

@hsong-rh
Is active => active needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, one type of automated request needs it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@hsong-rh do you know which one of the automate request. Also if the next_state == current_state meaning active == active can't we just skip that state change

@hsong-rh
Copy link
Contributor Author

@bzwei @mkanoor @agrare @gmcculloug Changed to focus on request cancellation for V2V. Refactor for state machine mixin will be in separate PR. Please review.

@hsong-rh hsong-rh changed the title Enable cancel operation for service template transformation plan request [WIP] Enable cancel operation for service template transformation plan request Aug 30, 2018
@miq-bot miq-bot added the wip label Aug 30, 2018
@hsong-rh hsong-rh changed the title [WIP] Enable cancel operation for service template transformation plan request Enable cancel operation for service template transformation plan request Sep 6, 2018
@miq-bot miq-bot removed the wip label Sep 6, 2018
@hsong-rh hsong-rh closed this Sep 11, 2018
@hsong-rh hsong-rh reopened this Sep 11, 2018
@hsong-rh hsong-rh force-pushed the miq_request_cancel branch 2 times, most recently from 65f62fd to 3452fe1 Compare September 12, 2018 17:52
Copy link
Member

@gmcculloug gmcculloug left a comment

Choose a reason for hiding this comment

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

A few minor suggestions around the spec, but otherwise this looks good.

@@ -38,4 +38,24 @@
expect(ServiceResource.find_by(:resource => vms[0]).status).to eq(ServiceResource::STATUS_APPROVED)
end
end

context "gets cancel request" do
Copy link
Member

Choose a reason for hiding this comment

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

Suggest "when request gets canceled"

Also, you can move the call to cancel into a before block: before { request.cancel }

@@ -38,4 +38,24 @@
expect(ServiceResource.find_by(:resource => vms[0]).status).to eq(ServiceResource::STATUS_APPROVED)
end
end

context "gets cancel request" do
it "gets cancel_requested request" do
Copy link
Member

Choose a reason for hiding this comment

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

"cancelation status is set to requested"

expect(request.canceled?).to be_falsey
end

it "calls do_cancel" do
Copy link
Member

Choose a reason for hiding this comment

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

"marks request as finished in error"

@miq-bot
Copy link
Member

miq-bot commented Sep 13, 2018

Checked commit hsong-rh@5f10870 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
7 files checked, 0 offenses detected
Everything looks fine. 🏆

@gmcculloug gmcculloug merged commit 9f3c401 into ManageIQ:master Sep 13, 2018
@gmcculloug gmcculloug added this to the Sprint 95 Ending Sep 24, 2018 milestone Sep 13, 2018
@bzwei
Copy link
Contributor

bzwei commented Sep 13, 2018

@fdupont-redhat @priley86 Though this PR is related to https://bugzilla.redhat.com/show_bug.cgi?id=1614864, it will not back ported because it relies on schema migration.

To summarize the changes

  1. We now support transformation plan cancellation at both request and task levels.
  2. Cancel status is stored in a new column, namely cancel_status; thus UI should look at this attribute to show the canceling status. Valid values are cancel_requested, canceling, and canceled.
  3. Automate should call task's cancel_requested? method to check whether user has requested a cancellation.
  4. Automate should call task's canceling and canceled methods to report the status change.
  5. Automate (and UI) should clean up and remove the cancel status in options field.

With this PR being merged the V2V cancellation will not work properly until automate and UI make the above modifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants