| 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()
|
|
|
90 |
OraSession.Dispose()
|
|
|
91 |
' --- End of Mainline
|
|
|
92 |
'------------------------------------------------------------------------------
|
|
|
93 |
'
|
|
|
94 |
' Create a new collection and add it to an existing colelction
|
|
|
95 |
' sname - Name of the new collection (Key Name)
|
|
|
96 |
' pset - Parent collection. The collection to add it to
|
|
|
97 |
' Returns a Collection ( Scripting Dictionary)
|
|
|
98 |
Function newDataSet(sname, pset)
|
|
|
99 |
Set newDataSet = oJSON.Collection()
|
|
|
100 |
Set pset(sname) = newDataSet
|
|
|
101 |
End Function
|
|
|
102 |
|
|
|
103 |
'------------------------------------------------------------------------------
|
|
|
104 |
'
|
|
|
105 |
' Perform the body of the query
|
|
|
106 |
' Done in a Sub so that errors can be better captured and reported
|
|
|
107 |
Sub DoWork
|
|
|
108 |
|
|
|
109 |
' Create a collection to contain the returned data
|
|
|
110 |
'
|
|
|
111 |
Dim dataSet : Set dataSet = newDataSet("data", oJSON.data)
|
|
|
112 |
|
|
|
113 |
'
|
|
|
114 |
' Support time limited query
|
|
|
115 |
'
|
| 5046 |
dpurdie |
116 |
Dim repday : repday = NiceInt( Request("day"), -1 )
|
| 5045 |
dpurdie |
117 |
Dim limit : limit = ""
|
| 5046 |
dpurdie |
118 |
If repday >= 0 Then
|
|
|
119 |
infoSet("day") = repday
|
|
|
120 |
limit = " AND bi.TIMESTAMP > TRUNC(SYSDATE - "& repday &")"
|
|
|
121 |
limit = limit & " AND bi.TIMESTAMP < TRUNC(SYSDATE - "& repday - 1 &")"
|
| 5045 |
dpurdie |
122 |
End If
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
' The query
|
|
|
126 |
'
|
|
|
127 |
SqlQry = _
|
|
|
128 |
"SELECT proj_name," &_
|
|
|
129 |
" rtag_name," &_
|
|
|
130 |
" state," &_
|
|
|
131 |
" reason, " &_
|
|
|
132 |
" COUNT(reason) AS rc," &_
|
|
|
133 |
" SUM(test_count) AS tc" &_
|
|
|
134 |
" FROM" &_
|
|
|
135 |
" (SELECT pj.PROJ_NAME," &_
|
|
|
136 |
" RTAG_NAME," &_
|
|
|
137 |
" DECODE(bi.reason, 'N', 'NewVersion', 'R', 'Ripple', 'T', 'Test', 'P', 'Restored', 'Unknown') as REASON," &_
|
|
|
138 |
" DECODE(bi.state, 'B', 'Buiding', 'C', 'Complete', 'E', 'Error', 'S', 'SysErr', 'Unknown') as STATE," &_
|
|
|
139 |
" (SELECT COUNT(*) FROM TEST_RUN tr WHERE tr.build_id = bi.build_id ) AS test_count" &_
|
|
|
140 |
" FROM BUILD_INSTANCES bi," &_
|
|
|
141 |
" projects pj," &_
|
|
|
142 |
" RELEASE_TAGS rt" &_
|
|
|
143 |
" WHERE bi.RTAG_ID = rt.RTAG_ID" &_
|
|
|
144 |
" AND rt.proj_id = pj.proj_id" & limit &_
|
|
|
145 |
" ) group by proj_name, rtag_name, state, reason" &_
|
|
|
146 |
" ORDER BY PROJ_NAME, rtag_name, state, reason"
|
|
|
147 |
|
|
|
148 |
On Error Resume Next
|
|
|
149 |
objEH.ErrorRedirect = FALSE
|
|
|
150 |
objEH.TryORA ( OraSession )
|
|
|
151 |
Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
|
|
|
152 |
objEH.CatchORA ( OraSession )
|
|
|
153 |
|
|
|
154 |
' Process each row and return required fields to the user
|
|
|
155 |
If objEH.Finally Then
|
|
|
156 |
On Error goto 0
|
|
|
157 |
Dim lastProjectName, proj : lastProjectName = ""
|
|
|
158 |
Dim lastReleaseName, rel : lastReleaseName = ""
|
|
|
159 |
Dim dataOk, dataError
|
|
|
160 |
While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
|
|
|
161 |
' Attempt to speed up access tot he data
|
|
|
162 |
' Extract all fields for the row
|
|
|
163 |
' Access fields by index
|
|
|
164 |
Dim fields
|
|
|
165 |
Set fields = rsQry.Fields
|
|
|
166 |
Dim pname : pname = fields(0)
|
|
|
167 |
Dim rname : rname = fields(1)
|
|
|
168 |
Dim state : state = fields(2)
|
|
|
169 |
Dim reason : reason = fields(3)
|
|
|
170 |
Dim rc : rc = CInt(fields(4))
|
|
|
171 |
Dim tc : tc = CInt(fields(5))
|
|
|
172 |
Set fields = nothing
|
|
|
173 |
|
|
|
174 |
' Create new Items as required
|
|
|
175 |
'
|
|
|
176 |
If pname <> lastProjectName Then
|
|
|
177 |
lastProjectName = pname
|
|
|
178 |
Set proj = newDataSet(pname,dataSet )
|
|
|
179 |
End If
|
|
|
180 |
|
|
|
181 |
If rname <> lastReleaseName Then
|
|
|
182 |
Set rel = newDataSet(rname, proj)
|
|
|
183 |
lastReleaseName = rname
|
|
|
184 |
|
|
|
185 |
Set dataOk = newDataSet("BuildsCompleted", rel)
|
|
|
186 |
dataOk("Count") = 0
|
|
|
187 |
Set dataError = newDataSet("BuildsInError", rel)
|
|
|
188 |
dataError("Count") = 0
|
|
|
189 |
End If
|
|
|
190 |
|
|
|
191 |
' Accumulate data
|
|
|
192 |
'
|
|
|
193 |
If state = "Complete" Then
|
|
|
194 |
dataOk(reason) = dataOk(reason) + rc
|
|
|
195 |
dataOk("Count") = dataOk("Count") + rc
|
|
|
196 |
dataOk("UnitTests") = dataOk("UnitTests") + tc
|
|
|
197 |
Else
|
|
|
198 |
dataError(reason) = dataError(reason) + rc
|
|
|
199 |
dataError("Count") = dataError("Count") + rc
|
|
|
200 |
dataError("UnitTests") = dataError("UnitTests") + tc
|
|
|
201 |
End If
|
|
|
202 |
|
|
|
203 |
rsQry.MoveNext
|
|
|
204 |
Wend
|
|
|
205 |
End IF
|
|
|
206 |
|
|
|
207 |
rsQry.Close
|
|
|
208 |
Set rsQry = Nothing
|
|
|
209 |
result = 0
|
|
|
210 |
End Sub
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
%>
|