-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise_state.py
34 lines (28 loc) · 971 Bytes
/
exercise_state.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
"""
Define State classes and State transition table of the HTTP monitoring program
"""
class AbstractState(object):
"""
Abstract base class of tracking state of monitoring
"""
name = None
allowed = []
def check_state(self, type):
return isinstance(self, type)
def switch(self, state):
if state.name in self.allowed:
self.__class__ = state
else:
raise Exception("Unsupported State transation: "+self.name+' -> '+state.name)
class LearnState(AbstractState):
name = 'learn_baseline'
allowed = ['learn_baseline', 'enforce_normal', 'enforce_alert']
class NormalState(AbstractState):
name = 'enforce_normal'
allowed = ['enforce_normal', 'enforce_alert']
class AlertState(AbstractState):
name = 'enforce_alert'
allowed = ['enforce_alert', 'enforce_dismiss']
class DismissState(AbstractState):
name = 'enforce_dismiss'
allowed = ['enforce_alert', 'enforce_normal']