import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.server.StartupLogWatcher;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
+import org.sonarqube.ws.Issues;
import org.sonarqube.ws.client.rule.SearchWsRequest;
import util.ItUtils;
orchestrator.stop();
}
+ @Test
+ public void start_cluster_of_elasticsearch_and_web_nodes() {
+ Orchestrator elasticsearch = null;
+ Orchestrator web = null;
+
+ try {
+ ElasticsearchStartupWatcher esWatcher = new ElasticsearchStartupWatcher();
+ elasticsearch = Orchestrator.builderEnv()
+ .setServerProperty("sonar.cluster.enabled", "true")
+ .setServerProperty("sonar.cluster.web.disabled", "true")
+ .setServerProperty("sonar.cluster.ce.disabled", "true")
+ .setStartupLogWatcher(esWatcher)
+ .build();
+ elasticsearch.start();
+ assertThat(esWatcher.port).isGreaterThan(0);
+
+ web = Orchestrator.builderEnv()
+ .setServerProperty("sonar.cluster.enabled", "true")
+ .setServerProperty("sonar.cluster.startupLeader", "true")
+ .setServerProperty("sonar.cluster.search.disabled", "true")
+ .setServerProperty("sonar.cluster.search.hosts", "localhost:" + esWatcher.port)
+ // no need for compute engine in this test. Disable it for faster test.
+ .setServerProperty("sonar.cluster.ce.disabled", "true")
+ // override the default watcher provided by Orchestrator
+ // which waits for Compute Engine to be up
+ .setStartupLogWatcher(log -> log.contains("Process[web] is up"))
+ .build();
+ web.start();
+
+ // call a web service that requires Elasticsearch
+ Issues.SearchWsResponse wsResponse = ItUtils.newWsClient(web).issues().search(new org.sonarqube.ws.client.issue.SearchWsRequest());
+ assertThat(wsResponse.getIssuesCount()).isEqualTo(0);
+
+ } finally {
+ if (web != null) {
+ web.stop();
+ }
+ if (elasticsearch != null) {
+ elasticsearch.stop();
+ }
+ }
+ }
+
+ private static class ElasticsearchStartupWatcher implements StartupLogWatcher {
+ private final Pattern pattern = Pattern.compile("Elasticsearch listening on .*:(\\d+)");
+ private int port = -1;
+
+ @Override
+ public boolean isStarted(String log) {
+ Matcher matcher = pattern.matcher(log);
+ if (matcher.find()) {
+ port = Integer.parseInt(matcher.group(1));
+ }
+ return log.contains("Process[es] is up");
+ }
+ }
+
private static void expectLog(Orchestrator orchestrator, String expectedLog) throws IOException {
File logFile = orchestrator.getServer().getLogs();
try (Stream<String> lines = Files.lines(logFile.toPath())) {
<slf4j.version>1.7.12</slf4j.version>
<tomcat.version>8.0.32</tomcat.version>
<elasticsearch.version>2.3.3</elasticsearch.version>
- <orchestrator.version>3.11</orchestrator.version>
+ <orchestrator.version>3.13-build640</orchestrator.version>
<okhttp.version>3.3.1</okhttp.version>
<jackson.version>2.6.6</jackson.version>
*/
package org.sonarsource.sonarqube.upgrade;
-import static org.assertj.core.api.Assertions.assertThat;
-
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.OrchestratorBuilder;
import com.sonar.orchestrator.build.MavenBuild;
import org.sonarqube.ws.client.WsClientFactories;
import org.sonarqube.ws.client.WsResponse;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class UpgradeTest {
public static final String PROJECT_KEY = "org.apache.struts:struts-parent";
}
@Test
- public void test_upgrade_from_4_5_lts() {
- testDatabaseUpgrade(Version.create("4.5.7"), "3.14");
+ public void test_upgrade_from_5_6() {
+ testDatabaseUpgrade(Version.create("5.6.1"), "3.14");
}
@Test
}
private void testDatabaseUpgrade(Version fromVersion, String javaVersion) {
- startServer(fromVersion, javaVersion, false);
+ startOldServer(fromVersion, javaVersion);
scanProject();
int files = countFiles(PROJECT_KEY);
assertThat(files).isGreaterThan(0);
-
stopServer();
- // latest version
- startServer(Version.create(Orchestrator.builderEnv().getSonarVersion()), "LATEST_RELEASE", true);
+
+ startNewServer();
checkSystemStatus(ServerStatusResponse.Status.DB_MIGRATION_NEEDED);
checkUrlsBeforeUpgrade();
- upgradeDatabase();
+ upgrade();
checkSystemStatus(ServerStatusResponse.Status.UP);
checkUrlsAfterUpgrade();
testUrl("/profiles");
}
- private void upgradeDatabase() {
+ private void upgrade() {
ServerMigrationResponse serverMigrationResponse = new ServerMigrationCall(orchestrator).callAndWait();
assertThat(serverMigrationResponse.getStatus()).isEqualTo(ServerMigrationResponse.Status.MIGRATION_SUCCEEDED);
}
- private void startServer(Version sqVersion, String javaVersion, boolean keepDatabase) {
+ private void startOldServer(Version sqVersion, String javaVersion) {
String jdbcUrl = MssqlConfig.fixUrl(Configuration.createEnv(), sqVersion);
- OrchestratorBuilder builder = Orchestrator.builderEnv()
+ orchestrator = Orchestrator.builderEnv()
.setOrchestratorProperty("sonar.jdbc.url", jdbcUrl)
- .setSonarVersion(sqVersion.toString());
- builder.setOrchestratorProperty("orchestrator.keepDatabase", String.valueOf(keepDatabase));
- if (!keepDatabase) {
- builder.restoreProfileAtStartup(FileLocation.ofClasspath("/sonar-way-5.1.xml"));
- }
- builder.setOrchestratorProperty("javaVersion", javaVersion).addPlugin("java");
+ .setSonarVersion(sqVersion.toString())
+ .setOrchestratorProperty("orchestrator.keepDatabase", "false")
+ .restoreProfileAtStartup(FileLocation.ofClasspath("/sonar-way-5.1.xml"))
+ .setOrchestratorProperty("javaVersion", javaVersion)
+ .addPlugin("java").build();
+ orchestrator.start();
+ }
+
+ private void startNewServer() {
+ OrchestratorBuilder builder = Orchestrator.builderEnv()
+ .setSonarVersion("DEV")
+ .setOrchestratorProperty("orchestrator.keepDatabase", "true")
+ .setOrchestratorProperty("javaVersion", "LATEST_RELEASE")
+ .setStartupLogWatcher(log -> log.contains("Process[web] is up"))
+ .addPlugin("java");
orchestrator = builder.build();
orchestrator.start();
}