changeset 330:dd55596a5753

Add ability to specify timeout for pull operation (teamcity.hg.pull.timeout.seconds)
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Fri, 28 Oct 2011 19:08:33 +0300
parents d9aa1194e4ba
children e5b15dc36e63
files mercurial-agent/src/META-INF/build-agent-plugin-mercurial.xml mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentPluginConfig.java mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentPluginConfigImpl.java mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/PluginConfig.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/PullCommand.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfig.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigImpl.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSubreposTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigBuilder.java
diffstat 13 files changed, 107 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-agent/src/META-INF/build-agent-plugin-mercurial.xml	Fri Oct 28 13:11:12 2011 +0300
+++ b/mercurial-agent/src/META-INF/build-agent-plugin-mercurial.xml	Fri Oct 28 19:08:33 2011 +0300
@@ -5,4 +5,5 @@
   <bean id="mercurialAgent" class="jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialAgentSideVcsSupport" />
   <bean id="hgPathProvider" class="jetbrains.buildServer.buildTriggers.vcs.mercurial.AgentHgPathProvider" />
   <bean id="hgDetector" class="jetbrains.buildServer.buildTriggers.vcs.mercurial.HgDetector" />
+  <bean id="pluginConfig" class="jetbrains.buildServer.buildTriggers.vcs.mercurial.AgentPluginConfigImpl"/>
 </beans>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentPluginConfig.java	Fri Oct 28 19:08:33 2011 +0300
@@ -0,0 +1,14 @@
+package jetbrains.buildServer.buildTriggers.vcs.mercurial;
+
+import jetbrains.buildServer.agent.AgentRunningBuild;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author dmitry.neverov
+ */
+public interface AgentPluginConfig extends PluginConfig {
+
+  boolean isUseLocalMirrors(@NotNull AgentRunningBuild build);
+
+  int getPullTimeout(@NotNull AgentRunningBuild build);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentPluginConfigImpl.java	Fri Oct 28 19:08:33 2011 +0300
@@ -0,0 +1,54 @@
+package jetbrains.buildServer.buildTriggers.vcs.mercurial;
+
+import jetbrains.buildServer.agent.AgentRunningBuild;
+import jetbrains.buildServer.agent.BuildAgentConfiguration;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.File;
+
+/**
+ * @author dmitry.neverov
+ */
+public class AgentPluginConfigImpl implements AgentPluginConfig {
+
+  private static final String PULL_TIMEOUT_SECONDS = "teamcity.hg.pull.timeout.seconds";
+  private final int DEFAULT_PULL_TIMEOUT_SECONDS = 3600;
+
+  private final BuildAgentConfiguration myAgentConfig;
+
+  public AgentPluginConfigImpl(@NotNull BuildAgentConfiguration agentConfig) {
+    myAgentConfig = agentConfig;
+  }
+
+  public boolean isUseLocalMirrors(@NotNull AgentRunningBuild build) {
+    return "true".equals(build.getSharedConfigParameters().get("teamcity.hg.use.local.mirrors"));
+  }
+
+  @NotNull
+  public File getCachesDir() {
+    return myAgentConfig.getCacheDirectory("mercurial");
+  }
+
+  public int getPullTimeout(@NotNull AgentRunningBuild build) {
+    Integer timeout = parseTimeout(build.getSharedConfigParameters().get(PULL_TIMEOUT_SECONDS));
+    if (timeout != null)
+      return timeout;
+    return DEFAULT_PULL_TIMEOUT_SECONDS;
+  }
+
+  @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-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java	Fri Oct 28 13:11:12 2011 +0300
+++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java	Fri Oct 28 19:08:33 2011 +0300
@@ -15,41 +15,33 @@
  */
 package jetbrains.buildServer.buildTriggers.vcs.mercurial;
 
-import com.intellij.openapi.util.Pair;
 import jetbrains.buildServer.agent.AgentRunningBuild;
-import jetbrains.buildServer.agent.BuildAgentConfiguration;
-import jetbrains.buildServer.agent.BuildProgressLogger;
 import jetbrains.buildServer.agent.vcs.AgentVcsSupport;
 import jetbrains.buildServer.agent.vcs.IncludeRuleUpdater;
 import jetbrains.buildServer.agent.vcs.UpdateByIncludeRules2;
 import jetbrains.buildServer.agent.vcs.UpdatePolicy;
-import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.*;
-import jetbrains.buildServer.util.FileUtil;
 import jetbrains.buildServer.vcs.CheckoutRules;
-import jetbrains.buildServer.vcs.IncludeRule;
 import jetbrains.buildServer.vcs.VcsException;
 import jetbrains.buildServer.vcs.VcsRoot;
 import org.jetbrains.annotations.NotNull;
 
 import java.io.File;
-import java.io.IOException;
-import java.util.*;
-
-import static jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandUtil.removePrivateData;
 
 public class MercurialAgentSideVcsSupport extends AgentVcsSupport implements UpdateByIncludeRules2 {
 
+  private final AgentPluginConfig myConfig;
+  private final HgPathProvider myHgPathProvider;
   private final MirrorManager myMirrorManager;
-  private final HgPathProvider myHgPathProvider;
 
-  public MercurialAgentSideVcsSupport(@NotNull final BuildAgentConfiguration agentConfiguration,
+  public MercurialAgentSideVcsSupport(@NotNull final AgentPluginConfig pluginConfig,
                                       @NotNull final HgPathProvider hgPathProvider) {
-    myMirrorManager = new MirrorManager(agentConfiguration.getCacheDirectory("mercurial"));
+    myConfig = pluginConfig;
     myHgPathProvider = hgPathProvider;
+    myMirrorManager = new MirrorManager(myConfig.getCachesDir());
   }
 
   public IncludeRuleUpdater getUpdater(@NotNull final VcsRoot vcsRoot, @NotNull final CheckoutRules checkoutRules, @NotNull final String toVersion, @NotNull final File checkoutDirectory, @NotNull final AgentRunningBuild build, boolean cleanCheckoutRequested) throws VcsException {
-    return new MercurialIncludeRuleUpdater(myMirrorManager, myHgPathProvider, vcsRoot, toVersion, build);
+    return new MercurialIncludeRuleUpdater(myConfig, myMirrorManager, myHgPathProvider, vcsRoot, toVersion, build);
   }
 
   @NotNull
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java	Fri Oct 28 13:11:12 2011 +0300
+++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java	Fri Oct 28 19:08:33 2011 +0300
@@ -25,6 +25,7 @@
  */
 public class MercurialIncludeRuleUpdater implements IncludeRuleUpdater {
 
+  private final AgentPluginConfig myConfig;
   private final MirrorManager myMirrorManager;
   private final HgPathProvider myHgPathProvider;
   private final VcsRoot myRoot;
@@ -32,20 +33,23 @@
   private final String myToVersion;
   private final BuildProgressLogger myLogger;
   private final boolean myUseLocalMirrors;
+  private int myPullTimeout;
 
-
-  public MercurialIncludeRuleUpdater(@NotNull final MirrorManager mirrorManager,
+  public MercurialIncludeRuleUpdater(@NotNull final AgentPluginConfig pluginConfig,
+                                     @NotNull final MirrorManager mirrorManager,
                                      @NotNull final HgPathProvider hgPathProvider,
                                      @NotNull final VcsRoot root,
                                      @NotNull final String toVersion,
                                      @NotNull final AgentRunningBuild build) {
+    myConfig = pluginConfig;
     myMirrorManager = mirrorManager;
     myHgPathProvider = hgPathProvider;
     myRoot = root;
     mySettings = new Settings(myHgPathProvider, myRoot);
     myToVersion = toVersion;
     myLogger = build.getBuildLogger();
-    myUseLocalMirrors = isUseLocalMirrors(build);
+    myUseLocalMirrors = myConfig.isUseLocalMirrors(build);
+    myPullTimeout = myConfig.getPullTimeout(build);
   }
 
 
@@ -74,12 +78,6 @@
   }
 
 
-  private boolean isUseLocalMirrors(AgentRunningBuild build) {
-    String value = build.getSharedConfigParameters().get("teamcity.hg.use.local.mirrors");
-    return "true".equals(value);
-  }
-
-
   private void initRepository(Settings settings, File workingDir, boolean useLocalMirrors) throws VcsException {
     try {
       String defaultPullUrl = getDefaultPullUrl(settings, useLocalMirrors);
@@ -100,7 +98,7 @@
     }
     String defaultPullUrl = getDefaultPullUrl(mySettings, myUseLocalMirrors);
     myLogger.message("Start pulling changes from " + removePrivateData(defaultPullUrl, Collections.singleton(mySettings.getPassword())));
-    new PullCommand(mySettings, workingDir).execute();
+    new PullCommand(mySettings, workingDir).execute(myPullTimeout);
     myLogger.message("Changes successfully pulled");
   }
 
@@ -128,7 +126,7 @@
     }
     final String defaultPullUrl = getDefaultPullUrl(settings, true);
     myLogger.message("Start pulling changes from " + removePrivateData(defaultPullUrl, Collections.singleton(settings.getPassword())));
-    new PullCommand(settings, mirrorDir).execute();
+    new PullCommand(settings, mirrorDir).execute(myPullTimeout);
     myLogger.message("Local mirror changes successfully pulled");
   }
 
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/PluginConfig.java	Fri Oct 28 13:11:12 2011 +0300
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/PluginConfig.java	Fri Oct 28 19:08:33 2011 +0300
@@ -1,7 +1,6 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial;
 
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
 
 import java.io.File;
 
@@ -10,9 +9,6 @@
  */
 public interface PluginConfig {
 
-  @Nullable
-  String getHgPath();
-
   @NotNull
   File getCachesDir();
 
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/PullCommand.java	Fri Oct 28 13:11:12 2011 +0300
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/PullCommand.java	Fri Oct 28 19:08:33 2011 +0300
@@ -31,10 +31,10 @@
     super(settings, workingDir);
   }
 
-  public void execute() throws VcsException {
+  public void execute(int timeout) throws VcsException {
     GeneralCommandLine cli = createCommandLine();
     cli.addParameter("pull");
     cli.addParameter(getSettings().getRepositoryUrl());
-    runCommand(cli);
+    runCommand(cli, timeout);
   }
 }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Fri Oct 28 13:11:12 2011 +0300
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Fri Oct 28 19:08:33 2011 +0300
@@ -416,7 +416,7 @@
       if (Settings.isValidRepository(workingDir)) {
         if (!isChangeSetExist(settings, workingDir, cset)) {
           PullCommand pull = new PullCommand(settings, workingDir);
-          pull.execute();
+          pull.execute(myConfig.getPullTimeout());
         }
       } else {
         CloneCommand cl = new CloneCommand(settings, workingDir);
@@ -434,7 +434,7 @@
     try {
       if (Settings.isValidRepository(workingDir)) {
         PullCommand pull = new PullCommand(settings, workingDir);
-        pull.execute();
+        pull.execute(myConfig.getPullTimeout());
       } else {
         CloneCommand cl = new CloneCommand(settings, workingDir);
         cl.setUpdateWorkingDir(false);
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfig.java	Fri Oct 28 13:11:12 2011 +0300
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfig.java	Fri Oct 28 19:08:33 2011 +0300
@@ -1,6 +1,7 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial;
 
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import java.io.File;
 
@@ -9,9 +10,13 @@
  */
 public interface ServerPluginConfig extends PluginConfig {
 
+  @Nullable
+  String getHgPath();
+
   public boolean isUsePullProtocol();
 
   @NotNull
   public File getPluginDataDir();
 
+  int getPullTimeout();
 }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigImpl.java	Fri Oct 28 13:11:12 2011 +0300
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigImpl.java	Fri Oct 28 19:08:33 2011 +0300
@@ -12,6 +12,9 @@
  */
 public class ServerPluginConfigImpl implements ServerPluginConfig {
 
+  private static final String PULL_TIMEOUT_SECONDS = "teamcity.hg.pull.timeout.seconds";
+  public static final int DEFAULT_PULL_TIMEOUT_SECONDS = 3600;
+
   private final File myCachesDir;
   private final File myPluginDataDir;
 
@@ -38,4 +41,9 @@
   public File getPluginDataDir() {
     return myPluginDataDir;
   }
+
+  public int getPullTimeout() {
+    int timeout = TeamCityProperties.getInteger(PULL_TIMEOUT_SECONDS, DEFAULT_PULL_TIMEOUT_SECONDS);
+    return timeout > 0 ? timeout : DEFAULT_PULL_TIMEOUT_SECONDS;
+  }
 }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java	Fri Oct 28 13:11:12 2011 +0300
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java	Fri Oct 28 19:08:33 2011 +0300
@@ -66,7 +66,7 @@
       allowing(agentConfig).getParametersResolver(); will(returnValue(new HgPathResolver()));
     }});
 
-    myVcsSupport = new MercurialAgentSideVcsSupport(agentConfig, new AgentHgPathProvider(agentConfig));
+    myVcsSupport = new MercurialAgentSideVcsSupport(new AgentPluginConfigImpl(agentConfig), new AgentHgPathProvider(agentConfig));
 
     myLogger = myContext.mock(BuildProgressLogger.class);
     myContext.checking(new Expectations() {{
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSubreposTest.java	Fri Oct 28 13:11:12 2011 +0300
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSubreposTest.java	Fri Oct 28 19:08:33 2011 +0300
@@ -55,7 +55,7 @@
       allowing(agentConfig).getParametersResolver(); will(returnValue(new HgPathResolver()));
     }});
 
-    myVcsSupport = new MercurialAgentSideVcsSupport(agentConfig, new AgentHgPathProvider(agentConfig));
+    myVcsSupport = new MercurialAgentSideVcsSupport(new AgentPluginConfigImpl(agentConfig), new AgentHgPathProvider(agentConfig));
 
     myLogger = myContext.mock(BuildProgressLogger.class);
     myContext.checking(new Expectations() {{
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigBuilder.java	Fri Oct 28 13:11:12 2011 +0300
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigBuilder.java	Fri Oct 28 19:08:33 2011 +0300
@@ -40,6 +40,10 @@
           throw new IllegalStateException("Plugin data dir is not set");
         return myPluginDataDir;
       }
+
+      public int getPullTimeout() {
+        return ServerPluginConfigImpl.DEFAULT_PULL_TIMEOUT_SECONDS;
+      }
     };
   }