mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 04:47:44 -02:30
Implement gathering overall task capacity
For use when running/planning jobs
This commit is contained in:
@@ -178,7 +178,7 @@ class ApiV1PingView(APIView):
|
|||||||
|
|
||||||
response['instances'] = []
|
response['instances'] = []
|
||||||
for instance in Instance.objects.all():
|
for instance in Instance.objects.all():
|
||||||
response['instances'].append(dict(node=instance.hostname, heartbeat=instance.modified))
|
response['instances'].append(dict(node=instance.hostname, heartbeat=instance.modified, capacity=instance.capacity))
|
||||||
response['instances'].sort()
|
response['instances'].sort()
|
||||||
return Response(response)
|
return Response(response)
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.models import Sum
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
@@ -40,6 +41,9 @@ class InstanceManager(models.Manager):
|
|||||||
"""Return count of active Tower nodes for licensing."""
|
"""Return count of active Tower nodes for licensing."""
|
||||||
return self.all().count()
|
return self.all().count()
|
||||||
|
|
||||||
|
def total_capacity(self):
|
||||||
|
return self.aggregate(total_capacity=Sum('capacity'))['total_capacity']
|
||||||
|
|
||||||
def my_role(self):
|
def my_role(self):
|
||||||
# NOTE: TODO: Likely to repurpose this once standalone ramparts are a thing
|
# NOTE: TODO: Likely to repurpose this once standalone ramparts are a thing
|
||||||
return "tower"
|
return "tower"
|
||||||
|
|||||||
19
awx/main/migrations/0048_310_instance_capacity.py
Normal file
19
awx/main/migrations/0048_310_instance_capacity.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0047_v310_tower_state'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='instance',
|
||||||
|
name='capacity',
|
||||||
|
field=models.PositiveIntegerField(default=100, editable=False),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -26,6 +26,10 @@ class Instance(models.Model):
|
|||||||
hostname = models.CharField(max_length=250, unique=True)
|
hostname = models.CharField(max_length=250, unique=True)
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
modified = models.DateTimeField(auto_now=True)
|
modified = models.DateTimeField(auto_now=True)
|
||||||
|
capacity = models.PositiveIntegerField(
|
||||||
|
default=100,
|
||||||
|
editable=False,
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
app_label = 'main'
|
app_label = 'main'
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ logger = logging.getLogger('awx.main.scheduler')
|
|||||||
class TaskManager():
|
class TaskManager():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.graph = DependencyGraph()
|
self.graph = DependencyGraph()
|
||||||
self.capacity_total = 200
|
self.capacity_total = Instance.objects.total_capacity()
|
||||||
self.capacity_used = 0
|
self.capacity_used = 0
|
||||||
|
|
||||||
def get_tasks(self):
|
def get_tasks(self):
|
||||||
@@ -152,7 +152,7 @@ class TaskManager():
|
|||||||
map(lambda at: active_tasks.add(at['id']), active_task_queues[queue])
|
map(lambda at: active_tasks.add(at['id']), active_task_queues[queue])
|
||||||
else:
|
else:
|
||||||
if not hasattr(settings, 'CELERY_UNIT_TEST'):
|
if not hasattr(settings, 'CELERY_UNIT_TEST'):
|
||||||
return None
|
return (None, None)
|
||||||
|
|
||||||
return (active_task_queues, active_tasks)
|
return (active_task_queues, active_tasks)
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ from awx.main.queue import CallbackQueueDispatcher
|
|||||||
from awx.main.task_engine import TaskEnhancer
|
from awx.main.task_engine import TaskEnhancer
|
||||||
from awx.main.utils import (get_ansible_version, get_ssh_version, decrypt_field, update_scm_url,
|
from awx.main.utils import (get_ansible_version, get_ssh_version, decrypt_field, update_scm_url,
|
||||||
check_proot_installed, build_proot_temp_dir, wrap_args_with_proot,
|
check_proot_installed, build_proot_temp_dir, wrap_args_with_proot,
|
||||||
OutputEventFilter)
|
get_system_task_capacity, OutputEventFilter)
|
||||||
from awx.main.consumers import emit_channel_notification
|
from awx.main.consumers import emit_channel_notification
|
||||||
|
|
||||||
__all__ = ['RunJob', 'RunSystemJob', 'RunProjectUpdate', 'RunInventoryUpdate',
|
__all__ = ['RunJob', 'RunSystemJob', 'RunProjectUpdate', 'RunInventoryUpdate',
|
||||||
@@ -131,6 +131,7 @@ def cluster_node_heartbeat(self):
|
|||||||
inst = Instance.objects.filter(hostname=settings.CLUSTER_HOST_ID)
|
inst = Instance.objects.filter(hostname=settings.CLUSTER_HOST_ID)
|
||||||
if inst.exists():
|
if inst.exists():
|
||||||
inst = inst[0]
|
inst = inst[0]
|
||||||
|
inst.capacity = get_system_task_capacity()
|
||||||
inst.save()
|
inst.save()
|
||||||
return
|
return
|
||||||
raise RuntimeError("Cluster Host Not Found: {}".format(settings.CLUSTER_HOST_ID))
|
raise RuntimeError("Cluster Host Not Found: {}".format(settings.CLUSTER_HOST_ID))
|
||||||
|
|||||||
Reference in New Issue
Block a user