diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-10-19 15:07:37 +0200 |
---|---|---|
committer | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2017-10-23 08:01:13 -0700 |
commit | 1046ae09ec9d2ccba31f54dc395831baa3d01b56 (patch) | |
tree | dd4e427a592904047cc308121d6452a96aeaa0b9 /server | |
parent | d0189372d6db69b38a1af4eab50ebc2ab6721b3f (diff) | |
download | sonarqube-1046ae09ec9d2ccba31f54dc395831baa3d01b56.tar.gz sonarqube-1046ae09ec9d2ccba31f54dc395831baa3d01b56.zip |
SONAR-10002 add message to finalizeInstallation
Diffstat (limited to 'server')
5 files changed, 188 insertions, 20 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/edition/CommitPendingEditionOnStartup.java b/server/sonar-server/src/main/java/org/sonar/server/edition/CommitPendingEditionOnStartup.java index bd518af77e1..e132003b3c7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/edition/CommitPendingEditionOnStartup.java +++ b/server/sonar-server/src/main/java/org/sonar/server/edition/CommitPendingEditionOnStartup.java @@ -58,7 +58,7 @@ public class CommitPendingEditionOnStartup implements Startable { break; case UNINSTALL_IN_PROGRESS: failIfLicenseCommitIsPresent(); - editionManagementState.finalizeInstallation(); + editionManagementState.finalizeInstallation(null); break; default: throw new IllegalStateException("Unsupported status " + status); @@ -81,7 +81,7 @@ public class CommitPendingEditionOnStartup implements Startable { String newLicense = editionManagementState.getPendingLicense() .orElseThrow(() -> new IllegalStateException(String.format("When state is %s, a license should be available in staging", status))); licenseCommit.update(newLicense); - editionManagementState.finalizeInstallation(); + editionManagementState.finalizeInstallation(null); } @Override diff --git a/server/sonar-server/src/main/java/org/sonar/server/edition/MutableEditionManagementState.java b/server/sonar-server/src/main/java/org/sonar/server/edition/MutableEditionManagementState.java index cd96b760a3d..af26266315a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/edition/MutableEditionManagementState.java +++ b/server/sonar-server/src/main/java/org/sonar/server/edition/MutableEditionManagementState.java @@ -92,12 +92,13 @@ public interface MutableEditionManagementState extends EditionManagementState { PendingStatus uninstall(); /** - * Finalize an automatic or manual install + * Finalize an automatic or manual install with the specified (optional) error message to explain a partially + * finalized install. * * @return the new pending status, always {@link PendingStatus#NONE} * * @throws IllegalStateException if current status is neither {@link PendingStatus#AUTOMATIC_READY} nor * {@link PendingStatus#MANUAL_IN_PROGRESS} */ - PendingStatus finalizeInstallation(); + PendingStatus finalizeInstallation(@Nullable String errorMessage); } 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 1b89c142ccc..76d358c988d 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 @@ -193,11 +193,12 @@ public class StandaloneEditionManagementStateImpl implements MutableEditionManag } @Override - public synchronized PendingStatus finalizeInstallation() { + public synchronized PendingStatus finalizeInstallation(@Nullable String errorMessage) { ensureStarted(); State newState = changeStatusToFrom(NONE, AUTOMATIC_READY, MANUAL_IN_PROGRESS, UNINSTALL_IN_PROGRESS) .commitPendingEditionKey() .clearPendingFields() + .setInstallErrorMessage(nullableTrimmedEmptyToNull(errorMessage)) .build(); persistProperties(newState); return newState.getPendingInstallationStatus(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/edition/CommitPendingEditionOnStartupTest.java b/server/sonar-server/src/test/java/org/sonar/server/edition/CommitPendingEditionOnStartupTest.java index 478c9d066e6..5318e3a8944 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/edition/CommitPendingEditionOnStartupTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/edition/CommitPendingEditionOnStartupTest.java @@ -96,7 +96,7 @@ public class CommitPendingEditionOnStartupTest { verify(editionManagementState).getPendingInstallationStatus(); verify(editionManagementState).getPendingLicense(); - verify(editionManagementState).finalizeInstallation(); + verify(editionManagementState).finalizeInstallation(null); verifyNoMoreInteractions(editionManagementState); verify(licenseCommit).update(license); verifyNoMoreInteractions(licenseCommit); @@ -126,7 +126,7 @@ public class CommitPendingEditionOnStartupTest { verify(editionManagementState).getPendingInstallationStatus(); verify(editionManagementState).getPendingLicense(); - verify(editionManagementState).finalizeInstallation(); + verify(editionManagementState).finalizeInstallation(null); verifyNoMoreInteractions(editionManagementState); verify(licenseCommit).update(license); verifyNoMoreInteractions(licenseCommit); @@ -163,7 +163,7 @@ public class CommitPendingEditionOnStartupTest { underTest.start(); verify(editionManagementState).getPendingInstallationStatus(); - verify(editionManagementState).finalizeInstallation(); + verify(editionManagementState).finalizeInstallation(null); verifyNoMoreInteractions(editionManagementState); } 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 db97fb09441..485c9ad0398 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 @@ -282,6 +282,39 @@ public class StandaloneEditionManagementStateImplTest { } @Test + public void startAutomaticInstall_sets_pending_fields_after_finalizeInstallation() { + underTest.start(); + underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); + underTest.automaticInstallReady(); + underTest.finalizeInstallation(null); + + PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); + + assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS); + assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS); + assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey()); + assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent()); + assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey()); + assertThat(underTest.getInstallErrorMessage()).isEmpty(); + } + + @Test + public void startAutomaticInstall_sets_pending_fields_and_clears_error_message_after_finalizeInstallation() { + underTest.start(); + underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS); + underTest.finalizeInstallation(errorMessage); + + PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); + + assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS); + assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS); + assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey()); + assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent()); + assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey()); + assertThat(underTest.getInstallErrorMessage()).isEmpty(); + } + + @Test public void startAutomaticInstall_fails_with_ISE_if_called_after_startAutomaticInstall() { underTest.start(); underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); @@ -328,6 +361,71 @@ public class StandaloneEditionManagementStateImplTest { } @Test + public void startAutomaticInstall_sets_pending_fields_after_installFailed() { + underTest.start(); + underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); + underTest.installFailed(null); + + PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); + + assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS); + assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS); + assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey()); + assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent()); + assertThat(underTest.getCurrentEditionKey()).isEmpty(); + assertThat(underTest.getInstallErrorMessage()).isEmpty(); + } + + @Test + public void startAutomaticInstall_sets_pending_fields_and_clears_error_message_after_installFailed_with_message() { + underTest.start(); + underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); + underTest.installFailed(errorMessage); + + PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); + + assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS); + assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS); + assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey()); + assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent()); + assertThat(underTest.getCurrentEditionKey()).isEmpty(); + assertThat(underTest.getInstallErrorMessage()).isEmpty(); + } + + @Test + public void startAutomaticInstall_sets_pending_fields_after_finalizeInstall() { + underTest.start(); + underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); + underTest.automaticInstallReady(); + underTest.finalizeInstallation(null); + + PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); + + assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS); + assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS); + assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey()); + assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent()); + assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey()); + assertThat(underTest.getInstallErrorMessage()).isEmpty(); + } + + @Test + public void startAutomaticInstall_sets_pending_fields_and_clears_error_message_after_finalizeInstall_with_message() { + underTest.start(); + underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS); + underTest.finalizeInstallation(errorMessage); + + PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); + + assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS); + assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS); + assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey()); + assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent()); + assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey()); + assertThat(underTest.getInstallErrorMessage()).isEmpty(); + } + + @Test public void uninstall_fails_with_ISE_if_not_started() { expectISENotStarted(); @@ -337,9 +435,9 @@ public class StandaloneEditionManagementStateImplTest { @Test public void uninstall_resets_fields_after_start_and_install() { String value = randomAlphanumeric(10); - underTest.start(); underTest.newEditionWithoutInstall(value); + PendingStatus newStatus = underTest.uninstall(); assertThat(newStatus).isEqualTo(UNINSTALL_IN_PROGRESS); @@ -347,6 +445,7 @@ public class StandaloneEditionManagementStateImplTest { assertThat(underTest.getPendingEditionKey()).isEmpty(); assertThat(underTest.getPendingLicense()).isEmpty(); assertThat(underTest.getCurrentEditionKey()).isEmpty(); + assertThat(underTest.getInstallErrorMessage()).isEmpty(); } @Test @@ -375,6 +474,7 @@ public class StandaloneEditionManagementStateImplTest { assertThat(underTest.getPendingEditionKey()).isEmpty(); assertThat(underTest.getPendingLicense()).isEmpty(); assertThat(underTest.getCurrentEditionKey()).isEmpty(); + assertThat(underTest.getInstallErrorMessage()).isEmpty(); } @Test @@ -773,7 +873,7 @@ public class StandaloneEditionManagementStateImplTest { public void finalizeInstallation_fails_with_ISE_if_not_started() { expectISENotStarted(); - underTest.finalizeInstallation(); + underTest.finalizeInstallation(nullableErrorMessage); } @Test @@ -783,7 +883,7 @@ public class StandaloneEditionManagementStateImplTest { expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS, UNINSTALL_IN_PROGRESS])"); - underTest.finalizeInstallation(); + underTest.finalizeInstallation(nullableErrorMessage); } @Test @@ -794,7 +894,7 @@ public class StandaloneEditionManagementStateImplTest { expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS, UNINSTALL_IN_PROGRESS])"); - underTest.finalizeInstallation(); + underTest.finalizeInstallation(nullableErrorMessage); } @Test @@ -805,7 +905,7 @@ public class StandaloneEditionManagementStateImplTest { expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Can't move to NONE when status is AUTOMATIC_IN_PROGRESS (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS, UNINSTALL_IN_PROGRESS])"); - underTest.finalizeInstallation(); + underTest.finalizeInstallation(nullableErrorMessage); } @Test @@ -814,7 +914,7 @@ public class StandaloneEditionManagementStateImplTest { underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); underTest.automaticInstallReady(); - PendingStatus newStatus = underTest.finalizeInstallation(); + PendingStatus newStatus = underTest.finalizeInstallation(null); assertThat(newStatus).isEqualTo(NONE); assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE); @@ -825,11 +925,27 @@ public class StandaloneEditionManagementStateImplTest { } @Test + public void finalizeInstallation_set_new_edition_and_clear_pending_fields_and_sets_error_message_after_manualInstallationReady() { + underTest.start(); + underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); + underTest.automaticInstallReady(); + + PendingStatus newStatus = underTest.finalizeInstallation(errorMessage); + + assertThat(newStatus).isEqualTo(NONE); + assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE); + assertThat(underTest.getPendingEditionKey()).isEmpty(); + assertThat(underTest.getPendingLicense()).isEmpty(); + assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey()); + assertThat(underTest.getInstallErrorMessage()).contains(errorMessage); + } + + @Test public void finalizeInstallation_set_new_edition_and_clear_pending_fields_after_startManualInstall() { underTest.start(); underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS); - PendingStatus newStatus = underTest.finalizeInstallation(); + PendingStatus newStatus = underTest.finalizeInstallation(null); assertThat(newStatus).isEqualTo(NONE); assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE); @@ -840,13 +956,28 @@ public class StandaloneEditionManagementStateImplTest { } @Test + public void finalizeInstallation_set_new_edition_and_clear_pending_fields_and_sets_error_message_after_startManualInstall() { + underTest.start(); + underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS); + + PendingStatus newStatus = underTest.finalizeInstallation(errorMessage); + + assertThat(newStatus).isEqualTo(NONE); + assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE); + assertThat(underTest.getPendingEditionKey()).isEmpty(); + assertThat(underTest.getPendingLicense()).isEmpty(); + assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey()); + assertThat(underTest.getInstallErrorMessage()).contains(errorMessage); + } + + @Test public void finalizeInstallation_overwrites_current_edition_and_clear_pending_fields_after_startManualInstall() { String value = randomAlphanumeric(10); dbTester.properties().insertInternal("currentEditionKey", value); underTest.start(); underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS); - PendingStatus newStatus = underTest.finalizeInstallation(); + PendingStatus newStatus = underTest.finalizeInstallation(null); assertThat(newStatus).isEqualTo(NONE); assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE); @@ -857,6 +988,23 @@ public class StandaloneEditionManagementStateImplTest { } @Test + public void finalizeInstallation_overwrites_current_edition_and_clear_pending_fields_and_sets_error_message_after_startManualInstall() { + String value = randomAlphanumeric(10); + dbTester.properties().insertInternal("currentEditionKey", value); + underTest.start(); + underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS); + + PendingStatus newStatus = underTest.finalizeInstallation(errorMessage); + + assertThat(newStatus).isEqualTo(NONE); + assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE); + assertThat(underTest.getPendingEditionKey()).isEmpty(); + assertThat(underTest.getPendingLicense()).isEmpty(); + assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey()); + assertThat(underTest.getInstallErrorMessage()).contains(errorMessage); + } + + @Test public void finalizeInstallation_fails_with_ISE_after_installFailed() { underTest.start(); underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS); @@ -865,7 +1013,7 @@ public class StandaloneEditionManagementStateImplTest { expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS, UNINSTALL_IN_PROGRESS])"); - underTest.finalizeInstallation(); + underTest.finalizeInstallation(nullableErrorMessage); } @Test @@ -875,25 +1023,43 @@ public class StandaloneEditionManagementStateImplTest { underTest.newEditionWithoutInstall(value); underTest.uninstall(); - PendingStatus newStatus = underTest.finalizeInstallation(); + PendingStatus newStatus = underTest.finalizeInstallation(null); + + assertThat(newStatus).isEqualTo(NONE); + assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE); + assertThat(underTest.getPendingEditionKey()).isEmpty(); + assertThat(underTest.getPendingLicense()).isEmpty(); + assertThat(underTest.getCurrentEditionKey()).isEmpty(); + assertThat(underTest.getInstallErrorMessage()).isEmpty(); + } + + @Test + public void finalizeInstallation_set_new_edition_and_clear_pending_fields_and_sets_error_message_after_uninstall() { + underTest.start(); + String value = randomAlphanumeric(10); + underTest.newEditionWithoutInstall(value); + underTest.uninstall(); + + PendingStatus newStatus = underTest.finalizeInstallation(errorMessage); assertThat(newStatus).isEqualTo(NONE); assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE); assertThat(underTest.getPendingEditionKey()).isEmpty(); assertThat(underTest.getPendingLicense()).isEmpty(); assertThat(underTest.getCurrentEditionKey()).isEmpty(); + assertThat(underTest.getInstallErrorMessage()).contains(errorMessage); } @Test public void finalizeInstallation_fails_with_ISE_after_finalizeInstallation() { underTest.start(); underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS); - underTest.finalizeInstallation(); + underTest.finalizeInstallation(nullableErrorMessage); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS, UNINSTALL_IN_PROGRESS])"); - underTest.finalizeInstallation(); + underTest.finalizeInstallation(nullableErrorMessage); } @Test |