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

Refactor Exporter models based on pulpcore changes #366

Merged
merged 1 commit into from
Mar 24, 2020
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/6328.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added history for filesystem exports at ``/exporters/file/filesystem/<uuid>/exports/``.
5 changes: 5 additions & 0 deletions CHANGES/6328.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The fileystem exporter endpoint has been moved from ``/exporters/file/file/`` to
``/exporters/file/filesystem/`` and the export endpoint is now at POST
``/exporters/file/filesystem/<uuid>/exports/``. Additionally, the table is being dropped and
recreated due to a data structure change in core so users will lose any filesystem exporter data on
upgrade.
16 changes: 16 additions & 0 deletions docs/_scripts/export.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
export EXPORTER_NAME=$(head /dev/urandom | tr -dc a-z | head -c5)
export DEST_DIR="/data"

echo "Created a new file system exporter $EXPORTER_NAME."
export EXPORTER_HREF=$(http POST $BASE_ADDR/pulp/api/v3/exporters/file/filesystem/ \
name=$EXPORTER_NAME path=$DEST_DIR | jq -r '.pulp_href')

export TASK_URL=$(http POST $BASE_ADDR$EXPORTER_HREF'exports/' publication=$PUBLICATION_HREF
| jq -r '.task')

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
wait_until_task_finished $BASE_ADDR$TASK_URL

echo "Inspecting export at $DEST_DIR"
ls $DEST_DIR
14 changes: 5 additions & 9 deletions pulp_file/app/migrations/0004_filefilesystemexporter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Generated by Django 2.2.6 on 2019-11-04 20:00

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations

# Note: This migration was throwing exceptions so all of the fields/etc were removed.
# The table gets deleted later in 0006_delete_filefilesystemexporter.py.


class Migration(migrations.Migration):
Expand All @@ -14,12 +16,6 @@ class Migration(migrations.Migration):
operations = [
migrations.CreateModel(
name='FileFileSystemExporter',
fields=[
('filesystemexporter_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='file_filefilesystemexporter', serialize=False, to='core.FileSystemExporter')),
],
options={
'default_related_name': '%(app_label)s_%(model_name)s',
},
bases=('core.filesystemexporter',),
fields=[],
),
]
16 changes: 16 additions & 0 deletions pulp_file/app/migrations/0006_delete_filefilesystemexporter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 2.2.6 on 2020-03-13 16:18

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('file', '0005_filerepository'),
]

operations = [
migrations.DeleteModel(
name='FileFileSystemExporter',
),
]
26 changes: 26 additions & 0 deletions pulp_file/app/migrations/0007_filefilesystemexporter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 2.2.6 on 2020-03-17 13:07

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('core', '0023_change_exporter_models'),
('file', '0006_delete_filefilesystemexporter'),
]

operations = [
migrations.CreateModel(
name='FileFileSystemExporter',
fields=[
('exporter_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='file_filefilesystemexporter', serialize=False, to='core.Exporter')),
('path', models.TextField()),
],
options={
'default_related_name': '%(app_label)s_%(model_name)s',
},
bases=('core.exporter',),
),
]
6 changes: 3 additions & 3 deletions pulp_file/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pulpcore.plugin.models import (
Content,
FileSystemPublicationExporter,
FileSystemExporter,
Publication,
PublicationDistribution,
Remote,
Expand Down Expand Up @@ -106,12 +106,12 @@ class Meta:
default_related_name = "%(app_label)s_%(model_name)s"


class FileFileSystemExporter(FileSystemPublicationExporter):
class FileFileSystemExporter(FileSystemExporter):
"""
File system exporter for 'file' content.
"""

TYPE = "file"
TYPE = "filesystem"

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
1 change: 0 additions & 1 deletion pulp_file/app/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from .exporting import file_export # noqa
from .publishing import publish # noqa
from .synchronizing import synchronize # noqa
31 changes: 0 additions & 31 deletions pulp_file/app/tasks/exporting.py

This file was deleted.

30 changes: 22 additions & 8 deletions pulp_file/app/viewsets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.http import Http404
from django_filters import CharFilter
from drf_yasg.utils import swagger_auto_schema
from rest_framework.decorators import action
Expand All @@ -8,11 +9,12 @@
PublicationExportSerializer,
RepositorySyncURLSerializer,
)
from pulpcore.plugin.tasking import enqueue_with_reservation
from pulpcore.plugin.tasking import enqueue_with_reservation, fs_publication_export
from pulpcore.plugin.viewsets import (
BaseDistributionViewSet,
ContentFilter,
FileSystemExporterViewSet,
ExporterViewSet,
ExportViewSet,
OperationPostponedResponse,
PublicationViewSet,
RemoteViewSet,
Expand Down Expand Up @@ -178,35 +180,47 @@ class FileDistributionViewSet(BaseDistributionViewSet):
serializer_class = FileDistributionSerializer


class FileFileSystemExporterViewSet(FileSystemExporterViewSet):
class FileFileSystemExporterViewSet(ExporterViewSet):
"""
FileSystemExporters export content from a publication to a path on the file system.

WARNING: This feature is provided as a tech preview and may change in the future. Backwards
compatibility is not guaranteed.
"""

endpoint_name = "file"
endpoint_name = "filesystem"
Copy link
Member

Choose a reason for hiding this comment

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

👍

queryset = FileFileSystemExporter.objects.all()
serializer_class = FileFileSystemExporterSerializer


class FileFileSystemExportViewSet(ExportViewSet):
"""
FileSystemExports provide a history of previous exports.
"""

parent_viewset = FileFileSystemExporterViewSet

@swagger_auto_schema(
request_body=PublicationExportSerializer,
operation_description="Trigger an asynchronous task to export a file publication.",
responses={202: AsyncOperationResponseSerializer},
)
@action(detail=True, methods=["post"], serializer_class=PublicationExportSerializer)
def export(self, request, pk):
def create(self, request, exporter_pk):
"""
Export a publication to the file system.

The ``repository`` field has to be provided.
"""
exporter = self.get_object()
try:
exporter = FileFileSystemExporter.objects.get(pk=exporter_pk)
except FileFileSystemExporter.DoesNotExist:
raise Http404

serializer = PublicationExportSerializer(data=request.data, context={"request": request})
serializer.is_valid(raise_exception=True)
publication = serializer.validated_data.get("publication")
result = enqueue_with_reservation(
tasks.file_export,
fs_publication_export,
[publication, exporter],
kwargs={"exporter_pk": exporter.pk, "publication_pk": publication.pk},
)
Expand Down