aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/main/java/org/sonar
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-07-11 12:22:50 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-07-11 12:57:52 +0200
commit195d307840e5e4aaf6d64fab2227b5d8230108b3 (patch)
treedd28f7024e1c0985952415ade1ef3f01b8983342 /sonar-batch/src/main/java/org/sonar
parentac46595adb827cbc615fa6cb2702d00f7bf41937 (diff)
downloadsonarqube-195d307840e5e4aaf6d64fab2227b5d8230108b3.tar.gz
sonarqube-195d307840e5e4aaf6d64fab2227b5d8230108b3.zip
SONAR-4488 Increase timeout for /batch_bootstrap/db
Diffstat (limited to 'sonar-batch/src/main/java/org/sonar')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java25
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java18
2 files changed, 33 insertions, 10 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java
index 0f73212e337..e8326e916b1 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java
@@ -32,6 +32,7 @@ import org.sonar.api.utils.HttpDownloader.HttpException;
import org.sonar.api.utils.SonarException;
import java.io.File;
+import java.net.SocketTimeoutException;
/**
* @since 3.4
@@ -45,6 +46,8 @@ public class DryRunDatabase implements BatchComponent {
private static final String USER = "sonar";
private static final String PASSWORD = "sonar";
+ private static final int DEFAULT_DRY_RUN_READ_TIMEOUT = 60 * 1000;
+
private final Settings settings;
private final ServerClient server;
private final TempDirectories tempDirectories;
@@ -59,14 +62,19 @@ public class DryRunDatabase implements BatchComponent {
if (settings.getBoolean(CoreProperties.DRY_RUN)) {
LOG.info("Dry run");
File databaseFile = tempDirectories.getFile("", "dryrun.h2.db");
- downloadDatabase(databaseFile);
+
+ // SONAR-4488 Allow to increase dryRun timeout
+ int readTimeout = settings.getInt(CoreProperties.DRY_RUN_READ_TIMEOUT);
+ readTimeout = (readTimeout == 0) ? DEFAULT_DRY_RUN_READ_TIMEOUT : readTimeout;
+
+ downloadDatabase(databaseFile, readTimeout);
String databasePath = StringUtils.removeEnd(databaseFile.getAbsolutePath(), ".h2.db");
replaceSettings(databasePath);
}
}
- private void downloadDatabase(File toFile) {
+ private void downloadDatabase(File toFile, int readTimeout) {
String projectKey = null;
try {
projectKey = settings.getString(CoreProperties.PROJECT_KEY_PROPERTY);
@@ -75,15 +83,22 @@ public class DryRunDatabase implements BatchComponent {
projectKey = String.format("%s:%s", projectKey, branch);
}
if (StringUtils.isBlank(projectKey)) {
- server.download("/batch_bootstrap/db", toFile);
+ server.download("/batch_bootstrap/db", toFile, readTimeout);
} else {
- server.download("/batch_bootstrap/db?project=" + projectKey, toFile);
+ server.download("/batch_bootstrap/db?project=" + projectKey, toFile, readTimeout);
}
LOG.debug("Dry Run database size: {}", FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(toFile)));
} catch (SonarException e) {
Throwable rootCause = Throwables.getRootCause(e);
+ if (rootCause instanceof SocketTimeoutException) {
+ // Pico will unwrap the first runtime exception
+ throw new SonarException(new SonarException(String.format("DryRun database read timed out after %s ms. You can try to increase read timeout with property -D"
+ + CoreProperties.DRY_RUN_READ_TIMEOUT,
+ readTimeout), e));
+ }
if (projectKey != null && (rootCause instanceof HttpException) && (((HttpException) rootCause).getResponseCode() == 401)) {
- throw new SonarException(String.format("You don't have access rights to project [%s]", projectKey), e);
+ // Pico will unwrap the first runtime exception
+ throw new SonarException(new SonarException(String.format("You don't have access rights to project [%s]", projectKey), e));
}
throw e;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java
index 16028be1299..b04bd67a360 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java
@@ -58,8 +58,12 @@ public class ServerClient implements BatchComponent {
}
public void download(String pathStartingWithSlash, File toFile) {
+ download(pathStartingWithSlash, toFile, null);
+ }
+
+ public void download(String pathStartingWithSlash, File toFile, Integer readTimeoutMillis) {
try {
- InputSupplier<InputStream> inputSupplier = doRequest(pathStartingWithSlash);
+ InputSupplier<InputStream> inputSupplier = doRequest(pathStartingWithSlash, readTimeoutMillis);
Files.copy(inputSupplier, toFile);
} catch (HttpDownloader.HttpException he) {
throw handleHttpException(he);
@@ -73,7 +77,11 @@ public class ServerClient implements BatchComponent {
}
public String request(String pathStartingWithSlash, boolean wrapHttpException) {
- InputSupplier<InputStream> inputSupplier = doRequest(pathStartingWithSlash);
+ return request(pathStartingWithSlash, wrapHttpException, null);
+ }
+
+ public String request(String pathStartingWithSlash, boolean wrapHttpException, Integer timeoutMillis) {
+ InputSupplier<InputStream> inputSupplier = doRequest(pathStartingWithSlash, timeoutMillis);
try {
return IOUtils.toString(inputSupplier.getInput(), "UTF-8");
} catch (HttpDownloader.HttpException e) {
@@ -83,7 +91,7 @@ public class ServerClient implements BatchComponent {
}
}
- private InputSupplier<InputStream> doRequest(String pathStartingWithSlash) {
+ private InputSupplier<InputStream> doRequest(String pathStartingWithSlash, Integer timeoutMillis) {
Preconditions.checkArgument(pathStartingWithSlash.startsWith("/"), "Path must start with slash /");
String path = StringEscapeUtils.escapeHtml(pathStartingWithSlash);
@@ -91,9 +99,9 @@ public class ServerClient implements BatchComponent {
try {
InputSupplier<InputStream> inputSupplier;
if (Strings.isNullOrEmpty(getLogin())) {
- inputSupplier = downloader.newInputSupplier(uri);
+ inputSupplier = downloader.newInputSupplier(uri, timeoutMillis);
} else {
- inputSupplier = downloader.newInputSupplier(uri, getLogin(), getPassword());
+ inputSupplier = downloader.newInputSupplier(uri, getLogin(), getPassword(), timeoutMillis);
}
return inputSupplier;
} catch (Exception e) {