Implement gathering overall task capacity

For use when running/planning jobs
This commit is contained in:
Matthew Jones 2016-11-07 13:44:17 -05:00
parent db5ffa7e03
commit 343966f744
6 changed files with 32 additions and 4 deletions

View File

@ -178,7 +178,7 @@ class ApiV1PingView(APIView):
response['instances'] = []
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()
return Response(response)

View File

@ -4,6 +4,7 @@
import sys
from django.db import models
from django.db.models import Sum
from django.conf import settings
@ -40,6 +41,9 @@ class InstanceManager(models.Manager):
"""Return count of active Tower nodes for licensing."""
return self.all().count()
def total_capacity(self):
return self.aggregate(total_capacity=Sum('capacity'))['total_capacity']
def my_role(self):
# NOTE: TODO: Likely to repurpose this once standalone ramparts are a thing
return "tower"

View 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),
),
]

View File

@ -26,6 +26,10 @@ class Instance(models.Model):
hostname = models.CharField(max_length=250, unique=True)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
capacity = models.PositiveIntegerField(
default=100,
editable=False,
)
class Meta:
app_label = 'main'

View File

@ -37,7 +37,7 @@ logger = logging.getLogger('awx.main.scheduler')
class TaskManager():
def __init__(self):
self.graph = DependencyGraph()
self.capacity_total = 200
self.capacity_total = Instance.objects.total_capacity()
self.capacity_used = 0
def get_tasks(self):
@ -152,7 +152,7 @@ class TaskManager():
map(lambda at: active_tasks.add(at['id']), active_task_queues[queue])
else:
if not hasattr(settings, 'CELERY_UNIT_TEST'):
return None
return (None, None)
return (active_task_queues, active_tasks)

View File

@ -51,7 +51,7 @@ from awx.main.queue import CallbackQueueDispatcher
from awx.main.task_engine import TaskEnhancer
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,
OutputEventFilter)
get_system_task_capacity, OutputEventFilter)
from awx.main.consumers import emit_channel_notification
__all__ = ['RunJob', 'RunSystemJob', 'RunProjectUpdate', 'RunInventoryUpdate',
@ -131,6 +131,7 @@ def cluster_node_heartbeat(self):
inst = Instance.objects.filter(hostname=settings.CLUSTER_HOST_ID)
if inst.exists():
inst = inst[0]
inst.capacity = get_system_task_capacity()
inst.save()
return
raise RuntimeError("Cluster Host Not Found: {}".format(settings.CLUSTER_HOST_ID))