-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplanner.py
64 lines (44 loc) · 2.24 KB
/
planner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Planner:
stabilization_window_time: int = 300
def planner(self, deploys):
from math import ceil
for _, deploy in deploys.items():
for name, query in deploy['queries'].items():
print(name, query['ratio'])
ratio = query['ratio']
if not 0.9 <= ratio <= 1.1:
print(query)
query['replicas'] = ceil(deploy['replicas']['current'] * ratio)
deploy['adaptation_command'] = 'scale'
if deploy['adaptation_command'] != '':
self.assessment_of_the_possibility_of_adaptation(deploy)
self.can_adapt(deploy)
def assessment_of_the_possibility_of_adaptation(self, deploy):
if self.stabilization:
self.check_stabilization(deploy)
def check_stabilization(self, deploy):
from time import time
if deploy['stabilization'][deploy['adaptation_command']] != -1:
current_stabilization_time = time() - deploy['stabilization'][deploy['adaptation_command']]
if current_stabilization_time >= self.stabilization_window_time:
deploy['stabilization'][deploy['adaptation_command']] = -1
else:
deploy['adaptation_command'] = ''
"""
def planner(deployments):
from math import ceil
for d in deployments:
for key, dt_metric in deployments[d]['metrics'].items():
ratio = deployments[d][key + '_ratio']
if not 0.9 <= ratio <= 1.1:
deployments[d][key + 'replicas_needed'] = ceil(deployments[d]['replicas']['current'] * ratio)
deployments[d][key + 'adapt'] = True
else:
deployments[d][key + 'adapt'] = False
deployments[d][key + 'replicas_needed'] = better_two(deployments[d])
# deployments[d]['replicas']['needed'] = ceil(deployments[d]['replicas']['current'] * ratio)
# print(key, ratio, deployments[d]['replicas']['needed'])
# print(d, deployments[d]['replicas']['needed'], workload_ratio)
# is_it_blocked_by_quarantine(deployments[d])
# print('Is ' + d + ' blocked by quarantine? ' + str(is_it_blocked_by_quarantine(deployments[d])))
"""