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

Fixes #13987 - Capsule Sync Optimization #5830

Merged

Conversation

johnpmitsch
Copy link
Contributor

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.

@@ -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
Copy link
Member

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.

@ehelms
Copy link
Member

ehelms commented Mar 2, 2016

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) }
Copy link
Member

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?

Copy link
Contributor Author

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

@johnpmitsch johnpmitsch force-pushed the capsule_sync_optimization_13989 branch from 2d5f141 to c7b0a75 Compare March 7, 2016 21:02
@johnpmitsch johnpmitsch changed the title [WIP] Fixes #13989 - Capsule Sync Optimization Fixes #13989 - Capsule Sync Optimization Mar 7, 2016
@johnpmitsch johnpmitsch force-pushed the capsule_sync_optimization_13989 branch 2 times, most recently from 50bfad7 to e98e6cc Compare March 7, 2016 21:08
@johnpmitsch johnpmitsch changed the title Fixes #13989 - Capsule Sync Optimization Fixes #13987 - Capsule Sync Optimization Mar 7, 2016
@johnpmitsch johnpmitsch changed the title Fixes #13987 - Capsule Sync Optimization [WIP] Fixes #13987 - Capsule Sync Optimization Mar 7, 2016
"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
Copy link
Contributor Author

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 👂 👂

@johnpmitsch johnpmitsch changed the title [WIP] Fixes #13987 - Capsule Sync Optimization Fixes #13987 - Capsule Sync Optimization Mar 8, 2016
@johnpmitsch johnpmitsch force-pushed the capsule_sync_optimization_13989 branch 3 times, most recently from 0dfbcbe to 0884416 Compare March 8, 2016 20:04
capsule_distributors = repo_details["distributors"]
distributors_changed?(capsule_distributors, generated_distributors)
end
update_distributors
Copy link
Member

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

@johnpmitsch johnpmitsch force-pushed the capsule_sync_optimization_13989 branch from 0884416 to 00bd7f9 Compare March 10, 2016 21:30
@johnpmitsch
Copy link
Contributor Author

@ehelms refactored according to your suggestions

@@ -757,8 +757,38 @@ def capsule_download_policy
end
end

def distributors_change?(capsule_distributors)
Copy link
Member

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?

Copy link
Contributor Author

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? ?

Copy link
Member

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?()

Copy link
Member

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 :)

Copy link
Contributor Author

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

@johnpmitsch johnpmitsch force-pushed the capsule_sync_optimization_13989 branch from 00bd7f9 to fedaf52 Compare March 16, 2016 19:26
generated_importer = object_to_hash(self.generate_importer(true))
(generated_importer.to_a - capsule_importer.to_a).empty?
end

Copy link
Contributor Author

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)

@johnpmitsch johnpmitsch force-pushed the capsule_sync_optimization_13989 branch from fedaf52 to 19be4a1 Compare March 17, 2016 18:22
end

def importer_matches?(capsule_importer)
generated_importer = object_to_hash(self.generate_importer(true))
Copy link
Member

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"} 

@jlsherrill
Copy link
Member

Other than the as_json comment, everything looks good and seems to be working well!

@johnpmitsch
Copy link
Contributor Author

@ehelms @jlsherrill updated to use as_json and tested a sync, which ran fine. (wouldn't hurt to double check though)

@jlsherrill
Copy link
Member

Looks good to me, just one test failure and this is good to go.

@johnpmitsch johnpmitsch force-pushed the capsule_sync_optimization_13989 branch from ee999bd to 4c4628e Compare March 18, 2016 13:43
@jlsherrill
Copy link
Member

ACK

johnpmitsch pushed a commit that referenced this pull request Mar 18, 2016
…3989

Fixes #13987 - Capsule Sync Optimization
@johnpmitsch johnpmitsch merged commit c84d75a into Katello:master Mar 18, 2016
@johnpmitsch johnpmitsch deleted the capsule_sync_optimization_13989 branch March 18, 2016 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants