diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-03-10 15:01:21 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-03-13 13:54:03 +0100 |
commit | 8743da42906ff7030b33c4a13f867f58aa8f99be (patch) | |
tree | e9059ac77a7c852cdee780c3984556dd62bcb679 /server/sonar-ce | |
parent | 6fa3d925c688fa8e67480c7a69ded9f86aba5326 (diff) | |
download | sonarqube-8743da42906ff7030b33c4a13f867f58aa8f99be.tar.gz sonarqube-8743da42906ff7030b33c4a13f867f58aa8f99be.zip |
SONAR-8816 drop web startup barrier from Compute Engine
Diffstat (limited to 'server/sonar-ce')
7 files changed, 4 insertions, 314 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 dd73aec0bf2..d5ad3095af8 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 @@ -28,11 +28,11 @@ import org.sonar.api.utils.log.Loggers; import org.sonar.ce.ComputeEngine; import org.sonar.ce.ComputeEngineImpl; import org.sonar.ce.container.ComputeEngineContainerImpl; +import org.sonar.ce.log.CeProcessLogging; import org.sonar.process.MinimumViableSystem; import org.sonar.process.Monitored; import org.sonar.process.ProcessEntryPoint; import org.sonar.process.Props; -import org.sonar.ce.log.CeProcessLogging; import static com.google.common.base.Preconditions.checkState; import static org.sonar.process.ProcessUtils.awaitTermination; @@ -55,14 +55,12 @@ public class CeServer implements Monitored { private AtomicReference<Thread> awaitThread = new AtomicReference<>(); private volatile boolean stopAwait = false; - private final StartupBarrier startupBarrier; private final ComputeEngine computeEngine; @CheckForNull private CeMainThread ceMainThread = null; @VisibleForTesting - protected CeServer(StartupBarrier startupBarrier, ComputeEngine computeEngine, MinimumViableSystem mvs) { - this.startupBarrier = startupBarrier; + protected CeServer(ComputeEngine computeEngine, MinimumViableSystem mvs) { this.computeEngine = computeEngine; mvs .checkWritableTempDir() @@ -123,7 +121,6 @@ public class CeServer implements Monitored { Props props = entryPoint.getProps(); new CeProcessLogging().configure(props); CeServer server = new CeServer( - new StartupBarrierFactory().create(entryPoint), new ComputeEngineImpl(props, new ComputeEngineContainerImpl()), new MinimumViableSystem()); entryPoint.launch(server); @@ -140,16 +137,6 @@ public class CeServer implements Monitored { @Override public void run() { - 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) - this.started = true; - // release thread (if any) in CeServer#awaitStop() - stopAwait(); - return; - } - boolean startupSuccessful = attemptStartup(); this.started = true; if (startupSuccessful) { diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/app/WebServerBarrier.java b/server/sonar-ce/src/main/java/org/sonar/ce/app/WebServerBarrier.java deleted file mode 100644 index caf6a12ecca..00000000000 --- a/server/sonar-ce/src/main/java/org/sonar/ce/app/WebServerBarrier.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.io.File; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.process.DefaultProcessCommands; -import org.sonar.process.ProcessId; - -import static org.sonar.server.app.ServerProcessLogging.STARTUP_LOGGER_NAME; - -/** - * Waits for the web server to be 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 WebServerBarrier(File sharedDir) { - this.sharedDir = sharedDir; - } - - @Override - public boolean waitForOperational() { - try (DefaultProcessCommands processCommands = DefaultProcessCommands.secondary(sharedDir, ProcessId.WEB_SERVER.getIpcIndex())) { - if (processCommands.isOperational()) { - return true; - } - - Loggers.get(STARTUP_LOGGER_NAME).info("Compute Engine startup is on hold. Waiting for Web Server to be operational."); - LOG.info("Waiting for Web Server to be operational..."); - Logger logarithmicLogger = LogarithmicLogger.from(LOG).applyingCallRatio(CALL_RATIO).build(); - while (!processCommands.isOperational()) { - logarithmicLogger.info("Still waiting for WebServer..."); - try { - Thread.sleep(POLL_DELAY); - } catch (InterruptedException e) { - return false; - } - } - return true; - } - } -} diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java index dd616f8c253..fdb860bf229 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java @@ -115,7 +115,6 @@ import org.sonar.server.platform.StartupMetadataProvider; import org.sonar.server.platform.TempFolderProvider; import org.sonar.server.platform.UrlSettings; import org.sonar.server.platform.cluster.ClusterImpl; -import org.sonar.server.platform.cluster.ClusterProperties; import org.sonar.server.platform.db.migration.MigrationConfigurationModule; import org.sonar.server.platform.db.migration.version.DatabaseVersion; import org.sonar.server.plugins.InstalledPluginReferentialFactory; @@ -159,8 +158,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { this.level1 .add(props.rawProperties()) .add(level1Components()) - .add(toArray(CorePropertyDefinitions.all())) - .add(toArray(ClusterProperties.definitions())); + .add(toArray(CorePropertyDefinitions.all())); configureFromModules(this.level1); this.level1.startComponents(); 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 35ff680c919..758c0eaf92d 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 @@ -140,19 +140,6 @@ public class CeServerTest { } @Test - public void getStatus_returns_OPERATIONAL_when_waiting_for_WebServer_failed() throws InterruptedException { - final CountDownLatch webServerWatcherCalled = new CountDownLatch(1); - CeServer ceServer = newCeServer(() -> { - webServerWatcherCalled.countDown(); - return false; - }, DoNothingComputeEngine.INSTANCE); - - ceServer.start(); - ceServer.awaitStop(); - assertThat(ceServer.getStatus()).isEqualTo(Monitored.Status.OPERATIONAL); - } - - @Test public void awaitStop_throws_ISE_if_called_before_start() throws IOException { CeServer ceServer = newCeServer(); @@ -208,23 +195,6 @@ 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 StartupBarrier() { - @Override - public boolean waitForOperational() { - webServerWatcherCalled.countDown(); - return false; - } - }, DoNothingComputeEngine.INSTANCE); - - ceServer.start(); - // if awaitStop does not unblock, the test will fail with timeout - ceServer.awaitStop(); - } - - - @Test public void awaitStop_unblocks_when_waiting_for_ComputeEngine_startup_fails() throws InterruptedException, IOException { CeServer ceServer = newCeServer(new ComputeEngine() { @Override @@ -273,18 +243,10 @@ 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( - // return instantly simulating WebServer is already operational - () -> true, computeEngine, minimumViableSystem); return underTest; } - private CeServer newCeServer(StartupBarrier startupBarrier, ComputeEngine computeEngine) { - checkState(this.underTest == null, "Only one CeServer can be created per test method"); - this.underTest = new CeServer(startupBarrier, computeEngine, minimumViableSystem); - return underTest; - } - private Thread newWaitingThread(Runnable runnable) { Thread t = new Thread(runnable); checkState(this.waitingThread == null, "Only one waiting thread can be created per test method"); 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 deleted file mode 100644 index 848e7c14f0f..00000000000 --- a/server/sonar-ce/src/test/java/org/sonar/ce/app/StartupBarrierFactoryTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.CLUSTER_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/WebServerBarrierTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/app/WebServerBarrierTest.java deleted file mode 100644 index 28637b95931..00000000000 --- a/server/sonar-ce/src/test/java/org/sonar/ce/app/WebServerBarrierTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.io.File; -import java.util.Random; -import java.util.concurrent.CountDownLatch; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.rules.Timeout; -import org.sonar.api.utils.log.LogTester; -import org.sonar.api.utils.log.LoggerLevel; -import org.sonar.process.DefaultProcessCommands; -import org.sonar.process.ProcessId; - -import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static org.assertj.core.api.Assertions.assertThat; - -public class WebServerBarrierTest { - - @Rule - public Timeout timeout = Timeout.seconds(5); - @Rule - public LogTester logTester = new LogTester(); - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - - private Thread waitingThread; - private File sharedDir; - private WebServerBarrier underTest; - - @Before - public void setUp() throws Exception { - sharedDir = temporaryFolder.newFolder(); - underTest = new WebServerBarrier(sharedDir); - } - - @After - public void tearDown() throws Exception { - if (this.waitingThread != null) { - this.waitingThread.interrupt(); - } - } - - @Test - public void waitForOperational_does_not_log_anything_if_WebServer_already_operational() { - setWebServerOperational(); - - underTest.waitForOperational(); - - assertThat(logTester.logs()).isEmpty(); - } - - @Test - public void waitForOperational_blocks_until_WebServer_is_operational() throws InterruptedException { - final CountDownLatch startedLatch = new CountDownLatch(1); - final CountDownLatch doneLatch = new CountDownLatch(1); - waitingThread = new Thread(() -> { - startedLatch.countDown(); - underTest.waitForOperational(); - doneLatch.countDown(); - }); - waitingThread.start(); - - // wait for waitingThread to be running - assertThat(startedLatch.await(50, MILLISECONDS)).isTrue(); - - // assert that we can wait, in vain, more than 50ms because waitingThread is blocked - assertThat(doneLatch.await(50 + Math.abs(new Random().nextInt(300)), MILLISECONDS)).isFalse(); - - setWebServerOperational(); - - // wait up to 400 ms (because polling delay is 200ms) that waitingThread is done running - assertThat(doneLatch.await(400, MILLISECONDS)).isTrue(); - - assertThat(logTester.logs(LoggerLevel.INFO)).contains("Waiting for Web Server to be operational..."); - } - - @Test - public void waitForOperational_returns_false_if_thread_is_interrupted() throws InterruptedException { - WaitingThread localThread = new WaitingThread(new CountDownLatch(1)); - waitingThread = localThread; - localThread.start(); - - assertThat(localThread.latch.await(50, MILLISECONDS)).isTrue(); - localThread.interrupt(); - - assertThat(localThread.result).isFalse(); - } - - private void setWebServerOperational() { - try (DefaultProcessCommands processCommands = DefaultProcessCommands.main(sharedDir, ProcessId.WEB_SERVER.getIpcIndex())) { - processCommands.setOperational(); - } - } - - private class WaitingThread extends Thread { - CountDownLatch latch; - boolean result = true; - - public WaitingThread(CountDownLatch latch) { - this.latch = latch; - result = false; - } - - @Override - public void run() { - latch.countDown(); - this.result = underTest.waitForOperational(); - } - } -} diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java index 36fc693da10..c416ceb7a9d 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java @@ -107,7 +107,7 @@ public class ComputeEngineContainerImplTest { ); assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize( COMPONENTS_IN_LEVEL_1_AT_CONSTRUCTION - + 25 // level 1 + + 23 // level 1 + 47 // content of DaoModule + 3 // content of EsSearchModule + 57 // content of CorePropertyDefinitions |