-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add event state machine for refresh.
- Loading branch information
Showing
8 changed files
with
301 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__class__.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
--- | ||
object_type: class | ||
version: 1.0 | ||
object: | ||
attributes: | ||
description: Refresh State Machine | ||
display_name: | ||
name: Refresh | ||
type: | ||
inherits: | ||
visibility: | ||
owner: | ||
schema: | ||
- field: | ||
aetype: state | ||
name: pre | ||
display_name: | ||
datatype: string | ||
priority: 1 | ||
owner: | ||
default_value: | ||
substitute: true | ||
message: create | ||
visibility: | ||
collect: | ||
scope: | ||
description: | ||
condition: | ||
on_entry: '' | ||
on_exit: '' | ||
on_error: '' | ||
max_retries: '100' | ||
max_time: | ||
- field: | ||
aetype: state | ||
name: refresh | ||
display_name: | ||
datatype: string | ||
priority: 2 | ||
owner: | ||
default_value: | ||
substitute: true | ||
message: create | ||
visibility: | ||
collect: | ||
scope: | ||
description: | ||
condition: | ||
on_entry: | ||
on_exit: | ||
on_error: | ||
max_retries: '100' | ||
max_time: | ||
- field: | ||
aetype: state | ||
name: check_refreshed | ||
display_name: | ||
datatype: string | ||
priority: 3 | ||
owner: | ||
default_value: | ||
substitute: true | ||
message: create | ||
visibility: | ||
collect: | ||
scope: | ||
description: | ||
condition: | ||
on_entry: | ||
on_exit: | ||
on_error: | ||
max_retries: '100' | ||
max_time: | ||
- field: | ||
aetype: state | ||
name: post | ||
display_name: | ||
datatype: string | ||
priority: 4 | ||
owner: | ||
default_value: | ||
substitute: true | ||
message: create | ||
visibility: | ||
collect: | ||
scope: | ||
description: | ||
condition: | ||
on_entry: '' | ||
on_exit: '' | ||
on_error: '' | ||
max_retries: '100' | ||
max_time: | ||
- field: | ||
aetype: state | ||
name: policy | ||
display_name: | ||
datatype: string | ||
priority: 5 | ||
owner: | ||
default_value: | ||
substitute: true | ||
message: create | ||
visibility: | ||
collect: | ||
scope: | ||
description: | ||
condition: | ||
on_entry: | ||
on_exit: | ||
on_error: | ||
max_retries: | ||
max_time: | ||
- field: | ||
aetype: state | ||
name: finished | ||
display_name: | ||
datatype: string | ||
priority: 6 | ||
owner: | ||
default_value: | ||
substitute: true | ||
message: create | ||
visibility: | ||
collect: | ||
scope: | ||
description: | ||
condition: | ||
on_entry: | ||
on_exit: | ||
on_error: | ||
max_retries: | ||
max_time: |
64 changes: 64 additions & 0 deletions
64
...automate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/check_refreshed.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# | ||
# Description: This method checks the refresh completion. | ||
# | ||
|
||
module ManageIQ | ||
module Automate | ||
module System | ||
module Event | ||
module StateMachines | ||
module Refresh | ||
class CheckRefreshed | ||
STATE_FINISHED = 'Finished'.freeze | ||
STATUS_OK = 'Ok'.freeze | ||
|
||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
def main | ||
check_status(refresh_task) | ||
end | ||
|
||
private | ||
|
||
def check_status(task) | ||
case task.state | ||
when STATE_FINISHED | ||
if task.status == STATUS_OK | ||
@handle.root['ae_result'] = 'ok' | ||
else | ||
@handle.root['ae_result'] = 'error' | ||
@handle.log(:error, "Refresh task ended with error: #{task.message}") | ||
end | ||
else | ||
@handle.root['ae_result'] = 'retry' | ||
@handle.root['ae_retry_interval'] = '1.minute' | ||
end | ||
end | ||
|
||
def refresh_task | ||
task_id = @handle.get_state_var(:refresh_task_id).first | ||
@handle.log(:info, "Stored refresh task ID: [#{task_id}]") | ||
fetch_task(task_id) | ||
end | ||
|
||
def fetch_task(task_id) | ||
@handle.vmdb(:miq_task).find_by(:id => task_id).tap do |task| | ||
if task.nil? | ||
@handle.log(:error, "Refresh task with id: #{task_id} not found") | ||
raise "Refresh task with id: #{task_id} not found" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if $PROGRAM_NAME == __FILE__ | ||
ManageIQ::Automate::System::Event::StateMachines::Refresh::CheckRefreshed.new.main | ||
end |
13 changes: 13 additions & 0 deletions
13
...tomate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/check_refreshed.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
object_type: method | ||
version: 1.0 | ||
object: | ||
attributes: | ||
name: check_refreshed | ||
display_name: | ||
description: | ||
scope: instance | ||
language: ruby | ||
location: inline | ||
options: {} | ||
inputs: [] |
51 changes: 51 additions & 0 deletions
51
.../automate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/target_refresh.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# | ||
# Description: This method starts a synchronous refresh and save the | ||
# task id in the state variables so we can use it when | ||
# waiting for the refresh to finish. | ||
# | ||
|
||
module ManageIQ | ||
module Automate | ||
module System | ||
module Event | ||
module StateMachines | ||
module Refresh | ||
class TargetRefresh | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
def main | ||
task_id = event.refresh(refresh_target, true) | ||
raise "Refresh task not created" if task_id.blank? | ||
@handle.set_state_var(:refresh_task_id, task_id) | ||
end | ||
|
||
private | ||
|
||
def event | ||
@handle.root["event_stream"].tap do |event| | ||
if event.nil? | ||
@handle.log(:error, 'Event object is nil') | ||
raise 'Event object not found' | ||
end | ||
end | ||
end | ||
|
||
def refresh_target | ||
@handle.object["refresh_target"].tap do |target| | ||
@handle.log(:info, "Refresh target: [#{target}]") | ||
raise "Refresh target not found" if target.nil? | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if $PROGRAM_NAME == __FILE__ | ||
ManageIQ::Automate::System::Event::StateMachines::Refresh::TargetRefresh.new.main | ||
end |
13 changes: 13 additions & 0 deletions
13
...utomate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/target_refresh.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
object_type: method | ||
version: 1.0 | ||
object: | ||
attributes: | ||
name: target_refresh | ||
display_name: | ||
description: | ||
scope: instance | ||
language: ruby | ||
location: inline | ||
options: {} | ||
inputs: [] |
16 changes: 16 additions & 0 deletions
16
content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/default.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
object_type: instance | ||
version: 1.0 | ||
object: | ||
attributes: | ||
display_name: | ||
name: default | ||
inherits: | ||
description: | ||
fields: | ||
- refresh: | ||
value: METHOD::target_refresh | ||
- check_refreshed: | ||
value: METHOD::check_refreshed | ||
- policy: | ||
value: "/System/event_handlers/event_action_policy?target=${#policy_target}&policy_event=${#policy_event}¶m=" |
10 changes: 10 additions & 0 deletions
10
content/automate/ManageIQ/System/Event/StateMachines/__namespace__.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
object_type: namespace | ||
version: 1.0 | ||
object: | ||
attributes: | ||
name: StateMachines | ||
description: | ||
display_name: | ||
priority: | ||
enabled: |