@@ -125,32 +125,84 @@ def add_project_runs(args):
125
125
project_run_data ['hostOses_set' ] = set ()
126
126
project_run_data ['hostOses_set' ].add (args .host_os )
127
127
128
- add_report (project_run_data , args .build_report , True , args .build_id , args .host_os )
128
+ if args .build_report :
129
+ add_report (project_run_data , args .build_report , True , args .build_id , args .host_os )
129
130
130
- if ( args .test_report ) :
131
+ if args .test_report :
131
132
add_report (project_run_data , args .test_report , False , args .build_id , args .host_os )
132
133
133
- ts_data = format_project_run_data (project_run_data )
134
- r = requests .post (urlparse .urljoin (args .url , "api/projectRuns" ), headers = create_headers (args ), json = ts_data )
135
- finish_command ('add-project-runs' , r )
134
+ ts_data = format_project_run_data (project_run_data , args .limit )
135
+ total_result = True
136
+
137
+ total_parts = len (ts_data )
138
+ print "Uploading project runs in %d parts" % total_parts
139
+
140
+ for index , data in enumerate (ts_data ):
141
+ r = requests .post (urlparse .urljoin (args .url , "api/projectRuns" ), headers = create_headers (args ), json = data )
142
+ print ("add-project-runs part %d/%d" % (index + 1 , total_parts ), r .status_code , r .reason )
143
+ print (r .text )
144
+
145
+ if r .status_code >= 400 :
146
+ total_result = False
147
+
148
+ if total_result :
149
+ print "'add-project-runs' completed successfully"
150
+ sys .exit (0 )
151
+ else :
152
+ print "'add-project-runs' failed"
153
+ sys .exit (2 )
136
154
137
- def format_project_run_data ( project_run_data ):
155
+ def prep_ts_data ( ):
138
156
ts_data = {}
139
157
ts_data ['projectRuns' ] = []
158
+ ts_data ['platforms' ] = set ()
159
+ ts_data ['vendors' ] = set ()
160
+ ts_data ['toolchains' ] = set ()
161
+ ts_data ['names' ] = set ()
162
+ ts_data ['hostOses' ] = set ()
163
+ return ts_data
140
164
141
- for hostOs in project_run_data ['projectRuns' ].values ():
142
- for platform in hostOs .values ():
143
- for toolchain in platform .values ():
144
- for project in toolchain .values ():
145
- ts_data ['projectRuns' ].append (project )
146
-
147
- ts_data ['platforms' ] = list (project_run_data ['platforms_set' ])
165
+ def finish_ts_data (ts_data , project_run_data ):
166
+ ts_data ['platforms' ] = list (ts_data ['platforms' ])
167
+ ts_data ['vendors' ] = list (ts_data ['vendors' ])
168
+ ts_data ['toolchains' ] = list (ts_data ['toolchains' ])
169
+ ts_data ['names' ] = list (ts_data ['names' ])
170
+ ts_data ['hostOses' ] = list (ts_data ['hostOses' ])
171
+
172
+ # Add all vendors to every projectRun submission
173
+ # TODO Either add "vendor" to the "project_run_data"
174
+ # or remove "vendor" entirely from the viewer
148
175
ts_data ['vendors' ] = list (project_run_data ['vendors_set' ])
149
- ts_data ['toolchains' ] = list (project_run_data ['toolchains_set' ])
150
- ts_data ['names' ] = list (project_run_data ['names_set' ])
151
- ts_data ['hostOses' ] = list (project_run_data ['hostOses_set' ])
176
+
177
+ def format_project_run_data (project_run_data , limit ):
178
+ all_ts_data = []
179
+ current_limit_count = 0
180
+
181
+ ts_data = prep_ts_data ()
182
+ ts_data ['projectRuns' ] = []
152
183
153
- return ts_data
184
+ for hostOs_name , hostOs in project_run_data ['projectRuns' ].iteritems ():
185
+ for platform_name , platform in hostOs .iteritems ():
186
+ for toolchain_name , toolchain in platform .iteritems ():
187
+ for project_name , project in toolchain .iteritems ():
188
+ if current_limit_count >= limit :
189
+ finish_ts_data (ts_data , project_run_data )
190
+ all_ts_data .append (ts_data )
191
+ ts_data = prep_ts_data ()
192
+ current_limit_count = 0
193
+
194
+ ts_data ['projectRuns' ].append (project )
195
+ ts_data ['platforms' ].add (platform_name )
196
+ ts_data ['toolchains' ].add (toolchain_name )
197
+ ts_data ['names' ].add (project_name )
198
+ ts_data ['hostOses' ].add (hostOs_name )
199
+ current_limit_count += 1
200
+
201
+ if current_limit_count > 0 :
202
+ finish_ts_data (ts_data , project_run_data )
203
+ all_ts_data .append (ts_data )
204
+
205
+ return all_ts_data
154
206
155
207
def find_project_run (projectRuns , project ):
156
208
keys = ['hostOs' , 'platform' , 'toolchain' , 'project' ]
@@ -308,9 +360,10 @@ def main(arguments):
308
360
309
361
add_project_runs_parser = subparsers .add_parser ('add-project-runs' , help = 'add project runs to a build' )
310
362
add_project_runs_parser .add_argument ('-b' , '--build-id' , required = True , help = 'build id' )
311
- add_project_runs_parser .add_argument ('-r' , '--build-report' , required = True , help = 'path to junit xml build report' )
363
+ add_project_runs_parser .add_argument ('-r' , '--build-report' , required = False , help = 'path to junit xml build report' )
312
364
add_project_runs_parser .add_argument ('-t' , '--test-report' , required = False , help = 'path to junit xml test report' )
313
365
add_project_runs_parser .add_argument ('-o' , '--host-os' , required = True , help = 'host os on which test was run' )
366
+ add_project_runs_parser .add_argument ('-l' , '--limit' , required = False , type = int , default = 1000 , help = 'Limit the number of project runs sent at a time to avoid HTTP errors (default is 1000)' )
314
367
add_project_runs_parser .set_defaults (func = add_project_runs )
315
368
316
369
args = parser .parse_args (arguments )
0 commit comments