summaryrefslogtreecommitdiffstats
path: root/scripts/settimeseriesnote.py
blob: 7e4aa5b1b0b618579b34882300ce7cfa0f4caa01 (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
import sys
import json
from dbaccess import execQuery, database, commit
from misc import textToId, printJSONHeader

class SetTimeSeriesNote:

    def __init__(
        self, host, platform, branch, benchmark, metric, note):
        self.host_id = textToId('host', host)
        self.platform_id = textToId('platform', platform)
        self.branch_id = textToId('branch', branch)
        self.benchmark_id = textToId('benchmark', benchmark)
        self.metric_id = textToId('metric', metric)
        max_length = 256
        self.note = note.strip()[:max_length]

    def execute(self):

        if len(self.note) == 0:
            # Delete the row from the table:
            query = (
                "DELETE FROM timeSeriesAnnotation"
                " WHERE hostId = %d"
                "   AND platformId = %d"
                "   AND branchId = %d"
                "   AND benchmarkId = %d"
                "   AND metricId = %d;"
                % (self.host_id, self.platform_id, self.branch_id,
                   self.benchmark_id, self.metric_id))
            execQuery(query, False)
        else:
            # Insert or update table row:
            query = (
                "SELECT merge_timeSeriesNote(%d, %d, %d, %d, %d, '%s');"
                % (self.host_id, self.platform_id, self.branch_id,
                   self.benchmark_id, self.metric_id, self.note))
            execQuery(query, False)

        # Write to database:
        commit()

        # Return empty reply to client:
        printJSONHeader()
        json.dump({ }, sys.stdout)