Skip to content
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

Check Redis server when creating project. #17669

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<PackageReference Include="Polly" Version="$(PollyPackageVersion)" />
<PackageReference Include="Polly.Extensions.Http" Version="3.0.0" />
<PackageReference Include="LibGit2Sharp" Version="0.26.2" />
<PackageReference Include="StackExchange.Redis" Version="2.6.122" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using StackExchange.Redis;
using Volo.Abp.Cli.Args;
using Volo.Abp.Cli.Bundling;
using Volo.Abp.Cli.Commands.Services;
using Volo.Abp.Cli.LIbs;
using Volo.Abp.Cli.ProjectBuilding;
using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectBuilding.Templates.App;
using Volo.Abp.Cli.ProjectModification;
using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection;
Expand Down Expand Up @@ -89,6 +91,8 @@

var projectArgs = await GetProjectBuildArgsAsync(commandLineArgs, template, projectName);

await CheckCreatingRequirements(projectArgs);

Check warning on line 94 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs#L94

Added line #L94 was not covered by tests

var result = await TemplateProjectBuilder.BuildAsync(
projectArgs
);
Expand All @@ -97,6 +101,8 @@

Logger.LogInformation($"'{projectName}' has been successfully created to '{projectArgs.OutputFolder}'");

await CheckCreatedRequirements(projectArgs);

Check warning on line 104 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs#L104

Added line #L104 was not covered by tests

ConfigureNpmPackagesForTheme(projectArgs);
await CreateOpenIddictPfxFilesAsync(projectArgs);
await RunGraphBuildForMicroserviceServiceTemplate(projectArgs);
Expand All @@ -120,6 +126,46 @@
OpenRelatedWebPage(projectArgs, template, isTiered, commandLineArgs);
}

private Task CheckCreatingRequirements(ProjectBuildArgs projectArgs)
{
return Task.CompletedTask;
}

Check warning on line 132 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs#L130-L132

Added lines #L130 - L132 were not covered by tests

private async Task CheckCreatedRequirements(ProjectBuildArgs projectArgs)
{
var errors = new List<string>();

Check warning on line 136 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs#L135-L136

Added lines #L135 - L136 were not covered by tests

if (projectArgs.ExtraProperties.ContainsKey("PreRequirements:Redis"))
{
var isConnected = false;

Check warning on line 140 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs#L138-L140

Added lines #L138 - L140 were not covered by tests
try
{
var redis = await ConnectionMultiplexer.ConnectAsync("127.0.0.1", options => options.ConnectTimeout = 3000);
isConnected = redis.IsConnected;
}
catch (Exception e)
{

Check warning on line 147 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs#L142-L147

Added lines #L142 - L147 were not covered by tests
// ignored
}

Check warning on line 149 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs#L149

Added line #L149 was not covered by tests
finally
{
if (!isConnected)
{
errors.Add("\t* Redis is not installed or not running on your computer.");
}
}
}

Check warning on line 157 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs#L151-L157

Added lines #L151 - L157 were not covered by tests

if (errors.Any())
{
Logger.LogWarning("NOTICE: The following tools is required to run your solution.");
foreach (var error in errors)
{
Logger.LogWarning(error);
}
}
}

Check warning on line 167 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs#L159-L167

Added lines #L159 - L167 were not covered by tests

public string GetUsageInfo()
{
var sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Volo.Abp.Cli.ProjectBuilding.Templates;

namespace Volo.Abp.Cli.ProjectBuilding.Building;

Expand Down Expand Up @@ -28,7 +29,14 @@

public virtual IEnumerable<ProjectBuildPipelineStep> GetCustomSteps(ProjectBuildContext context)
{
return Array.Empty<ProjectBuildPipelineStep>();
var steps = new List<ProjectBuildPipelineStep>();
ConfigureCheckPreRequirements(context, steps);
return steps;
}

Check warning on line 35 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/TemplateInfo.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/TemplateInfo.cs#L32-L35

Added lines #L32 - L35 were not covered by tests

protected void ConfigureCheckPreRequirements(ProjectBuildContext context, List<ProjectBuildPipelineStep> steps)
{
steps.Add(new CheckRedisPreRequirements());

Check warning on line 39 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/TemplateInfo.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/TemplateInfo.cs#L38-L39

Added lines #L38 - L39 were not covered by tests
}

public bool IsPro()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectBuilding.Building.Steps;

Expand All @@ -20,7 +21,7 @@

public override IEnumerable<ProjectBuildPipelineStep> GetCustomSteps(ProjectBuildContext context)
{
var steps = new List<ProjectBuildPipelineStep>();
var steps = base.GetCustomSteps(context).ToList();

Check warning on line 24 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppNoLayersTemplateBase.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppNoLayersTemplateBase.cs#L24

Added line #L24 was not covered by tests

switch (context.BuildArgs.DatabaseProvider)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public override IEnumerable<ProjectBuildPipelineStep> GetCustomSteps(ProjectBuildContext context)
{
var steps = new List<ProjectBuildPipelineStep>();
var steps = base.GetCustomSteps(context).ToList();

Check warning on line 31 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs#L31

Added line #L31 was not covered by tests

ConfigureTenantSchema(context, steps);
SwitchDatabaseProvider(context, steps);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Linq;
using Volo.Abp.Cli.ProjectBuilding.Building;

namespace Volo.Abp.Cli.ProjectBuilding.Templates;

public class CheckRedisPreRequirements : ProjectBuildPipelineStep
{
public override void Execute(ProjectBuildContext context)
{
var modules = context.Files.Where(f => f.Name.EndsWith("Module.cs", StringComparison.OrdinalIgnoreCase));
if (modules.Any(module => !module.Content.Contains("Redis:Configuration")))
EngincanV marked this conversation as resolved.
Show resolved Hide resolved
{
context.BuildArgs.ExtraProperties["PreRequirements:Redis"] = "true";
}
}

Check warning on line 16 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/CheckRedisPreRequirements.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/CheckRedisPreRequirements.cs#L10-L16

Added lines #L10 - L16 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using JetBrains.Annotations;
using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectBuilding.Building.Steps;
Expand Down Expand Up @@ -33,14 +34,14 @@

public override IEnumerable<ProjectBuildPipelineStep> GetCustomSteps(ProjectBuildContext context)
{
var steps = new List<ProjectBuildPipelineStep>();
var steps = base.GetCustomSteps(context).ToList();

Check warning on line 37 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Microservice/MicroserviceServiceTemplateBase.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Microservice/MicroserviceServiceTemplateBase.cs#L37

Added line #L37 was not covered by tests

DeleteUnrelatedUiProject(context, steps);
SetRandomPortForHostProject(context, steps);
RandomizeStringEncryption(context, steps);
RandomizeAuthServerPassPhrase(context, steps);
ChangeConnectionString(context, steps);

return steps;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectBuilding.Building.Steps;
Expand All @@ -19,7 +20,7 @@

public override IEnumerable<ProjectBuildPipelineStep> GetCustomSteps(ProjectBuildContext context)
{
var steps = new List<ProjectBuildPipelineStep>();
var steps = base.GetCustomSteps(context).ToList();

Check warning on line 23 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Microservice/MicroserviceTemplateBase.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Microservice/MicroserviceTemplateBase.cs#L23

Added line #L23 was not covered by tests

DeleteUnrelatedProjects(context, steps);
RandomizeStringEncryption(context, steps);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Volo.Abp.Cli.ProjectBuilding.Building;
using Volo.Abp.Cli.ProjectBuilding.Building.Steps;
Expand All @@ -21,7 +22,7 @@

public override IEnumerable<ProjectBuildPipelineStep> GetCustomSteps(ProjectBuildContext context)
{
var steps = new List<ProjectBuildPipelineStep>();
var steps = base.GetCustomSteps(context).ToList();

Check warning on line 25 in framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Module/ModuleTemplateBase.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Module/ModuleTemplateBase.cs#L25

Added line #L25 was not covered by tests

DeleteUnrelatedProjects(context, steps);
RandomizeSslPorts(context, steps);
Expand Down
Loading