summaryrefslogtreecommitdiffstats
path: root/Monitoring/src/main/python/Service/mock_framework.py
blob: 3f0094539445ab21b4277d897e26e24b92c376be (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'''
Created on Nov 20, 2012

@author: steger
'''
from Service.interface import MSInterface
import logging
from logging.handlers import TimedRotatingFileHandler
from os import path, unlink

class FrameworkError(Exception):
    pass

class PolicyMock(object):
    def __init__(self):
        fn = "/tmp/ps.log"
        if path.exists(fn):
            unlink(fn)
        hdlr = TimedRotatingFileHandler(filename = fn)
        self.logger = logging.getLogger("NOVI.PS")
        self.logger.setLevel(level = logging.DEBUG)
        self.logger.addHandler(hdlr = hdlr)

    def trigger(self, what):
        self.logger.info(what)

class Framework(object):
    '''
    This class mimics the integration framework. It helps to look up remote Monitoring Service instances
    '''

    def __init__(self, baseurl, conf):
        '''
        Constructor
        '''
        self._if = {}
        self._pol = PolicyMock()
        for platform, config_owl in conf.iteritems():
            fn = "/tmp/ms_%s.log" % platform
            if path.exists(fn):
                unlink(fn)
            hdlr = TimedRotatingFileHandler(filename = fn)
            l = logging.getLogger("NOVI.MS.%s" % platform)
            l.setLevel(level = logging.DEBUG)
            l.addHandler(hdlr = hdlr)
            l = logging.getLogger("NOVI.MSI.%s" % platform)
            l.setLevel(level = logging.DEBUG)
            l.addHandler(hdlr = hdlr)
            self._if[platform] = MSInterface(self, platform, baseurl, config_owl)
    
    def _getInterface(self, platform):
        try:
            return self._if[platform]
        except:
            print "EE: %s platform not found" % platform
            raise FrameworkError

    def getService(self, platform):
        try:
            return self._if[platform]
        except:
            print "EE: %s platform not found" % platform
            raise FrameworkError
    
    def _getPolicyService(self, platform):
        return self._pol
        
    def _serviceList(self):
        return self._if.values()