summaryrefslogtreecommitdiff
path: root/heat/scaling/cooldown.py
diff options
context:
space:
mode:
authorOmar Soriano <osoriano2@gmail.com>2016-03-10 09:44:57 -0800
committerRakesh H S <rh-s@hpe.com>2016-03-29 11:26:57 +0530
commit917f10cb3f664962178c818b745f9f0899566557 (patch)
tree297e5328ffaac5804c008a761a876e6a7263c779 /heat/scaling/cooldown.py
parentb8cd5f9ac30629eb6ae48051fbe0b6df16719f48 (diff)
downloadheat-917f10cb3f664962178c818b745f9f0899566557.tar.gz
Avoid cooldown when group size does not change
Cooldown behavior changed in commit: 50cc71e33c40a9e3be604b16f77d3c3cf030a63b Restore the cooldown behavior so that when a group does not encounter scaling activity, a cooldown period is not activated. Closes-Bug: #1555748 Change-Id: Icf5df6a48afb9f56aa1c3f1622d33b9998aca39c (cherry picked from commit 6c25e8302db02203fcb933e5b104507c83b6672c)
Diffstat (limited to 'heat/scaling/cooldown.py')
-rw-r--r--heat/scaling/cooldown.py34
1 files changed, 16 insertions, 18 deletions
diff --git a/heat/scaling/cooldown.py b/heat/scaling/cooldown.py
index e5d523a0c..effa4e6b3 100644
--- a/heat/scaling/cooldown.py
+++ b/heat/scaling/cooldown.py
@@ -22,8 +22,10 @@ class CooldownMixin(object):
This logic includes both cooldown timestamp comparing and scaling in
progress checking.
"""
- def _cooldown_inprogress(self):
- inprogress = False
+ def _is_scaling_allowed(self):
+ metadata = self.metadata_get()
+ if metadata.get('scaling_in_progress'):
+ return False
try:
# Negative values don't make sense, so they are clamped to zero
cooldown = max(0, self.properties[self.COOLDOWN])
@@ -31,34 +33,30 @@ class CooldownMixin(object):
# If not specified, it will be None, same as cooldown == 0
cooldown = 0
- metadata = self.metadata_get()
- if metadata.get('scaling_in_progress'):
- return True
-
if 'cooldown' not in metadata:
# Note: this is for supporting old version cooldown checking
if metadata and cooldown != 0:
last_adjust = next(six.iterkeys(metadata))
if not timeutils.is_older_than(last_adjust, cooldown):
- inprogress = True
+ return False
elif cooldown != 0:
last_adjust = next(six.iterkeys(metadata['cooldown']))
if not timeutils.is_older_than(last_adjust, cooldown):
- inprogress = True
-
- if not inprogress:
- metadata['scaling_in_progress'] = True
- self.metadata_set(metadata)
-
- return inprogress
+ return False
+ # Assumes _finished_scaling is called
+ # after the scaling operation completes
+ metadata['scaling_in_progress'] = True
+ self.metadata_set(metadata)
+ return True
- def _cooldown_timestamp(self, reason):
- # Save cooldown timestamp into metadata and clean the
- # scaling_in_progress state.
+ def _finished_scaling(self, cooldown_reason,
+ changed_size=True):
# If we wanted to implement the AutoScaling API like AWS does,
# we could maintain event history here, but since we only need
# the latest event for cooldown, just store that for now
metadata = self.metadata_get()
- metadata['cooldown'] = {timeutils.utcnow().isoformat(): reason}
+ if changed_size:
+ now = timeutils.utcnow().isoformat()
+ metadata['cooldown'] = {now: cooldown_reason}
metadata['scaling_in_progress'] = False
self.metadata_set(metadata)