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 | # Port Latency Graph (https://jenkins.onosproject.org/view/QA/job/postjob-BM/lastSuccessfulBuild/artifact/SCPFportLat_master_UpErrBarWithStack.jpg): |
| 22 | # Rscript SCPFportLat.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 | errBarOutputFileUp <- paste( args[ save_directory ], |
| 68 | "SCPFportLat_", |
| 69 | args[ branch_name ], |
| 70 | "_UpErrBarWithStack.jpg", |
| 71 | sep = "" ) |
| 72 | |
| 73 | errBarOutputFileDown <- paste( args[ save_directory ], |
| 74 | "SCPFportLat_", |
| 75 | args[ branch_name ], |
| 76 | "_DownErrBarWithStack.jpg", |
| 77 | sep = "" ) |
| 78 | |
| 79 | # ------------------ |
| 80 | # SQL Initialization |
| 81 | # ------------------ |
| 82 | |
| 83 | print( "Initializing SQL" ) |
| 84 | |
| 85 | con <- initSQL( args[ database_host ], |
| 86 | args[ database_port ], |
| 87 | args[ database_u_id ], |
| 88 | args[ database_pw ] ) |
| 89 | |
| 90 | # ------------------------ |
| 91 | # Port Latency SQL Command |
| 92 | # ------------------------ |
| 93 | |
| 94 | print( "Generating Port Latency SQL Command" ) |
| 95 | |
| 96 | command <- paste( "SELECT * FROM port_latency_details WHERE branch = '", |
| 97 | args[ branch_name ], |
| 98 | "' AND date IN ( SELECT MAX( date ) FROM port_latency_details WHERE branch = '", |
| 99 | args[ branch_name ], |
| 100 | "' ) ", |
| 101 | sep = "" ) |
| 102 | |
| 103 | fileData <- retrieveData( con, command ) |
| 104 | |
| 105 | # ********************************************************** |
| 106 | # STEP 2: Organize data. |
| 107 | # ********************************************************** |
| 108 | |
| 109 | print( "**********************************************************" ) |
| 110 | print( "STEP 2: Organize Data." ) |
| 111 | print( "**********************************************************" ) |
| 112 | |
| 113 | # ----------------------------- |
| 114 | # Port Up Averages Data Sorting |
| 115 | # ----------------------------- |
| 116 | |
| 117 | print( "Sorting data for Port Up Averages." ) |
| 118 | |
| 119 | requiredColumns <- c( "up_ofp_to_dev_avg", "up_dev_to_link_avg", "up_link_to_graph_avg" ) |
| 120 | |
| 121 | tryCatch( upAvgs <- c( fileData[ requiredColumns] ), |
| 122 | error = function( e ) { |
| 123 | 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." ) |
| 124 | print( "Required columns: " ) |
| 125 | print( requiredColumns ) |
| 126 | print( "Actual columns: " ) |
| 127 | print( names( fileData ) ) |
| 128 | print( "Error dump:" ) |
| 129 | print( e ) |
| 130 | quit( status = 1 ) |
| 131 | } |
| 132 | ) |
| 133 | |
| 134 | # ---------------------------- |
| 135 | # Port Up Construct Data Frame |
| 136 | # ---------------------------- |
| 137 | |
| 138 | print( "Constructing Port Up data frame." ) |
| 139 | |
| 140 | upAvgsDataFrame <- melt( upAvgs ) |
| 141 | upAvgsDataFrame$scale <- fileData$scale |
| 142 | upAvgsDataFrame$up_std <- fileData$up_std |
| 143 | |
| 144 | colnames( upAvgsDataFrame ) <- c( "ms", |
| 145 | "type", |
| 146 | "scale", |
| 147 | "stds" ) |
| 148 | |
| 149 | upAvgsDataFrame <- na.omit( upAvgsDataFrame ) |
| 150 | |
| 151 | upAvgsDataFrame$type <- as.character( upAvgsDataFrame$type ) |
| 152 | upAvgsDataFrame$type <- factor( upAvgsDataFrame$type, levels=unique( upAvgsDataFrame$type ) ) |
| 153 | |
| 154 | sumOfUpAvgs <- fileData[ 'up_ofp_to_dev_avg' ] + |
| 155 | fileData[ 'up_dev_to_link_avg' ] + |
| 156 | fileData[ 'up_link_to_graph_avg' ] |
| 157 | |
| 158 | print( "Up Averages Results:" ) |
| 159 | print( upAvgsDataFrame ) |
| 160 | |
| 161 | # ------------------------------- |
| 162 | # Port Down Averages Data Sorting |
| 163 | # ------------------------------- |
| 164 | |
| 165 | print( "Sorting data for Port Down Averages." ) |
| 166 | |
| 167 | requiredColumns <- c( "down_ofp_to_dev_avg", "down_dev_to_link_avg", "down_link_to_graph_avg" ) |
| 168 | |
| 169 | tryCatch( downAvgs <- c( fileData[ requiredColumns] ), |
| 170 | error = function( e ) { |
| 171 | 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." ) |
| 172 | print( "Required columns: " ) |
| 173 | print( requiredColumns ) |
| 174 | print( "Actual columns: " ) |
| 175 | print( names( fileData ) ) |
| 176 | print( "Error dump:" ) |
| 177 | print( e ) |
| 178 | quit( status = 1 ) |
| 179 | } |
| 180 | ) |
| 181 | |
| 182 | # ------------------------------ |
| 183 | # Port Down Construct Data Frame |
| 184 | # ------------------------------ |
| 185 | |
| 186 | print( "Constructing Port Down data frame." ) |
| 187 | |
| 188 | downAvgsDataFrame <- melt( downAvgs ) |
| 189 | downAvgsDataFrame$scale <- fileData$scale |
| 190 | downAvgsDataFrame$down_std <- fileData$down_std |
| 191 | |
| 192 | colnames( downAvgsDataFrame ) <- c( "ms", |
| 193 | "type", |
| 194 | "scale", |
| 195 | "stds" ) |
| 196 | |
| 197 | downAvgsDataFrame <- na.omit( downAvgsDataFrame ) |
| 198 | |
| 199 | downAvgsDataFrame$type <- as.character( downAvgsDataFrame$type ) |
| 200 | downAvgsDataFrame$type <- factor( downAvgsDataFrame$type, levels=unique( downAvgsDataFrame$type ) ) |
| 201 | |
| 202 | sumOfDownAvgs <- fileData[ 'down_ofp_to_dev_avg' ] + |
| 203 | fileData[ 'down_dev_to_link_avg' ] + |
| 204 | fileData[ 'down_link_to_graph_avg' ] |
| 205 | |
| 206 | print( "Down Averages Results:" ) |
| 207 | print( downAvgsDataFrame ) |
| 208 | |
| 209 | # ********************************************************** |
| 210 | # STEP 3: Generate graphs. |
| 211 | # ********************************************************** |
| 212 | |
| 213 | print( "**********************************************************" ) |
| 214 | print( "STEP 3: Generate Graph." ) |
| 215 | print( "**********************************************************" ) |
| 216 | |
| 217 | # ------------------------------------ |
| 218 | # Initialize Variables For Both Graphs |
| 219 | # ------------------------------------ |
| 220 | |
| 221 | print( "Initializing variables used in both graphs." ) |
| 222 | |
| 223 | defaultTextSize() |
| 224 | xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9 ) ) |
| 225 | |
| 226 | xLabel <- xlab( "Scale" ) |
| 227 | yLabel <- ylab( "Latency (ms)" ) |
| 228 | fillLabel <- labs( fill="Type" ) |
| 229 | |
| 230 | barWidth <- 1 |
| 231 | |
| 232 | wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) ) |
| 233 | |
| 234 | theme <- graphTheme() |
| 235 | |
| 236 | subtitle <- lastUpdatedLabel() |
| 237 | |
| 238 | colors <- scale_fill_manual( values=c( webColor( "redv2" ), |
| 239 | webColor( "light_blue" ), |
| 240 | webColor( "green" ) ) ) |
| 241 | |
| 242 | errorBarColor <- webColor( "darkerGray" ) |
| 243 | |
| 244 | # -------------------------- |
| 245 | # Port Up Generate Main Plot |
| 246 | # -------------------------- |
| 247 | |
| 248 | print( "Generating main plot (Port Up Latency)." ) |
| 249 | |
| 250 | mainPlot <- ggplot( data = upAvgsDataFrame, aes( x = scale, |
| 251 | y = ms, |
| 252 | fill = type, |
| 253 | ymin = fileData[ 'up_end_to_end_avg' ], |
| 254 | ymax = fileData[ 'up_end_to_end_avg' ] + stds ) ) |
| 255 | |
| 256 | # -------------------------------------- |
| 257 | # Port Up Fundamental Variables Assigned |
| 258 | # -------------------------------------- |
| 259 | |
| 260 | print( "Generating fundamental graph data (Port Up Latency)." ) |
| 261 | |
| 262 | title <- labs( title = "Port Up Latency", subtitle = lastUpdatedLabel() ) |
| 263 | |
| 264 | fundamentalGraphData <- mainPlot + |
| 265 | xScaleConfig + |
| 266 | xLabel + |
| 267 | yLabel + |
| 268 | fillLabel + |
| 269 | theme + |
| 270 | wrapLegend + |
| 271 | title + |
| 272 | colors |
| 273 | |
| 274 | # ----------------------------------- |
| 275 | # Port Up Generating Bar Graph Format |
| 276 | # ----------------------------------- |
| 277 | |
| 278 | print( "Generating bar graph with error bars (Port Up Latency)." ) |
| 279 | |
| 280 | barGraphFormat <- geom_bar( stat = "identity", |
| 281 | width = barWidth ) |
| 282 | |
| 283 | errorBarFormat <- geom_errorbar( width = barWidth, |
| 284 | color = errorBarColor ) |
| 285 | |
| 286 | values <- geom_text( aes( x = upAvgsDataFrame$scale, |
| 287 | y = sumOfUpAvgs + 0.03 * max( sumOfUpAvgs ), |
| 288 | label = format( sumOfUpAvgs, |
| 289 | digits=3, |
| 290 | big.mark = ",", |
| 291 | scientific = FALSE ) ), |
| 292 | size = 7.0, |
| 293 | fontface = "bold" ) |
| 294 | |
| 295 | result <- fundamentalGraphData + |
| 296 | barGraphFormat + |
| 297 | errorBarFormat + |
| 298 | values |
| 299 | |
| 300 | # ------------------------------- |
| 301 | # Port Up Exporting Graph to File |
| 302 | # ------------------------------- |
| 303 | |
| 304 | saveGraph( errBarOutputFileUp ) |
| 305 | |
| 306 | # ---------------------------- |
| 307 | # Port Down Generate Main Plot |
| 308 | # ---------------------------- |
| 309 | |
| 310 | print( "Generating main plot (Port Down Latency)." ) |
| 311 | |
| 312 | mainPlot <- ggplot( data = downAvgsDataFrame, aes( x = scale, |
| 313 | y = ms, |
| 314 | fill = type, |
| 315 | ymin = fileData[ 'down_end_to_end_avg' ], |
| 316 | ymax = fileData[ 'down_end_to_end_avg' ] + stds ) ) |
| 317 | |
| 318 | # ---------------------------------------- |
| 319 | # Port Down Fundamental Variables Assigned |
| 320 | # ---------------------------------------- |
| 321 | |
| 322 | print( "Generating fundamental graph data (Port Down Latency)." ) |
| 323 | |
| 324 | title <- labs( title = "Port Down Latency", subtitle = lastUpdatedLabel() ) |
| 325 | |
| 326 | fundamentalGraphData <- mainPlot + |
| 327 | xScaleConfig + |
| 328 | xLabel + |
| 329 | yLabel + |
| 330 | fillLabel + |
| 331 | theme + |
| 332 | wrapLegend + |
| 333 | title + |
| 334 | colors |
| 335 | |
| 336 | # ------------------------------------- |
| 337 | # Port Down Generating Bar Graph Format |
| 338 | # ------------------------------------- |
| 339 | |
| 340 | print( "Generating bar graph with error bars (Port Down Latency)." ) |
| 341 | |
| 342 | barGraphFormat <- geom_bar( stat = "identity", |
| 343 | width = barWidth ) |
| 344 | |
| 345 | errorBarFormat <- geom_errorbar( width = barWidth, |
| 346 | color = errorBarColor ) |
| 347 | |
| 348 | values <- geom_text( aes( x = downAvgsDataFrame$scale, |
| 349 | y = sumOfDownAvgs + 0.03 * max( sumOfDownAvgs ), |
| 350 | label = format( sumOfDownAvgs, |
| 351 | digits=3, |
| 352 | big.mark = ",", |
| 353 | scientific = FALSE ) ), |
| 354 | size = 7.0, |
| 355 | fontface = "bold" ) |
| 356 | |
| 357 | result <- fundamentalGraphData + |
| 358 | barGraphFormat + |
| 359 | errorBarFormat + |
| 360 | values |
| 361 | |
| 362 | # --------------------------------- |
| 363 | # Port Down Exporting Graph to File |
| 364 | # --------------------------------- |
| 365 | |
| 366 | saveGraph( errBarOutputFileDown ) |
| 367 | quit( status = 0 ) |