AdHocCommand support added to task manager

This commit is contained in:
Chris Meyers
2016-10-25 10:11:11 -04:00
parent 46faeffbb3
commit 9802b1f379
4 changed files with 29 additions and 11 deletions

View File

@@ -25,6 +25,7 @@ from awx.main.scheduler.partial import (
InventoryUpdateLatestDict,
InventorySourceDict,
SystemJobDict,
AdHocCommandDict,
)
# Celery
@@ -42,15 +43,11 @@ class Scheduler():
status_list = ('pending', 'waiting', 'running')
jobs = JobDict.filter_partial(status=status_list)
'''
graph_ad_hoc_commands = [ahc for ahc in AdHocCommand.objects.filter(**kv)]
'''
inventory_updates = InventoryUpdateDict.filter_partial(status=status_list)
project_updates = ProjectUpdateDict.filter_partial(status=status_list)
system_jobs = SystemJobDict.filter_partial(status=status_list)
ad_hoc_commands = AdHocCommandDict.filter_partial(status=status_list)
'''
graph_system_jobs = [sj for sj in
SystemJob.objects.filter(**kv)]
graph_workflow_jobs = [wf for wf in
WorkflowJob.objects.filter(**kv)]
all_actions = sorted(graph_jobs + graph_ad_hoc_commands + graph_inventory_updates +
@@ -58,7 +55,7 @@ class Scheduler():
graph_workflow_jobs,
key=lambda task: task.created)
'''
all_actions = sorted(jobs + project_updates + inventory_updates + system_jobs,
all_actions = sorted(jobs + project_updates + inventory_updates + system_jobs + ad_hoc_commands,
key=lambda task: task['created'])
return all_actions
@@ -236,7 +233,7 @@ class Scheduler():
map(lambda task: self.graph.add_latest_inventory_update(task), latest_inventory_updates)
def process_inventory_sources(self, inventory_id_sources):
map(lambda inventory_id, inventory_sources: self.graph.add_inventory_sources(inventory_id, inventory_sources), inventory_id_sources)
map(lambda (inventory_id, inventory_sources): self.graph.add_inventory_sources(inventory_id, inventory_sources), inventory_id_sources)
def process_dependencies(self, dependent_task, dependency_tasks):
for task in dependency_tasks:

View File

@@ -6,6 +6,7 @@ from awx.main.scheduler.partial import (
ProjectUpdateDict,
InventoryUpdateDict,
SystemJobDict,
AdHocCommandDict,
)
class DependencyGraph(object):
PROJECT_UPDATES = 'project_updates'
@@ -140,8 +141,8 @@ class DependencyGraph(object):
def can_project_update_run(self, job):
return self.data[self.PROJECT_UPDATES].get(job['project_id'], True)
def can_inventory_update_run(self, inventory_source_id):
return self.data[self.INVENTORY_SOURCE_UPDATES].get(inventory_source_id, True)
def can_inventory_update_run(self, job):
return self.data[self.INVENTORY_SOURCE_UPDATES].get(job['inventory_source_id'], True)
def can_job_run(self, job):
if self.can_project_update_run(job) is True and \
@@ -155,15 +156,20 @@ class DependencyGraph(object):
def can_system_job_run(self):
return self.data[self.SYSTEM_JOB]
def can_ad_hoc_command_run(self, job):
return self.data[self.INVENTORY_UPDATES].get(job['inventory_id'], True)
def is_job_blocked(self, job):
if type(job) is ProjectUpdateDict:
return not self.can_project_update_run(job)
elif type(job) is InventoryUpdateDict:
return not self.can_inventory_update_run(job['inventory_source_id'])
return not self.can_inventory_update_run(job)
elif type(job) is JobDict:
return not self.can_job_run(job)
elif type(job) is SystemJobDict:
return not self.can_system_job_run()
elif type(job) is AdHocCommandDict:
return not self.can_ad_hoc_command_run(job)
def add_job(self, job):
if type(job) is ProjectUpdateDict:
@@ -175,6 +181,8 @@ class DependencyGraph(object):
self.mark_job_template_job(job)
elif type(job) is SystemJobDict:
self.mark_system_job()
elif type(job) is AdHocCommandDict:
self.mark_inventory_update(job['inventory_id'])
def add_jobs(self, jobs):
map(lambda j: self.add_job(j), jobs)

View File

@@ -6,6 +6,7 @@ from awx.main.models import (
InventoryUpdate,
InventorySource,
SystemJob,
AdHocCommand,
)
class PartialModelDict(object):
@@ -192,3 +193,15 @@ class SystemJobDict(PartialModelDict):
}
return [cls(o) for o in cls.model.objects.filter(**kv).values(*cls.get_db_values())]
class AdHocCommandDict(PartialModelDict):
FIELDS = (
'id', 'created', 'status', 'inventory_id',
)
model = AdHocCommand
def get_job_type_str(self):
return 'ad_hoc_command'
def task_impact(self):
return 20

View File

@@ -1756,7 +1756,7 @@ class RunAdHocCommand(BaseTask):
'''
Hook for actions to run after ad hoc command has completed.
'''
super(RunAdHocCommand, self).post_run_hook(ad_hoc_command, **kwargs)
super(RunAdHocCommand, self).post_run_hook(ad_hoc_command, status, **kwargs)
class RunSystemJob(BaseTask):