blob: c6e3503891d2fb4767b6edac97dd2216d5adceef [file] [log] [blame]
Jeremy Ronquillodae11042018-02-21 09:21:44 -08001# Copyright 2017 Open Networking Foundation (ONF)
2#
3# Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
4# the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
5# or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
6#
7# TestON is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 2 of the License, or
10# (at your option) any later version.
11#
12# TestON is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with TestON. If not, see <http://www.gnu.org/licenses/>.
19#
20# Example script:
21# Mastership Failover Graph (https://jenkins.onosproject.org/view/QA/job/postjob-BM/lastSuccessfulBuild/artifact/SCPFmastershipFailoverLat_master_errGraph.jpg):
22# Rscript SCPFspecificGraphRScripts/SCPFmastershipFailoverLat.R <url> <port> <username> <pass> SCPFmastershipFailoverLat master /path/to/save/directory/
23
24# **********************************************************
25# STEP 1: Data management.
26# **********************************************************
27
28print( "**********************************************************" )
29print( "STEP 1: Data management." )
30print( "**********************************************************" )
31
32save_directory <- 7
33
34# Command line arguments are read.
35print( "Reading commmand-line args." )
36args <- commandArgs( trailingOnly=TRUE )
37
38# ----------------
39# Import Libraries
40# ----------------
41
42print( "Importing libraries." )
43library( ggplot2 )
44library( reshape2 )
45library( RPostgreSQL ) # For databases
Devin Lim324806b2018-05-11 15:36:52 -070046source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" )
47source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" )
48source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" )
49source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" )
Jeremy Ronquillodae11042018-02-21 09:21:44 -080050
51# -------------------
52# Check CLI Arguments
53# -------------------
54
55print( "Verifying CLI args." )
56
57if ( length( args ) != save_directory ){
58 usage( "SCPFmastershipFailoverLat.R" )
59 quit( status = 1 )
60}
61
62# -----------------
63# Create File Names
64# -----------------
65
66print( "Creating filenames and title of graph." )
67
68chartTitle <- "Mastership Failover Latency"
69
70errBarOutputFile <- paste( args[ save_directory ],
71 args[ graph_title ],
72 "_",
73 args[ branch_name ],
74 "_errGraph.jpg",
75 sep="" )
76
77stackedBarOutputFile <- paste( args[ save_directory ],
78 args[ graph_title ],
79 "_",
80 args[ branch_name ],
81 "_stackedGraph.jpg",
82 sep="" )
83
84# ------------------
85# SQL Initialization
86# ------------------
87
88print( "Initializing SQL" )
89
90con <- initSQL( args[ database_host ],
91 args[ database_port ],
92 args[ database_u_id ],
93 args[ database_pw ] )
94
95# ---------------------------------------
96# Mastership Failover Latency SQL Command
97# ---------------------------------------
98
99print( "Generating Mastership Failover Latency SQL command" )
100
101command <- paste( "SELECT * FROM mastership_failover_tests WHERE branch = '",
102 args[ branch_name ],
103 "' AND date IN ( SELECT MAX( date ) FROM mastership_failover_tests WHERE branch = '",
104 args[ branch_name ],
105 "' ) ",
106 sep = "" )
107
108fileData <- retrieveData( con, command )
109
110# **********************************************************
111# STEP 2: Organize data.
112# **********************************************************
113
114print( "**********************************************************" )
115print( "STEP 2: Organize Data." )
116print( "**********************************************************" )
117
118# ------------
119# Data Sorting
120# ------------
121
122print( "Combining averages into a list." )
123
124requiredColumns <- c( "kill_deact_avg", "deact_role_avg" )
125
126tryCatch( avgs <- c( fileData[ requiredColumns] ),
127 error = function( e ) {
128 print( "[ERROR] One or more expected columns are missing from the data. Please check that the data and SQL command are valid, then try again." )
129 print( "Required columns: " )
130 print( requiredColumns )
131 print( "Actual columns: " )
132 print( names( fileData ) )
133 print( "Error dump:" )
134 print( e )
135 quit( status = 1 )
136 }
137 )
138
139# --------------------
140# Construct Data Frame
141# --------------------
142
143print( "Constructing Data Frame from list." )
144
145dataFrame <- melt( avgs )
146dataFrame$scale <- fileData$scale
147dataFrame$stds <- c( fileData$kill_deact_std,
148 fileData$deact_role_std )
149
150colnames( dataFrame ) <- c( "ms",
151 "type",
152 "scale",
153 "stds" )
154
155dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
156
157sum <- fileData[ 'deact_role_avg' ] +
158 fileData[ 'kill_deact_avg' ]
159
160print( "Data Frame Results:" )
161print( dataFrame )
162
163
164# **********************************************************
165# STEP 3: Generate graphs.
166# **********************************************************
167
168print( "**********************************************************" )
169print( "STEP 3: Generate Graph." )
170print( "**********************************************************" )
171
172# ------------------------------------
173# Initialize Variables for Both Graphs
174# ------------------------------------
175
176print( "Initializing variables used in both graphs." )
177
178defaultTextSize()
179xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9) )
180
181xLabel <- xlab( "Scale" )
182yLabel <- ylab( "Latency (ms)" )
183fillLabel <- labs( fill = "Type" )
184
185barWidth <- 0.9
186
187theme <- graphTheme()
188
189barColors <- scale_fill_manual( values=c( webColor( "redv2" ),
190 webColor( "light_blue" ) ) )
191
192wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
193
194# ----------------------------------
195# Error Bar Graph Generate Main Plot
196# ----------------------------------
197
198print( "Creating main plot." )
199
200mainPlot <- ggplot( data = dataFrame, aes( x = scale,
201 y = ms,
202 ymin = ms,
203 ymax = ms + stds,
204 fill = type ) )
205
206# ----------------------------------------------
207# Error Bar Graph Fundamental Variables Assigned
208# ----------------------------------------------
209
210print( "Generating fundamental graph data for the error bar graph." )
211
212title <- labs( title = chartTitle, subtitle = lastUpdatedLabel() )
213
214fundamentalGraphData <- mainPlot +
215 xScaleConfig +
216 xLabel +
217 yLabel +
218 fillLabel +
219 theme +
220 title +
221 wrapLegend
222
223# -------------------------------------------
224# Error Bar Graph Generating Bar Graph Format
225# -------------------------------------------
226
227print( "Generating bar graph with error bars." )
228
229barGraphFormat <- geom_bar( stat = "identity",
230 position = position_dodge(),
231 width = barWidth )
232
233errorBarFormat <- geom_errorbar( width = barWidth,
234 position = position_dodge(),
235 color = webColor( "darkerGray" ) )
236
237values <- geom_text( aes( x = dataFrame$scale,
238 y = dataFrame$ms + 0.02 * max( dataFrame$ms ),
239 label = format( dataFrame$ms,
240 digits = 3,
241 big.mark = ",",
242 scientific = FALSE ) ),
243 size = 7.0,
244 fontface = "bold",
245 position = position_dodge( 0.9 ) )
246
247result <- fundamentalGraphData +
248 barGraphFormat +
249 barColors +
250 errorBarFormat +
251 values
252
253# ---------------------------------------
254# Error Bar Graph Exporting Graph to File
255# ---------------------------------------
256
257saveGraph( errBarOutputFile )
258
259# ------------------------------------------------
260# Stacked Bar Graph Fundamental Variables Assigned
261# ------------------------------------------------
262
263print( "Generating fundamental graph data for the stacked bar graph." )
264
265title <- labs( title = chartTitle, subtitle = lastUpdatedLabel() )
266
267fundamentalGraphData <- mainPlot +
268 xScaleConfig +
269 xLabel +
270 yLabel +
271 fillLabel +
272 theme +
273 title +
274 wrapLegend
275
276# ---------------------------------------------
277# Stacked Bar Graph Generating Bar Graph Format
278# ---------------------------------------------
279
280print( "Generating stacked bar chart." )
281stackedBarFormat <- geom_bar( stat = "identity",
282 width = barWidth )
283
284values <- geom_text( aes( x = dataFrame$scale,
285 y = sum + 0.02 * max( sum ),
286 label = format( sum,
287 digits = 3,
288 big.mark = ",",
289 scientific = FALSE ) ),
290 size = 7.0,
291 fontface = "bold" )
292
293result <- fundamentalGraphData +
294 stackedBarFormat +
295 barColors +
296 title +
297 values
298
299# -----------------------------------------
300# Stacked Bar Graph Exporting Graph to File
301# -----------------------------------------
302
303saveGraph( stackedBarOutputFile )