mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 23:46:05 -03:30
Implement model/view/launch paradigm for shard/split job templates
This commit is contained in:
committed by
AlanCoding
parent
89c2038ea3
commit
0b1776098b
@@ -277,6 +277,12 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, SurveyJobTemplateMixin, Resour
|
||||
default=False,
|
||||
allows_field='credentials'
|
||||
)
|
||||
job_shard_count = models.IntegerField(
|
||||
blank=True,
|
||||
default=0,
|
||||
help_text=_("The number of jobs to split into at runtime. Will cause the Job Template to launch a workflow."),
|
||||
)
|
||||
|
||||
admin_role = ImplicitRoleField(
|
||||
parent_role=['project.organization.job_template_admin_role', 'inventory.organization.job_template_admin_role']
|
||||
)
|
||||
@@ -318,6 +324,11 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, SurveyJobTemplateMixin, Resour
|
||||
'''
|
||||
Create a new job based on this template.
|
||||
'''
|
||||
if self.job_shard_count > 1:
|
||||
# A sharded Job Template will generate a WorkflowJob rather than a Job
|
||||
from awx.main.models.workflow import WorkflowJobTemplate
|
||||
kwargs['_unified_job_class'] = WorkflowJobTemplate._get_unified_job_class()
|
||||
kwargs['_unified_job_field_names'] = WorkflowJobTemplate._get_unified_job_field_names()
|
||||
return self.create_unified_job(**kwargs)
|
||||
|
||||
def get_absolute_url(self, request=None):
|
||||
|
||||
@@ -328,6 +328,8 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
|
||||
'''
|
||||
Create a new unified job based on this unified job template.
|
||||
'''
|
||||
from awx.main.models import JobTemplate, WorkflowJob
|
||||
|
||||
new_job_passwords = kwargs.pop('survey_passwords', {})
|
||||
eager_fields = kwargs.pop('_eager_fields', None)
|
||||
|
||||
@@ -336,8 +338,10 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
|
||||
password_list = self.survey_password_variables()
|
||||
encrypt_dict(kwargs.get('extra_vars', {}), password_list)
|
||||
|
||||
unified_job_class = self._get_unified_job_class()
|
||||
fields = self._get_unified_job_field_names()
|
||||
unified_job_class = kwargs.pop("_unified_job_class", self._get_unified_job_class())
|
||||
fields = kwargs.pop("_unified_job_field_names", self._get_unified_job_field_names())
|
||||
print("UJC: {}".format(unified_job_class))
|
||||
print("fields: {}".format(fields))
|
||||
unallowed_fields = set(kwargs.keys()) - set(fields)
|
||||
if unallowed_fields:
|
||||
logger.warn('Fields {} are not allowed as overrides.'.format(unallowed_fields))
|
||||
@@ -350,7 +354,11 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
|
||||
setattr(unified_job, fd, val)
|
||||
|
||||
# Set the unified job template back-link on the job
|
||||
parent_field_name = unified_job_class._get_parent_field_name()
|
||||
# TODO: fix this hack properly before merge matburt
|
||||
if isinstance(self, JobTemplate) and isinstance(unified_job, WorkflowJob):
|
||||
parent_field_name = "job_template"
|
||||
else:
|
||||
parent_field_name = unified_job_class._get_parent_field_name()
|
||||
setattr(unified_job, parent_field_name, self)
|
||||
|
||||
# For JobTemplate-based jobs with surveys, add passwords to list for perma-redaction
|
||||
|
||||
@@ -433,6 +433,14 @@ class WorkflowJob(UnifiedJob, WorkflowJobOptions, SurveyJobMixin, JobNotificatio
|
||||
default=None,
|
||||
on_delete=models.SET_NULL,
|
||||
)
|
||||
job_template = models.ForeignKey(
|
||||
'JobTemplate',
|
||||
related_name='sharded_jobs',
|
||||
blank=True,
|
||||
null=True,
|
||||
default=None,
|
||||
on_delete=models.SET_NULL,
|
||||
)
|
||||
|
||||
@property
|
||||
def workflow_nodes(self):
|
||||
|
||||
Reference in New Issue
Block a user