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

query also archived objects for a new ems #16886

Merged
merged 1 commit into from
Feb 23, 2018
Merged
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
32 changes: 30 additions & 2 deletions app/models/manager_refresh/inventory_collection_default.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
class ManagerRefresh::InventoryCollectionDefault
INVENTORY_RECONNECT_BLOCK = lambda do |inventory_collection, inventory_objects_index, attributes_index|
relation = inventory_collection.model_class.where(:ems_id => nil)

return if relation.count <= 0

inventory_objects_index.each_slice(100) do |batch|
batch_refs = batch.map(&:first)
relation.where(inventory_collection.manager_ref.first => batch_refs).each do |record|
index = inventory_collection.object_index_with_keys(inventory_collection.manager_ref_to_cols, record)

# We need to delete the record from the inventory_objects_index
# and attributes_index, otherwise it would be sent for create.
inventory_object = inventory_objects_index.delete(index)
hash = attributes_index.delete(index)

record.assign_attributes(hash.except(:id, :type))
if !inventory_collection.check_changed? || record.changed?
record.save!
inventory_collection.store_updated_records(record)
end

inventory_object.id = record.id
end
end
end.freeze

class << self
def vms(extra_attributes = {})
attributes = {
Expand Down Expand Up @@ -42,7 +68,8 @@ def vms(extra_attributes = {})
:ems_id => ->(persister) { persister.manager.id },
:name => "unknown",
:location => "unknown",
}
},
:custom_reconnect_block => INVENTORY_RECONNECT_BLOCK,
}

attributes.merge!(extra_attributes)
Expand Down Expand Up @@ -82,7 +109,8 @@ def miq_templates(extra_attributes = {})
:name => "unknown",
:location => "unknown",
:template => true
}
},
:custom_reconnect_block => INVENTORY_RECONNECT_BLOCK,
}

attributes.merge!(extra_attributes)
Expand Down