Mercurial > hg > mercurial
changeset 328:41529b72c059 Eluru-6.0.x
Add ability to specify timeout for pull operation
* * *
Add option teamcity.hg.pull.timeout.seconds, default value is 600
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Fri, 28 Oct 2011 15:08:17 +0300 |
parents | 9c9b59163e6c |
children | |
files | mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/PullCommand.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java |
diffstat | 5 files changed, 62 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java Thu Sep 15 11:41:06 2011 +0400 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java Fri Oct 28 15:08:17 2011 +0300 @@ -15,10 +15,11 @@ */ package jetbrains.buildServer.buildTriggers.vcs.mercurial; +import jetbrains.buildServer.agent.AgentRunningBuild; import jetbrains.buildServer.agent.BuildProgressLogger; import jetbrains.buildServer.agent.vcs.AgentVcsSupport; import jetbrains.buildServer.agent.vcs.IncludeRuleUpdater; -import jetbrains.buildServer.agent.vcs.UpdateByIncludeRules; +import jetbrains.buildServer.agent.vcs.UpdateByIncludeRules2; import jetbrains.buildServer.agent.vcs.UpdatePolicy; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.*; import jetbrains.buildServer.vcs.CheckoutRules; @@ -26,10 +27,14 @@ import jetbrains.buildServer.vcs.VcsException; import jetbrains.buildServer.vcs.VcsRoot; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; -public class MercurialAgentSideVcsSupport extends AgentVcsSupport implements UpdateByIncludeRules { +public class MercurialAgentSideVcsSupport extends AgentVcsSupport implements UpdateByIncludeRules2 { + + private final static String AGENT_PULL_TIMEOUT = "teamcity.hg.pull.timeout.seconds"; + private void updateWorkingDir(final Settings settings, final String version, final BuildProgressLogger logger) throws VcsException { logger.message("Updating working directory from the local repository copy"); UpdateCommand uc = new UpdateCommand(settings); @@ -51,7 +56,13 @@ return Constants.VCS_NAME; } - public IncludeRuleUpdater getUpdater(@NotNull final VcsRoot vcsRoot, @NotNull final CheckoutRules checkoutRules, @NotNull final String toVersion, @NotNull final File checkoutDirectory, @NotNull final BuildProgressLogger logger) throws VcsException { + public IncludeRuleUpdater getUpdater(@NotNull final VcsRoot root, + @NotNull CheckoutRules checkoutRules, + @NotNull final String toVersion, + @NotNull File checkoutDirectory, + @NotNull final AgentRunningBuild build, + boolean cleanCheckoutRequested) throws VcsException { + final BuildProgressLogger logger = build.getBuildLogger(); return new IncludeRuleUpdater() { public void process(@NotNull final IncludeRule includeRule, @NotNull final File workingDir) throws VcsException { if (includeRule.getTo() != null && includeRule.getTo().length() > 0) { @@ -60,7 +71,7 @@ } } - Settings settings = new Settings(workingDir, vcsRoot); + Settings settings = new Settings(workingDir, root); settings.setWorkingDir(workingDir); if (!settings.hasCopyOfRepository()) { logger.message("Init repository at " + workingDir.getAbsolutePath()); @@ -69,7 +80,7 @@ logger.message("Repository is found at " + workingDir.getAbsolutePath()); } logger.message("Start pulling changes to repository at " + workingDir.getAbsolutePath()); - new PullCommand(settings).execute(); + new PullCommand(settings).execute(getPullTimeout(build)); logger.message("Changes successfully pulled"); updateWorkingDir(settings, toVersion, logger); } @@ -78,4 +89,29 @@ } }; } + + + private int getPullTimeout(@NotNull AgentRunningBuild build) { + Integer timeout = parseTimeout(build.getSharedConfigParameters().get(AGENT_PULL_TIMEOUT)); + if (timeout != null) + return timeout; + + return CommandUtil.DEFAULT_COMMAND_TIMEOUT_SEC; + } + + + @Nullable + public Integer parseTimeout(@Nullable String timeoutStr) { + if (timeoutStr == null) + return null; + try { + int timeout = Integer.parseInt(timeoutStr); + if (timeout > 0) + return timeout; + else + return null; + } catch (NumberFormatException e) { + return null; + } + } }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java Thu Sep 15 11:41:06 2011 +0400 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java Fri Oct 28 15:08:17 2011 +0300 @@ -27,7 +27,7 @@ import java.util.Set; public class CommandUtil { - private static final int DEFAULT_COMMAND_TIMEOUT_SEC = 3600; + public static final int DEFAULT_COMMAND_TIMEOUT_SEC = 3600; public static void checkCommandFailed(@NotNull String cmdName, @NotNull ExecResult res) throws VcsException { if (res.getExitCode() != 0 || res.getException() != null) {
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/PullCommand.java Thu Sep 15 11:41:06 2011 +0400 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/PullCommand.java Fri Oct 28 15:08:17 2011 +0300 @@ -29,9 +29,13 @@ } public void execute() throws VcsException { + execute(CommandUtil.DEFAULT_COMMAND_TIMEOUT_SEC); + } + + public void execute(int executionTimeout) throws VcsException { GeneralCommandLine cli = createCommandLine(); cli.addParameter("pull"); cli.addParameter(getSettings().getRepositoryUrl()); - runCommand(cli); + runCommand(cli, executionTimeout); } }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Thu Sep 15 11:41:06 2011 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Fri Oct 28 15:08:17 2011 +0300 @@ -400,7 +400,7 @@ if (settings.hasCopyOfRepository()) { if (!isChangeSetExist(settings, cset)) { PullCommand pull = new PullCommand(settings); - pull.execute(); + pull.execute(getPullTimeout()); } } else { CloneCommand cl = new CloneCommand(settings); @@ -442,7 +442,7 @@ if (settings.hasCopyOfRepository()) { // update PullCommand pull = new PullCommand(settings); - pull.execute(); + pull.execute(getPullTimeout()); } else { // clone CloneCommand cl = new CloneCommand(settings); @@ -690,4 +690,9 @@ throw new VcsException("Unable to create temporary directory"); } } + + private int getPullTimeout() { + int timeout = TeamCityProperties.getInteger("teamcity.hg.pull.timeout.seconds", CommandUtil.DEFAULT_COMMAND_TIMEOUT_SEC); + return timeout > 0 ? timeout : CommandUtil.DEFAULT_COMMAND_TIMEOUT_SEC; + } }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java Thu Sep 15 11:41:06 2011 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java Fri Oct 28 15:08:17 2011 +0300 @@ -15,6 +15,7 @@ */ package jetbrains.buildServer.buildTriggers.vcs.mercurial; +import jetbrains.buildServer.agent.AgentRunningBuild; import jetbrains.buildServer.agent.BuildProgressLogger; import jetbrains.buildServer.util.FileUtil; import jetbrains.buildServer.vcs.CheckoutRules; @@ -22,11 +23,13 @@ import jetbrains.buildServer.vcs.VcsException; import jetbrains.buildServer.vcs.VcsRoot; import org.jmock.Mock; +import org.jmock.core.stub.ReturnStub; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.io.File; import java.io.IOException; +import java.util.HashMap; /** * @author Pavel.Sher @@ -37,6 +40,7 @@ private MercurialAgentSideVcsSupport myVcsSupport; private Mock myProgressLoggerMock; private File myWorkDir; + private Mock myBuild; @Override @BeforeMethod @@ -47,6 +51,9 @@ myProgressLoggerMock = new Mock(BuildProgressLogger.class); myWorkDir = myTempFiles.createTempDir(); myProgressLoggerMock.stubs().method("message"); + myBuild = new Mock(AgentRunningBuild.class); + myBuild.stubs().method("getBuildLogger").will(new ReturnStub(myProgressLoggerMock.proxy())); + myBuild.stubs().method("getSharedConfigParameters").will(new ReturnStub(new HashMap<String, String>())); } public void checkout_on_agent() throws IOException, VcsException { @@ -70,7 +77,7 @@ private File doUpdate(final VcsRoot vcsRoot, final String version, final IncludeRule includeRule) throws VcsException { File actualWorkDir = new File(myWorkDir, includeRule.getTo()); - myVcsSupport.getUpdater(vcsRoot, new CheckoutRules(""), version, myWorkDir, (BuildProgressLogger) myProgressLoggerMock.proxy()).process(includeRule, actualWorkDir); + myVcsSupport.getUpdater(vcsRoot, new CheckoutRules(""), version, myWorkDir, (AgentRunningBuild) myBuild.proxy(), false).process(includeRule, actualWorkDir); File hgDir = new File(actualWorkDir, ".hg"); assertTrue(hgDir.isDirectory());