-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added `refresh` endpoint to support ACS. closes: #9377 https://pulp.plan.io/issues/9377 Required PR: pulp/pulpcore#1496
- Loading branch information
1 parent
de0ad4b
commit 9674b61
Showing
7 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added refresh endpoint for Alernate Content Sources. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Alternate Content Sources | ||
========================= | ||
|
||
To use an Alternate Content Source you need a ``FileRemote`` with base path of your | ||
ACS. | ||
|
||
.. code-block:: bash | ||
http POST localhost:24817/pulp/api/v3/remotes/file/file/ name="remoteForACS" policy="on_demand" url="http://fixtures.pulpproject.org/" | ||
Create Alternate Content Source | ||
------------------------------- | ||
|
||
.. code-block:: bash | ||
http POST localhost:24817/pulp/api/v3/acs/file/file/ name="fileAcs" remote=<pulp-remote-href> paths:='["file/PULP_MANIFEST", "backup/MANIFEST"]' | ||
Refresh ACS | ||
----------- | ||
|
||
To make your ACS available for future syncs you need to call ``refresh`` endpoint | ||
on your ACS. | ||
|
||
.. code-block:: bash | ||
http POST localhost:24817/pulp/api/v3/acs/file/file/<ACS-UUID>/refresh/ | ||
Alternate Content Source has a global scope so if any content found in ACS it | ||
will be used in all future syncs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,4 @@ library with: | |
sync | ||
upload | ||
publish-host | ||
alternate-content-source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
from .publishing import publish # noqa | ||
from .synchronizing import synchronize # noqa | ||
|
||
# file_acs_refresh must be imported after synchronize to avoid circular import | ||
from .acs import file_acs_refresh # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import os | ||
|
||
from datetime import datetime | ||
|
||
from pulpcore.plugin.models import ( | ||
AlternateContentSource, | ||
AlternateContentSourcePath, | ||
ProgressReport, | ||
TaskGroup, | ||
) | ||
from pulpcore.plugin.tasking import dispatch | ||
|
||
from pulp_file.app.tasks import synchronize | ||
from pulp_file.app.models import FileRepository | ||
|
||
metadata_files = [] | ||
|
||
|
||
def file_acs_refresh(acs_pk): | ||
""" | ||
Refresh alternative content sources. | ||
""" | ||
acs = AlternateContentSource.objects.get(pk=acs_pk) | ||
acs_paths = AlternateContentSourcePath.objects.filter(alternate_content_source=acs_pk) | ||
with ProgressReport( | ||
message="Refreshing ACS metadata", code="acs.refreshing.metadata", total=len(acs_paths) | ||
) as pb: | ||
for acs_path in acs_paths: | ||
# Create or get repository for each path | ||
repo_data = { | ||
"name": f"{acs.name}--{acs_path.pk}--repository", | ||
"retain_repo_versions": 1, | ||
"user_hidden": True, | ||
} | ||
repo, created = FileRepository.objects.get_or_create(**repo_data) | ||
if created: | ||
acs_path.repository = repo | ||
acs_path.save() | ||
acs_url = os.path.join(acs.remote.url, acs_path.path) | ||
# Dispatch each ACS path to own task and assign it to common TaskGroup | ||
task_group = TaskGroup.objects.create(description=f"Refresh of {acs_path.path}") | ||
dispatch( | ||
synchronize, | ||
shared_resources=[acs.remote], | ||
exclusive_resources=[acs], | ||
task_group=task_group, | ||
kwargs={ | ||
"remote_pk": str(acs.remote.pk), | ||
"repository_pk": str(acs_path.repository.pk), | ||
"mirror": False, | ||
"url": acs_url, | ||
}, | ||
) | ||
pb.increment() | ||
acs.last_refreshed = datetime.now() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters