aboutsummaryrefslogtreecommitdiffstats
path: root/tests/plugins/wait-at-platform-level4-plugin
diff options
context:
space:
mode:
authorEric Hartmann <hartmann.eric@gmail.com>2017-09-05 15:00:44 +0200
committerEric Hartmann <hartmann.eric@gmail.Com>2017-09-14 18:18:20 +0200
commit0cf148c9666a0c293921d391f3fffcc851bf4393 (patch)
tree59eb6ee0b7bc99e346d725253585e3162a574db8 /tests/plugins/wait-at-platform-level4-plugin
parent9a4c4e50641c73064fef10fa4c2073439bc38651 (diff)
downloadsonarqube-0cf148c9666a0c293921d391f3fffcc851bf4393.tar.gz
sonarqube-0cf148c9666a0c293921d391f3fffcc851bf4393.zip
SONAR-9762 Implement resiliency on startup
Diffstat (limited to 'tests/plugins/wait-at-platform-level4-plugin')
-rw-r--r--tests/plugins/wait-at-platform-level4-plugin/pom.xml51
-rw-r--r--tests/plugins/wait-at-platform-level4-plugin/src/main/java/WaitAtPlaformLevel4Plugin.java32
-rw-r--r--tests/plugins/wait-at-platform-level4-plugin/src/main/java/WaitAtPlatformLevel4.java65
3 files changed, 148 insertions, 0 deletions
diff --git a/tests/plugins/wait-at-platform-level4-plugin/pom.xml b/tests/plugins/wait-at-platform-level4-plugin/pom.xml
new file mode 100644
index 00000000000..07d4196c888
--- /dev/null
+++ b/tests/plugins/wait-at-platform-level4-plugin/pom.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.sonarsource.sonarqube.tests</groupId>
+ <artifactId>plugins</artifactId>
+ <version>6.6-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>wait-at-platform-level4-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>sonar-plugin</packaging>
+ <name>Plugins :: Wait at platform level4 initialization phase</name>
+ <description>Test for failing Elasticsearch on platform4</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.sonarsource.sonarqube</groupId>
+ <artifactId>sonar-plugin-api</artifactId>
+ <version>${apiVersion}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>17.0</version>
+ <exclusions>
+ <exclusion>
+ <!-- should be declared with scope provided -->
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
+ <artifactId>sonar-packaging-maven-plugin</artifactId>
+ <version>1.15</version>
+ <configuration>
+ <pluginClass>WaitAtPlaformLevel4Plugin</pluginClass>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/plugins/wait-at-platform-level4-plugin/src/main/java/WaitAtPlaformLevel4Plugin.java b/tests/plugins/wait-at-platform-level4-plugin/src/main/java/WaitAtPlaformLevel4Plugin.java
new file mode 100644
index 00000000000..c4713f9f49d
--- /dev/null
+++ b/tests/plugins/wait-at-platform-level4-plugin/src/main/java/WaitAtPlaformLevel4Plugin.java
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+import java.util.ArrayList;
+import java.util.List;
+import org.sonar.api.SonarPlugin;
+
+public final class WaitAtPlaformLevel4Plugin extends SonarPlugin {
+
+ public List getExtensions() {
+ List extensions = new ArrayList();
+ extensions.add(WaitAtPlatformLevel4.class);
+ return extensions;
+ }
+
+}
diff --git a/tests/plugins/wait-at-platform-level4-plugin/src/main/java/WaitAtPlatformLevel4.java b/tests/plugins/wait-at-platform-level4-plugin/src/main/java/WaitAtPlatformLevel4.java
new file mode 100644
index 00000000000..8bb87583865
--- /dev/null
+++ b/tests/plugins/wait-at-platform-level4-plugin/src/main/java/WaitAtPlatformLevel4.java
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.util.Optional;
+import org.sonar.api.Startable;
+import org.sonar.api.config.Configuration;
+import org.sonar.api.server.ServerSide;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+
+@ServerSide
+public class WaitAtPlatformLevel4 implements Startable {
+
+ private static final Logger LOGGER = Loggers.get(WaitAtPlatformLevel4.class);
+
+ private final Configuration configuration;
+
+ public WaitAtPlatformLevel4(Configuration configuration) {
+ this.configuration = configuration;
+ }
+
+ @Override
+ public void start() {
+ Optional<String> path = configuration.get("sonar.web.pause.path");
+ path.ifPresent(WaitAtPlatformLevel4::waitForFileToBeDeleted);
+ }
+
+ @Override
+ public void stop() {
+ // Nothing to do
+ }
+
+ private static void waitForFileToBeDeleted(String path) {
+ LOGGER.info("PlatformLevel4 initialization phase is paused. Waiting for file to be deleted: " + path);
+ File file = new File(path);
+ try {
+ while (file.exists()) {
+ Thread.sleep(500L);
+ }
+ LOGGER.info("PlatformLevel4 initilization is resumed");
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ LOGGER.info("PlatformLevel4 pause has been interrupted");
+ throw new IllegalStateException("Platform4 pause has been interrupted");
+ }
+ }
+}