summaryrefslogtreecommitdiffstats
path: root/Monitoring/src/main/python/Semantics/Query.py.old
blob: 80e7e4194435364eb4cac75fd5f0ad1b5fd9c9a6 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
'''
Created on Feb 21, 2012

@author: steger
'''
from DataProcessing.Parameter import ParameterList
from Resource.resource import resource as coreresource
from DataProcessing.DataFormatter import JsonFormatter, DumbFormatter

class SingleQuery(object):
    '''
    @summary: represents a (feature, resource) pair, representing what and where to measure
    The requested output format is also stored here 
    Optionally some measurement specific parameters can be added and post processing can be applied
    '''
    def __init__(self):
        self._feature = None
        self._resource = None
        self._samplechain = None
        self._formatter = None
        self._parameters = ParameterList()

    @property
    def resource(self):
        return self._resource
    @resource.setter
    def resource(self, (resourceid, resource)):
        if not isinstance(resource, coreresource):
            raise Exception("%s is not a resource type" % resource)
        self._resource = (resourceid, resource)
    
    @property
    def feature(self):
        return self._feature
    @feature.setter
    def feature(self, feature):
        self._feature = feature

    @property
    def samplechain(self):
        return self._samplechain
    @samplechain.setter
    def samplechain(self, samplechain):
        self._samplechain = samplechain

    @property
    def formatter(self):
        return self._formatter
    @formatter.setter
    def formatter(self, uri_formatter):
        if str(uri_formatter).endswith("Formatter_JSON"):
            self._formatter = JsonFormatter
        elif str(uri_formatter).endswith("Formatter_CSV"):
            self._formatter = DumbFormatter
        else:
            raise Exception("%s is not a formatter type" % uri_formatter)

    @property
    def paramlist(self):
        return self._parameters
    
    def addParameter(self, parameter):
        self._parameters.append(parameter)

class QueryBundle(object):
    '''
    @summary: represents a collection of SingleQueries
    '''
    def __init__(self):
        self.atoms = {}

    def __len__(self):
        return len(self.atoms)

    def has_key(self, key):
        return self.atoms.has_key(key)

    def __iter__(self):
        for q in self.atoms.itervalues():
            yield q
    
    def getResource(self, resourceid):
        for q in self:
            if q.resource[0] == resourceid:
                return q.resource[1]
        return None

    def add(self, reference, q):
        if self.atoms.has_key(reference):
            raise Exception("Duplicate MonitoringQuery entry")
        if not isinstance(q, SingleQuery):
            raise Exception("Wrong type")
        self.atoms[reference] = q





#class BundleQueryBundle(QueryBundle):
#    def newQuery(self, key, feature, samplechain, resource, formatter):
#        if self.atoms.has_key(key):
#            raise Exception("Atomic query %s exists" % key)
#        Q = MonitorQuery()
#        Q.resource = resource 
#        Q.feature = feature
#        Q.samplechain = samplechain
#        Q.formatter = formatter
#        self.atoms[key] = Q
            
#    def addParameter(self, key, parameter):
#        if not self.atoms.has_key(key):
#            raise Exception("Atomic query %s does not exist" % key)
#        self.atoms[key].addParameter(parameter)
    

#class AggregatorQuery(Query):
#    def __init__(self):
#        Query.__init__(self)
#        self._processid = None
    
#    @property
#    def processid(self):
#        return self._processid
#    @processid.setter
#    def processid(self, processid):
#        self._processid = processid



#class SampleQuery(QueryBundle):
#    def newQuery(self, key, processid, feature, samplechain, formatter):
#        if self.atoms.has_key(key):
#            raise Exception("Atomic query %s exists" % key)
#        Q = AggregatorQuery()
#        Q.processid = processid
#        Q.feature = feature
#        Q.samplechain = samplechain
#        Q.formatter = formatter
#        self.atoms[key] = Q