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
Fixes #13987 - Capsule Sync Optimization #5830
Fixes #13987 - Capsule Sync Optimization #5830
Conversation
94e5f49
to
2d5f141
Compare
@@ -19,6 +19,14 @@ def plan(capsule_content, options = {}) | |||
|
|||
fail _("Action not allowed for the default capsule.") if capsule_content.default_capsule? | |||
|
|||
need_importer_update = repos_needing_importer_updates(capsule_content, environment, content_view) | |||
need_distributor_update = repos_needing_distributor_updates(capsule_content, environment, content_view) | |||
need_refresh = (need_distributor_update && need_importer_update).uniq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushing these three lines into a function that returns repositories needing update could help readability and hide away those details to keep the plan function succinct.
Please update to point at 13987 since you marked 13989 as a duplicate |
end | ||
|
||
def distributors_changed?(capsule_distributors, generated_distributors) | ||
generated_distributors = generated_distributors.map { |dist| object_to_hash(dist) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed due to the format that generated_distributors is in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes that is correct, so I can compare hash object to hash object
2d5f141
to
c7b0a75
Compare
50bfad7
to
e98e6cc
Compare
"feed": generated_importer.feed || nil | ||
}.delete_if { |_k, v| v.nil? }.to_json | ||
generated_importer_config != capsule_importer.slice("download_policy", "remove_missing", "feed").to_json | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If anyone has any idea where all these methods could potentially live, I am all 👂 👂
0dfbcbe
to
0884416
Compare
capsule_distributors = repo_details["distributors"] | ||
distributors_changed?(capsule_distributors, generated_distributors) | ||
end | ||
update_distributors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spit balling on this one as an example of how you might think about it, if it doesn't make sense to attach to the repo object itself, at least take a look at the logic updates to see if they match expectation:
def repos_needing_distributor_updates(capsule, environment, content_view)
repos = capsule.repos_available_to_capsule(environment, content_view)
repos.select do |repo|
repo_details = capsule.pulp_repo_facts(repo.pulp_id)
next unless repo_details
capsule_distributors = repo_details["distributors"]
repo.distributors_changed?(repo_details["distributors"])
end
end
in glue/pulp/repo.rb:
def distributors_changed?(distributors)
generated_distributors = repo.generate_distributors.map { |dist| object_to_hash(dist) }
distributors.each do |dist|
dist.merge!(dist["config"])
dist.delete("config")
end
generated_distributors.any? do |gen_dist|
capsule_distributors.any? do |cap_dist|
(gen_dist.to_a - cap_dist.to_a).empty?
end
end
end
end
0884416
to
00bd7f9
Compare
@ehelms refactored according to your suggestions |
@@ -757,8 +757,38 @@ def capsule_download_policy | |||
end | |||
end | |||
|
|||
def distributors_change?(capsule_distributors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be distributors_changed? to be consistent with importer_changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll double check what it was, but there was an issue with naming it that, not sure if there is some sort of magic method thing going on. Any objection to having them both end with _change?
if I run into that issue changing it back to _changed?
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhhh probably due to distributors being a lazy accessor. What about:
distributors_match?()
importer_matches?()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's the best i could come up with :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is fairly clear, I'll try that
00bd7f9
to
fedaf52
Compare
generated_importer = object_to_hash(self.generate_importer(true)) | ||
(generated_importer.to_a - capsule_importer.to_a).empty? | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jlsherrill updated here (importer matches)
fedaf52
to
19be4a1
Compare
end | ||
|
||
def importer_matches?(capsule_importer) | ||
generated_importer = object_to_hash(self.generate_importer(true)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you just use .as_json() here instead of the object_to_hash method?
2.2.4 :013 > Katello::Repository.first.generate_distributors[0].as_json
=> {"relative_url"=>"Default_Organization/Library/custom/testproduct/tester", "http"=>true, "https"=>true, "auto_publish"=>true, "id"=>"Default_Organization-testproduct-tester", "protected"=>true, "checksum_type"=>"sha256"}
Other than the as_json comment, everything looks good and seems to be working well! |
@ehelms @jlsherrill updated to use as_json and tested a sync, which ran fine. (wouldn't hurt to double check though) |
Looks good to me, just one test failure and this is good to go. |
ee999bd
to
4c4628e
Compare
ACK |
…3989 Fixes #13987 - Capsule Sync Optimization
Capsule sync should check if importers or distributors in repos need updating before updating them ( as opposed to blindly updating all of them as it does now). This will speed up capsule syncs and use less dynflow actions.