Cooldown time defines the minimum time that needs to happen between
each scaling action. If an alarm triggers before this has happened,
no action should be executed. When POL receives an alarm notification
it will check that the difference between the current time and the
last scaling action of the alarm's scaling policy is bigger than the
cooldown time.
During configuration of the scaling groups, POL will now store the
cooldown time of the scaling policy. Also, it adds a new last_scale
var to ScalingPolicy, which has as default the oldest time supported
by Python datetime.
Signed-off-by: Benjamin Diaz <bdiaz@whitestack.com>
Change-Id: I6d110ccc7f89af29500c602d05054e7ba78808a0
# For those usages not covered by the Apache License, Version 2.0 please
# contact: bdiaz@whitestack.com or glavado@whitestack.com
##
# For those usages not covered by the Apache License, Version 2.0 please
# contact: bdiaz@whitestack.com or glavado@whitestack.com
##
import json
import logging
import threading
import json
import logging
import threading
alarm_id, metric_name, operation, threshold, vdu_name, vnf_member_index, ns_id)
try:
alarm = ScalingAlarm.select().where(ScalingAlarm.alarm_id == alarm_id).get()
alarm_id, metric_name, operation, threshold, vdu_name, vnf_member_index, ns_id)
try:
alarm = ScalingAlarm.select().where(ScalingAlarm.alarm_id == alarm_id).get()
+ delta = datetime.datetime.now() - alarm.scaling_criteria.scaling_policy.last_scale
+ if delta.total_seconds() < alarm.scaling_criteria.scaling_policy.cooldown_time:
+ log.info("Time between last scale and now is less than cooldown time. Skipping.")
+ return
log.info("Sending scaling action message for ns: %s", alarm_id)
self.lcm_client.scale(alarm.scaling_criteria.scaling_policy.scaling_group.nsr_id,
alarm.scaling_criteria.scaling_policy.scaling_group.name,
alarm.vnf_member_index,
alarm.action)
log.info("Sending scaling action message for ns: %s", alarm_id)
self.lcm_client.scale(alarm.scaling_criteria.scaling_policy.scaling_group.nsr_id,
alarm.scaling_criteria.scaling_policy.scaling_group.name,
alarm.vnf_member_index,
alarm.action)
+ alarm.scaling_criteria.scaling_policy.last_scale = datetime.datetime.now()
+ alarm.scaling_criteria.scaling_policy.save()
except ScalingAlarm.DoesNotExist:
log.info("There is no action configured for alarm %s.", alarm_id)
except ScalingAlarm.DoesNotExist:
log.info("There is no action configured for alarm %s.", alarm_id)
scaling_policy_record = ScalingPolicy.create(
nsr_id=nsr_id,
name=scaling_policy['name'],
scaling_policy_record = ScalingPolicy.create(
nsr_id=nsr_id,
name=scaling_policy['name'],
+ cooldown_time=scaling_policy['cooldown-time'],
scaling_group=scaling_group_record
)
log.info("Created scaling policy record in DB : name=%s, scaling_group.name=%s",
scaling_group=scaling_group_record
)
log.info("Created scaling policy record in DB : name=%s, scaling_group.name=%s",
# For those usages not covered by the Apache License, Version 2.0 please
# contact: bdiaz@whitestack.com or glavado@whitestack.com
##
# For those usages not covered by the Apache License, Version 2.0 please
# contact: bdiaz@whitestack.com or glavado@whitestack.com
##
-from peewee import CharField, IntegerField, ForeignKeyField, Model, TextField, AutoField
+from peewee import CharField, IntegerField, ForeignKeyField, Model, TextField, AutoField, DateTimeField
from playhouse.sqlite_ext import SqliteExtDatabase
from osm_policy_module.core.config import Config
from playhouse.sqlite_ext import SqliteExtDatabase
from osm_policy_module.core.config import Config
class ScalingPolicy(BaseModel):
name = CharField()
class ScalingPolicy(BaseModel):
name = CharField()
+ cooldown_time = IntegerField()
+ last_scale = DateTimeField(default=datetime.datetime.min)
scaling_group = ForeignKeyField(ScalingGroup, related_name='scaling_policies')
scaling_group = ForeignKeyField(ScalingGroup, related_name='scaling_policies')