Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 1 | # 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 | |
| 28 | print( "**********************************************************" ) |
| 29 | print( "STEP 1: Data management." ) |
| 30 | print( "**********************************************************" ) |
| 31 | |
| 32 | save_directory <- 7 |
| 33 | |
| 34 | # Command line arguments are read. |
| 35 | print( "Reading commmand-line args." ) |
| 36 | args <- commandArgs( trailingOnly=TRUE ) |
| 37 | |
| 38 | # ---------------- |
| 39 | # Import Libraries |
| 40 | # ---------------- |
| 41 | |
| 42 | print( "Importing libraries." ) |
| 43 | library( ggplot2 ) |
| 44 | library( reshape2 ) |
| 45 | library( RPostgreSQL ) # For databases |
Devin Lim | 324806b | 2018-05-11 15:36:52 -0700 | [diff] [blame] | 46 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" ) |
| 47 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" ) |
| 48 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" ) |
| 49 | source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 50 | |
| 51 | # ------------------- |
| 52 | # Check CLI Arguments |
| 53 | # ------------------- |
| 54 | |
| 55 | print( "Verifying CLI args." ) |
| 56 | |
| 57 | if ( length( args ) != save_directory ){ |
| 58 | usage( "SCPFmastershipFailoverLat.R" ) |
| 59 | quit( status = 1 ) |
| 60 | } |
| 61 | |
| 62 | # ----------------- |
| 63 | # Create File Names |
| 64 | # ----------------- |
| 65 | |
| 66 | print( "Creating filenames and title of graph." ) |
| 67 | |
| 68 | chartTitle <- "Mastership Failover Latency" |
| 69 | |
| 70 | errBarOutputFile <- paste( args[ save_directory ], |
| 71 | args[ graph_title ], |
| 72 | "_", |
| 73 | args[ branch_name ], |
| 74 | "_errGraph.jpg", |
| 75 | sep="" ) |
| 76 | |
| 77 | stackedBarOutputFile <- 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 | |
| 88 | print( "Initializing SQL" ) |
| 89 | |
| 90 | con <- 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 | |
| 99 | print( "Generating Mastership Failover Latency SQL command" ) |
| 100 | |
| 101 | command <- 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 | |
| 108 | fileData <- retrieveData( con, command ) |
| 109 | |
| 110 | # ********************************************************** |
| 111 | # STEP 2: Organize data. |
| 112 | # ********************************************************** |
| 113 | |
| 114 | print( "**********************************************************" ) |
| 115 | print( "STEP 2: Organize Data." ) |
| 116 | print( "**********************************************************" ) |
| 117 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 118 | latestBuildDate <- fileData$date[1] |
| 119 | |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 120 | # ------------ |
| 121 | # Data Sorting |
| 122 | # ------------ |
| 123 | |
| 124 | print( "Combining averages into a list." ) |
| 125 | |
| 126 | requiredColumns <- c( "kill_deact_avg", "deact_role_avg" ) |
| 127 | |
| 128 | tryCatch( 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 | |
| 145 | print( "Constructing Data Frame from list." ) |
| 146 | |
| 147 | dataFrame <- melt( avgs ) |
| 148 | dataFrame$scale <- fileData$scale |
| 149 | dataFrame$stds <- c( fileData$kill_deact_std, |
| 150 | fileData$deact_role_std ) |
| 151 | |
| 152 | colnames( dataFrame ) <- c( "ms", |
| 153 | "type", |
| 154 | "scale", |
| 155 | "stds" ) |
| 156 | |
| 157 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 158 | |
| 159 | sum <- fileData[ 'deact_role_avg' ] + |
| 160 | fileData[ 'kill_deact_avg' ] |
| 161 | |
| 162 | print( "Data Frame Results:" ) |
| 163 | print( dataFrame ) |
| 164 | |
| 165 | |
| 166 | # ********************************************************** |
| 167 | # STEP 3: Generate graphs. |
| 168 | # ********************************************************** |
| 169 | |
| 170 | print( "**********************************************************" ) |
| 171 | print( "STEP 3: Generate Graph." ) |
| 172 | print( "**********************************************************" ) |
| 173 | |
| 174 | # ------------------------------------ |
| 175 | # Initialize Variables for Both Graphs |
| 176 | # ------------------------------------ |
| 177 | |
| 178 | print( "Initializing variables used in both graphs." ) |
| 179 | |
| 180 | defaultTextSize() |
| 181 | xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9) ) |
| 182 | |
| 183 | xLabel <- xlab( "Scale" ) |
| 184 | yLabel <- ylab( "Latency (ms)" ) |
| 185 | fillLabel <- labs( fill = "Type" ) |
| 186 | |
| 187 | barWidth <- 0.9 |
| 188 | |
| 189 | theme <- graphTheme() |
| 190 | |
| 191 | barColors <- scale_fill_manual( values=c( webColor( "redv2" ), |
| 192 | webColor( "light_blue" ) ) ) |
| 193 | |
| 194 | wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) ) |
| 195 | |
| 196 | # ---------------------------------- |
| 197 | # Error Bar Graph Generate Main Plot |
| 198 | # ---------------------------------- |
| 199 | |
| 200 | print( "Creating main plot." ) |
| 201 | |
| 202 | mainPlot <- 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 | |
| 212 | print( "Generating fundamental graph data for the error bar graph." ) |
| 213 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 214 | title <- labs( title = chartTitle, subtitle = lastUpdatedLabel( latestBuildDate ) ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 215 | |
| 216 | fundamentalGraphData <- 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 | |
| 229 | print( "Generating bar graph with error bars." ) |
| 230 | |
| 231 | barGraphFormat <- geom_bar( stat = "identity", |
| 232 | position = position_dodge(), |
| 233 | width = barWidth ) |
| 234 | |
| 235 | errorBarFormat <- geom_errorbar( width = barWidth, |
| 236 | position = position_dodge(), |
| 237 | color = webColor( "darkerGray" ) ) |
| 238 | |
| 239 | values <- 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 | |
| 249 | result <- fundamentalGraphData + |
| 250 | barGraphFormat + |
| 251 | barColors + |
| 252 | errorBarFormat + |
| 253 | values |
| 254 | |
| 255 | # --------------------------------------- |
| 256 | # Error Bar Graph Exporting Graph to File |
| 257 | # --------------------------------------- |
| 258 | |
| 259 | saveGraph( errBarOutputFile ) |
| 260 | |
| 261 | # ------------------------------------------------ |
| 262 | # Stacked Bar Graph Fundamental Variables Assigned |
| 263 | # ------------------------------------------------ |
| 264 | |
| 265 | print( "Generating fundamental graph data for the stacked bar graph." ) |
| 266 | |
Jeremy Ronquillo | 76efee4 | 2020-01-13 13:27:44 -0800 | [diff] [blame] | 267 | title <- labs( title = chartTitle, subtitle = lastUpdatedLabel( latestBuildDate ) ) |
Jeremy Ronquillo | dae1104 | 2018-02-21 09:21:44 -0800 | [diff] [blame] | 268 | |
| 269 | fundamentalGraphData <- 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 | |
| 282 | print( "Generating stacked bar chart." ) |
| 283 | stackedBarFormat <- geom_bar( stat = "identity", |
| 284 | width = barWidth ) |
| 285 | |
| 286 | values <- 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 | |
| 295 | result <- fundamentalGraphData + |
| 296 | stackedBarFormat + |
| 297 | barColors + |
| 298 | title + |
| 299 | values |
| 300 | |
| 301 | # ----------------------------------------- |
| 302 | # Stacked Bar Graph Exporting Graph to File |
| 303 | # ----------------------------------------- |
| 304 | |
| 305 | saveGraph( stackedBarOutputFile ) |