Skip to content

Commit

Permalink
Fix plugin API 0.01b18 compat.
Browse files Browse the repository at this point in the history
closes #4381
  • Loading branch information
jortel committed Feb 5, 2019
1 parent 48a05bf commit cee12d2
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 174 deletions.
23 changes: 5 additions & 18 deletions pulp_docker/app/models.py
Expand Up @@ -22,20 +22,7 @@
)


class SingleArtifact:
"""
Mixin for Content with only 1 artifact.
"""

@property
def _artifact(self):
"""
Return the artifact (there is only one for this content type).
"""
return self._artifacts.get()


class ManifestBlob(Content, SingleArtifact):
class ManifestBlob(Content):
"""
A blob defined within a manifest.
Expand Down Expand Up @@ -64,7 +51,7 @@ class Meta:
unique_together = ('digest',)


class ImageManifest(Content, SingleArtifact):
class ImageManifest(Content):
"""
A docker manifest.
Expand Down Expand Up @@ -95,7 +82,7 @@ class Meta:
unique_together = ('digest',)


class ManifestList(Content, SingleArtifact):
class ManifestList(Content):
"""
A manifest list.
Expand Down Expand Up @@ -173,7 +160,7 @@ class Meta:
unique_together = ('manifest', 'manifest_list')


class ManifestTag(Content, SingleArtifact):
class ManifestTag(Content):
"""
A tagged Manifest.
Expand All @@ -198,7 +185,7 @@ class Meta:
)


class ManifestListTag(Content, SingleArtifact):
class ManifestListTag(Content):
"""
A tagged Manifest List.
Expand Down
5 changes: 3 additions & 2 deletions pulp_docker/app/registry.py
Expand Up @@ -194,8 +194,9 @@ async def dispatch_tag(tag, response_headers):
streamed back to the client.
"""
artifact = tag._artifact
if not artifact:
try:
artifact = tag._artifacts.get()
except ObjectDoesNotExist:
raise ArtifactNotFound(tag.name)
else:
return await Registry._dispatch(artifact.file.name, response_headers)
Expand Down
110 changes: 55 additions & 55 deletions pulp_docker/app/serializers.py
Expand Up @@ -7,132 +7,132 @@
from rest_framework import serializers
from rest_framework.validators import UniqueValidator

from pulpcore.plugin import serializers as platform
from pulpcore.plugin.models import Artifact, Publication, Repository
from pulpcore.plugin.serializers import (
DetailRelatedField,
IdentityField,
ModelSerializer,
PublisherSerializer,
RelatedField,
RemoteSerializer,
SingleArtifactContentSerializer,
)
from pulpcore.plugin.models import Publication, Repository

from . import models


class MinimalArtifactSerializer(platform.ArtifactSerializer):
"""
Serialize Artifacts associated with Docker Content.
We overrided the platform serializer because it does not include size, and includes digest.
Since digest is a field on the content units, it would be redundant.
"""

class Meta:
fields = ('size', '_href')
model = Artifact


class ManifestListTagSerializer(platform.ContentSerializer):
class ManifestListTagSerializer(SingleArtifactContentSerializer):
"""
Serializer for ManifestListTags.
"""

name = serializers.CharField(help_text="Tag name")
manifest_list = platform.DetailRelatedField(
manifest_list = DetailRelatedField(
many=False,
help_text="Manifest List that is tagged",
view_name='docker-manifest-lists-detail',
queryset=models.ManifestList.objects.all()
)
_artifact = MinimalArtifactSerializer(many=False, help_text="File related to this content")

class Meta:
fields = tuple(
set(platform.ContentSerializer.Meta.fields) - {'_artifacts'}
) + ('name', 'manifest_list', '_artifact')
fields = SingleArtifactContentSerializer.Meta.fields + (
'name',
'manifest_list',
)
model = models.ManifestListTag


class ManifestTagSerializer(platform.ContentSerializer):
class ManifestTagSerializer(SingleArtifactContentSerializer):
"""
Serializer for ManifestTags.
"""

name = serializers.CharField(help_text="Tag name")
manifest = platform.DetailRelatedField(
manifest = DetailRelatedField(
many=False,
help_text="Manifest that is tagged",
view_name='docker-manifests-detail',
queryset=models.ImageManifest.objects.all()
)
_artifact = MinimalArtifactSerializer(many=False, help_text="File related to this content")

class Meta:
fields = tuple(
set(platform.ContentSerializer.Meta.fields) - {'_artifacts'}
) + ('name', 'manifest', '_artifact')
fields = SingleArtifactContentSerializer.Meta.fields + (
'name',
'manifest',
)
model = models.ManifestTag


class ManifestListSerializer(platform.ContentSerializer):
class ManifestListSerializer(SingleArtifactContentSerializer):
"""
Serializer for ManifestLists.
"""

digest = serializers.CharField(help_text="sha256 of the ManifestList file")
schema_version = serializers.IntegerField(help_text="Docker schema version")
media_type = serializers.CharField(help_text="Docker media type of the file")
manifests = platform.DetailRelatedField(
manifests = DetailRelatedField(
many=True,
help_text="Manifests that are referenced by this Manifest List",
view_name='docker-manifests-detail',
queryset=models.ImageManifest.objects.all()
)
_artifact = MinimalArtifactSerializer(many=False, help_text="File related to this content")

class Meta:
fields = tuple(
set(platform.ContentSerializer.Meta.fields) - {'_artifacts'}
) + ('digest', 'schema_version', 'media_type', 'manifests', '_artifact')
fields = SingleArtifactContentSerializer.Meta.fields + (
'digest',
'schema_version',
'media_type',
'manifests',
)
model = models.ManifestList


class ManifestSerializer(platform.ContentSerializer):
class ManifestSerializer(SingleArtifactContentSerializer):
"""
Serializer for Manifests.
"""

digest = serializers.CharField(help_text="sha256 of the Manifest file")
schema_version = serializers.IntegerField(help_text="Docker schema version")
media_type = serializers.CharField(help_text="Docker media type of the file")
blobs = platform.DetailRelatedField(
blobs = DetailRelatedField(
many=True,
help_text="Blobs that are referenced by this Manifest",
view_name='docker-blobs-detail',
queryset=models.ManifestBlob.objects.all()
)
config_blob = platform.DetailRelatedField(
config_blob = DetailRelatedField(
many=False,
help_text="Blob that contains configuration for this Manifest",
view_name='docker-blobs-detail',
queryset=models.ManifestBlob.objects.all()
)
_artifact = MinimalArtifactSerializer(many=False, help_text="File related to this content")

class Meta:
fields = tuple(
set(platform.ContentSerializer.Meta.fields) - {'_artifacts'}
) + ('digest', 'schema_version', 'media_type', 'blobs', 'config_blob', '_artifact')
fields = SingleArtifactContentSerializer.Meta.fields + (
'digest',
'schema_version',
'media_type',
'blobs',
'config_blob',
)
model = models.ImageManifest


class BlobSerializer(platform.ContentSerializer):
class BlobSerializer(SingleArtifactContentSerializer):
"""
Serializer for Blobs.
"""

digest = serializers.CharField(help_text="sha256 of the Blob file")
media_type = serializers.CharField(help_text="Docker media type of the file")
_artifact = MinimalArtifactSerializer(many=False, help_text="File related to this content")

class Meta:
fields = tuple(
set(platform.ContentSerializer.Meta.fields) - {'_artifacts'}
) + ('digest', 'media_type', '_artifact')
fields = SingleArtifactContentSerializer.Meta.fields + (
'digest',
'media_type',
)
model = models.ManifestBlob


Expand All @@ -152,7 +152,7 @@ def to_representation(self, value):
return ''.join([host, '/', value])


class DockerRemoteSerializer(platform.RemoteSerializer):
class DockerRemoteSerializer(RemoteSerializer):
"""
A Serializer for DockerRemote.
Expand All @@ -173,11 +173,11 @@ class Meta:
)

class Meta:
fields = platform.RemoteSerializer.Meta.fields + ('upstream_name',)
fields = RemoteSerializer.Meta.fields + ('upstream_name',)
model = models.DockerRemote


class DockerPublisherSerializer(platform.PublisherSerializer):
class DockerPublisherSerializer(PublisherSerializer):
"""
A Serializer for DockerPublisher.
Expand All @@ -192,16 +192,16 @@ class Meta:
"""

class Meta:
fields = platform.PublisherSerializer.Meta.fields
fields = PublisherSerializer.Meta.fields
model = models.DockerPublisher


class DockerDistributionSerializer(platform.ModelSerializer):
class DockerDistributionSerializer(ModelSerializer):
"""
A serializer for DockerDistribution.
"""

_href = platform.IdentityField(
_href = IdentityField(
view_name='docker-distributions-detail'
)
name = serializers.CharField(
Expand All @@ -224,21 +224,21 @@ class DockerDistributionSerializer(platform.ModelSerializer):
UniqueValidator(queryset=models.DockerDistribution.objects.all()),
]
)
publisher = platform.DetailRelatedField(
publisher = DetailRelatedField(
required=False,
help_text=_('Publications created by this publisher and repository are automatically'
'served as defined by this distribution'),
queryset=models.DockerPublisher.objects.all(),
allow_null=True
)
publication = platform.RelatedField(
publication = RelatedField(
required=False,
help_text=_('The publication being served as defined by this distribution'),
queryset=Publication.objects.exclude(complete=False),
view_name='publications-detail',
allow_null=True
)
repository = platform.RelatedField(
repository = RelatedField(
required=False,
help_text=_('Publications created by this repository and publisher are automatically'
'served as defined by this distribution'),
Expand All @@ -254,7 +254,7 @@ class DockerDistributionSerializer(platform.ModelSerializer):

class Meta:
model = models.DockerDistribution
fields = platform.ModelSerializer.Meta.fields + (
fields = ModelSerializer.Meta.fields + (
'name',
'base_path',
'publisher',
Expand Down
21 changes: 5 additions & 16 deletions pulp_docker/app/tasks/dedupe_save.py
Expand Up @@ -20,35 +20,24 @@ class SerialContentSave(Stage):
Save Content one at a time, combining duplicates.
"""

async def __call__(self, in_q, out_q):
async def run(self):
"""
The coroutine for this stage.
Args:
in_q (:class:`asyncio.Queue`): The queue to receive
:class:`~pulpcore.plugin.stages.DeclarativeContent` objects from.
out_q (:class:`asyncio.Queue`): The queue to put
:class:`~pulpcore.plugin.stages.DeclarativeContent` into.
Returns:
The coroutine for this stage.
"""
while True:
dc = await in_q.get()
# finished
if dc is None:
break

async for dc in self.items():
# Do not save Content that contains Artifacts which have not been downloaded
if not self.settled(dc):
await out_q.put(dc)
await self.put(dc)
# already saved
elif dc.content.pk is not None:
await out_q.put(dc)
await self.put(dc)
else:
self.save_and_dedupe_content(dc)
await out_q.put(dc)
await out_q.put(None)
await self.put(dc)

def save_and_dedupe_content(self, dc):
"""
Expand Down

0 comments on commit cee12d2

Please sign in to comment.