blob: 7684a5f0ff5177995460e4e8145c35221ff761ca [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# 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
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( "SCPFscaleTopo.R" )
59 quit( status = 1 )
60}
61
62# -----------------
63# Create File Names
64# -----------------
65
66print( "Creating filenames and title of graph." )
67
68outputFile <- paste( args[ save_directory ],
69 args[ graph_title ],
70 "_",
71 args[ branch_name ],
72 "_graph.jpg",
73 sep="" )
74
75chartTitle <- "Scale Topology Latency Test"
76
77# ------------------
78# SQL Initialization
79# ------------------
80
81print( "Initializing SQL" )
82
83con <- 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
92print( "Generating Scale Topology SQL Command" )
93
94command <- 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
101fileData <- retrieveData( con, command )
102
103# **********************************************************
104# STEP 2: Organize data.
105# **********************************************************
106
107print( "**********************************************************" )
108print( "STEP 2: Organize Data." )
109print( "**********************************************************" )
110
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800111latestBuildDate <- fileData$date[1]
112
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800113# ------------
114# Data Sorting
115# ------------
116
117print( "Sorting data." )
118
119requiredColumns <- c( "last_role_request_to_last_topology", "last_connection_to_last_role_request", "first_connection_to_last_connection" )
120
121tryCatch( avgs <- 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# Construct Data Frame
136# --------------------
137
138print( "Constructing Data Frame" )
139
140# Parse lists into data frames.
141dataFrame <- melt( avgs )
142dataFrame$scale <- fileData$scale
143colnames( dataFrame ) <- c( "s",
144 "type",
145 "scale")
146
147# Format data frame so that the data is in the same order as it appeared in the file.
148dataFrame$type <- as.character( dataFrame$type )
149dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
150dataFrame$iterative <- seq( 1, nrow( fileData ), by = 1 )
151
152dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
153
154sum <- fileData[ 'last_role_request_to_last_topology' ] +
155 fileData[ 'last_connection_to_last_role_request' ] +
156 fileData[ 'first_connection_to_last_connection' ]
157
158print( "Data Frame Results:" )
159print( dataFrame )
160
161# **********************************************************
162# STEP 3: Generate graphs.
163# **********************************************************
164
165print( "**********************************************************" )
166print( "STEP 3: Generate Graph." )
167print( "**********************************************************" )
168
169# ------------------
170# Generate Main Plot
171# ------------------
172
173print( "Creating main plot." )
174
175mainPlot <- ggplot( data = dataFrame, aes( x = iterative,
176 y = s,
177 fill = type ) )
178
179# ------------------------------
180# Fundamental Variables Assigned
181# ------------------------------
182
183print( "Generating fundamental graph data." )
184
185defaultTextSize()
186xScaleConfig <- scale_x_continuous( breaks = dataFrame$iterative,
187 label = dataFrame$scale )
188xLabel <- xlab( "Scale" )
189yLabel <- ylab( "Latency (s)" )
190fillLabel <- labs( fill="Type" )
191
192width <- 0.6 # Width of the bars.
193
194theme <- graphTheme()
195
196colors <- scale_fill_manual( values=c( webColor( "redv2" ),
197 webColor( "green" ),
198 webColor( "light_blue" ) ) )
199
200values <- geom_text( aes( x = dataFrame$iterative,
201 y = sum + 0.02 * max( sum ),
202 label = format( sum,
203 big.mark = ",",
204 scientific = FALSE ),
205 fontface = "bold" ),
206 size = 7.0 )
207
208wrapLegend <- guides( fill = guide_legend( nrow=2, byrow=TRUE ) )
209
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800210title <- labs( title = chartTitle, subtitle = lastUpdatedLabel( latestBuildDate ) )
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800211
212# Store plot configurations as 1 variable
213fundamentalGraphData <- mainPlot +
214 xScaleConfig +
215 xLabel +
216 yLabel +
217 fillLabel +
218 theme +
219 values +
220 wrapLegend +
221 title +
222 colors
223
224# ---------------------------
225# Generating Bar Graph Format
226# ---------------------------
227
228print( "Generating bar graph." )
229
230barGraphFormat <- geom_bar( stat = "identity", width = width )
231
232result <- fundamentalGraphData +
233 barGraphFormat
234
235# -----------------------
236# Exporting Graph to File
237# -----------------------
238
239saveGraph( outputFile )
240quit( status = 0 )