From ff9149076f8a626d4e2f03cba394fb767ff98173 Mon Sep 17 00:00:00 2001 From: James Wong Date: Fri, 1 Jun 2018 13:32:45 -0400 Subject: [PATCH] workflow_node --- app/models/configuration_script.rb | 3 +++ app/models/configuration_script_base.rb | 14 -------------- app/models/configuration_script_node.rb | 5 ----- app/models/configuration_script_workflow.rb | 7 ------- .../manageiq/providers/automation_manager.rb | 2 ++ .../providers/automation_manager/workflow_node.rb | 2 ++ .../providers/external_automation_manager.rb | 2 +- .../external_automation_manager/workflow_node.rb | 2 ++ .../inventory/automation_manager.rb | 10 ++++++++++ app/models/manager_refresh/inventory/core.rb | 8 ++++++++ app/models/workflow.rb | 2 ++ app/models/workflow_node.rb | 5 +++++ 12 files changed, 35 insertions(+), 27 deletions(-) delete mode 100644 app/models/configuration_script_node.rb delete mode 100644 app/models/configuration_script_workflow.rb create mode 100644 app/models/manageiq/providers/automation_manager/workflow_node.rb create mode 100644 app/models/manageiq/providers/external_automation_manager/workflow_node.rb create mode 100644 app/models/workflow_node.rb diff --git a/app/models/configuration_script.rb b/app/models/configuration_script.rb index ed1d8aea1a73..83301b69137d 100644 --- a/app/models/configuration_script.rb +++ b/app/models/configuration_script.rb @@ -2,4 +2,7 @@ class ConfigurationScript < ConfigurationScriptBase def self.base_model ConfigurationScript end + + has_many :workflow_nodes + has_many :workflows, :through => :workflow_nodes end diff --git a/app/models/configuration_script_base.rb b/app/models/configuration_script_base.rb index b3459694a9be..1273da01af13 100644 --- a/app/models/configuration_script_base.rb +++ b/app/models/configuration_script_base.rb @@ -19,20 +19,6 @@ class ConfigurationScriptBase < ApplicationRecord has_many :authentications, :through => :authentication_configuration_script_bases - has_many :parent_nodes, - :foreign_key => :child_id, - :class_name => "ConfigurationScriptNode" - has_many :parents, - :through => :parent_nodes, - :source => :parent - - has_many :child_nodes, - :foreign_key => :parent_id, - :class_name => "ConfigurationScriptNode" - has_many :children, - :through => :child_nodes, - :source => :child - scope :with_manager, ->(manager_id) { where(:manager_id => manager_id) } include ProviderObjectMixin diff --git a/app/models/configuration_script_node.rb b/app/models/configuration_script_node.rb deleted file mode 100644 index 5d3ae0643133..000000000000 --- a/app/models/configuration_script_node.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ConfigurationScriptNode < ApplicationRecord - self.table_name = 'configuration_script_base_configuration_script_bases' - belongs_to :child, :foreign_key => "child_id", :class_name => "ConfigurationScriptBase" - belongs_to :parent, :foreign_key => "parent_id", :class_name => "ConfigurationScriptBase" -end diff --git a/app/models/configuration_script_workflow.rb b/app/models/configuration_script_workflow.rb deleted file mode 100644 index dd1c0ecd17c8..000000000000 --- a/app/models/configuration_script_workflow.rb +++ /dev/null @@ -1,7 +0,0 @@ -class ConfigurationScriptWorkflow < ApplicationRecord - # belongs_to :configuration_script, :foreign_key => "configuration_script_id" - # belongs_to :workflow, :foreign_key => "workflow_id" - - belongs_to :workflow_node, :foreign_key => "configuration_script_id", :class_name => "ConfigurationScriptBase" - belongs_to :workflow, :foreign_key => "workflow_id", :class_name => "ConfigurationScriptBase" -end diff --git a/app/models/manageiq/providers/automation_manager.rb b/app/models/manageiq/providers/automation_manager.rb index 9b43ef865ecd..f18b06820685 100644 --- a/app/models/manageiq/providers/automation_manager.rb +++ b/app/models/manageiq/providers/automation_manager.rb @@ -8,11 +8,13 @@ class ManageIQ::Providers::AutomationManager < ManageIQ::Providers::BaseManager require_nested :InventoryRootGroup require_nested :OrchestrationStack require_nested :Workflow + require_nested :WorkflowNode has_many :configured_systems, :dependent => :destroy, :foreign_key => "manager_id" has_many :configuration_profiles, :dependent => :destroy, :foreign_key => "manager_id" has_many :configuration_scripts, :dependent => :destroy, :foreign_key => "manager_id" has_many :workflows, :dependent => :destroy, :foreign_key => "manager_id" + has_many :workflow_nodes, :dependent => :destroy, :foreign_key => "manager_id" has_many :credentials, :class_name => "ManageIQ::Providers::AutomationManager::Authentication", :as => :resource, :dependent => :destroy has_many :inventory_groups, :dependent => :destroy, :foreign_key => "ems_id", :inverse_of => :manager diff --git a/app/models/manageiq/providers/automation_manager/workflow_node.rb b/app/models/manageiq/providers/automation_manager/workflow_node.rb new file mode 100644 index 000000000000..366e79644114 --- /dev/null +++ b/app/models/manageiq/providers/automation_manager/workflow_node.rb @@ -0,0 +1,2 @@ +class ManageIQ::Providers::AutomationManager::WorkflowNode < ::WorkflowNode +end diff --git a/app/models/manageiq/providers/external_automation_manager.rb b/app/models/manageiq/providers/external_automation_manager.rb index ea8201958c52..8ae6d6aa51f1 100644 --- a/app/models/manageiq/providers/external_automation_manager.rb +++ b/app/models/manageiq/providers/external_automation_manager.rb @@ -6,5 +6,5 @@ class ManageIQ::Providers::ExternalAutomationManager < ManageIQ::Providers::Auto require_nested :ConfiguredSystem require_nested :OrchestrationStack require_nested :Workflow - + require_nested :WorkflowNode end diff --git a/app/models/manageiq/providers/external_automation_manager/workflow_node.rb b/app/models/manageiq/providers/external_automation_manager/workflow_node.rb new file mode 100644 index 000000000000..80170661db9b --- /dev/null +++ b/app/models/manageiq/providers/external_automation_manager/workflow_node.rb @@ -0,0 +1,2 @@ +class ManageIQ::Providers::ExternalAutomationManager::WorkflowNode < ManageIQ::Providers::AutomationManager::WorkflowNode +end diff --git a/app/models/manager_refresh/inventory/automation_manager.rb b/app/models/manager_refresh/inventory/automation_manager.rb index 075371dde00d..e9c47f2f0e12 100644 --- a/app/models/manager_refresh/inventory/automation_manager.rb +++ b/app/models/manager_refresh/inventory/automation_manager.rb @@ -13,6 +13,16 @@ def has_automation_manager_workflows(options = {}) }.merge(options)) end + def has_automation_manager_workflow_nodes(options = {}) + has_workflow_nodes({ + :model_class => provider_module::AutomationManager::WorkflowNode, + :association => :workflow_nodes, + :builder_params => { + :manager => ->(persister) { persister.manager } + }, + }.merge(options)) + end + def has_automation_manager_configuration_scripts(options = {}) has_configuration_scripts({ :model_class => provider_module::AutomationManager::ConfigurationScript, diff --git a/app/models/manager_refresh/inventory/core.rb b/app/models/manager_refresh/inventory/core.rb index cdb786616bd1..ea424cf24d13 100644 --- a/app/models/manager_refresh/inventory/core.rb +++ b/app/models/manager_refresh/inventory/core.rb @@ -22,6 +22,14 @@ def has_workflows(options = {}) }.merge(options)) end + def has_workflow_nodes(options = {}) + has_inventory({ + :model_class => ::WorkflowNode, + :manager_ref => [:manager_ref], + :inventory_object_attributes => %i(conditions parent configuration_script workflow), + }.merge(options)) + end + def has_configuration_scripts(options = {}) has_inventory({ :model_class => ::ConfigurationScript, diff --git a/app/models/workflow.rb b/app/models/workflow.rb index aff85a848b6b..fa84f1d33590 100644 --- a/app/models/workflow.rb +++ b/app/models/workflow.rb @@ -2,4 +2,6 @@ class Workflow < ConfigurationScriptBase def self.base_model Workflow end + has_many :workflow_nodes + has_many :configuration_scripts, :through => :workflow_nodes end diff --git a/app/models/workflow_node.rb b/app/models/workflow_node.rb new file mode 100644 index 000000000000..ca4287277577 --- /dev/null +++ b/app/models/workflow_node.rb @@ -0,0 +1,5 @@ +class WorkflowNode < ApplicationRecord + belongs_to :parent, :foreign_key => :parent_id, :class_name => "WorkflowNode" + belongs_to :configuration_script + belongs_to :workflow +end