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

tja-develop branch PR (When a Sitecore instance is selected you can install/uninstall SPS) #489

Open
wants to merge 55 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
3012eed
created Install PS button, enabled it as long as an instance is selec…
sc-TylerJass Nov 13, 2020
b8aef0a
Added first Wizard step page (not completed, not visible)
sc-TylerJass Nov 13, 2020
6372657
Completed wizard pipeline (bare minumum required, second page to come…
sc-TylerJass Nov 17, 2020
ff9c599
Added a new first wizard page to select PS version and provide links …
sc-TylerJass Nov 18, 2020
fd6a992
Pipeline processors are working, installation seems good. Project ef…
sc-TylerJass Nov 20, 2020
58dbeea
Added Install Publishing Service button to right click context menu
sc-TylerJass Nov 20, 2020
d2c681e
Fixed bug where moving back and forward in wizard incorrectly adds mo…
sc-TylerJass Nov 20, 2020
df2f4f4
Added another processor to check the status endpoint after installati…
sc-TylerJass Nov 20, 2020
1168c05
Added completion instructions for installing the PS module afterward
sc-TylerJass Nov 20, 2020
06d6b23
Fixed a typo and added an overwrite option (work in progress)
sc-TylerJass Nov 20, 2020
fa65944
Finished overwrite functionality
sc-TylerJass Nov 21, 2020
b19b3b8
Finished overwrite functionality
sc-TylerJass Nov 21, 2020
05fa0e0
Created uninstall publishing service button
sc-TylerJass Nov 21, 2020
bf278df
Renamed class names and members to use 'SPS' instead of 'PublishingSe…
sc-TylerJass Nov 21, 2020
aec2399
Fixed merge conflicts from tja-develop-sps-install branch
sc-TylerJass Nov 21, 2020
a81936f
First wizard page created for sps uninstall (work in progress)
sc-TylerJass Nov 21, 2020
644a047
Added sps uninstall to right-click context menu
sc-TylerJass Nov 21, 2020
83f2ced
Cleaned up some code, attempted to add port, but now bad gateway issu…
sc-TylerJass Nov 21, 2020
c928506
Resolved bad gateway issue (not caused by port, it was missing connec…
sc-TylerJass Nov 21, 2020
27c9b22
resolved merge
sc-TylerJass Nov 21, 2020
3de75b3
Fixed class name
sc-TylerJass Nov 21, 2020
de03f6e
joining branches
sc-TylerJass Nov 21, 2020
be23467
Uninstall sps wizard essentially complete (want to pull site name fro…
sc-TylerJass Nov 21, 2020
62849d9
Finished uninstall pipeline
sc-TylerJass Nov 25, 2020
1539d02
Pulled develop branch, resolving final merge conflicts before pull re…
sc-TylerJass Dec 3, 2020
2ebbdfd
Pulled and merged develop into this 'tja-develop' branch to resolve m…
sc-TylerJass Jan 25, 2021
c3294ac
Removing exception stacktrace from WindowHelper popup message (previo…
sc-TylerJass Jan 25, 2021
b0e6c91
Extended Instance class to return a collection of Roles, and bool pro…
sc-TylerJass Feb 6, 2021
4cd73e2
Install group of Edit tab is no longer visible for all instances, mov…
sc-TylerJass Feb 6, 2021
b2f3f4c
Preventing potential NullRefenceExceptions if a package is not selected
sc-TylerJass Feb 6, 2021
0ec9fbd
Removed '#' from wizard pipeline step names
sc-TylerJass Feb 6, 2021
0e1c0ea
SPS Installer now looks for packages in the SIM local repo and any su…
sc-TylerJass Feb 6, 2021
6a69d06
Only display Sitecore Publishing Service packages that are compatible…
sc-TylerJass Feb 6, 2021
17ca458
Fixed visibility for install/uninstall button given the selected inst…
sc-TylerJass Mar 7, 2021
1b80d85
Fixed some potential nullreferenceexceptions, and cleaned up unused u…
sc-TylerJass Mar 7, 2021
3310e93
Removed code that was intended only for debugging
sc-TylerJass Mar 7, 2021
311b466
Removed install/uninstall buttons from context menu
sc-TylerJass Mar 7, 2021
bef9012
Made install/uninstall wizard arg titles shorter
sc-TylerJass Mar 7, 2021
a4d3116
Initial sps name generated from cm instance name
sc-TylerJass Mar 7, 2021
e2721e5
Removed empty region
sc-TylerJass Mar 7, 2021
6b69cbd
Added special case for SPS 312 package name, wrapped IsCompatible bod…
sc-TylerJass Mar 20, 2021
ba829ca
Filtered connectionstring selection options and fixed typo
sc-TylerJass Mar 20, 2021
5b3310a
Removed overwrite functionality
sc-TylerJass Mar 20, 2021
491247d
Removed overwrite functionality (last commit, committed too early, no…
sc-TylerJass Mar 20, 2021
e993155
Updated instance roles logic
sc-TylerJass Mar 20, 2021
a33dbed
Changed auto generated SPS name
sc-TylerJass Mar 20, 2021
e446ee0
updated abstract SPSProcessor class
sc-TylerJass Mar 20, 2021
15e3857
Changed directory in the powershell context instead of changing the a…
sc-TylerJass Mar 20, 2021
4cdb9f1
added try-catch around instance role resolving logic
sc-TylerJass Mar 20, 2021
bf0f52a
Moved old compatibility to globalsettings config file
sc-TylerJass Mar 28, 2021
e223036
Add SPS to environment group when installed, and remove when uninstalled
sc-TylerJass Mar 28, 2021
d771238
Fixed bug where SPS instance only joined environment group if the gro…
sc-TylerJass Mar 28, 2021
a9f7d78
Instane list refreshes after sps install/uninstall
sc-TylerJass Mar 28, 2021
65c1294
Reorganized SPS Pipeline processors files
sc-TylerJass Mar 28, 2021
1bc8332
Moved all compatibility to globalsettings.config, added compatibility…
sc-TylerJass Mar 29, 2021
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
6 changes: 6 additions & 0 deletions src/SIM.Base/XmlDocumentEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ public void SetElementValue(string xpath, string value)
element.InnerText = value;
}

public bool ElementAttributeContains(string xpath, string attributeName, string substring)
{
string value = this.GetElementAttributeValue(xpath, attributeName).ToLower();
return !string.IsNullOrEmpty(value) && value.Contains(substring.ToLower());
}

#endregion

#region Private methods
Expand Down
90 changes: 89 additions & 1 deletion src/SIM.Instances/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class Instance : Website, IXmlSerializable

private Product _Product;

private ICollection<InstanceRole> _instanceRoles;

#endregion

#region Constructors
Expand Down Expand Up @@ -167,7 +169,6 @@ public virtual bool IsSitecoreEnvironmentMember
}
}
}

return false;
}
catch (Exception ex)
Expand Down Expand Up @@ -494,6 +495,78 @@ public InstanceType Type
}
}

/// <summary>
/// A collection of server roles this instance is defined as
/// </summary>
public ICollection<InstanceRole> Roles
{
get
{
if (_instanceRoles != null)
{
return _instanceRoles;
}

_instanceRoles = new List<InstanceRole>();

try
{
//Check if sitecore identity server
if (this.GetWebConfig().ElementAttributeContains("/configuration/system.webServer/aspNetCore", "arguments",
"sitecore.identityServer.host"))
{
_instanceRoles.Add(InstanceRole.IdentityServer);
return _instanceRoles;
}

//Check if xconnect
string instanceName = this.Name.ToLower();
if (instanceName.Contains(".xconnect"))
{
_instanceRoles.Add(InstanceRole.XConnect);
return _instanceRoles;
}

//Check if sitecore publishing service
if (this.GetWebConfig().ElementAttributeContains("/configuration/system.webServer/aspNetCore", "processPath",
"sitecore.framework.publishing.host"))
{
_instanceRoles.Add(InstanceRole.PublishingService);
return _instanceRoles;
}

//Find role by 'role:define' key in web.config
string roleDefine = this.GetWebConfig()
.GetElementAttributeValue("/configuration/appSettings/add[@key='role:define']", "value").ToLower();
if (string.IsNullOrEmpty(roleDefine))
{
_instanceRoles.Add((InstanceRole
.Unknown)); //If 'role:define' is not present, this is likely a pre-version 9 solution, and we don't know the role
return _instanceRoles;
}

//Add any and all roles that are found in the role:define key
foreach (InstanceRole role in Enum.GetValues(typeof(InstanceRole)).Cast<InstanceRole>())
{
if (roleDefine.Contains(role.ToString().ToLower()))
{
_instanceRoles.Add(role);
}
}
}
catch (Exception ex)
{
_instanceRoles.Add(InstanceRole.Unknown);
Log.Error(ex, "Instance role could not be resolved and was set to 'Unknown'");
}
return _instanceRoles;
}
}

public bool IsContentManagementInstance => this.Roles.Contains(InstanceRole.Standalone) ||
this.Roles.Contains(InstanceRole.ContentManagement) ||
this.Roles.Contains(InstanceRole.Unknown);

public enum InstanceType
{
Sitecore8AndEarlier,
Expand All @@ -503,6 +576,21 @@ public enum InstanceType
Unknown
}

public enum InstanceRole
{
Standalone,
ContentManagement,
ContentDelivery,
Reporting,
Processing,
Indexing,
DedicatedDispatch,
XConnect,
IdentityServer,
PublishingService,
Unknown
}
AndreyFilchenkov marked this conversation as resolved.
Show resolved Hide resolved

#endregion

#region Public methods
Expand Down
16 changes: 1 addition & 15 deletions src/SIM.Pipelines/Install/Containers/GenerateEnvironmentData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override void Process([NotNull] ProcessorArgs arguments)
string environmentName = args.EnvModel.ProjectName;
Assert.ArgumentNotNullOrEmpty(environmentName, "projectName");

this.AddEnvironment(this.CreateEnvironment(environmentName, destinationFolder));
SitecoreEnvironmentHelper.AddSitecoreEnvironment(this.CreateEnvironment(environmentName, destinationFolder));
}

private SitecoreEnvironment CreateEnvironment(string environmentName, string destinationFolder)
Expand Down Expand Up @@ -110,19 +110,5 @@ private string GetMemberType(string serviceName)

return null;
}

private void AddEnvironment(SitecoreEnvironment environment)
{
foreach (SitecoreEnvironment se in SitecoreEnvironmentHelper.SitecoreEnvironments)
{
if (se.Name == environment.Name)
{
return;
}
}

SitecoreEnvironmentHelper.SitecoreEnvironments.Add(environment);
SitecoreEnvironmentHelper.SaveSitecoreEnvironmentData(SitecoreEnvironmentHelper.SitecoreEnvironments);
}
}
}
17 changes: 1 addition & 16 deletions src/SIM.Pipelines/Install/GenerateSitecoreEnvironmentData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected override void Process([NotNull] ProcessorArgs args)
InstallParam sqlDbPrefixParam = arguments.Tasker.GlobalParams.FirstOrDefault(p => p.Name == SqlDbPrefix);
if (sqlDbPrefixParam != null && !string.IsNullOrEmpty(sqlDbPrefixParam.Value))
{
this.AddSitecoreEnvironment(this.CreateSitecoreEnvironment(arguments.Tasker, sqlDbPrefixParam.Value,arguments.UnInstallDataPath));
SitecoreEnvironmentHelper.AddSitecoreEnvironment(this.CreateSitecoreEnvironment(arguments.Tasker, sqlDbPrefixParam.Value,arguments.UnInstallDataPath));
}
}

Expand All @@ -52,20 +52,5 @@ private SitecoreEnvironment CreateSitecoreEnvironment(Tasker tasker, string sqlD

return sitecoreEnvironment;
}

private void AddSitecoreEnvironment(SitecoreEnvironment sitecoreEnvironment)
{
// Do not add new Sitecore environment if its name already exists in the Environments.json file
foreach (SitecoreEnvironment se in SitecoreEnvironmentHelper.SitecoreEnvironments)
{
if (se.Name == sitecoreEnvironment.Name)
{
return;
}
}

SitecoreEnvironmentHelper.SitecoreEnvironments.Add(sitecoreEnvironment);
SitecoreEnvironmentHelper.SaveSitecoreEnvironmentData(SitecoreEnvironmentHelper.SitecoreEnvironments);
}
}
}
30 changes: 29 additions & 1 deletion src/SIM.Pipelines/PipelinesConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,34 @@ public static class PipelinesConfig
<processor type=""SIM.Pipelines.Import.ImportHostNames, SIM.Pipelines"" title=""Update hosts file"" />
</processor>
</import>
<installpublishingservice title=""Installing Publishing Service"">
<processor type=""SIM.Pipelines.PublishingService.Install.AddToEnvironmentProcessor, SIM.Pipelines""
title=""Adding SPS instance to CM environment package"" />
<processor type=""SIM.Pipelines.PublishingService.Install.PrepareInstallationProcessor, SIM.Pipelines""
title=""Unzipping package"" />
<processor type=""SIM.Pipelines.PublishingService.Install.SetAdminConnectionStringsProcessor, SIM.Pipelines""
title=""Setting admin connection strings"" />
<processor type=""SIM.Pipelines.PublishingService.Install.UpgradeDatabaseSchemaProcessor, SIM.Pipelines""
title=""Upgrading database schema"" />
<processor type=""SIM.Pipelines.PublishingService.Install.ResetDatabaseSchemaProcessor, SIM.Pipelines""
title=""Resetting database schema"" />
<processor type=""SIM.Pipelines.PublishingService.Install.SetActualConnectionStringsProcessor, SIM.Pipelines""
title=""Setting actual connection strings"" />
<processor type=""SIM.Pipelines.PublishingService.Install.CreateIISiteProcessor, SIM.Pipelines""
title=""Creating IIS site"" />
<processor type=""SIM.Pipelines.PublishingService.Install.VerifyInstallationProcessor, SIM.Pipelines""
title=""Checking status endpoint for errors"" />
</installpublishingservice>
<uninstallpublishingservice title=""Removing Publishing Service"">
<processor type=""SIM.Pipelines.PublishingService.Uninstall.RemoveFromEnvironmentProcessor, SIM.Pipelines""
title=""Removing SPS instance from CM environment"" />
<processor type=""SIM.Pipelines.PublishingService.Uninstall.RemoveIISSiteProcessor, SIM.Pipelines""
title=""Removing iis site"" />
<processor type=""SIM.Pipelines.PublishingService.Uninstall.RemoveAppPoolProcessor, SIM.Pipelines""
title=""Removing application pool"" />
<processor type=""SIM.Pipelines.PublishingService.Uninstall.RemoveWebrootFolderProcessor, SIM.Pipelines""
title=""Removing webroot folder"" />
</uninstallpublishingservice>
</pipelines>";
}
}
}
43 changes: 43 additions & 0 deletions src/SIM.Pipelines/PublishingService/Commands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Management.Automation;

namespace SIM.Pipelines.PublishingService
{
public static class Commands
{
private const string SET_CONNECTION_STRING = "configuration setconnectionstring {0} \"{1}\"";
private const string SCHEMA_UPGRADE = "schema upgrade --force";
private const string SCHEMA_RESET = "schema reset --force";
private const string IIS_INSTALL = "iis install --sitename \"{0}\" --apppool \"{1}\" --port \"{2}\" --hosts --force";

public static string CommandRoot { get; set; }

public static void SetConnectionString(string connectionStringName, string connectionStringValue)
{
ExecuteCommand(SET_CONNECTION_STRING, connectionStringName, connectionStringValue);
}

public static void SchemaUpgrade()
{
ExecuteCommand(SCHEMA_UPGRADE);
}

public static void SchemaReset()
{
ExecuteCommand(SCHEMA_RESET);
}

public static void IISInstall(string siteName, string appPoolName, int port)
{
ExecuteCommand(IIS_INSTALL, siteName, appPoolName, port);
}

private static void ExecuteCommand(string commandArgs, params object[] args)
{
using (PowerShell PS = PowerShell.Create())
{
PS.AddScript($"Set-Location {CommandRoot}").Invoke();
PS.AddScript(string.Format(".\\Sitecore.Framework.Publishing.Host.exe " + commandArgs, args)).Invoke();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using SIM.SitecoreEnvironments;
using Sitecore.Diagnostics.Logging;

namespace SIM.Pipelines.PublishingService.Install
{
public class AddToEnvironmentProcessor : SPSProcessor<InstallSPSProcessorArgs>
{
protected override void ProcessCore(InstallSPSProcessorArgs args)
{
try
{
SitecoreEnvironment se = SitecoreEnvironmentHelper.GetExistingOrNewSitecoreEnvironment(args.CMInstance.Name);
if (se.Members == null)
{
se.Members = new List<SitecoreEnvironmentMember>();
}

se.Members.Add(new SitecoreEnvironmentMember(args.SPSSiteName, SitecoreEnvironmentMember.Types.Site.ToString()));
SitecoreEnvironmentHelper.AddOrUpdateSitecoreEnvironment(se);
}
catch (Exception ex)
{
Log.Warn(ex, $"Exception thrown while adding new SPS instance to CM environment:\n{ex}");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SIM.Pipelines.PublishingService.Install
{
public class CreateIISiteProcessor : SPSProcessor<InstallSPSProcessorArgs>
{
protected override void ProcessCore(InstallSPSProcessorArgs args)
{
Commands.IISInstall(args.SPSSiteName, args.SPSSiteName, args.SPSPort);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;
using System.Data.SqlClient;
using SIM.Instances;
using SIM.Pipelines.Processors;

namespace SIM.Pipelines.PublishingService.Install
{
public class InstallSPSProcessorArgs : ProcessorArgs
{
#region Properties
public Instance CMInstance { get; set; }
public string InstanceFolder { get; set; }
public string SPSInstanceFolder { get; set; }
public string SqlAdminUsername { get; set; }
public string SqlAdminPassword { get; set; }
public string SPSPackagePath { get; set; }
public string SPSSiteName { get; set; }
public string SPSAppPoolName { get; set; }
public string SPSWebroot { get; set; }
public int SPSPort { get; set; }
public Dictionary<string, SqlConnectionStringBuilder> SPSConnectionStrings { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.IO.Compression;

namespace SIM.Pipelines.PublishingService.Install
{
public class PrepareInstallationProcessor : SPSProcessor<InstallSPSProcessorArgs>
{
protected override void ProcessCore(InstallSPSProcessorArgs args)
{
ZipFile.ExtractToDirectory(args.SPSPackagePath, args.SPSWebroot);
Commands.CommandRoot = args.SPSWebroot;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace SIM.Pipelines.PublishingService.Install
{
public class ResetDatabaseSchemaProcessor : SPSProcessor<InstallSPSProcessorArgs>
{
//Resetting the schema is done to clear any potentially existing Publishing tables
protected override void ProcessCore(InstallSPSProcessorArgs args)
{
Commands.SchemaReset();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using System.Data.SqlClient;

namespace SIM.Pipelines.PublishingService.Install
{
public class SetActualConnectionStringsProcessor : SPSProcessor<InstallSPSProcessorArgs>
{
protected override void ProcessCore(InstallSPSProcessorArgs args)
{
foreach (KeyValuePair<string, SqlConnectionStringBuilder> connString in args.SPSConnectionStrings)
{
Commands.SetConnectionString(connString.Key, connString.Value.ToString());
}
}
}
}
Loading