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

Archive Container Nodes #15351

Merged
merged 1 commit into from
Sep 1, 2017
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
13 changes: 10 additions & 3 deletions app/models/container_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class ContainerNode < ApplicationRecord
include NewWithTypeStiMixin
include TenantIdentityMixin
include SupportsFeatureMixin
include ArchivedMixin
include_concern 'Purging'
Copy link

@moolitayer moolitayer Jun 19, 2017

Choose a reason for hiding this comment

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

Please remove

delegate :my_zone, :to => :ext_management_system

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, thanks


EXTERNAL_LOGGING_PATH = "/#/discover?_g=()&_a=(columns:!(hostname,level,kubernetes.pod_name,message),filters:!((meta:(disabled:!f,index:'%{index}',key:hostname,negate:!f),%{query})),index:'%{index}',interval:auto,query:(query_string:(analyze_wildcard:!t,query:'*')),sort:!(time,desc))".freeze

Expand Down Expand Up @@ -33,9 +35,6 @@ class ContainerNode < ApplicationRecord
virtual_column :system_distribution, :type => :string
virtual_column :kernel_version, :type => :string

# Needed for metrics
delegate :my_zone, :to => :ext_management_system

def ready_condition
container_conditions.find_by(:name => "Ready")
end
Expand Down Expand Up @@ -115,4 +114,12 @@ def external_logging_path
index = ".operations.*"
EXTERNAL_LOGGING_PATH % {:index => index, :query => query}
end

def disconnect_inv
return if archived?
_log.info("Disconnecting Node [#{name}] id [#{id}] from EMS [#{ext_management_system.name}]" \
"id [#{ext_management_system.id}] ")
self.deleted_on = Time.now.utc
save
end
end
20 changes: 20 additions & 0 deletions app/models/container_node/purging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ContainerNode < ApplicationRecord
module Purging
extend ActiveSupport::Concern
include PurgingMixin

module ClassMethods
def purge_date
::Settings.container_entities.history.keep_archived_entities.to_i_with_method.seconds.ago.utc
end

def purge_window_size
::Settings.container_entities.history.purge_window_size
end

def purge_scope(older_than)
where(arel_table[:deleted_on].lteq(older_than))
end
end
end
end
3 changes: 2 additions & 1 deletion app/models/ems_refresh/save_inventory_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def save_container_nodes_inventory(ems, hashes)

save_inventory_multi(ems.container_nodes, hashes, :use_association, [:ems_ref],
[:labels, :tags, :computer_system, :container_conditions,
:additional_attributes], [:namespace])
:additional_attributes], [:namespace], true)

store_ids_for_new_records(ems.container_nodes, hashes, :ems_ref)
end

Expand Down
3 changes: 2 additions & 1 deletion app/models/manageiq/providers/container_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ContainerManager < BaseManager
include HasMonitoringManagerMixin
include SupportsFeatureMixin

has_many :container_nodes, :foreign_key => :ems_id, :dependent => :destroy
has_many :container_nodes, -> { active }, :foreign_key => :ems_id
has_many :container_groups, -> { active }, :foreign_key => :ems_id
has_many :container_services, :foreign_key => :ems_id, :dependent => :destroy
has_many :container_replicators, :foreign_key => :ems_id, :dependent => :destroy
Expand Down Expand Up @@ -44,6 +44,7 @@ class ContainerManager < BaseManager
has_many :all_container_groups, :foreign_key => :ems_id, :dependent => :destroy, :class_name => "ContainerGroup"
has_many :all_container_projects, :foreign_key => :ems_id, :dependent => :destroy, :class_name => "ContainerProject"
has_many :all_container_images, :foreign_key => :ems_id, :dependent => :destroy, :class_name => "ContainerImage"
has_many :all_container_nodes, :foreign_key => :ems_id, :dependent => :destroy, :class_name => "ContainerNode"


virtual_column :port_show, :type => :string
Expand Down
1 change: 1 addition & 0 deletions app/models/miq_schedule_worker/jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def miq_report_result_purge_timer

def archived_entities_purge_timer
queue_work(:class_name => "Container", :method_name => "purge_timer", :zone => nil)
queue_work(:class_name => "ContainerNode", :method_name => "purge_timer", :zone => nil)
queue_work(:class_name => "ContainerGroup", :method_name => "purge_timer", :zone => nil)
queue_work(:class_name => "ContainerImage", :method_name => "purge_timer", :zone => nil)
queue_work(:class_name => "ContainerProject", :method_name => "purge_timer", :zone => nil)
Expand Down
47 changes: 47 additions & 0 deletions spec/models/container_node/purging_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
describe ContainerNode do
context "::Purging" do
context ".purge_queue" do
before do
EvmSpecHelper.create_guid_miq_server_zone
end
let(:purge_time) { (Time.zone.now + 10).round }

it "submits to the queue" do
expect(described_class).to receive(:purge_date).and_return(purge_time)
described_class.purge_timer

q = MiqQueue.all
expect(q.length).to eq(1)
expect(q.first).to have_attributes(
:class_name => described_class.name,
:method_name => "purge_by_date",
:args => [purge_time]
)
end
end

context ".purge" do
let(:deleted_date) { 6.months.ago }

before do
@old_container_node = FactoryGirl.create(:container_node, :deleted_on => deleted_date - 1.day)
@purge_date_container_node = FactoryGirl.create(:container_node, :deleted_on => deleted_date)
@new_container_node = FactoryGirl.create(:container_node, :deleted_on => deleted_date + 1.day)
end

def assert_unpurged_ids(unpurged_ids)
expect(described_class.order(:id).pluck(:id)).to eq(Array(unpurged_ids).sort)
end

it "purge_date and older" do
described_class.purge(deleted_date)
assert_unpurged_ids(@new_container_node.id)
end

it "with a window" do
described_class.purge(deleted_date, 1)
assert_unpurged_ids(@new_container_node.id)
end
end
end
end