import groovy.json.JsonSlurper class RerunStatsByHost { static void main(String[] args) { RerunStatsByHost runObject = new RerunStatsByHost() runObject.codeGoesHere() } // Performs the wget function with a given URL and returns the output. // Returns an empty string if fails. // Note: wget proved unreliable in groovy, so this performs a similar functionality without literally using wget. def callWgetSafely(String url) { URL urlObject = new URL ( url ) HttpURLConnection connect = (HttpURLConnection) urlObject.openConnection(); connect.setRequestMethod("HEAD") connect.connect() if (connect.getResponseCode() != 200) { println "Warning: Thisa URL's data could not be found, and is likely expired: ${url}" return "" } return urlObject.getText() } public void codeGoesHere() { def pipelines = ["8","11","17","21"] as String[] def sameHostStatsList = [] def differentHostStatsList = [] for ( int i = 0 ; i < pipelines.size() ; i++ ) { def listOfVersionPipelinesRaw = callWgetSafely("https://trss.adoptium.net/api/getBuildHistory?buildName=openjdk${pipelines[i]}-pipeline") def jsonSlurper = new JsonSlurper() def listOfVersionPipelines = jsonSlurper.parseText(listOfVersionPipelinesRaw) assert listOfVersionPipelines instanceof List for ( int j = 0 ; j < listOfVersionPipelines.size() && j < 10 ; j++ ) { println "Processing ${pipelines[i]} pipeline ${listOfVersionPipelines[j]._id}" // Get all builds for the pipeline def listOfBuildsRaw = callWgetSafely("https://trss.adoptium.net/api/getAllChildBuilds?parentId=${listOfVersionPipelines[j]._id}&buildNameRegex=^jdk.*") // Get all top-tier tests by build def listOfBuilds = jsonSlurper.parseText(listOfBuildsRaw) assert listOfBuilds instanceof List for ( int k = 0 ; k < listOfBuilds.size() ; k++ ) { def listOfRerunTestsRaw = callWgetSafely("https://trss.adoptium.net/api/getAllChildBuilds?parentId=${listOfBuilds[k]._id}&buildNameRegex=^Test.*rerun\$") // Get all rerun tests by build def listOfRerunTests = jsonSlurper.parseText(listOfRerunTestsRaw) assert listOfRerunTests instanceof List for ( int m = 0 ; m < listOfRerunTests.size() ; m++ ) { println "Processing rerun test ${listOfRerunTests[m]._id}" // Use the parent id to get the hosts used by either the parent or any testlist subjobs def listOfTestListTestsRaw = callWgetSafely("https://trss.adoptium.net/api/getAllChildBuilds?parentId=${listOfRerunTests[m].parentId}&buildNameRegex=^Test.*testList_[0-9]\$") def testIDsList = [] def testHostsList = [] if (listOfTestListTestsRaw.length() > 2) { // Then the primary test job didn't run any tests itself, and we should use the hosts in the testList subjobs def listOfTestListTests = jsonSlurper.parseText(listOfTestListTestsRaw) assert listOfTestListTests instanceof List for ( int n = 0 ; n < listOfTestListTests.size() ; n++ ) { if (!listOfTestListTests[n].buildResult.equals("SUCCESS")) { testIDsList.add(listOfTestListTests[n]._id) testHostsList.add(listOfTestListTests[n].machine) } } } else { testIDsList.add(listOfRerunTests[m].parentId) def parentTestDataRaw = callWgetSafely("https://trss.adoptium.net/api/getData?_id=${listOfRerunTests[m].parentId}") def parentTestData = jsonSlurper.parseText(parentTestDataRaw) assert parentTestData instanceof List testHostsList.add(parentTestData[0].machine) } // If the rerun host is a match for the original host/s, add it to our "same host" stats. if (testHostsList.contains(listOfRerunTests[m].machine)) { sameHostStatsList.add([listOfRerunTests[m]._id, testIDsList.toString(), listOfRerunTests[m].buildResult]) } else { // Else, add it to our "different host" stats. differentHostStatsList.add([listOfRerunTests[m]._id, testIDsList.toString(), listOfRerunTests[m].buildResult]) } } } } } def sameHostFails = 0 def differentHostFails = 0 for ( int p = 0 ; p < sameHostStatsList.size() ; p++ ) { if (!sameHostStatsList[p][2].equals("SUCCESS")) { sameHostFails++ } } for ( int q = 0 ; q < differentHostStatsList.size() ; q++ ) { if (!differentHostStatsList[q][2].equals("SUCCESS")) { differentHostFails++ } } // Now print all stats, followed by a list of links. println "Tests which failed and reran on the same host: ${sameHostStatsList.size()}" println "...of which this many failed: ${sameHostFails}" println "Tests which failed and reran on a different host: ${differentHostStatsList.size()}" println "...of which this many failed: ${differentHostFails}" println "Finished!" } }