-
Notifications
You must be signed in to change notification settings - Fork 76
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
base: develop
Are you sure you want to change the base?
Changes from 33 commits
3012eed
b8aef0a
6372657
ff9c599
fd6a992
58dbeea
d2c681e
df2f4f4
1168c05
06d6b23
fa65944
b19b3b8
05fa0e0
bf278df
aec2399
a81936f
644a047
83f2ced
c928506
27c9b22
3de75b3
de03f6e
be23467
62849d9
1539d02
2ebbdfd
c3294ac
b0e6c91
4cd73e2
b2f3f4c
0ec9fbd
0e1c0ea
6a69d06
17ca458
1b80d85
3310e93
311b466
bef9012
a4d3116
e2721e5
6b69cbd
ba829ca
5b3310a
491247d
e993155
a33dbed
e446ee0
15e3857
4cdb9f1
bf0f52a
e223036
d771238
a9f7d78
65c1294
1bc8332
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -494,6 +494,67 @@ public InstanceType Type | |
} | ||
} | ||
|
||
/// <summary> | ||
/// A collection of server roles this instance is defined as | ||
/// </summary> | ||
public ICollection<InstanceRole> Roles | ||
{ | ||
get | ||
{ | ||
ICollection<InstanceRole> InstanceRoles = new List<InstanceRole>(); | ||
|
||
//Find role by name | ||
string instanceName = this.Name; | ||
if (instanceName.Contains(".identityserver")) | ||
{ | ||
InstanceRoles.Add(InstanceRole.IdentityServer); | ||
return InstanceRoles; | ||
} | ||
if (instanceName.Contains(".xconnect")) | ||
{ | ||
InstanceRoles.Add(InstanceRole.XConnect); | ||
return InstanceRoles; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears that resolving the instance name is not relay reliable approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed now here e993155 Except xconnect still uses the site name. I agree it is not a good solution, however the xconnect web.config file doesn't really have a unique identifier in the xml like SPS and IdentityServer do, so I don't see an elegant way to do this. Do you have any suggestions for an attribute from the web.config that I should use? |
||
|
||
//Find role by 'role:define' key in web.config | ||
string roleDefine = this.GetWebConfig().GetElementAttributeValue("/configuration/appSettings/add[@key='role:define']", "value").ToLower(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code throws the exception if one clicks on the instance deployed to the container. In case we either cannot resolve the role, or the exception happens, we need to use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed now here 4cdb9f1 |
||
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; | ||
} | ||
if (roleDefine.Contains("standalone")) | ||
{ | ||
InstanceRoles.Add(InstanceRole.Standalone); | ||
} | ||
if (roleDefine.Contains("contentmanagement")) | ||
{ | ||
InstanceRoles.Add(InstanceRole.ContentManagement); | ||
} | ||
if (roleDefine.Contains("contentdelivery")) | ||
{ | ||
InstanceRoles.Add(InstanceRole.ContentDelivery); | ||
} | ||
if (roleDefine.Contains("reporting")) | ||
{ | ||
InstanceRoles.Add(InstanceRole.Reporting); | ||
} | ||
if (roleDefine.Contains("processing")) | ||
{ | ||
InstanceRoles.Add(InstanceRole.Processing); | ||
} | ||
if (roleDefine.Contains("indexing")) | ||
{ | ||
InstanceRoles.Add(InstanceRole.Indexing); | ||
} | ||
|
||
return InstanceRoles; | ||
} | ||
} | ||
public bool IsContentManagementInstance => this.Roles.Contains(InstanceRole.Standalone) || | ||
this.Roles.Contains(InstanceRole.ContentManagement) || | ||
this.Roles.Contains(InstanceRole.Unknown); | ||
|
||
public enum InstanceType | ||
{ | ||
Sitecore8AndEarlier, | ||
|
@@ -503,6 +564,19 @@ public enum InstanceType | |
Unknown | ||
} | ||
|
||
public enum InstanceRole | ||
{ | ||
Standalone, | ||
ContentManagement, | ||
ContentDelivery, | ||
Reporting, | ||
Processing, | ||
Indexing, | ||
XConnect, | ||
IdentityServer, | ||
Unknown | ||
} | ||
AndreyFilchenkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#endregion | ||
|
||
#region Public methods | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using MongoDB.Driver.Linq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
AndreyFilchenkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
namespace SIM.Pipelines.InstallPublishingService | ||
{ | ||
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 void SetConnectionString(string connectionStringName, string connectrionStringValue) | ||
AndreyFilchenkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
ExecuteCommand(SET_CONNECTION_STRING, connectionStringName, connectrionStringValue); | ||
} | ||
|
||
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(string.Format(".\\Sitecore.Framework.Publishing.Host.exe " + commandArgs, args)).Invoke(); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SIM.Pipelines.InstallPublishingService | ||
{ | ||
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,31 @@ | ||
using SIM.Pipelines.Processors; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.SqlClient; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SIM.Pipelines.InstallPublishingService | ||
{ | ||
public class InstallSPSProcessorArgs : ProcessorArgs | ||
{ | ||
#region Properties | ||
//Populated from InstallPublishingServiceWizardArgs | ||
public string InstanceName { 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; } | ||
public bool OverwriteExisting { get; set; } | ||
|
||
#endregion | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using JetBrains.Annotations; | ||
using Microsoft.Web.Administration; | ||
using SIM.Adapters.WebServer; | ||
using SIM.Pipelines.UninstallPublishingService; | ||
using Sitecore.Diagnostics.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SIM.Pipelines.InstallPublishingService | ||
{ | ||
public class RemoveExistingSPSProcessor : SPSProcessor<InstallSPSProcessorArgs> | ||
{ | ||
protected override void ProcessCore(InstallSPSProcessorArgs args) | ||
{ | ||
if (!args.OverwriteExisting) | ||
{ | ||
return; | ||
} | ||
|
||
UninstallSPSProcessorArgs uninstallArgs = new UninstallSPSProcessorArgs() | ||
{ | ||
SPSSiteName = args.SPSSiteName, | ||
SPSAppPoolName = args.SPSAppPoolName, | ||
SPSWebroot = args.SPSWebroot, | ||
SkipSPSSite = false, | ||
SkipSPSAppPool = false, | ||
SkipSPSWebroot = false | ||
}; | ||
|
||
new RemoveIISSiteProcessor().DoProcess(uninstallArgs); | ||
new RemoveAppPoolProcessor().DoProcess(uninstallArgs); | ||
new RemoveWebrootFolderProcessor().DoProcess(uninstallArgs); | ||
} | ||
AndreyFilchenkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SIM.Pipelines.InstallPublishingService | ||
{ | ||
public class ResetDatabaseSchemaProcessor : SPSProcessor<InstallSPSProcessorArgs> | ||
{ | ||
//Resetting the schema is done to clear any potentially existing Publishing tables | ||
protected override void ProcessCore(InstallSPSProcessorArgs args) | ||
{ | ||
Directory.SetCurrentDirectory(args.SPSWebroot); | ||
Commands.SchemaReset(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using JetBrains.Annotations; | ||
using SIM.Pipelines.Processors; | ||
using Sitecore.Diagnostics.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Deployment.Internal; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SIM.Pipelines.InstallPublishingService | ||
{ | ||
public abstract class SPSProcessor<T> : Processor where T : ProcessorArgs | ||
AndreyFilchenkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
protected static bool AbortPipeline = false; | ||
|
||
protected override void Process([NotNull] ProcessorArgs args) | ||
{ | ||
T processorArgs = args as T; | ||
|
||
if (AbortPipeline) | ||
{ | ||
Log.Warn($"The {this.GetType().Name} processor was skipped."); | ||
this.Skip(); | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
this.ProcessCore(processorArgs); | ||
} | ||
catch (Exception ex) | ||
{ | ||
AbortPipeline = true; | ||
Log.Error($"Publishing Service Pipeline was aborted. The remaining steps were skipped."); | ||
throw ex; | ||
} | ||
} | ||
|
||
protected abstract void ProcessCore([NotNull] T args); | ||
|
||
//Kind of a hack so I can resure some of the uninstall sps processors in the RemoveExistingSPSProcessor class | ||
internal void DoProcess([NotNull] T args) | ||
{ | ||
this.Process(args); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.SqlClient; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SIM.Pipelines.InstallPublishingService | ||
{ | ||
public class SetActualConnectionStringsProcessor : SPSProcessor<InstallSPSProcessorArgs> | ||
{ | ||
protected override void ProcessCore(InstallSPSProcessorArgs args) | ||
{ | ||
Directory.SetCurrentDirectory(args.SPSWebroot); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 'Directory.GetCurrentDirectory()' API is widely used in the SIM. So, modification of the CurrentDirectory, may break the existing code. Please avoid changing the current application directory. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed here 15e3857 |
||
foreach (KeyValuePair<string, SqlConnectionStringBuilder> connString in args.SPSConnectionStrings) | ||
{ | ||
Commands.SetConnectionString(connString.Key, connString.Value.ToString()); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.SqlClient; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SIM.Pipelines.InstallPublishingService | ||
{ | ||
public class SetAdminConnectionStringsProcessor : SPSProcessor<InstallSPSProcessorArgs> | ||
{ | ||
//Using the admin credentials for connection strings is necessary to upgrade and reset the database schema | ||
protected override void ProcessCore(InstallSPSProcessorArgs args) | ||
{ | ||
Directory.SetCurrentDirectory(args.SPSWebroot); | ||
foreach (KeyValuePair<string, SqlConnectionStringBuilder> connString in args.SPSConnectionStrings) | ||
{ | ||
string AdminConnString = new SqlConnectionStringBuilder(connString.Value.ToString()) | ||
{ | ||
UserID = args.SqlAdminUsername, | ||
Password = args.SqlAdminPassword | ||
}.ToString(); | ||
|
||
Commands.SetConnectionString(connString.Key, AdminConnString); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using JetBrains.Annotations; | ||
using SIM.Pipelines.Processors; | ||
using Sitecore.Diagnostics.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SIM.Pipelines.InstallPublishingService | ||
{ | ||
public class UnzipSPSPackageProcessor : SPSProcessor<InstallSPSProcessorArgs> | ||
{ | ||
protected override void ProcessCore(InstallSPSProcessorArgs args) | ||
{ | ||
ZipFile.ExtractToDirectory(args.SPSPackagePath, args.SPSWebroot); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SIM.Pipelines.InstallPublishingService | ||
{ | ||
public class UpgradeDatabaseSchemaProcessor : SPSProcessor<InstallSPSProcessorArgs> | ||
{ | ||
protected override void ProcessCore(InstallSPSProcessorArgs args) | ||
{ | ||
Directory.SetCurrentDirectory(args.SPSWebroot); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not change the Application Current Directory. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed here 15e3857 |
||
Commands.SchemaUpgrade(); | ||
} | ||
} | ||
} |
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.
The
getter
will allocate in the RAM a new list of the InstanceRoles every time when we access the roles property.It may cause performance issues.
Please consider caches the 'InstanceRoles' list once it is fulfilled.
For example:
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.
Fixed now here e993155