mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
Merge pull request #3865 from chrismeyersfsu/fix-enabled_still_online
disabled instance does not mean offline instance Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
@@ -339,10 +339,7 @@ class InstanceDetail(RetrieveUpdateAPIView):
|
|||||||
r = super(InstanceDetail, self).update(request, *args, **kwargs)
|
r = super(InstanceDetail, self).update(request, *args, **kwargs)
|
||||||
if status.is_success(r.status_code):
|
if status.is_success(r.status_code):
|
||||||
obj = self.get_object()
|
obj = self.get_object()
|
||||||
if obj.enabled:
|
obj.refresh_capacity()
|
||||||
obj.refresh_capacity()
|
|
||||||
else:
|
|
||||||
obj.capacity = 0
|
|
||||||
obj.save()
|
obj.save()
|
||||||
r.data = serializers.InstanceSerializer(obj, context=self.get_serializer_context()).to_representation(obj)
|
r.data = serializers.InstanceSerializer(obj, context=self.get_serializer_context()).to_representation(obj)
|
||||||
return r
|
return r
|
||||||
|
|||||||
@@ -144,7 +144,10 @@ class Instance(HasPolicyEditsMixin, BaseModel):
|
|||||||
def refresh_capacity(self):
|
def refresh_capacity(self):
|
||||||
cpu = get_cpu_capacity()
|
cpu = get_cpu_capacity()
|
||||||
mem = get_mem_capacity()
|
mem = get_mem_capacity()
|
||||||
self.capacity = get_system_task_capacity(self.capacity_adjustment)
|
if self.enabled:
|
||||||
|
self.capacity = get_system_task_capacity(self.capacity_adjustment)
|
||||||
|
else:
|
||||||
|
self.capacity = 0
|
||||||
self.cpu = cpu[0]
|
self.cpu = cpu[0]
|
||||||
self.memory = mem[0]
|
self.memory = mem[0]
|
||||||
self.cpu_capacity = cpu[1]
|
self.cpu_capacity = cpu[1]
|
||||||
@@ -231,9 +234,7 @@ class InstanceGroup(HasPolicyEditsMixin, BaseModel, RelatedJobsMixin):
|
|||||||
|
|
||||||
def fit_task_to_most_remaining_capacity_instance(self, task):
|
def fit_task_to_most_remaining_capacity_instance(self, task):
|
||||||
instance_most_capacity = None
|
instance_most_capacity = None
|
||||||
for i in self.instances.filter(capacity__gt=0).order_by('hostname'):
|
for i in self.instances.filter(capacity__gt=0, enabled=True).order_by('hostname'):
|
||||||
if not i.enabled:
|
|
||||||
continue
|
|
||||||
if i.remaining_capacity >= task.task_impact and \
|
if i.remaining_capacity >= task.task_impact and \
|
||||||
(instance_most_capacity is None or
|
(instance_most_capacity is None or
|
||||||
i.remaining_capacity > instance_most_capacity.remaining_capacity):
|
i.remaining_capacity > instance_most_capacity.remaining_capacity):
|
||||||
@@ -242,7 +243,7 @@ class InstanceGroup(HasPolicyEditsMixin, BaseModel, RelatedJobsMixin):
|
|||||||
|
|
||||||
def find_largest_idle_instance(self):
|
def find_largest_idle_instance(self):
|
||||||
largest_instance = None
|
largest_instance = None
|
||||||
for i in self.instances.filter(capacity__gt=0).order_by('hostname'):
|
for i in self.instances.filter(capacity__gt=0, enabled=True).order_by('hostname'):
|
||||||
if i.jobs_running == 0:
|
if i.jobs_running == 0:
|
||||||
if largest_instance is None:
|
if largest_instance is None:
|
||||||
largest_instance = i
|
largest_instance = i
|
||||||
@@ -253,7 +254,7 @@ class InstanceGroup(HasPolicyEditsMixin, BaseModel, RelatedJobsMixin):
|
|||||||
def choose_online_controller_node(self):
|
def choose_online_controller_node(self):
|
||||||
return random.choice(list(self.controller
|
return random.choice(list(self.controller
|
||||||
.instances
|
.instances
|
||||||
.filter(capacity__gt=0)
|
.filter(capacity__gt=0, enabled=True)
|
||||||
.values_list('hostname', flat=True)))
|
.values_list('hostname', flat=True)))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -393,14 +393,9 @@ def cluster_node_heartbeat():
|
|||||||
instance_list.remove(inst)
|
instance_list.remove(inst)
|
||||||
if this_inst:
|
if this_inst:
|
||||||
startup_event = this_inst.is_lost(ref_time=nowtime)
|
startup_event = this_inst.is_lost(ref_time=nowtime)
|
||||||
if this_inst.capacity == 0 and this_inst.enabled:
|
this_inst.refresh_capacity()
|
||||||
logger.warning('Rejoining the cluster as instance {}.'.format(this_inst.hostname))
|
|
||||||
if this_inst.enabled:
|
|
||||||
this_inst.refresh_capacity()
|
|
||||||
elif this_inst.capacity != 0 and not this_inst.enabled:
|
|
||||||
this_inst.capacity = 0
|
|
||||||
this_inst.save(update_fields=['capacity'])
|
|
||||||
if startup_event:
|
if startup_event:
|
||||||
|
logger.warning('Rejoining the cluster as instance {}.'.format(this_inst.hostname))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
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