-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate "Disable enabled Web farm servers" (#212)
- Loading branch information
1 parent
82672df
commit b75422f
Showing
10 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
KenticoInspector.Actions/WebFarmServerSummary/Metadata/en-US.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
7 changes: 7 additions & 0 deletions
7
KenticoInspector.Actions/WebFarmServerSummary/Models/Options.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
KenticoInspector.Actions/WebFarmServerSummary/Models/Results/WebFarmServer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
KenticoInspector.Actions/WebFarmServerSummary/Models/Terms.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
KenticoInspector.Actions/WebFarmServerSummary/Scripts/DisableServer.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
3 changes: 3 additions & 0 deletions
3
KenticoInspector.Actions/WebFarmServerSummary/Scripts/GetWebFarmServerSummary.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters