diff --git testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/JIRAService.java testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/JIRAService.java index ca59ac48d7401989948989e3fa8466ce00688b1f..27cd0e20e3a0f04516cc17cdc79b5dd2e65576fd 100644 --- testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/JIRAService.java +++ testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/JIRAService.java @@ -87,7 +87,7 @@ void postComment(boolean error, int numTestsExecuted, SortedSet failedTe List messages) { DefaultHttpClient httpClient = new DefaultHttpClient(); try { - String buildTag = formatBuildTag(mBuildTag); + BuildInfo buildInfo = formatBuildTag(mBuildTag); String buildTagForLogs = formatBuildTagForLogs(mBuildTag); List comments = Lists.newArrayList(); comments.add(""); @@ -120,8 +120,10 @@ void postComment(boolean error, int numTestsExecuted, SortedSet failedTe } comments.add(""); } - comments.add("Test results: " + mJenkinsURL + "/" + buildTag + "/testReport"); - comments.add("Console output: " + mJenkinsURL + "/" + buildTag + "/console"); + comments.add("Test results: " + mJenkinsURL + "/" + + buildInfo.getFormattedBuildTag() + "/testReport"); + comments.add("Console output: " + mJenkinsURL + "/" + + buildInfo.getFormattedBuildTag() + "/console"); comments.add("Test logs: " + mLogsURL + buildTagForLogs); comments.add(""); if(!messages.isEmpty()) { @@ -137,6 +139,9 @@ void postComment(boolean error, int numTestsExecuted, SortedSet failedTe comments.add(""); comments.add("ATTACHMENT ID: " + attachmentId); } + if(!buildInfo.getBuildName().isEmpty()) { + comments.add(" - " + buildInfo.getBuildName()); + } mLogger.info("Comment: " + Joiner.on("\n").join(comments)); String body = Joiner.on("\n").join(comments); String url = String.format("%s/rest/api/2/issue/%s/comment", mUrl, mName); @@ -193,16 +198,36 @@ public void setBody(String body) { } } + + public static class BuildInfo { + private String buildName; + private String formattedBuildTag; + + public BuildInfo (String buildName, String formattedBuildTag) { + this.buildName = buildName; + this.formattedBuildTag = formattedBuildTag; + } + + public String getBuildName() { + return buildName; + } + + public String getFormattedBuildTag() { + return formattedBuildTag; + } + } + /** * Hive-Build-123 to Hive-Build/123 */ @VisibleForTesting - static String formatBuildTag(String buildTag) { + static BuildInfo formatBuildTag(String buildTag) { if(buildTag.contains("-")) { int lastDashIndex = buildTag.lastIndexOf("-"); String buildName = buildTag.substring(0, lastDashIndex); String buildId = buildTag.substring(lastDashIndex + 1); - return buildName + "/" + buildId; + String formattedBuildTag = buildName + "/" + buildId; + return new BuildInfo(buildName, formattedBuildTag); } throw new IllegalArgumentException("Build tag '" + buildTag + "' must contain a -"); } diff --git testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/PTest.java testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/PTest.java index 3455137f9a9a1a17acd72ffc4b4c90b7ac50593e..696b790b4b88baa318584f004360f9c8e91012f1 100644 --- testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/PTest.java +++ testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/PTest.java @@ -287,77 +287,77 @@ public static void main(String[] args) throws Exception { String buildTag = System.getenv("BUILD_TAG") == null ? "undefined-" + System.currentTimeMillis() : System.getenv("BUILD_TAG"); File logDir = Dirs.create(new File(executionContextConfiguration.getGlobalLogDirectory(), buildTag)); - LogDirectoryCleaner cleaner = new LogDirectoryCleaner(new File(executionContextConfiguration. - getGlobalLogDirectory()), 5); - cleaner.setName("LogCleaner-" + executionContextConfiguration.getGlobalLogDirectory()); - cleaner.setDaemon(true); - cleaner.start(); - TestConfiguration conf = TestConfiguration.fromFile(testConfigurationFile, LOG); - String repository = Strings.nullToEmpty(commandLine.getOptionValue(REPOSITORY)).trim(); - if(!repository.isEmpty()) { - conf.setRepository(repository); - } - String repositoryName = Strings.nullToEmpty(commandLine.getOptionValue(REPOSITORY_NAME)).trim(); - if(!repositoryName.isEmpty()) { - conf.setRepositoryName(repositoryName); - } - String branch = Strings.nullToEmpty(commandLine.getOptionValue(BRANCH)).trim(); - if(!branch.isEmpty()) { - conf.setBranch(branch); - } - String patch = Strings.nullToEmpty(commandLine.getOptionValue(PATCH)).trim(); - if(!patch.isEmpty()) { - conf.setPatch(patch); - } - String javaHome = Strings.nullToEmpty(commandLine.getOptionValue(JAVA_HOME)).trim(); - if(!javaHome.isEmpty()) { - conf.setJavaHome(javaHome); - } - String javaHomeForTests = Strings.nullToEmpty(commandLine.getOptionValue(JAVA_HOME_TEST)).trim(); - if(!javaHomeForTests.isEmpty()) { - conf.setJavaHomeForTests(javaHomeForTests); - } - String antTestArgs = Strings.nullToEmpty(commandLine.getOptionValue(ANT_TEST_ARGS)).trim(); - if(!antTestArgs.isEmpty()) { - conf.setAntTestArgs(antTestArgs); - } - String antEnvOpts = Strings.nullToEmpty(commandLine.getOptionValue(ANT_ENV_OPTS)).trim(); - if(!antEnvOpts.isEmpty()) { - conf.setAntEnvOpts(antEnvOpts); - } - String antTestTarget = Strings.nullToEmpty(commandLine.getOptionValue(ANT_TEST_TARGET)).trim(); - if(!antTestTarget.isEmpty()) { - conf.setAntTestTarget(antTestTarget); - } - String[] supplementalAntArgs = commandLine.getOptionValues(ANT_ARG); - if(supplementalAntArgs != null && supplementalAntArgs.length > 0) { - String antArgs = Strings.nullToEmpty(conf.getAntArgs()); - if(!(antArgs.isEmpty() || antArgs.endsWith(" "))) { - antArgs += " "; - } - antArgs += "-" + ANT_ARG + Joiner.on(" -" + ANT_ARG).join(supplementalAntArgs); - conf.setAntArgs(antArgs); - } - ExecutionContextProvider executionContextProvider = null; - ExecutionContext executionContext = null; - int exitCode = 0; - try { - executionContextProvider = executionContextConfiguration - .getExecutionContextProvider(); - executionContext = executionContextProvider.createExecutionContext(); - LocalCommandFactory localCommandFactory = new LocalCommandFactory(LOG); - PTest ptest = new PTest(conf, executionContext, buildTag, logDir, - localCommandFactory, new SSHCommandExecutor(LOG, localCommandFactory, conf.getSshOpts()), - new RSyncCommandExecutor(LOG, 10, localCommandFactory), LOG); - exitCode = ptest.run(); - } finally { - if(executionContext != null) { - executionContext.terminate(); - } - if(executionContextProvider != null) { - executionContextProvider.close(); - } - } - System.exit(exitCode); + LogDirectoryCleaner cleaner = new LogDirectoryCleaner(new File(executionContextConfiguration. + getGlobalLogDirectory()), 5); + cleaner.setName("LogCleaner-" + executionContextConfiguration.getGlobalLogDirectory()); + cleaner.setDaemon(true); + cleaner.start(); + TestConfiguration conf = TestConfiguration.fromFile(testConfigurationFile, LOG); + String repository = Strings.nullToEmpty(commandLine.getOptionValue(REPOSITORY)).trim(); + if(!repository.isEmpty()) { + conf.setRepository(repository); + } + String repositoryName = Strings.nullToEmpty(commandLine.getOptionValue(REPOSITORY_NAME)).trim(); + if(!repositoryName.isEmpty()) { + conf.setRepositoryName(repositoryName); + } + String branch = Strings.nullToEmpty(commandLine.getOptionValue(BRANCH)).trim(); + if(!branch.isEmpty()) { + conf.setBranch(branch); + } + String patch = Strings.nullToEmpty(commandLine.getOptionValue(PATCH)).trim(); + if(!patch.isEmpty()) { + conf.setPatch(patch); + } + String javaHome = Strings.nullToEmpty(commandLine.getOptionValue(JAVA_HOME)).trim(); + if(!javaHome.isEmpty()) { + conf.setJavaHome(javaHome); + } + String javaHomeForTests = Strings.nullToEmpty(commandLine.getOptionValue(JAVA_HOME_TEST)).trim(); + if(!javaHomeForTests.isEmpty()) { + conf.setJavaHomeForTests(javaHomeForTests); + } + String antTestArgs = Strings.nullToEmpty(commandLine.getOptionValue(ANT_TEST_ARGS)).trim(); + if(!antTestArgs.isEmpty()) { + conf.setAntTestArgs(antTestArgs); + } + String antEnvOpts = Strings.nullToEmpty(commandLine.getOptionValue(ANT_ENV_OPTS)).trim(); + if(!antEnvOpts.isEmpty()) { + conf.setAntEnvOpts(antEnvOpts); + } + String antTestTarget = Strings.nullToEmpty(commandLine.getOptionValue(ANT_TEST_TARGET)).trim(); + if(!antTestTarget.isEmpty()) { + conf.setAntTestTarget(antTestTarget); + } + String[] supplementalAntArgs = commandLine.getOptionValues(ANT_ARG); + if(supplementalAntArgs != null && supplementalAntArgs.length > 0) { + String antArgs = Strings.nullToEmpty(conf.getAntArgs()); + if(!(antArgs.isEmpty() || antArgs.endsWith(" "))) { + antArgs += " "; + } + antArgs += "-" + ANT_ARG + Joiner.on(" -" + ANT_ARG).join(supplementalAntArgs); + conf.setAntArgs(antArgs); + } + ExecutionContextProvider executionContextProvider = null; + ExecutionContext executionContext = null; + int exitCode = 0; + try { + executionContextProvider = executionContextConfiguration + .getExecutionContextProvider(); + executionContext = executionContextProvider.createExecutionContext(); + LocalCommandFactory localCommandFactory = new LocalCommandFactory(LOG); + PTest ptest = new PTest(conf, executionContext, buildTag, logDir, + localCommandFactory, new SSHCommandExecutor(LOG, localCommandFactory, conf.getSshOpts()), + new RSyncCommandExecutor(LOG, 10, localCommandFactory), LOG); + exitCode = ptest.run(); + } finally { + if(executionContext != null) { + executionContext.terminate(); + } + if(executionContextProvider != null) { + executionContextProvider.close(); + } + } + System.exit(exitCode); } } diff --git testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.java testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.java index 121d7ac8e4e84ddf285ce055b9e8c01e83fccb9e..2ce1dc9606c6e4eea621d8d7120e32f1546f3fe2 100644 --- testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.java +++ testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.java @@ -18,17 +18,24 @@ */ package org.apache.hive.ptest.execution; +import com.google.common.collect.Lists; + import java.util.List; import junit.framework.Assert; + +import org.apache.hive.ptest.execution.JIRAService.BuildInfo; import org.junit.Test; -import com.google.common.collect.Lists; public class TestJIRAService { @Test public void testFormatBuildTagPositive() throws Throwable { - Assert.assertEquals("abc/123", JIRAService.formatBuildTag("abc-123")); - Assert.assertEquals("a-b-c/123", JIRAService.formatBuildTag("a-b-c-123")); + BuildInfo buildInfo = JIRAService.formatBuildTag("abc-123"); + Assert.assertEquals("abc/123", buildInfo.getFormattedBuildTag()); + Assert.assertEquals("abc", buildInfo.getBuildName()); + buildInfo = JIRAService.formatBuildTag("PreCommit-HIVE-TRUNK-Build-1115"); + Assert.assertEquals("PreCommit-HIVE-TRUNK-Build/1115", buildInfo.getFormattedBuildTag()); + Assert.assertEquals("PreCommit-HIVE-TRUNK-Build", buildInfo.getBuildName()); } @Test(expected=IllegalArgumentException.class) public void testFormatBuildTagNoDashSlash() throws Throwable {