Skip to content

Commit

Permalink
Merge branch 'develop' into feature/613-Make_the_Success_messages_mor…
Browse files Browse the repository at this point in the history
…e_informative
  • Loading branch information
DmitryKolinchuk authored Nov 8, 2021
2 parents d03b5dd + efeadd2 commit 88157d8
Show file tree
Hide file tree
Showing 30 changed files with 1,254 additions and 272 deletions.
35 changes: 33 additions & 2 deletions src/SIM.Base/ApplicationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public static class ApplicationManager
[NotNull]
public static string AppShortVersion { get; }

[NotNull]
public static string AppThreePartVersion { get; }

[NotNull]
public static string AppVersion { get; }

Expand Down Expand Up @@ -126,6 +129,7 @@ static ApplicationManager()
AppRevision = GetRevision();
AppVersion = GetVersion();
AppShortVersion = GetShortVersion();
AppThreePartVersion = GetThreePartVersion();
AppLabel = GetLabel();
UnInstallParamsFolder = InitializeDataFolder("UnInstallParams");
TempFolder = InitializeDataFolder("Temp");
Expand Down Expand Up @@ -362,8 +366,18 @@ private static string GetRevision()
}

var revision = revisionAttribute[0] as AssemblyInformationalVersionAttribute;
var rev = "rev. ";
return revision != null ? revision.InformationalVersion.Remove(0, revision.InformationalVersion.IndexOf(rev, StringComparison.Ordinal) + rev.Length) : string.Empty;
if (revision == null)
{
return String.Empty;
}

int revisionLength = revision.InformationalVersion.LastIndexOf(".", StringComparison.Ordinal);
if (revisionLength != -1)
{
return revision.InformationalVersion.Substring(revisionLength + 1);
}

return String.Empty;
}

private static string GetShortVersion()
Expand All @@ -377,6 +391,23 @@ private static string GetShortVersion()
return version.Substring(0, 3);
}

private static string GetThreePartVersion()
{
var version = GetVersion();
if (string.IsNullOrEmpty(version))
{
return string.Empty;
}

int threePartVersionLength = version.LastIndexOf(".", StringComparison.Ordinal);
if (threePartVersionLength != -1)
{
return version.Substring(0, threePartVersionLength);
}

return version;
}

private static string GetVersion()
{
var assembly = Assembly.GetExecutingAssembly();
Expand Down
8 changes: 8 additions & 0 deletions src/SIM.Base/SIM.Base.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>7.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -34,6 +35,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>7.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="Ionic.Zip.Reduced, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
Expand All @@ -43,6 +45,9 @@
<Reference Include="JetBrains.Annotations, Version=11.1.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
<HintPath>..\packages\JetBrains.Annotations.11.1.0\lib\net20\JetBrains.Annotations.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Sitecore.Diagnostics.Base, Version=2.1.4.203, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Sitecore.Diagnostics.Base.2.1.4.203\lib\Sitecore.Diagnostics.Base.dll</HintPath>
</Reference>
Expand All @@ -53,6 +58,7 @@
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Xml" />
Expand Down Expand Up @@ -109,6 +115,8 @@
<Compile Include="Services\ConnectionString.cs" />
<Compile Include="Services\SqlConnectionString.cs" />
<Compile Include="SolrDefinition.cs" />
<Compile Include="SolrState.cs" />
<Compile Include="SolrStateResolver.cs" />
<Compile Include="VersionToSolr.cs" />
<Compile Include="WebRequestHelper.cs" />
<Compile Include="XmlBasedAdvancedSettingsStorage.cs" />
Expand Down
23 changes: 23 additions & 0 deletions src/SIM.Base/SolrState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace SIM
{
public class SolrState
{
[RenderInDataGreed]
public string Name { get; set; }

[RenderInDataGreed]
public CurrentState State { get; set; }

[RenderInDataGreed]
public string Version { get; set; }

[RenderInDataGreed]
public string Url { get; set; }

public enum CurrentState
{
Running,
Stopped
}
}
}
97 changes: 97 additions & 0 deletions src/SIM.Base/SolrStateResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.ServiceProcess;
using Newtonsoft.Json;

namespace SIM
{
public class SolrStateResolver
{
public virtual SolrState.CurrentState GetServiceState(string solrServiceName)
{
ServiceControllerWrapper service = GetService(solrServiceName);

if (service == null)
{
return SolrState.CurrentState.Stopped;
}

if (service.Status != ServiceControllerStatus.Running)
{
return SolrState.CurrentState.Stopped;
}

return SolrState.CurrentState.Running;
}

public virtual SolrState.CurrentState GetUrlState(string solrUrl)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(solrUrl);
HttpWebResponse httpWebResponse;
try
{
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
}
catch
{
return SolrState.CurrentState.Stopped;
}

if (httpWebResponse.StatusCode != HttpStatusCode.OK)
{
return SolrState.CurrentState.Stopped;
}

return SolrState.CurrentState.Running;
}

public virtual string GetVersion(string solrUrl)
{
HttpClient client = new HttpClient();

using (Stream stream = client.GetStreamAsync($"{solrUrl}/admin/info/system?wt=json").Result)
using (StreamReader streamReader = new StreamReader(stream))
using (JsonReader reader = new JsonTextReader(streamReader))
{
while (reader.Read())
{
if (string.Equals(reader.Path, "lucene.solr-spec-version", StringComparison.OrdinalIgnoreCase)
&& !string.Equals((string)reader.Value, "solr-spec-version", StringComparison.OrdinalIgnoreCase))
{
return (string)reader.Value;
}
}
}

return string.Empty;
}

public virtual ServiceControllerWrapper GetService(string serviceName)
{
ServiceController service = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == serviceName);
if (service == null)
{
return null;
}

return new ServiceControllerWrapper(service);
}
}

public class ServiceControllerWrapper
{
ServiceController _service;

public ServiceControllerWrapper(ServiceController service)
{
this._service = service;
}

public virtual ServiceControllerStatus Status => this._service.Status;

public virtual string ServiceName => this._service.ServiceName;
}
}
1 change: 1 addition & 0 deletions src/SIM.Base/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<packages>
<package id="DotNetZip.Reduced" version="1.9.1.8" targetFramework="net45" />
<package id="JetBrains.Annotations" version="11.1.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net471" />
<package id="Sitecore.Diagnostics.Base" version="2.1.4.203" targetFramework="net471" />
<package id="Sitecore.Diagnostics.Logging" version="2.1.4.203" targetFramework="net471" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@
<Analyzer Include="..\packages\xunit.analyzers.0.10.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SIM.Base\SIM.Base.csproj">
<Project>{ca9339a0-9a7d-4900-839e-f21b7269bdaa}</Project>
<Name>SIM.Base</Name>
</ProjectReference>
<ProjectReference Include="..\SIM.Sitecore9Installer\SIM.Sitecore9Installer.csproj">
<Project>{5c870ab3-89f2-4e24-ae5d-3593ec816495}</Project>
<Name>SIM.Sitecore9Installer</Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ namespace SIM.Sitecore9Installer.Tests.Validation.Validators
{
public class PrerequisitesDownloadLinksValidatorTests
{
private const string KnownIssueMessage = "{0}: the '{1}' parameter contains the following link that is not accessible:\n\n{2}\n\nThis behavior looks to be related to the following known issue:\n\n{3}\n\nPlease try to apply the solution mentioned there.";
private const string OutdatedDownloadLinksKnownIssueMessage = "{0}: the '{1}' parameter contains the following link that is not accessible:\n\n{2}\n\nThis behavior looks to be related to the following known issue:\n\n{3}\n\nPlease try to apply the solution mentioned there.";

private const string InvalidLinkMessage = "{0}: the '{1}' parameter contains the following link that is not accessible:\n\n{2}\n\nPlease check the Internet connection and the link accessibility in a browser.\n\nThis behavior may also occur due to similar symptoms described in the following known issue:\n\n{3}";
private const string InternetAccessKnownIssueMessage = "{0}: the '{1}' parameter contains the following link that is not accessible:\n\n{2}\n\nPlease check the link accessibility in a browser and solution mentioned in the following known issue:\n\n{3}";

private const string InvalidValueMessage = "{0}: the '{1}' parameter contains the following invalid value:\n\n{2}\n\nIt should contain download link that starts with '{3}'.";

[Theory]
[InlineData("Prerequisites", "WebPlatformDownload", "https://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi", 1, KnownIssueMessage)]
[InlineData("Prerequisites", "WebPlatformDownload", "https://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi", 1, OutdatedDownloadLinksKnownIssueMessage)]
[InlineData("Global", "WebPlatformDownload", "https://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi", 0, "")]
[InlineData("Prerequisites", "SQLODBCDriversx64", "https://download.microsoft.com/download/D/5/E/D5EEF288-A277-45C8-855B-8E2CB7E25B96/x64/msodbcsql.msi", 0, "")]
[InlineData("Prerequisites", "SQLODBCDriversx64", "https://download.microsoft.com/download/test", 1, InvalidLinkMessage)]
[InlineData("Prerequisites", "SQLODBCDriversx64", "https://download.microsoft.com/download/test", 1, InternetAccessKnownIssueMessage)]
[InlineData("Prerequisites", "SQLODBCDriversx64", "test", 0, "")]
[InlineData("Prerequisites", "DotNetHostingDownload", "https://download.microsoft.com/download/6/E/B/6EBD972D-2E2F-41EB-9668-F73F5FDDC09C/dotnet-hosting-2.1.3-win.exe", 0, "")]
[InlineData("Prerequisites", "DotNetHostingDownload", "test", 1, InvalidValueMessage)]
Expand Down Expand Up @@ -50,9 +50,13 @@ public void EvaluateTests(string taskName, string paramName, string paramValue,

// Assert
Assert.Equal(warnings.Count(), warningsCount);
if (message == KnownIssueMessage || message == InvalidLinkMessage)
if (message == OutdatedDownloadLinksKnownIssueMessage)
{
this.ValidateMessage(warnings, message, taskName, paramName, paramValue, validator.KnownIssueLink);
this.ValidateMessage(warnings, message, taskName, paramName, paramValue, validator.OutdatedDownloadLinksKnownIssueLink);
}
else if (message == InternetAccessKnownIssueMessage)
{
this.ValidateMessage(warnings, message, taskName, paramName, paramValue, validator.InternetAccessKnownIssueLink);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using NSubstitute;
using SIM.Sitecore9Installer.Tasks;
using SIM.Sitecore9Installer.Validation;
Expand All @@ -14,19 +12,21 @@ public class SolrServiceValidatorTests
{
[Theory]
[ClassData(typeof(ValidatorTestSetup))]
public void ServiceDoesNotExist(IEnumerable<Task> tasks)
public void ServiceIsStopped(IEnumerable<Task> tasks)
{
foreach (Task t in tasks)
{
t.LocalParams.AddOrUpdateParam("SolrService", "nope",InstallParamType.String);
t.LocalParams.AddOrUpdateParam("SolrUrl", "https://localhost:8983/solr", InstallParamType.String);
}

SolrServiceValidator val = Substitute.ForPartsOf<SolrServiceValidator>();
val.Data["ParamNames"] = Guid.NewGuid().ToString();
ServiceControllerWrapper s = null;
val.GetService(Arg.Any<string>()).ReturnsForAnyArgs(s);
val.Data["Solr"] = "SolrUrl";
val.Data["Versions"] = "8.4.*";
SolrStateResolver solrStateResolver = Substitute.ForPartsOf<SolrStateResolver>();
solrStateResolver.GetServiceState(Arg.Any<string>()).ReturnsForAnyArgs(SolrState.CurrentState.Stopped);
val.SolrStateResolver.Returns(solrStateResolver);
IEnumerable<ValidationResult> res = val.Evaluate(tasks);
Assert.Equal(0, res.Count(r => r.State == ValidatorState.Error));
Assert.Equal(2, res.Count(r => r.State == ValidatorState.Error));
}

[Theory]
Expand All @@ -35,15 +35,15 @@ public void ServiceIsRunning(IEnumerable<Task> tasks)
{
foreach (Task t in tasks)
{
t.LocalParams.AddOrUpdateParam("SolrService", "nope",InstallParamType.String);
t.LocalParams.AddOrUpdateParam("SolrUrl", "https://localhost:8983/solr", InstallParamType.String);
}

SolrServiceValidator val = Substitute.ForPartsOf<SolrServiceValidator>();
val.Data["ParamNames"] = Guid.NewGuid().ToString();
ServiceController c = null;
ServiceControllerWrapper s = Substitute.For<ServiceControllerWrapper>(c);
s.Status.Returns(ServiceControllerStatus.Running);
val.GetService(Arg.Any<string>()).ReturnsForAnyArgs(s);
val.Data["Solr"] = "SolrUrl";
val.Data["Versions"] = "8.1.*";
SolrStateResolver solrStateResolver = Substitute.ForPartsOf<SolrStateResolver>();
solrStateResolver.GetServiceState(Arg.Any<string>()).ReturnsForAnyArgs(SolrState.CurrentState.Running);
val.SolrStateResolver.Returns(solrStateResolver);
IEnumerable<ValidationResult> res = val.Evaluate(tasks);
Assert.Equal(0, res.Count(r => r.State == ValidatorState.Error));
}
Expand Down
4 changes: 4 additions & 0 deletions src/SIM.Sitecore9Installer/SIM.Sitecore9Installer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SIM.Base\SIM.Base.csproj">
<Project>{ca9339a0-9a7d-4900-839e-f21b7269bdaa}</Project>
<Name>SIM.Base</Name>
</ProjectReference>
<ProjectReference Include="..\SIM.Products\SIM.Products.csproj">
<Project>{bc8b4ee5-c053-42e1-a5ba-07f8c41915a9}</Project>
<Name>SIM.Products</Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public class PrerequisitesDownloadLinksValidator : BaseValidator
// parameter to validate the following known issue: https://github.com/Sitecore/Sitecore-Instance-Manager/wiki/Known-Issue-Outdated-Download-Link-to-Microsoft-Web-Platform-Installer
public virtual string WebPlatformDownload => "WebPlatformDownload";

public virtual string KnownIssueLink => "https://github.com/Sitecore/Sitecore-Instance-Manager/wiki/Known-Issue-Outdated-Download-Link-to-Microsoft-Web-Platform-Installer";
public virtual string OutdatedDownloadLinksKnownIssueLink => "https://github.com/Sitecore/Sitecore-Instance-Manager/wiki/Known-Issue-Outdated-download-links-in-Prerequisites.json";

public virtual string InternetAccessKnownIssueLink => "https://github.com/Sitecore/Sitecore-Instance-Manager/wiki/Known-Issue-Prerequisites-require-Internet-access-to-be-installed";

protected override IEnumerable<ValidationResult> GetErrorsForTask(Task task, IEnumerable<InstallParam> paramsToValidate)
{
Expand Down Expand Up @@ -44,13 +46,13 @@ protected override IEnumerable<ValidationResult> GetErrorsForTask(Task task, IEn
if (installParam.Name == this.WebPlatformDownload)
{
yield return new ValidationResult(ValidatorState.Warning,
$"{TaskName}: the '{installParam.Name}' parameter contains the following link that is not accessible:\n\n{installParam.Value}\n\nThis behavior looks to be related to the following known issue:\n\n{KnownIssueLink}\n\nPlease try to apply the solution mentioned there.",
$"{TaskName}: the '{installParam.Name}' parameter contains the following link that is not accessible:\n\n{installParam.Value}\n\nThis behavior looks to be related to the following known issue:\n\n{OutdatedDownloadLinksKnownIssueLink}\n\nPlease try to apply the solution mentioned there.",
null);
}
else
{
yield return new ValidationResult(ValidatorState.Warning,
$"{TaskName}: the '{installParam.Name}' parameter contains the following link that is not accessible:\n\n{installParam.Value}\n\nPlease check the Internet connection and the link accessibility in a browser.\n\nThis behavior may also occur due to similar symptoms described in the following known issue:\n\n{KnownIssueLink}",
$"{TaskName}: the '{installParam.Name}' parameter contains the following link that is not accessible:\n\n{installParam.Value}\n\nPlease check the link accessibility in a browser and solution mentioned in the following known issue:\n\n{InternetAccessKnownIssueLink}",
null);
}
}
Expand Down
Loading

0 comments on commit 88157d8

Please sign in to comment.