Skip to content

Commit

Permalink
Merge pull request #594 from Sitecore/rc/1.10.2
Browse files Browse the repository at this point in the history
Release 1.10.2
  • Loading branch information
AndreyFilchenkov authored Jun 30, 2021
2 parents cb446c1 + c4a9edf commit 0dcd9f2
Show file tree
Hide file tree
Showing 28 changed files with 676 additions and 257 deletions.
24 changes: 17 additions & 7 deletions src/SIM.Base/WebRequestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading;
using Sitecore.Diagnostics.Base;
using Sitecore.Diagnostics.Logging;
using System.Collections.Generic;

public static class WebRequestHelper
{
Expand Down Expand Up @@ -130,9 +131,9 @@ public static void DownloadFile(string destFileName, Stream responseStream, Canc
}
}

public static string DownloadString(string url, int? timeout = null, int? readWriteTimeout = null)
public static string DownloadString(string url, int? timeout = null, int? readWriteTimeout = null, string cookies = null, IDictionary<string, string> headers = null)
{
using (var response = RequestAndGetResponse(url, timeout, readWriteTimeout))
using (var response = RequestAndGetResponse(url, timeout, readWriteTimeout, cookies: cookies, headers: headers))
{
Assert.IsNotNull(response, "No response provided");
var stream = response.GetResponseStream();
Expand Down Expand Up @@ -193,14 +194,14 @@ public static string GetFileName(WebResponse response)
return GetCookieValue(contentDisposition, "filename").Trim('"');
}

public static HttpWebResponse RequestAndGetResponse(string url, int? timeout = null, int? readWriteTimeout = null, string cookies = null)
public static HttpWebResponse RequestAndGetResponse(string url, int? timeout = null, int? readWriteTimeout = null, string cookies = null, IDictionary<string, string> headers = null)
{
return RequestAndGetResponse(new Uri(url), timeout, readWriteTimeout, cookies);
return RequestAndGetResponse(new Uri(url), timeout, readWriteTimeout, cookies, headers);
}

public static HttpWebResponse RequestAndGetResponse(Uri uri, int? timeout = null, int? readWriteTimeout = null, string cookies = null)
public static HttpWebResponse RequestAndGetResponse(Uri uri, int? timeout = null, int? readWriteTimeout = null, string cookies = null, IDictionary<string, string> headers = null)
{
var webRequest = CreateRequest(uri, timeout, readWriteTimeout, cookies);
var webRequest = CreateRequest(uri, timeout, readWriteTimeout, cookies, headers);

return webRequest.GetResponse() as HttpWebResponse;
}
Expand All @@ -214,16 +215,25 @@ private static HttpWebRequest CreateRequest(string url, int? timeout = null, int
return CreateRequest(new Uri(url), timeout, readWriteTimeout, cookies);
}

private static HttpWebRequest CreateRequest(Uri url, int? timeout = null, int? readWriteTimeout = null, string cookies = null)
private static HttpWebRequest CreateRequest(Uri url, int? timeout = null, int? readWriteTimeout = null, string cookies = null, IDictionary<string, string> headers = null)
{
var webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Timeout = timeout ?? Settings.CoreWebDownloadConnectionTimeout.Value;
webRequest.ReadWriteTimeout = readWriteTimeout ?? Settings.CoreWebDownloadTimeoutMinutes.Value * Minute;

if (cookies != null)
{
webRequest.Headers.Add(HttpRequestHeader.Cookie, cookies);
}

if (headers != null)
{
foreach (KeyValuePair<string, string> header in headers)
{
webRequest.Headers.Add(header.Key, header.Value);
}
}

return webRequest;
}

Expand Down
39 changes: 22 additions & 17 deletions src/SIM.Instances/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,25 +414,30 @@ public virtual string ModulesNames
{
get
{
try
{
var omsVersions = new[] {"6.2", "6.3", "6.4"};
var dmsVersions = new[] {"6.5", "6.6", "7.0", "7.1", "7.2"};
var dmsName = omsVersions.Any(x => ProductFullName.Contains(x))
? "OMS"
: (dmsVersions.Any(x => ProductFullName.Contains(x)) ? "DMS" : "xDB");

var modulesNames = Modules.Select(x => x.Name.TrimStart("Sitecore "));
return (string.Join(", ", modulesNames) +
(File.Exists(Path.Combine(WebRootPath, "App_Config\\Include\\Sitecore.Analytics.config"))
? $", {dmsName}"
: string.Empty)).TrimStart(" ,".ToCharArray());
}
catch (Exception ex)
if (this.Type == InstanceType.Sitecore8AndEarlier)
{
Log.Error(ex, $"Issue with reading ModulesNames propery of {this.Name} instance.");
return string.Empty;
try
{
var omsVersions = new[] { "6.2", "6.3", "6.4" };
var dmsVersions = new[] { "6.5", "6.6", "7.0", "7.1", "7.2" };
var dmsName = omsVersions.Any(x => ProductFullName.Contains(x))
? "OMS"
: (dmsVersions.Any(x => ProductFullName.Contains(x)) ? "DMS" : "xDB");

var modulesNames = Modules.Select(x => x.Name.TrimStart("Sitecore "));
return (string.Join(", ", modulesNames) +
(File.Exists(Path.Combine(WebRootPath, "App_Config\\Include\\Sitecore.Analytics.config"))
? $", {dmsName}"
: string.Empty)).TrimStart(" ,".ToCharArray());
}
catch (Exception ex)
{
Log.Error(ex, $"Issue with reading ModulesNames propery of {this.Name} instance.");
return string.Empty;
}
}

return string.Empty;
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/SIM.Instances/InstanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,23 @@ public Instance GetInstance([NotNull] string name)
Assert.ArgumentNotNull(name, nameof(name));
Log.Debug($"InstanceManager:GetInstance('{name}')");

if (Instances == null)
if (PartiallyCachedInstances == null)
{
Initialize();
}

if (Instances == null)
if (PartiallyCachedInstances == null)
{
return null;
}

return PartiallyCachedInstances?[name];
// This is needed to make sure that the newly installed Sitecore instance is added to the collection.
if (!PartiallyCachedInstances.Keys.Contains(name))
{
Initialize();
}

return PartiallyCachedInstances.Keys.Contains(name) ? PartiallyCachedInstances[name] : null;
}

public void Initialize([CanBeNull] string defaultRootFolder = null)
Expand Down
106 changes: 106 additions & 0 deletions src/SIM.Pipelines/Agent/AgentFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,112 @@ private string GetFilePath(string name)
#endregion
</script>";

public const string InstallPackageContentsForSitecore9AndLater = @"
<%@ Page Language=""C#"" AutoEventWireup=""true"" %>
<%@ Import Namespace=""System.IO"" %>
<%@ Import Namespace=""Sitecore.Configuration"" %>
<%@ Import Namespace=""Sitecore.Data.Engines"" %>
<%@ Import Namespace=""Sitecore.Diagnostics"" %>
<%@ Import Namespace=""Sitecore.Install"" %>
<%@ Import Namespace=""Sitecore.Install.Files"" %>
<%@ Import Namespace=""Sitecore.Install.Framework"" %>
<%@ Import Namespace=""Sitecore.Install.Items"" %>
<%@ Import Namespace=""Sitecore.Install.Utils"" %>
<%@ Import Namespace=""Sitecore.SecurityModel"" %>
<%@ Import Namespace=""Sitecore.Security.Accounts"" %>
<script runat=""server"">
#region Methods
protected override void OnInitComplete(EventArgs e)
{
this.Server.ScriptTimeout = 10*60*60; // 10 hours should be enough
var fileName = this.Request.QueryString[""fileName""];
if (string.IsNullOrEmpty(fileName))
{
this.Finish(""Error: fileName is empty"");
return;
}
var filePath = GetFilePath(fileName);
if (!File.Exists(filePath))
{
this.Finish(""Error: the '"" + filePath + ""' file doesn't exists"");
return;
}
try
{
Sitecore.Context.SetActiveSite(""shell"");
using (new UserSwitcher(""sitecore\\admin"", true))
{
using (new SyncOperationContext())
{
SimpleProcessingContext context = new SimpleProcessingContext();
DefaultItemInstallerEvents events = new DefaultItemInstallerEvents(new BehaviourOptions(InstallMode.Overwrite, MergeMode.Undefined));
context.AddAspect(events);
DefaultFileInstallerEvents events1 = new DefaultFileInstallerEvents(true);
context.AddAspect(events1);
this.UpdateStatus(@""Started: package is being installed"");
new Installer().InstallPackage(filePath, context);
new Installer().InstallSecurity(filePath, context);
this.Finish(@""Done: package installed"");
}
}
}
catch (Exception ex)
{
var inn = string.Empty;
if (ex.InnerException != null)
{
inn = ""\n\nInner Exception:\n"" + ex.InnerException;
}
this.Finish(@""Error: "" + ex + inn);
}
}
private void Finish(string message)
{
Log.Info(@""[SIM] " + InstallPackageFileName + @": "" + message, this);
this.UpdateStatus(message);
this.Response.Write(message);
}
private void UpdateStatus(string message)
{
var installedTemp = this.Server.MapPath(Path.Combine(Settings.TempFolderPath, ""sim.status""));
File.WriteAllText(installedTemp, message);
}
private string GetFilePath(string name)
{
Assert.ArgumentNotNullOrEmpty(name, ""name"");
var packageFolderPath = Sitecore.Configuration.Settings.PackagePath;
Assert.IsNotNullOrEmpty(packageFolderPath, ""packageFolderPath"");
// if path is virtual i.e. not C:\something then do a map path
if (packageFolderPath.Length < 2 || packageFolderPath[1] != ':')
{
packageFolderPath = packageFolderPath.TrimStart('/');
var prefix = ""~/"";
if (packageFolderPath.StartsWith(prefix))
{
packageFolderPath = packageFolderPath.Substring(prefix.Length);
}
packageFolderPath = Server.MapPath(prefix + packageFolderPath);
}
return Path.Combine(packageFolderPath, name);
}
#endregion
</script>";
public const string InstallPackageFileName = @"InstallPackage.aspx";

Expand Down
22 changes: 11 additions & 11 deletions src/SIM.Pipelines/Agent/AgentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void CopyAgentFiles([NotNull] Instance instance)
new
{
FileName = AgentFiles.InstallPackageFileName,
Contents = AgentFiles.InstallPackageContents
Contents = instance.Type == Instance.InstanceType.Sitecore9AndLater ? AgentFiles.InstallPackageContentsForSitecore9AndLater : AgentFiles.InstallPackageContents
},
new
{
Expand Down Expand Up @@ -101,7 +101,7 @@ public static void DeleteAgentFiles([NotNull] Instance instance)

#region Package installation

public static void InstallPackage([NotNull] Instance instance, [NotNull] Product module)
public static void InstallPackage([NotNull] Instance instance, [NotNull] Product module, [CanBeNull] string cookies = null, [CanBeNull] IDictionary<string, string> headers = null)
{
Assert.ArgumentNotNull(instance, nameof(instance));
Assert.ArgumentNotNull(module, nameof(module));
Expand All @@ -113,10 +113,10 @@ public static void InstallPackage([NotNull] Instance instance, [NotNull] Product

var statusUrl = GetUrl(instance, AgentFiles.StatusFileName);

ExecuteAgent(AgentFiles.StatusFileName, statusUrl, AgentFiles.InstallPackageFileName, installPackageUrl, PackageInstalling, PackageInstalled);
ExecuteAgent(AgentFiles.StatusFileName, statusUrl, AgentFiles.InstallPackageFileName, installPackageUrl, PackageInstalling, PackageInstalled, cookies: cookies, headers: headers);
}

public static void PerformPostStepAction([NotNull] Instance instance, [NotNull] Product module)
public static void PerformPostStepAction([NotNull] Instance instance, [NotNull] Product module, [CanBeNull] string cookies = null, [CanBeNull] IDictionary<string, string> headers = null)
{
XmlDocument xmlDocument = module.Manifest;
bool skipPostActions = module.SkipPostActions;
Expand Down Expand Up @@ -160,7 +160,7 @@ public static void PerformPostStepAction([NotNull] Instance instance, [NotNull]
{
var value = custom.Aggregate(string.Empty, (current, pair) => current + ($";{pair[0]}-{pair[1]}"));
var postInstallUrl = GetUrl(instance, AgentFiles.PostInstallActionsFileName, value.TrimStart(';'), "custom");
ExecuteAgent(AgentFiles.StatusFileName, statusUrl, AgentFiles.PostInstallActionsFileName, postInstallUrl, ActionsPerforming, ActionsPerformed);
ExecuteAgent(AgentFiles.StatusFileName, statusUrl, AgentFiles.PostInstallActionsFileName, postInstallUrl, ActionsPerforming, ActionsPerformed, cookies: cookies, headers: headers);
return;
}
}
Expand All @@ -174,7 +174,7 @@ public static void PerformPostStepAction([NotNull] Instance instance, [NotNull]
var fileName = Path.GetFileName(module.PackagePath);
Assert.IsNotNull(fileName, nameof(fileName));
var url = GetUrl(instance, AgentFiles.PostInstallActionsFileName, fileName);
ExecuteAgent(AgentFiles.StatusFileName, statusUrl, AgentFiles.PostInstallActionsFileName, url, ActionsPerforming, ActionsPerformed);
ExecuteAgent(AgentFiles.StatusFileName, statusUrl, AgentFiles.PostInstallActionsFileName, url, ActionsPerforming, ActionsPerformed, cookies: cookies, headers: headers);
}

#endregion
Expand All @@ -190,7 +190,7 @@ public static string GetUrl(Instance instance, string pageName, string value = n
}

[NotNull]
public static string Request([NotNull] string url, [NotNull] string pageName)
public static string Request([NotNull] string url, [NotNull] string pageName, [CanBeNull] string cookies = null, [CanBeNull] IDictionary<string, string> headers = null)
{
Assert.ArgumentNotNull(url, nameof(url));
Assert.ArgumentNotNullOrEmpty(pageName, nameof(pageName));
Expand All @@ -200,7 +200,7 @@ public static string Request([NotNull] string url, [NotNull] string pageName)
try
{
Log.Info($"Requesting URL {url}");
result = WebRequestHelper.DownloadString(url).Trim();
result = WebRequestHelper.DownloadString(url, cookies: cookies, headers: headers).Trim();
if (result.ToLower().StartsWith("error:"))
{
throw new InvalidOperationException(errorPrefix + result);
Expand All @@ -222,18 +222,18 @@ public static string Request([NotNull] string url, [NotNull] string pageName)

#region Private methods

private static void ExecuteAgent(string statusFileName, string statusUrl, string agentName, string operationUrl, string operationStartedStatus, string operationCompletedStatus)
private static void ExecuteAgent(string statusFileName, string statusUrl, string agentName, string operationUrl, string operationStartedStatus, string operationCompletedStatus, string cookies = null, IDictionary<string, string> headers = null)
{
// Call agent main operation
var status = Request(operationUrl, agentName);
var status = Request(operationUrl, agentName, cookies: cookies, headers: headers);

// If the package installation process takes more than http timeout, retrive status
if (status != operationCompletedStatus)
{
// Retrive status while the previous request timed out, status is in progress or package is already being installed
while (status == TimedOut || status == InProgress || status == operationStartedStatus)
{
status = Request(statusUrl, statusFileName);
status = Request(statusUrl, statusFileName, cookies: cookies, headers: headers);
Thread.Sleep(2000);
}

Expand Down
7 changes: 4 additions & 3 deletions src/SIM.Pipelines/Install/Modules/InstallPackages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ namespace SIM.Pipelines.Install.Modules
using SIM.Products;
using Sitecore.Diagnostics.Base;
using JetBrains.Annotations;
using SIM.Pipelines.InstallModules;

#region

#endregion

[UsedImplicitly]
public class InstallPackages : InstallProcessor
public class InstallPackages : InstallModulesProcessor
{
#region Fields

Expand All @@ -22,7 +23,7 @@ public class InstallPackages : InstallProcessor

#region Methods

protected override void Process([NotNull] InstallArgs args)
protected override void Process([NotNull] InstallModulesArgs args)
{
Assert.ArgumentNotNull(args, nameof(args));

Expand All @@ -35,7 +36,7 @@ protected override void Process([NotNull] InstallArgs args)
continue;
}

AgentHelper.InstallPackage(args.Instance, module);
AgentHelper.InstallPackage(args.Instance, module, args.Cookies, args.Headers);

_Done.Add(module);
}
Expand Down
Loading

0 comments on commit 0dcd9f2

Please sign in to comment.