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

Add event state machine for refresh. #243

Merged
merged 2 commits into from
Jan 25, 2018

Conversation

lfu
Copy link
Member

@lfu lfu commented Jan 19, 2018

This event state machine replaces the builtin method event_action_refresh_sync that waits for the completion of refresh and hence blocks the worker.

Part of ManageIQ/manageiq#16868.
https://bugzilla.redhat.com/show_bug.cgi?id=1534631

@miq-bot add_label bug, fine/yes, gaprindashvili/yes

cc @mkanoor @gmcculloug @tinaafitz

@lfu
Copy link
Member Author

lfu commented Jan 19, 2018

screen shot 2018-01-19 at 11 13 01 am

@lfu lfu force-pushed the event_action_refresh_sync branch from 4daa344 to b58ef1e Compare January 19, 2018 16:11
@gmcculloug gmcculloug requested a review from mkanoor January 19, 2018 16:27
@gmcculloug gmcculloug self-assigned this Jan 19, 2018
@lfu lfu force-pushed the event_action_refresh_sync branch 3 times, most recently from 162b676 to ddda53e Compare January 19, 2018 18:39
@lfu lfu changed the title Initial commit of event state machine for refresh. Add event state machine for refresh. Jan 19, 2018
@lfu lfu force-pushed the event_action_refresh_sync branch from ddda53e to a44a5b3 Compare January 19, 2018 18:53
target = @handle.object["refresh_target"]
@handle.log(:info, "Refresh target: [#{target}]")
raise "Refresh target not found" if target.nil?
target
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to do this but since you used tap above this feels like another example.

@handle.object["refresh_target"].tap do |target|
  @handle.log(:info, "Refresh target: [#{target}]")
  raise "Refresh target not found" if target.nil?
end

@handle.log(:error, "Refresh task with id : #{task_id} not found")
exit(MIQ_ERROR)
end
task
Copy link
Member

Choose a reason for hiding this comment

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

Same here with tap.

end

def refresh_task
task_id = @handle.get_state_var(:task_id).try(:first)
Copy link
Member

Choose a reason for hiding this comment

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

Suggest using a more descriptive key name in place of :task_id, like :refresh_task_id.


def check_status(task)
case task.state
when 'Finished'
Copy link
Member

Choose a reason for hiding this comment

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

Move this string into a constant: STATE_FINISHED = 'Finished'.freeze

Copy link
Contributor

@mkanoor mkanoor left a comment

Choose a reason for hiding this comment

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

@lfu For master all the methods would have to be builtin methods and can't be inline methods. These changes are appropriate for G and F release but not for master. For master they need to be builtin methods.

@mkanoor
Copy link
Contributor

mkanoor commented Jan 19, 2018

@lfu
The MiqTask is pretty generic so we should write the builtin method in a way that it can be reused by other methods that create a MiqTask. The task_id can be either passed into the builtin method or it could directly access some well know state var

@lfu lfu force-pushed the event_action_refresh_sync branch from a44a5b3 to 0817147 Compare January 19, 2018 21:52
@lfu
Copy link
Member Author

lfu commented Jan 19, 2018

@mkanoor ids of MiqTask is returned by EmsRefresh.queue_refresh. Event handler in this case does not create the task.

@jrafanie
Copy link
Member

@lfu can you add this BZ to the PR? Thanks!

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

It seems to go together with my change for the authentications.

Copy link
Contributor

@mkanoor mkanoor left a comment

Choose a reason for hiding this comment

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

For future release we might want to use builtin methods.

end

def fetch_task(task_id)
@handle.object.attributes.sort.each { |k, v| @handle.log(:info, "#{k}: #{v}") }
Copy link
Contributor

Choose a reason for hiding this comment

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

@lfu
Is this just for logging purpose? Do we need it?

Copy link
Member Author

Choose a reason for hiding this comment

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

@mkanoor This is for information purpose. It would be useful if anything goes wrong. I would prefer to print it out for our good.

Copy link
Member

Choose a reason for hiding this comment

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

We can get this information from the automation URL in the log already (in a less user-friendly format). This adds more clutter to an already verbose log. I would advise dropping it.


def check_status(task)
case task.state
when STATE_FINISHED
Copy link
Contributor

Choose a reason for hiding this comment

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

@lfu What about the error scenario when the task is finished but has an error? will that get flagged as a retry

Copy link
Member Author

Choose a reason for hiding this comment

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

@mkanoor A MiqTask's state may be one of Initialized, Queued, Active and Finished.

Copy link
Member

Choose a reason for hiding this comment

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

@mkanoor There is a separate status column for capturing that. app/models/miq_task.rb#L8-L12

Copy link
Member

@tinaafitz tinaafitz left a comment

Choose a reason for hiding this comment

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

@lfu Looks good.

@lfu lfu force-pushed the event_action_refresh_sync branch 2 times, most recently from 335d1d0 to a40dc43 Compare January 22, 2018 22:48
def check_status(task)
case task.state
when STATE_FINISHED
@handle.root['ae_result'] = 'ok'
Copy link
Contributor

Choose a reason for hiding this comment

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

@lfu If the State == "Finished" but Status != "Ok" we should set the ae_result as error and fail the state machine. Otherwise if there is a password failure during refresh we will continue processing the next state which is going to run the policy action.

@lfu lfu force-pushed the event_action_refresh_sync branch 2 times, most recently from fafe199 to 51c2755 Compare January 23, 2018 00:35

def fetch_task(task_id)
@handle.vmdb(:miq_task).find(task_id)
rescue MiqAeException::ServiceNotFound
Copy link
Member Author

Choose a reason for hiding this comment

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

@mkanoor @tinaafitz @gmcculloug Please review this change.
@handle.vmdb(:miq_task).find(task_id) would throw an exception instead of returning nil when task is not found.

Copy link
Member

Choose a reason for hiding this comment

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

Use @handle.vmdb(:miq_task).find_by(:id => task_id)

@lfu lfu force-pushed the event_action_refresh_sync branch from 51c2755 to b69ebd1 Compare January 23, 2018 14:07
@lfu lfu force-pushed the event_action_refresh_sync branch from 47d7bb9 to 97da41d Compare January 23, 2018 21:23
@lfu
Copy link
Member Author

lfu commented Jan 23, 2018

End-to-end testing worked well.

@lfu lfu closed this Jan 24, 2018
@lfu lfu reopened this Jan 24, 2018
@lfu lfu force-pushed the event_action_refresh_sync branch from 97da41d to 56ad2bd Compare January 24, 2018 14:42
@miq-bot
Copy link
Member

miq-bot commented Jan 24, 2018

Checked commits lfu/manageiq-content@1535271~...56ad2bd with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0
10 files checked, 1 offense detected

**

  • 💣 💥 🔥 🚒 - Linter/Yaml - missing config files

@gmcculloug
Copy link
Member

@tinaafitz Can you look this over again as some things have changed since you approved.

Copy link
Member

@tinaafitz tinaafitz left a comment

Choose a reason for hiding this comment

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

@lfu Looks good

@lfu
Copy link
Member Author

lfu commented Jan 24, 2018

Change in ManageIQ/manageiq#16868 caused the Travis failure.

@gmcculloug gmcculloug merged commit e0ec800 into ManageIQ:master Jan 25, 2018
@gmcculloug gmcculloug added this to the Sprint 78 Ending Jan 29, 2018 milestone Jan 25, 2018
@mfalesni
Copy link
Contributor

mfalesni commented Feb 1, 2018

What is the best way to test this change? Where does the state machine get called so I can see how does it work?

@lfu
Copy link
Member Author

lfu commented Feb 1, 2018

@mfalesni The state machine is called by reconfigvm_task_complete event.
Run Vm Reconfigure task via UI which would call the state machine at the end of the process. It would be even better if somehow the provider refresh takes longer time to get done.

simaishi pushed a commit that referenced this pull request Mar 1, 2018
@simaishi
Copy link
Contributor

simaishi commented Mar 1, 2018

Fine backport details:

$ git log -1
commit 473466ed60cf61e69ac7f1cad7ea9b5d08958cbd
Author: Greg McCullough <[email protected]>
Date:   Thu Jan 25 09:02:48 2018 -0500

    Merge pull request #243 from lfu/event_action_refresh_sync
    
    Add event state machine for refresh.
    (cherry picked from commit e0ec80069f3a5e2c75079fa519e9dfbf18e6771d)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1550725

@simaishi
Copy link
Contributor

simaishi commented Mar 6, 2018

Gaprindashvili backport details:

$ git log -1
commit 068779473d7cbc266754277d9b14793df00dc90c
Author: Greg McCullough <[email protected]>
Date:   Thu Jan 25 09:02:48 2018 -0500

    Merge pull request #243 from lfu/event_action_refresh_sync
    
    Add event state machine for refresh.
    (cherry picked from commit e0ec80069f3a5e2c75079fa519e9dfbf18e6771d)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1550724

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.

8 participants