summaryrefslogtreecommitdiffstats
path: root/Monitoring/MonitoringService/Service/WatchdogManager.py
blob: e40f1c3c2589f6babacef7d3fc55a60a7ad4c81c (plain)
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
'''
Created on Dec 10, 2012

@author: steger
'''
from DataProcessing.LinearCombination import LinearCombination
from DataProcessing.Bool import IsPositive, IsNotPositive, IsNegative,\
    IsNotNegative

class WatchdogManager(object):
    def __init__(self, am):
        self._id = 0;
        self._conditionals = {}
        self.am = am
        self._dep = {}

    def newConditional(self, dataSource, cellrequest, conditiontype, operation):
        deps = []
        if conditiontype in [ IsPositive, IsNegative, IsNotNegative, IsNotPositive ]:
            lincomb = LinearCombination()
            for factor, commandflow in operation:
                Aid, A = self.am.newAggregator(dataSource, cellrequest, commandflow)
                lincomb.addTerm(factor, A)
                deps.append(Aid)
            DS = conditiontype(lincomb)
        self._id += 1
        self._conditionals[ self._id ] = DS
        self._dep[ self._id ] = deps[:]
        return self._id, DS

    def __getitem__(self, watchdogid):
        try:
            return self._conditionals[ watchdogid ]
        except:
            raise Exception("Watchdog with id %s not found" % watchdogid)

    def pop(self, watchdogid):
        try:
            self._conditionals.pop( watchdogid )
            deps = self._dep.pop(watchdogid)
            while len(deps):
                Aid = deps.pop()
                self.am.pop(Aid)
        except KeyError:
            print "WW: Watchdog with id %s not found" % watchdogid