blob: 2eb41456f25bc220a6585476c3b8cc119e4bb0fc [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
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800118latestBuildDate <- fileData$date[1]
119
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800120# ------------
121# Data Sorting
122# ------------
123
124print( "Combining averages into a list." )
125
126requiredColumns <- c( "kill_deact_avg", "deact_role_avg" )
127
128tryCatch( avgs <- c( fileData[ requiredColumns] ),
129 error = function( e ) {
130 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." )
131 print( "Required columns: " )
132 print( requiredColumns )
133 print( "Actual columns: " )
134 print( names( fileData ) )
135 print( "Error dump:" )
136 print( e )
137 quit( status = 1 )
138 }
139 )
140
141# --------------------
142# Construct Data Frame
143# --------------------
144
145print( "Constructing Data Frame from list." )
146
147dataFrame <- melt( avgs )
148dataFrame$scale <- fileData$scale
149dataFrame$stds <- c( fileData$kill_deact_std,
150 fileData$deact_role_std )
151
152colnames( dataFrame ) <- c( "ms",
153 "type",
154 "scale",
155 "stds" )
156
157dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
158
159sum <- fileData[ 'deact_role_avg' ] +
160 fileData[ 'kill_deact_avg' ]
161
162print( "Data Frame Results:" )
163print( dataFrame )
164
165
166# **********************************************************
167# STEP 3: Generate graphs.
168# **********************************************************
169
170print( "**********************************************************" )
171print( "STEP 3: Generate Graph." )
172print( "**********************************************************" )
173
174# ------------------------------------
175# Initialize Variables for Both Graphs
176# ------------------------------------
177
178print( "Initializing variables used in both graphs." )
179
180defaultTextSize()
181xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9) )
182
183xLabel <- xlab( "Scale" )
184yLabel <- ylab( "Latency (ms)" )
185fillLabel <- labs( fill = "Type" )
186
187barWidth <- 0.9
188
189theme <- graphTheme()
190
191barColors <- scale_fill_manual( values=c( webColor( "redv2" ),
192 webColor( "light_blue" ) ) )
193
194wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
195
196# ----------------------------------
197# Error Bar Graph Generate Main Plot
198# ----------------------------------
199
200print( "Creating main plot." )
201
202mainPlot <- ggplot( data = dataFrame, aes( x = scale,
203 y = ms,
204 ymin = ms,
205 ymax = ms + stds,
206 fill = type ) )
207
208# ----------------------------------------------
209# Error Bar Graph Fundamental Variables Assigned
210# ----------------------------------------------
211
212print( "Generating fundamental graph data for the error bar graph." )
213
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800214title <- labs( title = chartTitle, subtitle = lastUpdatedLabel( latestBuildDate ) )
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800215
216fundamentalGraphData <- mainPlot +
217 xScaleConfig +
218 xLabel +
219 yLabel +
220 fillLabel +
221 theme +
222 title +
223 wrapLegend
224
225# -------------------------------------------
226# Error Bar Graph Generating Bar Graph Format
227# -------------------------------------------
228
229print( "Generating bar graph with error bars." )
230
231barGraphFormat <- geom_bar( stat = "identity",
232 position = position_dodge(),
233 width = barWidth )
234
235errorBarFormat <- geom_errorbar( width = barWidth,
236 position = position_dodge(),
237 color = webColor( "darkerGray" ) )
238
239values <- geom_text( aes( x = dataFrame$scale,
240 y = dataFrame$ms + 0.02 * max( dataFrame$ms ),
241 label = format( dataFrame$ms,
242 digits = 3,
243 big.mark = ",",
244 scientific = FALSE ) ),
245 size = 7.0,
246 fontface = "bold",
247 position = position_dodge( 0.9 ) )
248
249result <- fundamentalGraphData +
250 barGraphFormat +
251 barColors +
252 errorBarFormat +
253 values
254
255# ---------------------------------------
256# Error Bar Graph Exporting Graph to File
257# ---------------------------------------
258
259saveGraph( errBarOutputFile )
260
261# ------------------------------------------------
262# Stacked Bar Graph Fundamental Variables Assigned
263# ------------------------------------------------
264
265print( "Generating fundamental graph data for the stacked bar graph." )
266
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800267title <- labs( title = chartTitle, subtitle = lastUpdatedLabel( latestBuildDate ) )
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800268
269fundamentalGraphData <- mainPlot +
270 xScaleConfig +
271 xLabel +
272 yLabel +
273 fillLabel +
274 theme +
275 title +
276 wrapLegend
277
278# ---------------------------------------------
279# Stacked Bar Graph Generating Bar Graph Format
280# ---------------------------------------------
281
282print( "Generating stacked bar chart." )
283stackedBarFormat <- geom_bar( stat = "identity",
284 width = barWidth )
285
286values <- geom_text( aes( x = dataFrame$scale,
287 y = sum + 0.02 * max( sum ),
288 label = format( sum,
289 digits = 3,
290 big.mark = ",",
291 scientific = FALSE ) ),
292 size = 7.0,
293 fontface = "bold" )
294
295result <- fundamentalGraphData +
296 stackedBarFormat +
297 barColors +
298 title +
299 values
300
301# -----------------------------------------
302# Stacked Bar Graph Exporting Graph to File
303# -----------------------------------------
304
305saveGraph( stackedBarOutputFile )