aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-07-29 22:22:41 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-08-03 17:57:17 +0200
commit80ada8c264e73426330c79e40e44f36ded7dcc19 (patch)
treedd34dd47e53720c68788abdadd9b7e65281f8d02 /server/sonar-ce
parent17f3a477fd6119172c89057acb80693af21c5ae6 (diff)
downloadsonarqube-80ada8c264e73426330c79e40e44f36ded7dcc19.tar.gz
sonarqube-80ada8c264e73426330c79e40e44f36ded7dcc19.zip
SONAR-7910 support sonar.cluster.web.disabled
Diffstat (limited to 'server/sonar-ce')
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java37
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/app/StartupBarrier.java (renamed from server/sonar-ce/src/main/java/org/sonar/ce/app/WebServerWatcher.java)2
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/app/StartupBarrierFactory.java33
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/app/WebServerBarrier.java (renamed from server/sonar-ce/src/main/java/org/sonar/ce/app/WebServerWatcherImpl.java)9
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java40
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/app/StartupBarrierFactoryTest.java59
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/app/WebServerBarrierTest.java (renamed from server/sonar-ce/src/test/java/org/sonar/ce/app/WebServerWatcherImplTest.java)6
7 files changed, 132 insertions, 54 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java b/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java
index 532d5b592a8..3bd492be85b 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java
@@ -57,34 +57,20 @@ public class CeServer implements Monitored {
private AtomicReference<Thread> awaitThread = new AtomicReference<>();
private volatile boolean stopAwait = false;
- private final WebServerWatcher webServerWatcher;
+ private final StartupBarrier startupBarrier;
private final ComputeEngine computeEngine;
@CheckForNull
private CeMainThread ceMainThread = null;
@VisibleForTesting
- protected CeServer(WebServerWatcher webServerWatcher, ComputeEngine computeEngine, MinimumViableSystem mvs) {
- this.webServerWatcher = webServerWatcher;
+ protected CeServer(StartupBarrier startupBarrier, ComputeEngine computeEngine, MinimumViableSystem mvs) {
+ this.startupBarrier = startupBarrier;
this.computeEngine = computeEngine;
mvs
.checkWritableTempDir()
.checkRequiredJavaOptions(ImmutableMap.of("file.encoding", "UTF-8"));
}
- /**
- * Can't be started as is. Needs to be bootstrapped by sonar-application
- */
- public static void main(String[] args) {
- ProcessEntryPoint entryPoint = ProcessEntryPoint.createForArguments(args);
- Props props = entryPoint.getProps();
- new ServerProcessLogging(PROCESS_NAME, LOG_LEVEL_PROPERTY).configure(props);
- CeServer server = new CeServer(
- new WebServerWatcherImpl(entryPoint.getSharedDir()),
- new ComputeEngineImpl(props, new ComputeEngineContainerImpl()),
- new MinimumViableSystem());
- entryPoint.launch(server);
- }
-
@Override
public void start() {
checkState(ceMainThread == null, "start() can not be called twice");
@@ -128,6 +114,20 @@ public class CeServer implements Monitored {
}
}
+ /**
+ * Can't be started as is. Needs to be bootstrapped by sonar-application
+ */
+ public static void main(String[] args) {
+ ProcessEntryPoint entryPoint = ProcessEntryPoint.createForArguments(args);
+ Props props = entryPoint.getProps();
+ new ServerProcessLogging(PROCESS_NAME, LOG_LEVEL_PROPERTY).configure(props);
+ CeServer server = new CeServer(
+ new StartupBarrierFactory().create(entryPoint),
+ new ComputeEngineImpl(props, new ComputeEngineContainerImpl()),
+ new MinimumViableSystem());
+ entryPoint.launch(server);
+ }
+
private class CeMainThread extends Thread {
private static final int CHECK_FOR_STOP_DELAY = 50;
private volatile boolean stop = false;
@@ -139,8 +139,7 @@ public class CeServer implements Monitored {
@Override
public void run() {
- // wait for WebServer to be operational
- boolean webServerOperational = webServerWatcher.waitForOperational();
+ boolean webServerOperational = startupBarrier.waitForOperational();
if (!webServerOperational) {
LOG.debug("Interrupted while waiting for WebServer to be operational. Assuming it will never be. Stopping.");
// signal CE is done booting (obviously, since we are about to stop)
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/app/WebServerWatcher.java b/server/sonar-ce/src/main/java/org/sonar/ce/app/StartupBarrier.java
index 0ce8733061e..cd66d555787 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/app/WebServerWatcher.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/app/StartupBarrier.java
@@ -20,7 +20,7 @@
package org.sonar.ce.app;
@FunctionalInterface
-public interface WebServerWatcher {
+interface StartupBarrier {
/**
* This blocking call, waits for the Web Server to be operational until either the Web Server is actually
* operational, or the calling thread is interrupted.
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/app/StartupBarrierFactory.java b/server/sonar-ce/src/main/java/org/sonar/ce/app/StartupBarrierFactory.java
new file mode 100644
index 00000000000..034a68094cc
--- /dev/null
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/app/StartupBarrierFactory.java
@@ -0,0 +1,33 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.ce.app;
+
+import org.sonar.process.ProcessEntryPoint;
+import org.sonar.process.ProcessProperties;
+
+class StartupBarrierFactory {
+
+ public StartupBarrier create(ProcessEntryPoint entryPoint) {
+ if (entryPoint.getProps().valueAsBoolean(ProcessProperties.WEB_DISABLED)) {
+ return () -> true;
+ }
+ return new WebServerBarrier(entryPoint.getSharedDir());
+ }
+}
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/app/WebServerWatcherImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/app/WebServerBarrier.java
index 73bde24aa0e..cc9761175ba 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/app/WebServerWatcherImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/app/WebServerBarrier.java
@@ -25,15 +25,18 @@ import org.sonar.api.utils.log.Loggers;
import org.sonar.process.DefaultProcessCommands;
import org.sonar.process.ProcessId;
-public class WebServerWatcherImpl implements WebServerWatcher {
- private static final Logger LOG = Loggers.get(WebServerWatcherImpl.class);
+/**
+ * Waits that web server is operational (started and datastores up-to-date)
+ */
+class WebServerBarrier implements StartupBarrier {
+ private static final Logger LOG = Loggers.get(WebServerBarrier.class);
private static final int POLL_DELAY = 200;
// accounting only every 5 log calls so that only one every second (because delay is 200ms) is taken into account
private static final int CALL_RATIO = 5;
private final File sharedDir;
- public WebServerWatcherImpl(File sharedDir) {
+ public WebServerBarrier(File sharedDir) {
this.sharedDir = sharedDir;
}
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java
index a83ae3e447b..647ce423d44 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java
@@ -141,12 +141,9 @@ public class CeServerTest {
@Test
public void isUp_returns_true_when_waiting_for_WebServer_failed() throws InterruptedException {
final CountDownLatch webServerWatcherCalled = new CountDownLatch(1);
- CeServer ceServer = newCeServer(new WebServerWatcher() {
- @Override
- public boolean waitForOperational() {
- webServerWatcherCalled.countDown();
- return false;
- }
+ CeServer ceServer = newCeServer(() -> {
+ webServerWatcherCalled.countDown();
+ return false;
}, DoNothingComputeEngine.INSTANCE);
ceServer.start();
@@ -191,12 +188,7 @@ public class CeServerTest {
@Test
public void awaitStop_keeps_blocking_calling_thread_even_if_calling_thread_is_interrupted_but_until_stop_is_called() throws InterruptedException, IOException {
final CeServer ceServer = newCeServer();
- Thread waitingThread = newWaitingThread(new Runnable() {
- @Override
- public void run() {
- ceServer.awaitStop();
- }
- });
+ Thread waitingThread = newWaitingThread(ceServer::awaitStop);
ceServer.start();
waitingThread.start();
@@ -217,7 +209,7 @@ public class CeServerTest {
@Test
public void awaitStop_unblocks_when_waiting_for_WebServer_failed() throws InterruptedException {
final CountDownLatch webServerWatcherCalled = new CountDownLatch(1);
- CeServer ceServer = newCeServer(new WebServerWatcher() {
+ CeServer ceServer = newCeServer(new StartupBarrier() {
@Override
public boolean waitForOperational() {
webServerWatcherCalled.countDown();
@@ -263,12 +255,7 @@ public class CeServerTest {
throw new Error("Faking ComputeEngine.shutdown() failing");
}
});
- Thread waitingThread = newWaitingThread(new Runnable() {
- @Override
- public void run() {
- ceServer.awaitStop();
- }
- });
+ Thread waitingThread = newWaitingThread(ceServer::awaitStop);
ceServer.start();
waitingThread.start();
@@ -284,19 +271,16 @@ public class CeServerTest {
private CeServer newCeServer(ComputeEngine computeEngine) throws IOException {
checkState(this.underTest == null, "Only one CeServer can be created per test method");
- this.underTest = new CeServer(new WebServerWatcher() {
- @Override
- public boolean waitForOperational() {
- // return instantly simulating WebServer is already operational
- return true;
- }
- }, computeEngine, minimumViableSystem);
+ this.underTest = new CeServer(
+ // return instantly simulating WebServer is already operational
+ () -> true,
+ computeEngine, minimumViableSystem);
return underTest;
}
- private CeServer newCeServer(WebServerWatcher webServerWatcher, ComputeEngine computeEngine) {
+ private CeServer newCeServer(StartupBarrier startupBarrier, ComputeEngine computeEngine) {
checkState(this.underTest == null, "Only one CeServer can be created per test method");
- this.underTest = new CeServer(webServerWatcher, computeEngine, minimumViableSystem);
+ this.underTest = new CeServer(startupBarrier, computeEngine, minimumViableSystem);
return underTest;
}
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/app/StartupBarrierFactoryTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/app/StartupBarrierFactoryTest.java
new file mode 100644
index 00000000000..7d83fa3abfd
--- /dev/null
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/app/StartupBarrierFactoryTest.java
@@ -0,0 +1,59 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.ce.app;
+
+import java.util.Properties;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.process.ProcessEntryPoint;
+import org.sonar.process.ProcessProperties;
+import org.sonar.process.Props;
+
+import static org.assertj.core.api.Java6Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class StartupBarrierFactoryTest {
+
+ private Props props = new Props(new Properties());
+ private ProcessEntryPoint entryPoint = mock(ProcessEntryPoint.class);
+ private StartupBarrierFactory underTest = new StartupBarrierFactory();
+
+ @Before
+ public void setUp() {
+ when(entryPoint.getProps()).thenReturn(props);
+ }
+
+ @Test
+ public void wait_for_web_server_in_standard_mode() {
+ StartupBarrier barrier = underTest.create(entryPoint);
+
+ assertThat(barrier).isInstanceOf(WebServerBarrier.class);
+ }
+
+ @Test
+ public void do_not_wait_for_web_server_if_it_is_disabled() {
+ props.set(ProcessProperties.WEB_DISABLED, "true");
+ StartupBarrier barrier = underTest.create(entryPoint);
+
+ assertThat(barrier).isNotInstanceOf(WebServerBarrier.class);
+ assertThat(barrier.waitForOperational()).isTrue();
+ }
+}
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/app/WebServerWatcherImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/app/WebServerBarrierTest.java
index 72573ce6f22..8db3a8e8da8 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/app/WebServerWatcherImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/app/WebServerBarrierTest.java
@@ -35,7 +35,7 @@ import org.sonar.process.ProcessId;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.assertj.core.api.Assertions.assertThat;
-public class WebServerWatcherImplTest {
+public class WebServerBarrierTest {
@Rule
public Timeout timeout = Timeout.seconds(5);
@@ -45,12 +45,12 @@ public class WebServerWatcherImplTest {
public TemporaryFolder temporaryFolder = new TemporaryFolder();
private File sharedDir;
- private WebServerWatcherImpl underTest;
+ private WebServerBarrier underTest;
@Before
public void setUp() throws Exception {
sharedDir = temporaryFolder.newFolder();
- underTest = new WebServerWatcherImpl(sharedDir);
+ underTest = new WebServerBarrier(sharedDir);
}
@Test