Skip to content

Commit

Permalink
migrate "Disable enabled Web farm servers" (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
kentico-ericd committed Aug 9, 2023
1 parent 82672df commit b75422f
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 0 deletions.
9 changes: 9 additions & 0 deletions KenticoInspector.Actions/KenticoInspector.Actions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
<None Update="SiteStatusSummary\Scripts\GetSiteSummary.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="WebFarmServerSummary\Metadata\en-US.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="WebFarmServerSummary\Scripts\DisableServer.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="WebFarmServerSummary\Scripts\GetWebFarmServerSummary.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
78 changes: 78 additions & 0 deletions KenticoInspector.Actions/WebFarmServerSummary/Action.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using KenticoInspector.Actions.WebFarmServerSummary.Models;
using KenticoInspector.Core;
using KenticoInspector.Core.Constants;
using KenticoInspector.Core.Helpers;
using KenticoInspector.Core.Models;
using KenticoInspector.Core.Services.Interfaces;

using System;
using System.Collections.Generic;

namespace KenticoInspector.Actions.WebFarmServerSummary
{
public class Action : AbstractAction<Terms,Options>
{
private readonly IDatabaseService databaseService;

public override IList<Version> CompatibleVersions => VersionHelper.GetVersionList("12", "13");

public override IList<string> Tags => new List<string> {
ActionTags.Configuration
};

public Action(IDatabaseService databaseService, IModuleMetadataService moduleMetadataService) : base(moduleMetadataService)
{
this.databaseService = databaseService;
}

public override ActionResults Execute(Options options)
{
// No server provided, list servers
if (options.ServerID == 0)
{
return GetListingResult();
}

if (options.ServerID < 0)
{
return GetInvalidOptionsResult();
}

// Disable provided server
databaseService.ExecuteSqlFromFileGeneric(Scripts.DisableServer, new { ServerID = options.ServerID });
var result = GetListingResult();
result.Summary = Metadata.Terms.ServerDisabled.With(new
{
serverId = options.ServerID
});

return result;
}

public override ActionResults GetInvalidOptionsResult()
{
return new ActionResults {
Status = ResultsStatus.Error,
Summary = Metadata.Terms.InvalidOptions
};
}

private ActionResults GetListingResult()
{
var servers = databaseService.ExecuteSqlFromFile<WebFarmServer>(Scripts.GetWebFarmServerSummary);
var data = new TableResult<WebFarmServer>()
{
Name = Metadata.Terms.TableTitle,
Rows = servers
};

return new ActionResults
{
Type = ResultsType.Table,
Status = ResultsStatus.Information,
Summary = Metadata.Terms.ListSummary,
Data = data
};
}
}
}
12 changes: 12 additions & 0 deletions KenticoInspector.Actions/WebFarmServerSummary/Metadata/en-US.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
details:
name: Web Farm Server Summary
shortDescription: Review and disable web farm servers.
longDescription: |
Displays all web farm servers, and allows you to disable them.
Run the action without options to view the web farm server. To disable a server, re-run the action with the server ID below. Servers disabled by this action have the *.disabled* prefix applied to their name, so you can identify which servers were disabled by this action and which were disabled manually.
terms:
tableTitle: Web farm servers
invalidOptions: The server ID must be an integer greater than zero.
listSummary: Set the server ID you wish to disable and re-run
serverDisabled: Server ID <serverId> was disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace KenticoInspector.Actions.WebFarmServerSummary.Models
{
public class Options
{
public int ServerID { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace KenticoInspector.Actions.WebFarmServerSummary.Models
{
public class WebFarmServer
{
public int ID { get; internal set; }

public string Name { get; internal set; }

public string Enabled { get; internal set; }
}
}
15 changes: 15 additions & 0 deletions KenticoInspector.Actions/WebFarmServerSummary/Models/Terms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using KenticoInspector.Core.Models;

namespace KenticoInspector.Actions.WebFarmServerSummary.Models
{
public class Terms
{
public Term InvalidOptions { get; internal set; }

public Term TableTitle { get; internal set; }

public Term ListSummary { get; internal set; }

public Term ServerDisabled { get; internal set; }
}
}
11 changes: 11 additions & 0 deletions KenticoInspector.Actions/WebFarmServerSummary/Scripts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace KenticoInspector.Actions.WebFarmServerSummary
{
public static class Scripts
{
public static string BaseDirectory => $"{nameof(WebFarmServerSummary)}/Scripts";

public static string GetWebFarmServerSummary => $"{BaseDirectory}/{nameof(GetWebFarmServerSummary)}.sql";

public static string DisableServer => $"{BaseDirectory}/{nameof(DisableServer)}.sql";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
UPDATE CMS_WebFarmServer SET ServerDisplayName = ServerDisplayName + N'.disabled', ServerEnabled = 0
WHERE ServerID = @ServerID
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT ServerID AS 'ID', ServerName AS 'Name',
CASE WHEN ServerEnabled = 1 THEN 'true' ELSE 'false' END AS 'Enabled'
FROM CMS_WebFarmServer
1 change: 1 addition & 0 deletions KenticoInspector.Core/Constants/ActionTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public static class ActionTags
public const string Reset = "Reset";
public const string User = "User";
public const string Site = "Site";
public const string Configuration = "Configuration";

}
}

0 comments on commit b75422f

Please sign in to comment.