Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Ensure that only one migration plan can be run at a time.
Browse files Browse the repository at this point in the history
  • Loading branch information
ipanova committed May 19, 2020
1 parent f917fe6 commit 8b2fec7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/6639.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure that only one migration plan can be run at a time.
19 changes: 19 additions & 0 deletions pulp_2to3_migration/app/viewsets.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from django_filters.rest_framework import filters
from gettext import gettext as _

from drf_yasg.utils import swagger_auto_schema
from rest_framework import mixins
from rest_framework.decorators import action
from rest_framework.serializers import ValidationError

from pulpcore.app.viewsets.base import DATETIME_FILTER_OPTIONS
from pulpcore.app.viewsets.custom_filters import (
HyperlinkRelatedFilter,
IsoDateTimeFilter
)

from pulpcore.plugin.models import Task
from pulpcore.plugin.serializers import AsyncOperationResponseSerializer
from pulpcore.plugin.tasking import enqueue_with_reservation
from pulpcore.plugin.viewsets import (
Expand Down Expand Up @@ -57,6 +61,21 @@ def run(self, request, pk):
validate = serializer.validated_data.get('validate', False)
dry_run = serializer.validated_data.get('dry_run', False)

# find running/waiting migration plugin tasks
qs = Task.objects.filter(state__in=['waiting', 'running'],
reserved_resources_record__resource='pulp_2to3_migration')
if qs:
raise ValidationError(_("Only one migration plan can run at a time"))
groups_with_running_tasks = Task.objects.filter(
state__in=['waiting', 'running'],
task_group__isnull=False).values_list('task_group_id', flat=True)
groups_with_migration_tasks = Task.objects.filter(
task_group__isnull=False,
reserved_resources_record__resource='pulp_2to3_migration').values_list(
'task_group_id', flat=True)
if groups_with_running_tasks.intersection(groups_with_migration_tasks):
raise ValidationError(_("Only one migration plan can run at a time"))

result = enqueue_with_reservation(
migrate_from_pulp2,
[PULP_2TO3_MIGRATION_RESOURCE],
Expand Down

0 comments on commit 8b2fec7

Please sign in to comment.