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

move #my_zone from ArchivedMixin to OldEmsMixin #17539

Merged
merged 1 commit into from
Jun 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Container < ApplicationRecord
include SupportsFeatureMixin
include NewWithTypeStiMixin
include ArchivedMixin
include OldEmsMixin
include_concern 'Purging'

belongs_to :container_group
Expand Down
1 change: 1 addition & 0 deletions app/models/container_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ContainerGroup < ApplicationRecord
include NewWithTypeStiMixin
include TenantIdentityMixin
include ArchivedMixin
include OldEmsMixin
include CustomActionsMixin
include CockpitSupportMixin
include_concern 'Purging'
Expand Down
1 change: 1 addition & 0 deletions app/models/container_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ContainerImage < ApplicationRecord
include TenantIdentityMixin
include CustomAttributeMixin
include ArchivedMixin
include OldEmsMixin
include NewWithTypeStiMixin
include CustomActionsMixin
include_concern 'Purging'
Expand Down
1 change: 1 addition & 0 deletions app/models/container_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ContainerNode < ApplicationRecord
include TenantIdentityMixin
include SupportsFeatureMixin
include ArchivedMixin
include OldEmsMixin
include CockpitMixin
include CustomActionsMixin
include_concern 'Purging'
Expand Down
1 change: 1 addition & 0 deletions app/models/container_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class ContainerProject < ApplicationRecord
include SupportsFeatureMixin
include CustomAttributeMixin
include ArchivedMixin
include OldEmsMixin
include MiqPolicyMixin
include TenantIdentityMixin
include CustomActionsMixin
Expand Down
13 changes: 0 additions & 13 deletions app/models/mixins/archived_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module ArchivedMixin
included do
scope :archived, -> { where.not(:deleted_on => nil) }
scope :active, -> { where(:deleted_on => nil) }

belongs_to :old_ext_management_system, :foreign_key => :old_ems_id, :class_name => 'ExtManagementSystem'
end

def archived?
Expand All @@ -23,15 +21,4 @@ def archive!
def unarchive!
update_attributes!(:deleted_on => nil)
end

# Needed for metrics
def my_zone
if ext_management_system.present?
ext_management_system.my_zone
elsif old_ext_management_system.present?
# Archived container entities need to retain their zone for metric collection
# This makes the association more complex and might need a performance fix
old_ext_management_system.my_zone
end
end
end
18 changes: 18 additions & 0 deletions app/models/mixins/old_ems_mixin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module OldEmsMixin
extend ActiveSupport::Concern

included do
belongs_to :old_ext_management_system, :foreign_key => :old_ems_id, :class_name => 'ExtManagementSystem'
end

# Needed for metrics
def my_zone
Copy link
Member

Choose a reason for hiding this comment

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

Just saw this now, but this is a really weird place for this method. I get that OldEmsMixin should enhance the method, but it feels more correct for there to be a method in the base class that does my_zone normally, and this method can do what it does followed by calling super. @agrare ?

Copy link
Member

Choose a reason for hiding this comment

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

@Fryguy yeah I see what you mean, there doesn't seem to be a whole lot that the base model's my_zone method does though, they all look like:

  def my_zone
    ems = ext_management_system
    ems ? ems.my_zone : MiqServer.my_zone
  end

So we would have to refactor them all to allow this to get in the middle before falling back to MiqServer.my_zone.
Maybe a method my_ems which my_zone would call then this mixin could enhance the my_ems method?

if ext_management_system.present?
ext_management_system.my_zone
elsif old_ext_management_system.present?
# Archived container entities need to retain their zone for metric collection
# This makes the association more complex and might need a performance fix
old_ext_management_system.my_zone
end
end
end