Subversion Repositories DevTools

Rev

Rev 5506 | Rev 6585 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5045 dpurdie 1
<%@LANGUAGE="VBSCRIPT"%>
2
<%
3
'=====================================================
4
'   splunk_build_test_results.asp
5
'
6
'   This page is designed to be used by 'splunk'
7
'   It is a very simple REST style interface
8
'   It simple produces Build and Unit tests metrics
9
'
10
'   The output is pure JSON
11
'   There are two sections
12
'   info : {}       - Internal data about the process
13
'   data : {}       - Build and Test results
14
'
15
'   The data section is organised by:
16
'       Project and then Release
17
'       Within each release there is:
18
'           BuildsCompleted
19
'           BuildsInError
20
'       Within each of these there is:
21
'           Count           - Total packages
22
'           UnitTests       - Total Unit Tests
23
'           NewVersions     - Subset of Count
24
'           Ripples         - Subset of Count
25
'           Other           - Subset of Count
26
'   The data is for all time
27
'   [May need to rethink that if processing time blows out]
28
'
29
'   Get Requests
5046 dpurdie 30
'       ?day=n            - Limit result set n days ago
5045 dpurdie 31
'                             0 == Results since midnight
32
'                             1 == yesterday
33
'
34
'=====================================================
35
%>
36
<%
37
Option explicit
38
' Essential to get UTF through all the hoops. ie: VÄSTTRAFIK (VTK)
39
Response.ContentType = "text/html"
40
Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
41
Response.CodePage = 65001
42
Response.CharSet = "UTF-8"
43
%>
44
<!--#include file="common/conf.asp"-->
45
<!--#include file="common/globals.asp"-->
46
<!--#include file="common/qstr.asp"-->
47
<!--#include file="common/common_subs.asp"-->
48
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT> 
49
<%
50
'------------ Variable Definition -------------
51
Dim result : result = -1
52
Dim SqlQry
53
Dim rsQry
54
 
55
' Init the output JSON class
56
'   Default data will be added at the end
57
Dim oJSON   : Set oJSON = New aspJSON
58
Dim infoSet : Set infoSet = newDataSet("info", oJSON.data)
59
 
60
'
61
'   Perform the bulk of the work within a sub
62
'       Done so that errors propergate up
63
'       Using the On Error Resume Next, any error within the routine
64
'       will cause the routine to exit    
65
On Error Resume Next
66
Call DoWork
67
 
68
'
69
' SQL error detection and reporting
70
If objEH.LastOraFailed Then
71
    infoSet("error") = 1
72
    result = -2
73
    infoSet("emsgSummary") = objEH.MessageSummary
74
    infoSet("emsgDetails") = objEH.MessageDetails
75
    infoSet("SqlQry") = SqlQry
76
'
77
'   Detect program errors
78
ElseIf Err.number <> 0 Then
79
    result = -3
80
    infoSet("error") = 2
81
    infoSet("errnum") = Err.number
82
    infoSet("errtxt") = Err.description
83
    infoSet("errsrc") = Err.source
84
End If
85
 
86
infoSet("result") = result
87
 
88
'Return the object
89
Response.Write oJSON.JSONoutput()
5957 dpurdie 90
Set oJSON = Nothing
91
Call Destroy_All_Objects
5045 dpurdie 92
' --- End of Mainline
93
'------------------------------------------------------------------------------
94
'
95
'   Create a new collection and add it to an existing colelction
96
'       sname - Name of the new collection (Key Name)
97
'       pset  - Parent collection. The collection to add it to
98
'   Returns a Collection ( Scripting Dictionary)
99
Function newDataSet(sname, pset)
100
    Set newDataSet  = oJSON.Collection()
101
    Set pset(sname) = newDataSet
102
End Function
103
 
104
'------------------------------------------------------------------------------
105
'
106
'   Perform the body of the query
107
'   Done in a Sub so that errors can be better captured and reported
108
Sub DoWork
109
 
110
    '   Create a collection to contain the returned data
111
    '
112
    Dim dataSet : Set dataSet = newDataSet("data", oJSON.data)
113
 
114
    '
115
    '   Support time limited query
116
    '
5046 dpurdie 117
    Dim repday : repday = NiceInt( Request("day"), -1 )
5045 dpurdie 118
    Dim limit : limit = ""
5046 dpurdie 119
    If repday >= 0 Then
120
        infoSet("day") = repday
121
        limit = " AND bi.TIMESTAMP > TRUNC(SYSDATE - "& repday &")"
122
        limit = limit & " AND bi.TIMESTAMP < TRUNC(SYSDATE - "& repday - 1 &")"
5045 dpurdie 123
    End If
124
 
125
 
126
    '   The query
127
    '
128
    SqlQry = _
129
        "SELECT proj_name," &_
130
        "  rtag_name," &_
131
        "  state," &_
132
        "  reason,  " &_
133
        "  COUNT(reason)   AS rc," &_
134
        "  SUM(test_count) AS tc" &_
135
        " FROM" &_
136
        "  (SELECT pj.PROJ_NAME," &_
137
        "    RTAG_NAME," &_
138
        "    DECODE(bi.reason, 'N', 'NewVersion', 'R', 'Ripple', 'T', 'Test', 'P', 'Restored', 'Unknown') as REASON," &_
139
        "    DECODE(bi.state, 'B', 'Buiding', 'C', 'Complete', 'E', 'Error', 'S', 'SysErr', 'Unknown') as STATE," &_
140
        "    (SELECT COUNT(*) FROM TEST_RUN tr WHERE tr.build_id = bi.build_id ) AS test_count" &_
141
        "  FROM BUILD_INSTANCES bi," &_
142
        "    projects pj," &_
143
        "    RELEASE_TAGS rt" &_
144
        "  WHERE bi.RTAG_ID = rt.RTAG_ID" &_
145
        "  AND rt.proj_id   = pj.proj_id" & limit &_
146
        "  ) group by proj_name, rtag_name, state, reason" &_
147
        " ORDER BY PROJ_NAME, rtag_name,  state,  reason"
148
 
149
    On Error Resume Next
150
    objEH.ErrorRedirect = FALSE
151
    objEH.TryORA ( OraSession )
152
    Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
153
    objEH.CatchORA ( OraSession )
154
 
155
    ' Process each row and return required fields to the user
156
    If objEH.Finally Then
157
    On Error goto 0
158
        Dim lastProjectName, proj : lastProjectName = ""
159
        Dim lastReleaseName, rel : lastReleaseName = ""
160
        Dim dataOk, dataError
161
        While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
162
            ' Attempt to speed up access tot he data
163
            '    Extract all fields for the row
164
            '    Access fields by index
165
            Dim fields
166
            Set fields = rsQry.Fields
167
            Dim pname    : pname = fields(0)
168
            Dim rname    : rname = fields(1)
169
            Dim state    : state = fields(2)
170
            Dim reason   : reason = fields(3)
171
            Dim rc       : rc = CInt(fields(4))
172
            Dim tc       : tc = CInt(fields(5))
173
            Set fields = nothing
174
 
175
            ' Create new Items as required
176
            '
177
            If pname <> lastProjectName Then
178
                lastProjectName = pname
179
                Set proj = newDataSet(pname,dataSet )
180
            End If
181
 
182
            If rname <> lastReleaseName Then 
183
                Set rel = newDataSet(rname, proj)
184
                lastReleaseName = rname
185
 
186
                Set dataOk = newDataSet("BuildsCompleted", rel)
187
                dataOk("Count") = 0
188
                Set dataError = newDataSet("BuildsInError", rel)      
189
                dataError("Count") = 0
190
            End If
191
 
192
            '   Accumulate data
193
            '
194
            If state = "Complete" Then
195
                dataOk(reason)      = dataOk(reason) + rc 
196
                dataOk("Count")     = dataOk("Count") + rc 
197
                dataOk("UnitTests") = dataOk("UnitTests") + tc 
198
            Else
199
                dataError(reason)      = dataError(reason) + rc 
200
                dataError("Count")     = dataError("Count") + rc 
201
                dataError("UnitTests") = dataError("UnitTests") + tc 
202
            End If
203
 
204
            rsQry.MoveNext
205
        Wend
206
    End IF
207
 
208
    rsQry.Close
209
    Set rsQry = Nothing
210
    result = 0
211
End Sub
212
 
213
 
214
%>