-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In Auto setup, when IsUninitialized, response http status code 503 #16834
Open
infofromca
wants to merge
34
commits into
OrchardCMS:main
Choose a base branch
from
infofromca:409
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+317
−132
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
5c0cfbe
In Auto setup, when IsUninitialized, response http status code 409
infofromca cbb43d2
Remove ILogger
infofromca 1573e53
Update src/OrchardCore.Modules/OrchardCore.AutoSetup/Services/IAutoSe…
infofromca ff715ae
Update src/OrchardCore.Modules/OrchardCore.AutoSetup/Services/AutoSet…
infofromca 5ffc4aa
Update src/OrchardCore.Modules/OrchardCore.AutoSetup/Services/AutoSet…
infofromca c02123c
Update src/OrchardCore.Modules/OrchardCore.AutoSetup/Services/AutoSet…
infofromca 281daa4
Update src/OrchardCore.Modules/OrchardCore.AutoSetup/Services/AutoSet…
infofromca 511dc12
Update src/OrchardCore.Modules/OrchardCore.AutoSetup/Services/AutoSet…
infofromca 7a51f44
Move the docs to the interface
infofromca 1fbc8c6
Update src/OrchardCore.Modules/OrchardCore.AutoSetup/Services/IAutoSe…
infofromca 6f99df3
Update src/OrchardCore.Modules/OrchardCore.AutoSetup/Services/AutoSet…
infofromca 9c25005
change to 503
infofromca 2d52d80
Consider the failure situation
infofromca 37aaf73
Merge branch 'main' into 409
hishamco 1cf54b3
Show the error message to the user
infofromca 23333d7
Test -- InvokeAsync_InitializedShell_SkipsSetup
infofromca 4f665ce
InvokeAsync_FailedSetup_ReturnsServiceUnavailable
infofromca 4255865
InvokeAsync_FailedLockAcquisition_ThrowsTimeoutException
infofromca ed75f46
InvokeAsync_UnInitializedShell_PerformsSetup
infofromca 889565e
Clean
infofromca b039be0
Clean
infofromca 13ba574
Correct DI scope for IAutoSetupService
infofromca debdf12
Won't stop other Middlewares after success
infofromca 9d0902f
Code styling
Piedone 29a8a10
Shouldn't write error messages to the response directly
infofromca 4b5ae4b
Merge branch 'main' into 409
hishamco 3c806ab
Update test/OrchardCore.Tests/Modules/OrchardCore.AutoSetup/AutoSetup…
infofromca 30cf024
Update test/OrchardCore.Tests/Modules/OrchardCore.AutoSetup/AutoSetup…
infofromca d02b9e1
Update test/OrchardCore.Tests/Modules/OrchardCore.AutoSetup/AutoSetup…
infofromca 703a622
Update src/OrchardCore.Modules/OrchardCore.AutoSetup/Services/AutoSet…
infofromca e6be8ef
middleware creation to make reusable across the unit tests
infofromca e939807
create a private method for middleware creation to make reusable acro…
infofromca 5f3fb82
Merge branch 'main' into 409
hishamco c8b4dd8
Update test/OrchardCore.Tests/Modules/OrchardCore.AutoSetup/AutoSetup…
infofromca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/OrchardCore.Modules/OrchardCore.AutoSetup/Services/AutoSetupService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System.Text; | ||
using Microsoft.Extensions.Logging; | ||
using OrchardCore.Abstractions.Setup; | ||
using OrchardCore.AutoSetup.Options; | ||
using OrchardCore.Environment.Shell; | ||
using OrchardCore.Setup.Services; | ||
|
||
namespace OrchardCore.AutoSetup.Services; | ||
|
||
public class AutoSetupService : IAutoSetupService | ||
{ | ||
private readonly IShellHost _shellHost; | ||
private readonly IShellSettingsManager _shellSettingsManager; | ||
private readonly ISetupService _setupService; | ||
private readonly ILogger _logger; | ||
|
||
public AutoSetupService( | ||
IShellHost shellHost, | ||
IShellSettingsManager shellSettingsManager, | ||
ISetupService setupService, | ||
ILogger<AutoSetupService> logger | ||
) | ||
{ | ||
_shellHost = shellHost; | ||
_shellSettingsManager = shellSettingsManager; | ||
_setupService = setupService; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<(SetupContext, bool)> SetupTenantAsync(TenantSetupOptions setupOptions, ShellSettings shellSettings) | ||
{ | ||
var setupContext = await GetSetupContextAsync(setupOptions, shellSettings); | ||
|
||
_logger.LogInformation("The AutoSetup is initializing the site."); | ||
|
||
await _setupService.SetupAsync(setupContext); | ||
|
||
if (setupContext.Errors.Count == 0) | ||
{ | ||
_logger.LogInformation("The AutoSetup successfully provisioned the site '{SiteName}'.", setupOptions.SiteName); | ||
|
||
return (setupContext, true); | ||
} | ||
|
||
var stringBuilder = new StringBuilder(); | ||
foreach (var error in setupContext.Errors) | ||
{ | ||
stringBuilder.AppendLine($"{error.Key} : '{error.Value}'"); | ||
} | ||
|
||
_logger.LogError("The AutoSetup failed installing the site '{SiteName}' with errors: {Errors}.", setupOptions.SiteName, stringBuilder); | ||
|
||
return (setupContext, false); | ||
} | ||
|
||
public async Task<ShellSettings> CreateTenantSettingsAsync(TenantSetupOptions setupOptions) | ||
{ | ||
using var shellSettings = _shellSettingsManager | ||
.CreateDefaultSettings() | ||
.AsUninitialized() | ||
.AsDisposable(); | ||
|
||
shellSettings.Name = setupOptions.ShellName; | ||
shellSettings.RequestUrlHost = setupOptions.RequestUrlHost; | ||
shellSettings.RequestUrlPrefix = setupOptions.RequestUrlPrefix; | ||
shellSettings["ConnectionString"] = setupOptions.DatabaseConnectionString; | ||
shellSettings["TablePrefix"] = setupOptions.DatabaseTablePrefix; | ||
shellSettings["Schema"] = setupOptions.DatabaseSchema; | ||
shellSettings["DatabaseProvider"] = setupOptions.DatabaseProvider; | ||
shellSettings["Secret"] = Guid.NewGuid().ToString(); | ||
shellSettings["RecipeName"] = setupOptions.RecipeName; | ||
shellSettings["FeatureProfile"] = setupOptions.FeatureProfile; | ||
|
||
await _shellHost.UpdateShellSettingsAsync(shellSettings); | ||
|
||
return shellSettings; | ||
} | ||
|
||
public async Task<SetupContext> GetSetupContextAsync(TenantSetupOptions options, ShellSettings shellSettings) | ||
{ | ||
var recipe = (await _setupService.GetSetupRecipesAsync()) | ||
.SingleOrDefault(r => r.Name == options.RecipeName); | ||
|
||
var setupContext = new SetupContext | ||
{ | ||
Recipe = recipe, | ||
ShellSettings = shellSettings, | ||
Errors = new Dictionary<string, string>() | ||
}; | ||
|
||
if (shellSettings.IsDefaultShell()) | ||
{ | ||
// The 'Default' shell is first created by the infrastructure, | ||
// so the following 'Autosetup' options need to be passed. | ||
shellSettings.RequestUrlHost = options.RequestUrlHost; | ||
shellSettings.RequestUrlPrefix = options.RequestUrlPrefix; | ||
} | ||
|
||
setupContext.Properties[SetupConstants.AdminEmail] = options.AdminEmail; | ||
setupContext.Properties[SetupConstants.AdminPassword] = options.AdminPassword; | ||
setupContext.Properties[SetupConstants.AdminUsername] = options.AdminUsername; | ||
setupContext.Properties[SetupConstants.DatabaseConnectionString] = options.DatabaseConnectionString; | ||
setupContext.Properties[SetupConstants.DatabaseProvider] = options.DatabaseProvider; | ||
setupContext.Properties[SetupConstants.DatabaseTablePrefix] = options.DatabaseTablePrefix; | ||
setupContext.Properties[SetupConstants.DatabaseSchema] = options.DatabaseSchema; | ||
setupContext.Properties[SetupConstants.SiteName] = options.SiteName; | ||
setupContext.Properties[SetupConstants.SiteTimeZone] = options.SiteTimeZone; | ||
|
||
return setupContext; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/OrchardCore.Modules/OrchardCore.AutoSetup/Services/IAutoSetupService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using OrchardCore.AutoSetup.Options; | ||
using OrchardCore.Environment.Shell; | ||
using OrchardCore.Setup.Services; | ||
|
||
namespace OrchardCore.AutoSetup.Services; | ||
|
||
public interface IAutoSetupService | ||
{ | ||
/// <summary> | ||
/// Creates a tenant shell settings. | ||
/// </summary> | ||
/// <param name="setupOptions">The setup options.</param> | ||
/// <returns>The <see cref="ShellSettings"/>.</returns> | ||
Task<ShellSettings> CreateTenantSettingsAsync(TenantSetupOptions setupOptions); | ||
|
||
/// <summary> | ||
/// Gets a setup context from the configuration. | ||
/// </summary> | ||
/// <param name="options">The tenant setup options.</param> | ||
/// <param name="shellSettings">The tenant shell settings.</param> | ||
/// <returns> The <see cref="SetupContext"/> used to setup the site.</returns> | ||
Task<SetupContext> GetSetupContextAsync(TenantSetupOptions options, ShellSettings shellSettings); | ||
|
||
/// <summary> | ||
/// Sets up a tenant. | ||
/// </summary> | ||
/// <param name="setupOptions">The tenant setup options.</param> | ||
/// <param name="shellSettings">The tenant shell settings.</param> | ||
/// <returns> | ||
/// Returns <see langword="true" /> if successfully setup. | ||
/// </returns> | ||
Task<(SetupContext, bool)> SetupTenantAsync(TenantSetupOptions setupOptions, ShellSettings shellSettings); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would prevent the error message from being displayed to the user. Like server-side validation or database creation error.
Even if you still decide to keep 503 as the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sebastienros : Just committed
Won't stop other Middlewares after success