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

Update the import endpoint to return a task group #1631

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/9382.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated the pulp import creation endpoint to return a task group instead of a task.
6 changes: 1 addition & 5 deletions pulpcore/app/tasks/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,17 +367,13 @@ def validate_and_assemble(toc_filename):

log.info(_("Importing {}.").format(path))
current_task = Task.current()
task_group = TaskGroup.current()
importer = PulpImporter.objects.get(pk=importer_pk)
the_import = PulpImport.objects.create(
importer=importer, task=current_task, params={"path": path}
)
CreatedResource.objects.create(content_object=the_import)

task_group = TaskGroup.objects.create(description=f"Import of {path}")
Task.objects.filter(pk=current_task.pk).update(task_group=task_group)
current_task.refresh_from_db()
CreatedResource.objects.create(content_object=task_group)

with tempfile.TemporaryDirectory() as temp_dir:
with tarfile.open(path, "r:gz") as tar:
tar.extractall(path=temp_dir)
Expand Down
15 changes: 10 additions & 5 deletions pulpcore/app/viewsets/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
Importer,
PulpImport,
PulpImporter,
TaskGroup,
)
from pulpcore.app.response import OperationPostponedResponse
from pulpcore.app.response import TaskGroupOperationResponse
from pulpcore.app.serializers import (
AsyncOperationResponseSerializer,
ImportSerializer,
ImporterSerializer,
PulpImporterSerializer,
PulpImportSerializer,
TaskGroupOperationResponseSerializer,
)
from pulpcore.app.tasks import pulp_import
from pulpcore.app.viewsets import (
Expand Down Expand Up @@ -91,7 +92,7 @@ class PulpImportViewSet(ImportViewSet):
@extend_schema(
request=PulpImportSerializer,
description="Trigger an asynchronous task to import a Pulp export.",
responses={202: AsyncOperationResponseSerializer},
responses={202: TaskGroupOperationResponseSerializer},
)
def create(self, request, importer_pk):
"""Import a Pulp export into Pulp."""
Expand All @@ -102,11 +103,15 @@ def create(self, request, importer_pk):

serializer = PulpImportSerializer(data=request.data, context={"request": request})
serializer.is_valid(raise_exception=True)

path = serializer.validated_data.get("path")
toc = serializer.validated_data.get("toc")
task = dispatch(
task_group = TaskGroup.objects.create(description=f"Import of {path}")

dispatch(
pulp_import,
exclusive_resources=[importer],
task_group=task_group,
kwargs={"importer_pk": importer.pk, "path": path, "toc": toc},
)
return OperationPostponedResponse(task, request)
return TaskGroupOperationResponse(task_group, request)
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,7 @@ def _perform_import(self, importer, chunked=False, an_export=None):
else:
filenames = [f for f in list(an_export.output_file_info.keys()) if f.endswith("tar.gz")]
import_response = self.imports_api.create(importer.pulp_href, {"path": filenames[0]})
monitor_task(import_response.task)
task = self.client.get(import_response.task)
resources = task["created_resources"]
task_group_href = resources[1]
task_group = monitor_task_group(task_group_href)
task_group = monitor_task_group(import_response.task_group)

return task_group

Expand Down