Skip to content

Commit

Permalink
Reconnect host on provider add
Browse files Browse the repository at this point in the history
Persister expect all the methods to define collection attributes when
performin targeted refresh so moving the lambda.

Fixes https://bugzilla.redhat.com/1528859
  • Loading branch information
pkliczewski committed Jan 8, 2018
1 parent 2ede836 commit efaa339
Showing 1 changed file with 43 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,45 +281,64 @@ def hosts(extra_attributes = {})
:builder_params => {
:ems_id => ->(persister) { persister.manager.id },
},
:custom_reconnect_block => reconnect_block
:custom_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|
relation.where(inventory_collection.manager_ref.first => batch.map(&:first)).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
}

attributes.merge!(extra_attributes)
end

def vms(extra_attributes = {})
attributes = {
:custom_reconnect_block => reconnect_block
}
:custom_reconnect_block => lambda do |inventory_collection, inventory_objects_index, attributes_index|
relation = inventory_collection.model_class.where(:ems_id => nil)

super(attributes.merge!(extra_attributes))
end
return if relation.count <= 0

def reconnect_block
lambda do |inventory_collection, inventory_objects_index, attributes_index|
relation = inventory_collection.model_class.where(:ems_id => nil)
inventory_objects_index.each_slice(100) do |batch|
relation.where(inventory_collection.manager_ref.first => batch.map(&:first)).each do |record|
index = inventory_collection.object_index_with_keys(inventory_collection.manager_ref_to_cols, record)

return if relation.count <= 0
# 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)

inventory_objects_index.each_slice(100) do |batch|
relation.where(inventory_collection.manager_ref.first => batch.map(&:first)).each do |record|
index = inventory_collection.object_index_with_keys(inventory_collection.manager_ref_to_cols, record)
record.assign_attributes(hash.except(:id, :type))
if !inventory_collection.check_changed? || record.changed?
record.save!
inventory_collection.store_updated_records(record)
end

# 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)
inventory_object.id = record.id
end

inventory_object.id = record.id
end
end
end
}

super(attributes.merge!(extra_attributes))
end

def host_storages(extra_attributes = {})
Expand Down

0 comments on commit efaa339

Please sign in to comment.