Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6627 dpurdie 1
<%@LANGUAGE="VBSCRIPT"%>
2
<%
3
'=====================================================
4
'   release_stats_rest.asp
5
'
6
'   REST API(ish) interfaceo to extract Release Stats from Release Manager
7
'   This page will return JSON output
8
'
9
'   Parameters
10
'   rtag_id=nnn         - Release Tag
11
'   ignore=n            - 0 ignore none, else ignore COTS, SDK (default=1)
12
'   group=n             - 0 no group, 1 group (default 1)
13
'   summary=n           - 0 All data, 1 just summary (default 0)
14
'   json=n              - 0 CSV, 1JSON (default CSV)
15
'
16
'   The output is pure JSON
17
'   There are two sections
18
'   info : {}       - Internal data about the process
19
'   data : {}       - Build and Test results
20
'=====================================================
21
%>
22
<%
23
Option explicit
24
' Essential to get UTF through all the hoops. ie: VÄSTTRAFIK (VTK)
25
Response.ContentType = "text/html"
26
Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
27
Response.CodePage = 65001
28
Response.CharSet = "UTF-8"
29
%>
30
<!--#include file="common/conf.asp"-->
31
<!--#include file="common/globals.asp"-->
32
<!--#include file="common/qstr.asp"-->
33
<!--#include file="common/common_subs.asp"-->
34
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT> 
35
<%
36
'------------ Variable Definition -------------
37
Dim result : result = -1
38
Dim SqlQry
39
Dim rsQry
40
 
41
Dim parRtagId
42
Dim parIgnore
43
Dim parGroup
44
Dim parSummary
45
Dim parJson
46
 
47
' Init the output JSON class
48
'   Default data will be added at the end
49
Dim oJSON   : Set oJSON = New aspJSON
50
Dim infoSet : Set infoSet = newDataSet("info", oJSON.data)
51
 
52
'
53
' Global Data
54
'
55
Dim projName
56
Dim relName
57
Dim sDateTime
58
Dim dataSet
59
 
60
' Constants
61
'   Names of the Fields
62
'
63
Const fDate = "Date"
64
Const fRtagId = "RtagId"
65
Const fPname ="Project Name"
66
Const fRname = "Release Name"
67
Const fGroup = "Group"
68
Const fTPkgs = "Total Packages"
69
Const fTTested = "Packages with Tests"
70
Const fTTests = "Total Unit Tests"
71
Const fTLoc = "Total Lines of Code"
72
Const fpkg = "Package"
73
Const fTests = "Tests"
74
Const fLoc = "LoC"
75
 
76
'
77
'   Get parameters
78
parRtagId = RequestDefault("rtag_id", 0)
79
parIgnore = RequestDefault("ignore", 1)
80
parGroup = RequestDefault("group", 1)
81
parSummary = RequestDefault("summary",0)
82
parJson = RequestDefault("json",0)
83
 
84
 
85
'
86
'   Attempt to be helpful
87
'
88
If parRtagId = 0 Then
89
    Response.Write "<html>" & vbCrLf
90
    Response.Write "<body>" & vbCrLf
91
    Response.Write "<br>release_stats_rest.asp is designed to be used by automation scripts" & vbCrLf
92
    Response.Write "<br>It will accept the following parameters" & vbCrLf
93
    Response.Write "<br>rtag_id=nnn     - Specify Release to Process (mandatory)" & vbCrLf
94
    Response.Write "<br>ignore=0|1      - Ignore COTS and TOOL packages. Ignore packages provided by an SDK (default ignore)" & vbCrLf
95
    Response.Write "<br>group=0|1       - Output All or by Base View (default by Base View)" & vbCrLf
96
    Response.Write "<br>summary=0|1     - Display summary only (default ALL)" & vbCrLf
97
    Response.Write "<br>json=0|1        - Display CSV or JSON (default json)" & vbCrLf
98
    Response.Write "" & vbCrLf
99
    Response.Write "</body>" & vbCrLf
100
    Response.Write "</html>" & vbCrLf
101
    Response.End
102
End If
103
 
104
 
105
 
106
'
107
'   Perform the bulk of the work within a sub
108
'       Done so that errors propergate up
109
'       Using the On Error Resume Next, any error within the routine
110
'       will cause the routine to exit    
111
'On Error Resume Next
112
Call DoWork
113
 
114
'
115
' SQL error detection and reporting
116
If objEH.LastOraFailed Then
117
    infoSet("error") = 1
118
    result = -2
119
    infoSet("emsgSummary") = objEH.MessageSummary
120
    infoSet("emsgDetails") = objEH.MessageDetails
121
    infoSet("SqlQry") = SqlQry
122
'
123
'   Detect program errors
124
ElseIf Err.number <> 0 Then
125
    result = -3
126
    infoSet("error") = 2
127
    infoSet("errnum") = Err.number
128
    infoSet("errtxt") = Err.description
129
    infoSet("errsrc") = Err.source
130
End If
131
 
132
infoSet("result") = result
133
 
134
'Return the object
135
If parJson = 0 Then
136
    Call DumpAsCsv
137
Else
138
    Response.Write oJSON.JSONoutput()
139
End If
140
 
141
Set oJSON = Nothing
142
Call Destroy_All_Objects
143
' --- End of Mainline
144
'------------------------------------------------------------------------------
145
'
146
'   Create a new collection and add it to an existing colelction
147
'       sname - Name of the new collection (Key Name)
148
'       pset  - Parent collection. The collection to add it to
149
'   Returns a Collection ( Scripting Dictionary)
150
Function newDataSet(sname, pset)
151
    Set newDataSet  = oJSON.Collection()
152
    Set pset(sname) = newDataSet
153
End Function
154
 
155
'--------------------------------------------------------------------------------
156
'
157
'   Create or re-use structure to handle a given BaseView
158
'   
159
Function getGroupHeader( dataSet, sBaseView)
160
        If NOT dataSet.Exists(sBaseView) Then
161
            Dim vset
162
            Set vset =  newDataSet(sBaseView,dataSet )
163
 
164
            vset(fDate) = sDateTime
165
            vset(fRtagId) = parRtagId
166
            vset(fPname) = projName
167
            vset(fRname) = relName
168
            vset(fGroup) = sBaseView 
169
            vset(fTPkgs) = 0
170
            vset(fTLoc) = 0
171
            vset(fTTested) = 0
172
            vset(fTTests) = 0
173
       End If
174
       Set getGroupHeader = dataSet.Item(sBaseView)
175
End Function
176
 
177
'--------------------------------------------------------------------------------
178
'
179
'   Create or re-use structure to store detailed data for given basename
180
'   
181
Function getGroupData( dVset)
182
        If NOT dVset.Exists("DATA") Then
183
            Set getGroupData =  newDataSet("DATA",dVset )
184
       End If
185
       Set getGroupData = dVset.Item("DATA")
186
End Function
187
 
188
'------------------------------------------------------------------------------
189
'
190
'   Get Project Name and Release name for the rtag being processed
191
'
192
Sub getProjectReleaseName
193
    SqlQry = "select p.PROJ_NAME, rt.RTAG_NAME from RELEASE_TAGS rt, PROJECTS p WHERE rt.PROJ_ID = p.PROJ_ID and rt.RTAG_ID = :RTAG_ID"
194
    On Error Resume Next
195
    objEH.ErrorRedirect = FALSE
196
    objEH.TryORA ( OraSession )
197
 
198
    OraDatabase.Parameters.Add "RTAG_ID", parRtagId, ORAPARM_INPUT, ORATYPE_NUMBER
199
    Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
200
	OraDatabase.Parameters.Remove "RTAG_ID"
201
 
202
    objEH.CatchORA ( OraSession )
203
 
204
    ' Process one Row
205
    If objEH.Finally Then
206
        On Error goto 0
207
        projName = rsQry("PROJ_NAME")
208
        relName = rsQry("RTAG_NAME")
209
    End If
210
End Sub
211
 
212
'------------------------------------------------------------------------------
213
'
214
'   Perform the body of the query
215
'   Done in a Sub so that errors can be better captured and reported
216
Sub DoWork
217
 
218
    If parRtagId <= 0 Then
219
        result = -2
220
        infoSet("error") = 1
221
        infoSet("emsgSummary") = "Invalid rtag_id"
222
        Exit Sub
223
    End If
224
 
225
    '   Setup common data
226
    '       Calc timestamp for data
227
    '       Get Project and Release Name
228
    '           Use globals to pass data
229
    Dim date : date = Now
230
    sDateTime = Year(date) & Right(String(2, "0") & Month(date), 2) & Right(String(2, "0") & Day(date), 2)
231
    Call getProjectReleaseName 
232
 
233
    '   Create a collection to contain the returned data
234
    '
235
    Set dataSet = newDataSet("data", oJSON.data)
236
 
237
    On Error Resume Next
238
    objEH.ErrorRedirect = FALSE
239
    objEH.TryORA ( OraSession )
240
 
241
    OraDatabase.Parameters.Add "RTAG_ID", parRtagId, ORAPARM_INPUT, ORATYPE_NUMBER
242
    SqlQry =  GetQuery("release_stats.sql")
243
    Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
244
	OraDatabase.Parameters.Remove "RTAG_ID"
245
 
246
    objEH.CatchORA ( OraSession )
247
 
248
    ' Process each row and return required fields to the user
249
    If objEH.Finally Then
250
    On Error goto 0
251
 
252
    Dim includeThis
253
 
254
    Do While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
255
         includeThis = TRUE
256
 
257
        Dim pvId, buildId, buildTime, lastBuild, codeLines, isDeployable, viewName, isSdk, tcount, pVersion, pName, pExt
258
 
259
        pvId = rsQry("pv_id")
260
        tcount = NiceInt(rsQry("test_count"), 0)
261
        buildId = rsQry("build_id")
262
        buildTime = rsQry("build_time")
263
        If isNull(buildTime) Then buildTime = ""
264
        lastBuild = rsQry("lastBuild")
265
        If isNull(lastBuild) Then lastBuild = ""
266
        codeLines = NiceCLng(rsQry("code_lines"),0)
267
        If isNull(codeLines) Then codeLines = ""
268
        isDeployable = rsQry("is_deployable")
269
        If isNull(isDeployable) Then isDeployable = "N"
270
        viewName = rsQry("view_name")
271
        isSdk = rsQry("isSdk")
272
        pVersion = rsQry("pkg_version")
273
        pName = rsQry("pkg_name")
274
        pExt = rsQry("v_ext")
275
 
276
        ' Ignore some packages
277
        If parIgnore > 0 Then
278
            If isSdk = "Y" Then
279
                includeThis = FALSE
280
            End If
281
            Dim oRE, bMatch
282
            Set oRE = New RegExp
283
            oRE.IgnoreCase = True
284
            oRE.Pattern = ".cots$|.tool$"
285
            bMatch = oRE.Test(pVersion)
286
            If bMatch Then
287
                includeThis = FALSE
288
            End If
289
        End If
290
 
291
        ' Process active elements
292
        If includeThis Then
293
 
294
            If parGroup = 0 Then
295
                viewName = "ALL"
296
            End If
297
 
298
        ' Things for oJSON object
299
        '   obj(field) = data       (Will create a hash entry)
300
        '   newObj = oJSON.AddToCollection( obj ) (Will create an array)
301
 
302
        Dim dGroup : Set dGroup = getGroupHeader (dataSet, viewName)
303
        If parSummary = 0 Then
304
            Dim dData : Set dData = getGroupData(dGroup)
305
            Dim dEl :  Set dEl = oJSON.AddToCollection( dData )
306
            dEl(fpkg) = pName
307
            dEl(fTests) = tcount
308
            dEl(fLoc) = codeLines
309
        End If
310
 
311
        dGroup(fTPkgs) = dGroup(fTPkgs) + 1
312
        dGroup(fTLoc) = dGroup(fTLoc) + codeLines 
313
        If tcount > 0 Then
314
            dGroup(fTTested) = dGroup(fTTested) + 1
315
            dGroup(fTTests) = dGroup(fTTests) + tcount 
316
        End If
317
 
318
        End If
319
    rsQry.MoveNext
320
    Loop
321
 
322
    End If
323
    rsQry.Close
324
    Set rsQry = Nothing
325
    result = 0
326
End Sub
327
 
328
Sub csvAdd( sName, sData, byRef sHdr, byRef sDtr)
329
    sHdr = sHdr & "," & sName
330
    sDtr = sDtr & "," & sData
331
End Sub
332
'--------------------------------------------------------------------------------
333
'
334
'   Dump the data in CSV format
335
Sub DumpAsCsv
336
    On Error goto 0
337
    dim gKeys : gKeys = dataSet.Keys
338
    Dim ii,jj,kk
339
    Dim mHdr
340
    Dim sFullData
341
 
342
    for ii=0 to dataSet.Count-1
343
        ' Process one Base View
344
        Dim hdr, dtr
345
        hdr = ""
346
        dtr = ""
347
        Dim dGroup : Set dGroup = dataSet.Item(gKeys(ii))
348
        Dim hList: hList = Array(fDate, fRtagId, fPname, fRname, fGroup, fTPkgs, fTTested, fTTests,fTLoc)
349
        For jj=0 to Ubound(hList)
350
            Call csvAdd(hList(jj), dGroup(hList(jj)), hdr, dtr)   
351
        Next
352
 
353
        If  dGroup.Exists("DATA")Then
354
            Dim dData : Set dData = dGroup("DATA")
355
            dim dKeys : dKeys = dData.Keys
356
            For kk=0 to Ubound(dKeys)
357
                Dim dEl : Set dEl = dData(dKeys(kk))
358
                Dim eList: eList = Array(fpkg, fTests, fLoc )
359
                For jj=0 to Ubound(eList)
360
                    Call csvAdd(eList(jj), dEl(eList(jj)), hdr, dtr)   
361
                Next
362
            Next
363
        End If
364
 
365
        hdr = Mid(hdr, 2, Len(hdr)-1)
366
        dtr = Mid(dtr, 2, Len(dtr)-1)
367
 
368
        If Len(hdr) > Len(mHdr) Then
369
            mHdr = hdr
370
        End If
371
        sFullData = sFullData & dtr & vbCrLf  
372
    next
373
 
374
    Response.Write mHdr & vbCrLf
375
    Response.Write sFullData & vbCrLf
376
 
377
End Sub
378
%>