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 | # Scale Topology Latency Test Graph (https://jenkins.onosproject.org/view/QA/job/postjob-BM/lastSuccessfulBuild/artifact/SCPFscaleTopo_master_graph.jpg): |
| 22 | # Rscript SCPFspecificGraphRScripts/SCPFscaleTopo.R <url> <port> <username> <pass> SCPFscaleTopo 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( "SCPFscaleTopo.R" ) |
| 59 | quit( status = 1 ) |
| 60 | } |
| 61 | |
| 62 | # ----------------- |
| 63 | # Create File Names |
| 64 | # ----------------- |
| 65 | |
| 66 | print( "Creating filenames and title of graph." ) |
| 67 | |
| 68 | outputFile <- paste( args[ save_directory ], |
| 69 | args[ graph_title ], |
| 70 | "_", |
| 71 | args[ branch_name ], |
| 72 | "_graph.jpg", |
| 73 | sep="" ) |
| 74 | |
| 75 | chartTitle <- "Scale Topology Latency Test" |
| 76 | |
| 77 | # ------------------ |
| 78 | # SQL Initialization |
| 79 | # ------------------ |
| 80 | |
| 81 | print( "Initializing SQL" ) |
| 82 | |
| 83 | con <- initSQL( args[ database_host ], |
| 84 | args[ database_port ], |
| 85 | args[ database_u_id ], |
| 86 | args[ database_pw ] ) |
| 87 | |
| 88 | # -------------------------- |
| 89 | # Scale Topology SQL Command |
| 90 | # -------------------------- |
| 91 | |
| 92 | print( "Generating Scale Topology SQL Command" ) |
| 93 | |
| 94 | command <- paste( "SELECT * FROM scale_topo_latency_details WHERE branch = '", |
| 95 | args[ branch_name ], |
| 96 | "' AND date IN ( SELECT MAX( date ) FROM scale_topo_latency_details WHERE branch = '", |
| 97 | args[ branch_name ], |
| 98 | "' ) ", |
| 99 | sep = "" ) |
| 100 | |
| 101 | fileData <- retrieveData( con, command ) |
| 102 | |
| 103 | # ********************************************************** |
| 104 | # STEP 2: Organize data. |
| 105 | # ********************************************************** |
| 106 | |
| 107 | print( "**********************************************************" ) |
| 108 | print( "STEP 2: Organize Data." ) |
| 109 | print( "**********************************************************" ) |
| 110 | |
| 111 | # ------------ |
| 112 | # Data Sorting |
| 113 | # ------------ |
| 114 | |
| 115 | print( "Sorting data." ) |
| 116 | |
| 117 | requiredColumns <- c( "last_role_request_to_last_topology", "last_connection_to_last_role_request", "first_connection_to_last_connection" ) |
| 118 | |
| 119 | tryCatch( avgs <- c( fileData[ requiredColumns] ), |
| 120 | error = function( e ) { |
| 121 | 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." ) |
| 122 | print( "Required columns: " ) |
| 123 | print( requiredColumns ) |
| 124 | print( "Actual columns: " ) |
| 125 | print( names( fileData ) ) |
| 126 | print( "Error dump:" ) |
| 127 | print( e ) |
| 128 | quit( status = 1 ) |
| 129 | } |
| 130 | ) |
| 131 | |
| 132 | # -------------------- |
| 133 | # Construct Data Frame |
| 134 | # -------------------- |
| 135 | |
| 136 | print( "Constructing Data Frame" ) |
| 137 | |
| 138 | # Parse lists into data frames. |
| 139 | dataFrame <- melt( avgs ) |
| 140 | dataFrame$scale <- fileData$scale |
| 141 | colnames( dataFrame ) <- c( "s", |
| 142 | "type", |
| 143 | "scale") |
| 144 | |
| 145 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 146 | dataFrame$type <- as.character( dataFrame$type ) |
| 147 | dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) ) |
| 148 | dataFrame$iterative <- seq( 1, nrow( fileData ), by = 1 ) |
| 149 | |
| 150 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 151 | |
| 152 | sum <- fileData[ 'last_role_request_to_last_topology' ] + |
| 153 | fileData[ 'last_connection_to_last_role_request' ] + |
| 154 | fileData[ 'first_connection_to_last_connection' ] |
| 155 | |
| 156 | print( "Data Frame Results:" ) |
| 157 | print( dataFrame ) |
| 158 | |
| 159 | # ********************************************************** |
| 160 | # STEP 3: Generate graphs. |
| 161 | # ********************************************************** |
| 162 | |
| 163 | print( "**********************************************************" ) |
| 164 | print( "STEP 3: Generate Graph." ) |
| 165 | print( "**********************************************************" ) |
| 166 | |
| 167 | # ------------------ |
| 168 | # Generate Main Plot |
| 169 | # ------------------ |
| 170 | |
| 171 | print( "Creating main plot." ) |
| 172 | |
| 173 | mainPlot <- ggplot( data = dataFrame, aes( x = iterative, |
| 174 | y = s, |
| 175 | fill = type ) ) |
| 176 | |
| 177 | # ------------------------------ |
| 178 | # Fundamental Variables Assigned |
| 179 | # ------------------------------ |
| 180 | |
| 181 | print( "Generating fundamental graph data." ) |
| 182 | |
| 183 | defaultTextSize() |
| 184 | xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative, |
| 185 | label = dataFrame$scale ) |
| 186 | xLabel <- xlab( "Scale" ) |
| 187 | yLabel <- ylab( "Latency (s)" ) |
| 188 | fillLabel <- labs( fill="Type" ) |
| 189 | |
| 190 | width <- 0.6 # Width of the bars. |
| 191 | |
| 192 | theme <- graphTheme() |
| 193 | |
| 194 | colors <- scale_fill_manual( values=c( webColor( "redv2" ), |
| 195 | webColor( "green" ), |
| 196 | webColor( "light_blue" ) ) ) |
| 197 | |
| 198 | values <- geom_text( aes( x = dataFrame$iterative, |
| 199 | y = sum + 0.02 * max( sum ), |
| 200 | label = format( sum, |
| 201 | big.mark = ",", |
| 202 | scientific = FALSE ), |
| 203 | fontface = "bold" ), |
| 204 | size = 7.0 ) |
| 205 | |
| 206 | wrapLegend <- guides( fill = guide_legend( nrow=2, byrow=TRUE ) ) |
| 207 | |
| 208 | title <- labs( title = chartTitle, subtitle = lastUpdatedLabel() ) |
| 209 | |
| 210 | # Store plot configurations as 1 variable |
| 211 | fundamentalGraphData <- mainPlot + |
| 212 | xScaleConfig + |
| 213 | xLabel + |
| 214 | yLabel + |
| 215 | fillLabel + |
| 216 | theme + |
| 217 | values + |
| 218 | wrapLegend + |
| 219 | title + |
| 220 | colors |
| 221 | |
| 222 | # --------------------------- |
| 223 | # Generating Bar Graph Format |
| 224 | # --------------------------- |
| 225 | |
| 226 | print( "Generating bar graph." ) |
| 227 | |
| 228 | barGraphFormat <- geom_bar( stat = "identity", width = width ) |
| 229 | |
| 230 | result <- fundamentalGraphData + |
| 231 | barGraphFormat |
| 232 | |
| 233 | # ----------------------- |
| 234 | # Exporting Graph to File |
| 235 | # ----------------------- |
| 236 | |
| 237 | saveGraph( outputFile ) |
| 238 | quit( status = 0 ) |