|
7 | 7 | from django.db.models import Min |
8 | 8 | from pulp_glue.common import __version__ as pulp_glue_version |
9 | 9 | from pulp_glue.common.context import PluginRequirement |
| 10 | +from pulp_glue.common.exceptions import PulpException as GluePulpException |
10 | 11 |
|
11 | 12 | from pulpcore.app.apps import PulpAppConfig, pulp_plugin_configs |
12 | 13 | from pulpcore.app.models import Distribution, Repository, Task, TaskGroup, UpstreamPulp |
13 | 14 | from pulpcore.app.replica import ReplicaContext |
14 | 15 | from pulpcore.constants import TASK_STATES |
| 16 | +from pulpcore.exceptions import ExternalServiceError |
15 | 17 | from pulpcore.tasking.tasks import dispatch |
16 | 18 |
|
17 | 19 |
|
@@ -66,47 +68,52 @@ def replicate_distributions(server_pk): |
66 | 68 | "client_key": server.client_key, |
67 | 69 | } |
68 | 70 |
|
69 | | - task_group = TaskGroup.current() |
70 | | - supported_replicators = [] |
71 | | - # Load all the available replicators |
72 | | - for config in pulp_plugin_configs(): |
73 | | - if config.replicator_classes: |
74 | | - for replicator_class in config.replicator_classes: |
75 | | - req = PluginRequirement(config.label, specifier=replicator_class.required_version) |
76 | | - if ctx.has_plugin(req): |
77 | | - replicator = replicator_class(ctx, task_group, tls_settings, server) |
78 | | - supported_replicators.append(replicator) |
79 | | - |
80 | | - distro_repo_pairs = [] |
81 | | - for replicator in supported_replicators: |
82 | | - distros = replicator.upstream_distributions(q=server.q_select) |
83 | | - distro_names = [] |
84 | | - for distro in distros: |
85 | | - # Create remote |
86 | | - remote = replicator.create_or_update_remote(upstream_distribution=distro) |
87 | | - if not remote: |
88 | | - # The upstream distribution is not serving any content, |
89 | | - # let if fall through the cracks and be cleanup below. |
90 | | - continue |
91 | | - # Check if there is already a repository |
92 | | - repository = replicator.create_or_update_repository(remote=remote) |
93 | | - if not repository: |
94 | | - # No update occurred because server.policy==LABELED and there was |
95 | | - # an already existing local repository with the same name |
96 | | - continue |
97 | | - |
98 | | - # Dispatch a sync task if needed |
99 | | - if replicator.requires_syncing(distro): |
100 | | - replicator.sync(repository, remote) |
101 | | - |
102 | | - # Get or create a distribution |
103 | | - replicator.create_or_update_distribution(repository, distro) |
104 | | - |
105 | | - # Add name to the list of known distribution names |
106 | | - distro_names.append(distro["name"]) |
107 | | - distro_repo_pairs.append((distro["name"], str(repository.pk))) |
108 | | - |
109 | | - replicator.remove_missing(distro_names) |
| 71 | + try: |
| 72 | + task_group = TaskGroup.current() |
| 73 | + supported_replicators = [] |
| 74 | + # Load all the available replicators |
| 75 | + for config in pulp_plugin_configs(): |
| 76 | + if config.replicator_classes: |
| 77 | + for replicator_class in config.replicator_classes: |
| 78 | + req = PluginRequirement( |
| 79 | + config.label, specifier=replicator_class.required_version |
| 80 | + ) |
| 81 | + if ctx.has_plugin(req): |
| 82 | + replicator = replicator_class(ctx, task_group, tls_settings, server) |
| 83 | + supported_replicators.append(replicator) |
| 84 | + |
| 85 | + distro_repo_pairs = [] |
| 86 | + for replicator in supported_replicators: |
| 87 | + distro_names = [] |
| 88 | + distros = replicator.upstream_distributions(q=server.q_select) |
| 89 | + for distro in distros: |
| 90 | + # Create remote |
| 91 | + remote = replicator.create_or_update_remote(upstream_distribution=distro) |
| 92 | + if not remote: |
| 93 | + # The upstream distribution is not serving any content, |
| 94 | + # let if fall through the cracks and be cleanup below. |
| 95 | + continue |
| 96 | + # Check if there is already a repository |
| 97 | + repository = replicator.create_or_update_repository(remote=remote) |
| 98 | + if not repository: |
| 99 | + # No update occurred because server.policy==LABELED and there was |
| 100 | + # an already existing local repository with the same name |
| 101 | + continue |
| 102 | + |
| 103 | + # Dispatch a sync task if needed |
| 104 | + if replicator.requires_syncing(distro): |
| 105 | + replicator.sync(repository, remote) |
| 106 | + |
| 107 | + # Get or create a distribution |
| 108 | + replicator.create_or_update_distribution(repository, distro) |
| 109 | + |
| 110 | + # Add name to the list of known distribution names |
| 111 | + distro_names.append(distro["name"]) |
| 112 | + distro_repo_pairs.append((distro["name"], str(repository.pk))) |
| 113 | + |
| 114 | + replicator.remove_missing(distro_names) |
| 115 | + except GluePulpException as e: |
| 116 | + raise ExternalServiceError(service_name=server.base_url, details=str(e)) |
110 | 117 |
|
111 | 118 | dispatch( |
112 | 119 | finalize_replication, |
|
0 commit comments