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

Add Repository.finalize_new_version #369

Merged
merged 1 commit into from Nov 13, 2019
Merged

Add Repository.finalize_new_version #369

merged 1 commit into from Nov 13, 2019

Conversation

bmbouter
Copy link
Member

@bmbouter bmbouter commented Nov 7, 2019

This PR adds a central place for plugin writers to put validation and
content modification code.

  • RepositoryVersion.__exit__ calls finalize_new_version

  • Moves the /modify/ endpoint to pulpcore.plugin.actions as a mixin
    named ModifyRepositoryActionMixin.

  • Renames Repository.repo_key to Repository.repo_key_fields.

  • Remove the RemoveDuplicates stage for plugin writers to instead use
    Repository.finalize_new_version

  • Remove the implicit usage of RemoveDuplicates from
    RepositoryVerison.add_content and RepositoryVersion.remove_content.

  • Make the RemoveDuplicates available as
    pulpcore.plugin.repo_version_utils.remove_duplicates.

As an unrelated change, it also replaces the the >>> python
codeblocks in various docblocks with python codeblock using :: and
indention.

Required PR: pulp/pulp_file#307

https://pulp.plan.io/issues/3541
re #3541

@bmbouter bmbouter changed the title DeclarativeVersion no longer creates RepoVersion Move RepoVersion create to plugins Nov 7, 2019
@bmbouter bmbouter requested a review from a team November 7, 2019 22:02
goosemania
goosemania previously approved these changes Nov 11, 2019
Copy link
Member

@goosemania goosemania left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@goosemania goosemania dismissed their stale review November 11, 2019 22:12

new changes are on the way

goosemania added a commit to goosemania/pulp_rpm that referenced this pull request Nov 11, 2019
… and sync.

Also removes one_shot_upload as it's not used anymore.

Required PR: pulp/pulpcore#369

https://pulp.plan.io/issues/3541
re #3541
goosemania added a commit to goosemania/pulp_rpm that referenced this pull request Nov 12, 2019
… and sync.

Also removes one_shot_upload as it's not used anymore.

Required PR: pulp/pulpcore#369

https://pulp.plan.io/issues/3541
re #3541
goosemania added a commit to goosemania/pulp_rpm that referenced this pull request Nov 12, 2019
… and sync.

Also removes one_shot_upload as it's not used anymore.

Required PR: pulp/pulpcore#369

https://pulp.plan.io/issues/3541
re #3541
goosemania added a commit to goosemania/pulp_rpm that referenced this pull request Nov 12, 2019
… and sync.

Also removes one_shot_upload as it's not used anymore.

Required PR: pulp/pulpcore#369

https://pulp.plan.io/issues/3541
re #3541
ipanova added a commit to ipanova/pulp_container that referenced this pull request Nov 12, 2019
ipanova added a commit to ipanova/pulp_container that referenced this pull request Nov 12, 2019
ipanova added a commit to ipanova/pulp_container that referenced this pull request Nov 12, 2019
@bmbouter
Copy link
Member Author

@gmbnomis and @mdellweg I talked w/ @dralley, @daviddavis, @dkliban, and @goosemania; here is what we came up with:

  • We don't have a use case where the user wants to provide configuration of the vadifier currently. Even if we end up with one the plugin writer could still work around it because they are the owner of the viewset now.
  • Therefore moving the vadifier to a central place that SingleContentArtifactUploadSerializer.create, DeclarativeVersion.run, and modify can call is good to avoid passing it through the tasking system and into the core machinery with optional params.
  • We observe that it would be useful for the vodifier to have access to the Repository instance. For example a "retain N" feature for pulp_rpm. The user won't want to specify that call-by-call, but instead set it on a Repository itself as, e.g. retain=2, which now they can do with typed repos. Then having the vadifier have access to that Repository instance would be good. Thus making it an instance method is useful because it has access to self.
  • I got feedback that the vadifier name was confusing. We're planning to name this def new_version_finalize(self, new_version).
  • This would be useful for various other things also so it creates more value for the plugin writer, e.g. notifying a third party service upon finalization maybe?

I'm going to add this in as an additional commit to demonstrate the idea with the hopes of merging it. What do you think of this? Will this work your your needs?

@daviddavis
Copy link
Contributor

Does finalize_new_version make sense over new_version_finalize?

@bmbouter
Copy link
Member Author

Yes I'll use finalize_new_version instead.

@mdellweg
Copy link
Member

If i read correctly, the suggestion now is to make the validitator an instance method of repository, and any possible parameter to it a field on said repository. This is exactly, what i thought it to be, as i see this method to put some common (for all operations) constraints on the resulting repository versions.
And for the example of recursively adding dependencies, i would go as far as stating, that if one wants that (repo cosure) on a specific repository, than that validification should also be used on sync.
We would even need to think about the possibility, that changing such a flag on the repository might create a new repoversion to satisfy it.

@mdellweg
Copy link
Member

Because vadifiers also include modification, I think they don't belong to repo. They belong to the respective operation creating a repo version. The vadifiers are there to allow to reuse common parts (which may be 100% in many cases).

And i would argue here, that they belong to the repository to ensure the same constraints for all (future) versions independently of the operation performed.

ipanova added a commit to ipanova/pulp_container that referenced this pull request Nov 12, 2019
@bmbouter bmbouter changed the title Move RepoVersion create to plugins Add Repository.finalize_new_version Nov 12, 2019
"""
query_for_repo_duplicates_by_type = defaultdict(lambda: Q())
for item in repository_version.added():
detail_item = item.cast()
Copy link
Contributor

@dralley dralley Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future performance improvement to take note of

  • Sort these into groups based on their pulp_type which is present on the master Content model.
  • Look up the detail content models that represent the pulp_type strings
  • Query the detail content models directly, in bulk, provided a list of PKs, instead of cast() individually
  • Then within each type group check for duplicates

Or, alternately, each repository can list all of the content types it supports and step 2 can be skipped, and we can add an extra layer of protection around making sure you can't have e.g. file content in an RPM repository which we can't easily or centrally guarantee otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 'remove_content_units' in request.data:
for url in request.data['remove_content_units']:
if url == '*':
remove_content_units.append(url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does * mean remove everything?
Should we do

if url == "*":
    remove_content_units=["*"]
    break

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree with the break change because when at least one remove_content_units specifies to remove all, additional remove_content_units params specified are unproductive.

I am going to leave remove_content_units=[url] because it DRYs the definition of *.

add_content_units = []
remove_content_units = []
repository = Repository.objects.get(pk=pk)
repository.cast()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this detail_repository = repository.cast() ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this line is unproductive since the result is never saved. It's also not needed since we only use the pk and that's the same for both master and detail. Also I verified that when the line is removed a repository PATCH and a later 'modify' call both use the same reserved_resource so they will be serialized correctly. I'm pushing the change that removes this line now.

goosemania added a commit to goosemania/pulp_rpm that referenced this pull request Nov 13, 2019
Also removes one_shot_upload as it's not used anymore.

Required PR: pulp/pulpcore#369

closes #4898
https://pulp.plan.io/issues/4898
goosemania added a commit to goosemania/pulp_rpm that referenced this pull request Nov 13, 2019
Also removes one_shot_upload as it's not used anymore.

Required PR: pulp/pulpcore#369

closes #4898
https://pulp.plan.io/issues/4898
ipanova added a commit to ipanova/pulp_container that referenced this pull request Nov 13, 2019
ipanova added a commit to ipanova/pulp_container that referenced this pull request Nov 13, 2019
This PR adds a central place for plugin writers to put validation and
content modification code.

* `RepositoryVersion.__exit__` calls `finalize_new_version`
* Moves the `/modify/` endpoint to `pulpcore.plugin.actions` as a mixin
  named `ModifyRepositoryActionMixin`.

* Renames `Repository.repo_key` to `Repository.repo_key_fields`.
* Remove the `RemoveDuplicates` stage for plugin writers to instead use
  `Repository.finalize_new_version`
* Remove the implicit usage of `RemoveDuplicates` from
 `RepositoryVerison.add_content` and `RepositoryVersion.remove_content`.
* Make the `RemoveDuplicates` available as
  `pulpcore.plugin.repo_version_utils.remove_duplicates`.

As an unrelated change, it also replaces the the `>>>` python
codeblocks in various docblocks with python codeblock using `::` and
indention.

Required PR: pulp/pulp_file#307

https://pulp.plan.io/issues/3541
re pulp#3541
@@ -0,0 +1,4 @@
Renamed the Content.repo_key to be Content.repo_unit_key. Also the calling of `RemoveDuplicates`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean Content.repo_key_fields?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also RemoveDuplicates is now remove_duplicates

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but I want to fix in separate PR because I need to unblock the other Prs with the skiptest in this one. Is that ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

followup PR here: #382

a `repo_key_fields` attribute with the field names to be compared. If all `repo_key_fields`
contain the same value for two content units, they are considered "repository duplicates".

After instantiating `RemoveDuplicates` call it with the `run()` method and pass in the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove_duplicates

And there is no longer run since it's just a function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Followup PR here: #382

Copy link
Member

@goosemania goosemania left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Just a couple of docs comments which can be addressed in a follow-up PR

@bmbouter
Copy link
Member Author

Thank you! I will make the followup PR now and ensure it's merged pre-branch and pre-RC8.

@bmbouter bmbouter merged commit 93530a9 into pulp:master Nov 13, 2019
@bmbouter bmbouter deleted the 3541 branch November 13, 2019 18:52
gmbnomis added a commit to pulp/pulp_cookbook that referenced this pull request Nov 18, 2019
Adapt to pulp/pulpcore#369 (Repository /modify
mixin) and pulp/pulpcore#380 (Don't create a new
repository version if no content was added or removed).  No functional
changes.
gmbnomis added a commit to pulp/pulp_cookbook that referenced this pull request Nov 18, 2019
Adapt to pulp/pulpcore#369 (Repository /modify
mixin) and pulp/pulpcore#380 (Don't create a new
repository version if no content was added or removed).  No functional
changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants