aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-10-18 12:06:46 +0200
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-10-23 08:01:13 -0700
commite450a986a1b8f51f681d0fb0d84520b0a5c7784c (patch)
tree35421a0f947383cc3228259d0d0503b637d5cff3 /server
parent3550df8f4e9c5293e99463b65b921c5d1edda06e (diff)
downloadsonarqube-e450a986a1b8f51f681d0fb0d84520b0a5c7784c.tar.gz
sonarqube-e450a986a1b8f51f681d0fb0d84520b0a5c7784c.zip
SONAR-10002 add EditionManagementState#getInstallErrorMessage
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/edition/EditionManagementState.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/edition/StandaloneEditionManagementStateImpl.java40
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/edition/StandaloneEditionManagementStateImplTest.java122
3 files changed, 146 insertions, 24 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/edition/EditionManagementState.java b/server/sonar-server/src/main/java/org/sonar/server/edition/EditionManagementState.java
index bf14219a3cc..ee5210438be 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/edition/EditionManagementState.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/edition/EditionManagementState.java
@@ -46,6 +46,14 @@ public interface EditionManagementState {
*/
Optional<String> getPendingLicense();
+ /**
+ * The message explaining the error that made the install fail (if any).
+ *
+ * @return a {@link String} if {@link #getPendingInstallationStatus()} returns {@link PendingStatus#NONE} and an error
+ * occurred during install, otherwise {@link Optional#empty() empty}
+ */
+ Optional<String> getInstallErrorMessage();
+
enum PendingStatus {
NONE,
AUTOMATIC_IN_PROGRESS,
diff --git a/server/sonar-server/src/main/java/org/sonar/server/edition/StandaloneEditionManagementStateImpl.java b/server/sonar-server/src/main/java/org/sonar/server/edition/StandaloneEditionManagementStateImpl.java
index b9c691df422..674859d15a1 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/edition/StandaloneEditionManagementStateImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/edition/StandaloneEditionManagementStateImpl.java
@@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableSet;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
+import javax.annotation.Nullable;
import org.picocontainer.Startable;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
@@ -43,12 +44,14 @@ public class StandaloneEditionManagementStateImpl implements MutableEditionManag
private static final String PENDING_INSTALLATION_STATUS = "pendingInstallStatus";
private static final String PENDING_EDITION_KEY = "pendingEditionKey";
private static final String PENDING_LICENSE = "pendingLicense";
+ private static final String INSTALL_ERROR_MESSAGE = "installError";
private final DbClient dbClient;
private String currentEditionKey;
private PendingStatus pendingInstallationStatus;
private String pendingEditionKey;
private String pendingLicense;
+ private String installErrorMessage;
public StandaloneEditionManagementStateImpl(DbClient dbClient) {
this.dbClient = dbClient;
@@ -59,7 +62,7 @@ public class StandaloneEditionManagementStateImpl implements MutableEditionManag
try (DbSession dbSession = dbClient.openSession(false)) {
// load current state value
Map<String, Optional<String>> internalPropertyValues = dbClient.internalPropertiesDao().selectByKeys(dbSession,
- ImmutableSet.of(CURRENT_EDITION_KEY, PENDING_INSTALLATION_STATUS, PENDING_EDITION_KEY, PENDING_LICENSE));
+ ImmutableSet.of(CURRENT_EDITION_KEY, PENDING_INSTALLATION_STATUS, PENDING_EDITION_KEY, PENDING_LICENSE, INSTALL_ERROR_MESSAGE));
this.currentEditionKey = internalPropertyValues.getOrDefault(CURRENT_EDITION_KEY, empty())
.map(StandaloneEditionManagementStateImpl::emptyToNull)
.orElse(null);
@@ -73,6 +76,9 @@ public class StandaloneEditionManagementStateImpl implements MutableEditionManag
this.pendingLicense = internalPropertyValues.getOrDefault(PENDING_LICENSE, empty())
.map(StandaloneEditionManagementStateImpl::emptyToNull)
.orElse(null);
+ this.installErrorMessage = internalPropertyValues.getOrDefault(INSTALL_ERROR_MESSAGE, empty())
+ .map(StandaloneEditionManagementStateImpl::emptyToNull)
+ .orElse(null);
}
}
@@ -106,6 +112,12 @@ public class StandaloneEditionManagementStateImpl implements MutableEditionManag
}
@Override
+ public Optional<String> getInstallErrorMessage() {
+ ensureStarted();
+ return Optional.ofNullable(installErrorMessage);
+ }
+
+ @Override
public synchronized PendingStatus startAutomaticInstall(License license) {
ensureStarted();
checkLicense(license);
@@ -188,23 +200,23 @@ public class StandaloneEditionManagementStateImpl implements MutableEditionManag
private void persistProperties() {
try (DbSession dbSession = dbClient.openSession(false)) {
InternalPropertiesDao internalPropertiesDao = dbClient.internalPropertiesDao();
- if (pendingInstallationStatus == NONE || pendingInstallationStatus == UNINSTALL_IN_PROGRESS) {
- internalPropertiesDao.saveAsEmpty(dbSession, PENDING_EDITION_KEY);
- internalPropertiesDao.saveAsEmpty(dbSession, PENDING_LICENSE);
- } else {
- internalPropertiesDao.save(dbSession, PENDING_EDITION_KEY, pendingEditionKey);
- internalPropertiesDao.save(dbSession, PENDING_LICENSE, pendingLicense);
- }
- if (currentEditionKey == null) {
- internalPropertiesDao.saveAsEmpty(dbSession, CURRENT_EDITION_KEY);
- } else {
- internalPropertiesDao.save(dbSession, CURRENT_EDITION_KEY, currentEditionKey);
- }
- internalPropertiesDao.save(dbSession, PENDING_INSTALLATION_STATUS, pendingInstallationStatus.name());
+ saveInternalProperty(internalPropertiesDao, dbSession, PENDING_EDITION_KEY, pendingEditionKey);
+ saveInternalProperty(internalPropertiesDao, dbSession, PENDING_LICENSE, pendingLicense);
+ saveInternalProperty(internalPropertiesDao, dbSession, INSTALL_ERROR_MESSAGE, installErrorMessage);
+ saveInternalProperty(internalPropertiesDao, dbSession, CURRENT_EDITION_KEY, currentEditionKey);
+ saveInternalProperty(internalPropertiesDao, dbSession, PENDING_INSTALLATION_STATUS, pendingInstallationStatus.name());
dbSession.commit();
}
}
+ private static void saveInternalProperty(InternalPropertiesDao dao, DbSession dbSession, String key, @Nullable String value) {
+ if (value == null) {
+ dao.saveAsEmpty(dbSession, key);
+ } else {
+ dao.save(dbSession, key, value);
+ }
+ }
+
private static void checkLicense(License license) {
requireNonNull(license, "license can't be null");
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/edition/StandaloneEditionManagementStateImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/edition/StandaloneEditionManagementStateImplTest.java
index f1cbe67f43c..d28a757d8d5 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/edition/StandaloneEditionManagementStateImplTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/edition/StandaloneEditionManagementStateImplTest.java
@@ -184,6 +184,37 @@ public class StandaloneEditionManagementStateImplTest {
}
@Test
+ public void getInstallErrorMessage_fails_with_ISE_if_start_has_not_been_called() {
+ expectISENotStarted();
+
+ underTest.getInstallErrorMessage();
+ }
+
+ @Test
+ public void getInstallErrorMessage_returns_empty_when_internal_properties_table_is_empty() {
+ underTest.start();
+
+ assertThat(underTest.getInstallErrorMessage()).isEmpty();
+ }
+
+ @Test
+ public void getInstallErrorMessage_returns_value_in_db_for_key_pendingEditionKey() {
+ String value = randomAlphanumeric(10);
+ dbTester.properties().insertInternal("installError", value);
+ underTest.start();
+
+ assertThat(underTest.getInstallErrorMessage()).contains(value);
+ }
+
+ @Test
+ public void getInstallErrorMessage_returns_empty_when_value_in_db_is_empty_for_key_pendingEditionKey() {
+ dbTester.properties().insertEmptyInternal("installError");
+ underTest.start();
+
+ assertThat(underTest.getInstallErrorMessage()).isEmpty();
+ }
+
+ @Test
public void startAutomaticInstall_fails_with_ISE_if_not_started() {
expectISENotStarted();
@@ -278,6 +309,18 @@ public class StandaloneEditionManagementStateImplTest {
}
@Test
+ public void startAutomaticInstall_fails_with_ISE_if_called_after_uninstall() {
+ underTest.start();
+ underTest.newEditionWithoutInstall("foo");
+ underTest.uninstall();
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("Can't move to AUTOMATIC_IN_PROGRESS when status is UNINSTALL_IN_PROGRESS (should be any of [NONE])");
+
+ underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
+ }
+
+ @Test
public void uninstall_fails_with_ISE_if_not_started() {
expectISENotStarted();
@@ -456,6 +499,18 @@ public class StandaloneEditionManagementStateImplTest {
}
@Test
+ public void startManualInstall_fails_with_ISE_if_called_after_uninstall() {
+ underTest.start();
+ underTest.newEditionWithoutInstall("foo");
+ underTest.uninstall();
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("Can't move to MANUAL_IN_PROGRESS when status is UNINSTALL_IN_PROGRESS (should be any of [NONE])");
+
+ underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
+ }
+
+ @Test
public void automaticInstallReady_fails_with_ISE_if_not_started() {
expectISENotStarted();
@@ -484,6 +539,40 @@ public class StandaloneEditionManagementStateImplTest {
}
@Test
+ public void automaticInstallReady_fails_with_ISE_if_called_after_newEditionWithoutInstall() {
+ underTest.start();
+ underTest.newEditionWithoutInstall("foo");
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("Can't move to AUTOMATIC_READY when status is NONE (should be any of [AUTOMATIC_IN_PROGRESS])");
+
+ underTest.automaticInstallReady();
+ }
+
+ @Test
+ public void automaticInstallReady_fails_with_ISE_if_called_after_uninstall() {
+ underTest.start();
+ underTest.newEditionWithoutInstall("foo");
+ underTest.uninstall();
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("Can't move to AUTOMATIC_READY when status is UNINSTALL_IN_PROGRESS (should be any of [AUTOMATIC_IN_PROGRESS])");
+
+ underTest.automaticInstallReady();
+ }
+
+ @Test
+ public void automaticInstallReady_fails_with_ISE_if_called_after_startManualInstall() {
+ underTest.start();
+ underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("Can't move to AUTOMATIC_READY when status is MANUAL_IN_PROGRESS (should be any of [AUTOMATIC_IN_PROGRESS])");
+
+ underTest.automaticInstallReady();
+ }
+
+ @Test
public void automaticInstallReady_after_startAutomaticInstall_changes_status_to_AUTOMATIC_READY_but_does_not_change_editions() {
underTest.start();
underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
@@ -593,6 +682,19 @@ public class StandaloneEditionManagementStateImplTest {
}
@Test
+ public void newEditionWithoutInstall_fails_with_ISE_if_called_after_uninstall() {
+ String newEditionKey = randomAlphanumeric(3);
+ underTest.start();
+ underTest.newEditionWithoutInstall("foo");
+ underTest.uninstall();
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("Can't move to NONE when status is UNINSTALL_IN_PROGRESS (should be any of [NONE])");
+
+ underTest.newEditionWithoutInstall(newEditionKey);
+ }
+
+ @Test
public void finalizeInstallation_fails_with_ISE_if_not_started() {
expectISENotStarted();
@@ -661,11 +763,11 @@ public class StandaloneEditionManagementStateImplTest {
}
@Test
- public void finalizeInstallation_set_new_edition_and_clear_pending_fields_after_uninstall() {
- underTest.start();
+ public void finalizeInstallation_overwrites_current_edition_and_clear_pending_fields_after_startManualInstall() {
String value = randomAlphanumeric(10);
- underTest.newEditionWithoutInstall(value);
- underTest.uninstall();
+ dbTester.properties().insertInternal("currentEditionKey", value);
+ underTest.start();
+ underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
PendingStatus newStatus = underTest.finalizeInstallation();
@@ -673,15 +775,15 @@ public class StandaloneEditionManagementStateImplTest {
assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
assertThat(underTest.getPendingEditionKey()).isEmpty();
assertThat(underTest.getPendingLicense()).isEmpty();
- assertThat(underTest.getCurrentEditionKey()).isEmpty();
+ assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
}
@Test
- public void finalizeInstallation_overwrites_current_edition_and_clear_pending_fields_after_startManualInstall() {
- String value = randomAlphanumeric(10);
- dbTester.properties().insertInternal("currentEditionKey", value);
+ public void finalizeInstallation_set_new_edition_and_clear_pending_fields_after_uninstall() {
underTest.start();
- underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
+ String value = randomAlphanumeric(10);
+ underTest.newEditionWithoutInstall(value);
+ underTest.uninstall();
PendingStatus newStatus = underTest.finalizeInstallation();
@@ -689,7 +791,7 @@ public class StandaloneEditionManagementStateImplTest {
assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
assertThat(underTest.getPendingEditionKey()).isEmpty();
assertThat(underTest.getPendingLicense()).isEmpty();
- assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
+ assertThat(underTest.getCurrentEditionKey()).isEmpty();
}
@Test