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

Merge retirement checks #15645

Merged
merged 7 commits into from
Jul 26, 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
2 changes: 1 addition & 1 deletion app/models/load_balancer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class LoadBalancer < ApplicationRecord
include NewWithTypeStiMixin
include AsyncDeleteMixin
include ProcessTasksMixin
include_concern 'RetirementManagement'
include RetirementMixin
include TenantIdentityMixin
include CloudTenancyMixin

Expand Down
17 changes: 0 additions & 17 deletions app/models/load_balancer/retirement_management.rb

This file was deleted.

16 changes: 2 additions & 14 deletions app/models/miq_schedule_worker/jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,8 @@ def job_check_jobs_for_timeout
queue_work_on_each_zone(:class_name => "Job", :method_name => "check_jobs_for_timeout")
end

def service_retirement_check
queue_work_on_each_zone(:class_name => "Service", :method_name => "retirement_check")
end

def vm_retirement_check
queue_work_on_each_zone(:class_name => "Vm", :method_name => "retirement_check")
end

def orchestration_stack_retirement_check
queue_work_on_each_zone(:class_name => "OrchestrationStack", :method_name => "retirement_check")
end

def load_balancer_retirement_check
queue_work_on_each_zone(:class_name => "LoadBalancer", :method_name => "retirement_check")
def retirement_check
queue_work_on_each_zone(:class_name => 'RetirementManager', :method_name => 'check')
end

def host_authentication_check_schedule
Expand Down
25 changes: 4 additions & 21 deletions app/models/miq_schedule_worker/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,11 @@ def schedules_for_scheduler_role
enqueue :job_check_jobs_for_timeout
end

# Schedule - Check for Retired Services
every = worker_settings[:service_retired_interval]
# Schedule - Check for retired items and start retirement
# TODO: remove redundant settings in follow-up pr
every = [worker_settings[:service_retired_interval], worker_settings[:vm_retired_interval], worker_settings[:orchestration_stack_retired_interval], worker_settings[:load_balancer_retired_interval]].min
scheduler.schedule_every(every, :first_in => every) do
enqueue :service_retirement_check
end

# Schedule - Check for Retired VMs
every = worker_settings[:vm_retired_interval]
scheduler.schedule_every(every, :first_in => every) do
enqueue :vm_retirement_check
end

# Schedule - Check for Retired Orchestration Stacks
every = worker_settings[:orchestration_stack_retired_interval]
scheduler.schedule_every(every, :first_in => every) do
enqueue :orchestration_stack_retirement_check
end

# Schedule - Check for Retired Load Balancers
every = worker_settings[:load_balancer_retired_interval]
scheduler.schedule_every(every, :first_in => every) do
enqueue :load_balancer_retirement_check
enqueue :retirement_check
end

# Schedule - Periodic validation of authentications
Expand Down
6 changes: 5 additions & 1 deletion app/models/mixins/retirement_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ module RetirementMixin
RETIRING = 'retiring'
ERROR_RETIRING = 'error'

included do
scope :scheduled_to_retire, -> { where(arel_table[:retires_on].not_eq(nil).or(arel_table[:retired].not_eq(true))) }
end

module ClassMethods
def retire(ids, options = {})
ids.each do |id|
object = find_by(:id => id)
object.retire(options) if object.respond_to?(:retire)
end
MiqQueue.put(:class_name => base_model.name, :method_name => "retirement_check")
MiqQueue.put(:class_name => 'RetirementManager', :method_name => 'check')
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/orchestration_stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class OrchestrationStack < ApplicationRecord
include NewWithTypeStiMixin
include AsyncDeleteMixin
include ProcessTasksMixin
include_concern 'RetirementManagement'
include RetirementMixin
include TenantIdentityMixin

acts_as_miq_taggable
Expand Down
17 changes: 0 additions & 17 deletions app/models/orchestration_stack/retirement_management.rb

This file was deleted.

15 changes: 15 additions & 0 deletions app/models/retirement_manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class RetirementManager
def self.check
ems_ids = MiqServer.my_server.zone.ext_management_system_ids
[LoadBalancer, OrchestrationStack, Vm, Service].flat_map do |i|
instances = not_retired_with_ems(i, ems_ids)
instances.each(&:retirement_check)
end
end

def self.not_retired_with_ems(model, ems_ids)
return model.scheduled_to_retire unless model.column_names.include?('ems_id') # Service not assigned to ems_ids
model.scheduled_to_retire.where(:ems_id => ems_ids)
end
private_class_method :not_retired_with_ems
end
7 changes: 0 additions & 7 deletions app/models/service/retirement_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ module Service::RetirementManagement
extend ActiveSupport::Concern
include RetirementMixin

module ClassMethods
def retirement_check
services = Service.where("retires_on IS NOT NULL OR retired = ?", true)
services.each(&:retirement_check)
end
end

def before_retirement
children.each(&:retire_now)
end
Expand Down
1 change: 1 addition & 0 deletions app/models/vm_or_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class VmOrTemplate < ApplicationRecord
include NewWithTypeStiMixin
include RetirementMixin
include ScanningMixin
include SupportsFeatureMixin

Expand Down
10 changes: 0 additions & 10 deletions app/models/vm_or_template/retirement_management.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
module VmOrTemplate::RetirementManagement
extend ActiveSupport::Concern
include RetirementMixin

module ClassMethods
def retirement_check
zone = MiqServer.my_server.zone
ems_ids = zone.ext_management_system_ids
vms = Vm.where("(retires_on IS NOT NULL OR retired = ?) AND ems_id IN (?)", true, ems_ids)
vms.each(&:retirement_check)
end
end

def retired_validated?
['off', 'never'].include?(state)
Expand Down
19 changes: 19 additions & 0 deletions spec/models/retirement_manager_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe RetirementManager do
describe "#check" do
it "with retirement date, runs retirement checks" do
_, _, zone = EvmSpecHelper.local_guid_miq_server_zone
ems = FactoryGirl.create(:ems_network, :zone => zone)

load_balancer = FactoryGirl.create(:load_balancer, :retires_on => Time.zone.today + 1.day, :ext_management_system => ems)
FactoryGirl.create(:load_balancer, :retired => true)
orchestration_stack = FactoryGirl.create(:orchestration_stack, :retires_on => Time.zone.today + 1.day, :ext_management_system => ems)
FactoryGirl.create(:orchestration_stack, :retired => true)
vm = FactoryGirl.create(:vm, :retires_on => Time.zone.today + 1.day, :ems_id => ems.id)
FactoryGirl.create(:vm, :retired => true)
service = FactoryGirl.create(:service, :retires_on => Time.zone.today + 1.day)
FactoryGirl.create(:service, :retired => true)

expect(RetirementManager.check).to match_array([load_balancer, orchestration_stack, vm, service])
end
end
end