Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D5DFE17D9B for ; Thu, 21 May 2015 13:40:57 +0000 (UTC) Received: (qmail 97251 invoked by uid 500); 21 May 2015 13:40:57 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 97199 invoked by uid 500); 21 May 2015 13:40:57 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 97119 invoked by uid 99); 21 May 2015 13:40:57 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 May 2015 13:40:57 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 4A3AF182865 for ; Thu, 21 May 2015 13:40:57 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.77 X-Spam-Level: * X-Spam-Status: No, score=1.77 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id M5c3_S4mAYyB for ; Thu, 21 May 2015 13:40:52 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with SMTP id 41BA928076 for ; Thu, 21 May 2015 13:40:44 +0000 (UTC) Received: (qmail 95450 invoked by uid 99); 21 May 2015 13:40:40 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 May 2015 13:40:40 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 79D68E51B2; Thu, 21 May 2015 13:40:40 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Date: Thu, 21 May 2015 13:41:08 -0000 Message-Id: In-Reply-To: <629a77c0e2e0463387b3b3f562eda2ba@git.apache.org> References: <629a77c0e2e0463387b3b3f562eda2ba@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [30/34] incubator-ignite git commit: # ignite-456: second part # ignite-456: second part Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/4a23c2c8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/4a23c2c8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/4a23c2c8 Branch: refs/heads/ignite-861 Commit: 4a23c2c830b5dd5276e5b70a08b170a62060637b Parents: 3cc3fbe Author: null Authored: Thu May 21 13:56:37 2015 +0300 Committer: null Committed: Thu May 21 13:56:37 2015 +0300 ---------------------------------------------------------------------- dev-tools/build.gradle | 2 +- dev-tools/src/main/groovy/jiraslurp.groovy | 213 ++++++++++++++++++------ 2 files changed, 159 insertions(+), 56 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4a23c2c8/dev-tools/build.gradle ---------------------------------------------------------------------- diff --git a/dev-tools/build.gradle b/dev-tools/build.gradle index 164a775..10f9b64 100644 --- a/dev-tools/build.gradle +++ b/dev-tools/build.gradle @@ -36,7 +36,7 @@ task help { } task slurp(dependsOn: 'classes', type: JavaExec) { - args(project.buildDir, "slurp,${System.getenv('TEST_BUILDS')}") + args(project.buildDir) main = 'jiraslurp' classpath = sourceSets.main.runtimeClasspath } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4a23c2c8/dev-tools/src/main/groovy/jiraslurp.groovy ---------------------------------------------------------------------- diff --git a/dev-tools/src/main/groovy/jiraslurp.groovy b/dev-tools/src/main/groovy/jiraslurp.groovy index 34ac79c..0b8f090 100644 --- a/dev-tools/src/main/groovy/jiraslurp.groovy +++ b/dev-tools/src/main/groovy/jiraslurp.groovy @@ -19,7 +19,8 @@ * attachments to process. */ final GIT_REPO = "https://git1-us-west.apache.org/repos/asf/incubator-ignite.git" -final ATTACHMENT_URL = "https://issues.apache.org/jira/secure/attachment" +final JIRA_URL = "https://issues.apache.org" +final ATTACHMENT_URL = "$JIRA_URL/jira/secure/attachment" final validated_filename = "${System.getProperty("user.home")}/validated-jira.txt" final LAST_SUCCESSFUL_ARTIFACT = "guestAuth/repository/download/Ignite_PatchValidation_PatchChecker/.lastSuccessful/$validated_filename" @@ -119,8 +120,6 @@ def checkForAttachments = { * Monitors given process and show errors if exist. */ def checkprocess = { process -> - println process.text - process.waitFor() if (process.exitValue() != 0) { @@ -179,65 +178,162 @@ def JIRA_xml = { jiranum -> } /** - * Runs all given test builds to validate last patch from given jira. + * Gets all builds from TC project. */ -def runAllTestBuilds = { builds, jiraNum -> - assert jiraNum != 'null', 'Jira number should not be null.' - assert jiraNum != null, 'Jira number should not be null.' +def getTestBuilds = { -> + def projName = System.getenv('PROJECT_NAME') - if (jiraNum) { - def tcURL = System.getenv('TC_URL') - def user = System.getenv('TASK_RUNNER_USER') - def pwd = System.getenv('TASK_RUNNER_PWD') + if (projName == null || projName == 'null') + projName = "Ignite" - builds.each { - try { - println "Triggering $it build for $jiraNum jira..." + def tcURL = System.getenv('TC_URL') + def excludeListProp = System.getenv('BUILD_ID_EXCLUDES') + def excludeList = excludeListProp?.split(' ') as List - String postData = - "" + - " " + - " " + - " " + - " " + - ""; + if (excludeList == null || excludeList == 'null') + excludeList = ["Ignite_RunAllTestBuilds"] + + def project = new XmlSlurper().parse("http://$tcURL:80/guestAuth/app/rest/projects/id:$projName") + + def buildIds = [] - URL url = new URL("http://$tcURL:80/httpAuth/app/rest/buildQueue"); + def count = Integer.valueOf(project.buildTypes.@count as String) + + for (int i = 0; i < count; i++) { + def id = project.buildTypes.buildType[i].@id + + if (excludeList == null || !excludeList.contains(id)) + buildIds.add(id) + } + + buildIds +} + +/** + * Util method to send post request. + */ +def sendPostRequest = { urlString, user, pwd, postData, contentType -> + URL url = new URL(urlString as String); - HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + HttpURLConnection conn = (HttpURLConnection)url.openConnection(); - String encoded = new sun.misc.BASE64Encoder().encode("$user:$pwd".getBytes()); + String encoded = new sun.misc.BASE64Encoder().encode("$user:$pwd".getBytes()); + + conn.setRequestProperty("Authorization", "Basic " + encoded); + + conn.setDoOutput(true); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", contentType); + conn.setRequestProperty("Content-Length", String.valueOf(postData.length())); + + OutputStream os = conn.getOutputStream(); + os.write(postData.getBytes()); + os.flush(); + os.close(); + + conn.connect(); + + // Read response. + BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); + + String response = ""; + String line; + + while ((line = br.readLine()) != null) + response += line + + br.close(); + + response +} + +/** + * Adds comment to jira ticket. + */ +def addJiraComment = { jiraNum, comment -> + def user = System.getenv('JIRA_USER') + def pwd = System.getenv('JIRA_PWD') + + try { + println "Comment: $comment" - conn.setRequestProperty("Authorization", "Basic " + encoded); + def jsonComment = "{\n \"body\": \"${comment}\"\n}"; - conn.setDoOutput(true); - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", "application/xml"); - conn.setRequestProperty("Content-Length", String.valueOf(postData.length())); + def response = sendPostRequest( + "$JIRA_URL/jira/rest/api/2/issue/$jiraNum/comment" as String, + user, + pwd, + jsonComment, + "application/json") - OutputStream os = conn.getOutputStream(); - os.write(postData.getBytes()); - os.flush(); - os.close(); + println "Response: $response" + } + catch (Exception e) { + e.printStackTrace() + } +} - conn.connect(); +/** + * Runs all given test builds to validate last patch from given jira. + */ +def runAllTestBuilds = {builds, jiraNum -> + def tcURL = System.getenv('TC_URL') + def user = System.getenv('TASK_RUNNER_USER') + def pwd = System.getenv('TASK_RUNNER_PWD') - // Read response. - print "Response: " + def triggeredBuilds = [:] - BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); + builds.each { + try { + println "Triggering $it build for $jiraNum jira..." - String line; - while ((line = br.readLine()) != null) - println line + String postData - br.close(); + if (jiraNum == 'null' || jiraNum == null) { + postData = "" + + " " + + ""; } - catch (Exception e) { - e.printStackTrace() + else { + postData = "" + + " " + + " " + + " " + + " " + + ""; } + + println "Request: $postData" + + def response = sendPostRequest( + "http://$tcURL:80/httpAuth/app/rest/buildQueue" as String, + user, + pwd, + postData, + "application/xml") + + println "Response: $response" + + def build = new XmlSlurper().parseText(response) + + println "Triggered build: ${build.buildType.@name}" + println "Triggered build url: ${build.@webUrl}" + println "Triggered build branch: ${build.@branchName}" + + triggeredBuilds.put(build.buildType.@name, build.@webUrl) + } + catch (Exception e) { + e.printStackTrace() } } + + def triggeredBuildsComment = "There was triggered next test builds for last attached patch-file:\\n" + + triggeredBuilds.each { name, url -> + triggeredBuildsComment += "${name as String} - ${url as String}\\n" + } + + addJiraComment(jiraNum, triggeredBuildsComment) } /** @@ -250,22 +346,30 @@ args.each { println parameters - if (parameters.length == 2 && parameters[0] == "slurp" && parameters[1] != 'null') { - def builds = parameters[1].split(' '); - - println "Running in 'slurp' mode. Test builds=${builds}" + if (parameters.length >= 1 && parameters[0] == "slurp") { + println "Running in 'slurp' mode." checkForAttachments() + def builds = getTestBuilds() + + println "Test builds to be triggered=$builds" + // For each ticket with new attachment, let's trigger remove build jirasAttached.each { k, v -> // Trailing slash is important for download; only need to pass JIRA number println "Triggering the test builds for: $k = $ATTACHMENT_URL/$v/" - runAllTestBuilds(builds,k) + runAllTestBuilds(builds, k) } } - else if (parameters.length == 2 && parameters[0] == "patchApply" && parameters[1] ==~ /\w+-\d+/) { + else if (parameters.length > 1 && parameters[0] == "patchApply") { + if (parameters.length < 2 || parameters[1] !=~ /\w+-\d+/) { + println "There is no jira number to apply. Exit." + + return + } + def jiraNum = parameters[1] println "Running in 'patch apply' mode with jira number '$jiraNum'" @@ -285,17 +389,16 @@ args.each { applyPatch(jira, attachementURL) } } - else if (parameters.length >= 2 && parameters[0] == "runAllBuilds" && parameters[1] ==~ /\w+-\d+/) { + else if (parameters.length > 1 && parameters[0] == "runAllBuilds" ) { def jiraNum = parameters[1] - def attachementURL=null + println "Running in 'all builds' mode with jira number='$jiraNum'." - if (parameters[2] ==~ /\d+/) - attachementURL = parameters[2] + def builds = getTestBuilds() - println "Running in 'all builds' mode with jira number='$jiraNum' and attachment URL='$attachementURL'." + println "Test builds to be triggered=$builds" - runAllTestBuilds jiraNum attachmentURL + runAllTestBuilds(builds, jiraNum) } }