mirror of
https://github.com/ZwareBear/awx.git
synced 2026-04-23 00:11:48 -05:00
Merge pull request #1243 from matburt/fix_clustering_isolated
Fix isolated instance clustering implementation
This commit is contained in:
@@ -665,7 +665,7 @@ def get_mem_capacity():
|
||||
return (mem, max(1, ((mem / 1024 / 1024) - 2048) / forkmem))
|
||||
|
||||
|
||||
def get_system_task_capacity(scale=Decimal(1.0)):
|
||||
def get_system_task_capacity(scale=Decimal(1.0), cpu_capacity=None, mem_capacity=None):
|
||||
'''
|
||||
Measure system memory and use it as a baseline for determining the system's capacity
|
||||
'''
|
||||
@@ -678,8 +678,14 @@ def get_system_task_capacity(scale=Decimal(1.0)):
|
||||
elif settings_forks:
|
||||
return int(settings_forks)
|
||||
|
||||
_, cpu_cap = get_cpu_capacity()
|
||||
_, mem_cap = get_mem_capacity()
|
||||
if cpu_capacity is None:
|
||||
_, cpu_cap = get_cpu_capacity()
|
||||
else:
|
||||
cpu_cap = cpu_capacity
|
||||
if mem_capacity is None:
|
||||
_, mem_cap = get_mem_capacity()
|
||||
else:
|
||||
mem_cap = mem_capacity
|
||||
return min(mem_cap, cpu_cap) + ((max(mem_cap, cpu_cap) - min(mem_cap, cpu_cap)) * scale)
|
||||
|
||||
|
||||
|
||||
@@ -10,26 +10,27 @@ from django.conf import settings
|
||||
from awx.main.models import Instance
|
||||
|
||||
|
||||
def _add_remove_celery_worker_queues(app, instance, worker_queues, worker_name):
|
||||
def _add_remove_celery_worker_queues(app, controlled_instances, worker_queues, worker_name):
|
||||
removed_queues = []
|
||||
added_queues = []
|
||||
ig_names = set(instance.rampart_groups.values_list('name', flat=True))
|
||||
ig_names.add("tower_instance_router")
|
||||
ig_names = set(['tower_instance_router'])
|
||||
hostnames = set([instance.hostname for instance in controlled_instances])
|
||||
for instance in controlled_instances:
|
||||
ig_names.update(instance.rampart_groups.values_list('name', flat=True))
|
||||
worker_queue_names = set([q['name'] for q in worker_queues])
|
||||
|
||||
|
||||
# Remove queues that aren't in the instance group
|
||||
for queue in worker_queues:
|
||||
if queue['name'] in settings.AWX_CELERY_QUEUES_STATIC or \
|
||||
queue['alias'] in settings.AWX_CELERY_QUEUES_STATIC:
|
||||
continue
|
||||
|
||||
if queue['name'] not in ig_names | set([instance.hostname]) or not instance.enabled:
|
||||
if queue['name'] not in ig_names | hostnames or not instance.enabled:
|
||||
app.control.cancel_consumer(queue['name'], reply=True, destination=[worker_name])
|
||||
removed_queues.append(queue['name'])
|
||||
|
||||
# Add queues for instance and instance groups
|
||||
for queue_name in ig_names | set([instance.hostname]):
|
||||
for queue_name in ig_names | hostnames:
|
||||
if queue_name not in worker_queue_names:
|
||||
app.control.add_consumer(queue_name, reply=True, destination=[worker_name])
|
||||
added_queues.append(queue_name)
|
||||
@@ -59,13 +60,19 @@ def update_celery_worker_routes(instance, conf):
|
||||
|
||||
def register_celery_worker_queues(app, celery_worker_name):
|
||||
instance = Instance.objects.me()
|
||||
controlled_instances = [instance]
|
||||
if instance.is_controller():
|
||||
controlled_instances.extend(Instance.objects.filter(
|
||||
rampart_groups__controller__instances__hostname=instance.hostname
|
||||
))
|
||||
added_queues = []
|
||||
removed_queues = []
|
||||
|
||||
celery_host_queues = app.control.inspect([celery_worker_name]).active_queues()
|
||||
|
||||
celery_worker_queues = celery_host_queues[celery_worker_name] if celery_host_queues else []
|
||||
(added_queues, removed_queues) = _add_remove_celery_worker_queues(app, instance, celery_worker_queues, celery_worker_name)
|
||||
(added_queues, removed_queues) = _add_remove_celery_worker_queues(app, controlled_instances,
|
||||
celery_worker_queues, celery_worker_name)
|
||||
|
||||
return (instance, removed_queues, added_queues)
|
||||
return (controlled_instances, removed_queues, added_queues)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user