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

Warns admins about running search indexer on wrong server #4068

Merged
merged 1 commit into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,62 @@ class SchedulerEditor extends Component {
return;
}

props.onUpdate(props.scheduleItemDetail);
this.handleRecommendedServers(() => props.onUpdate(props.scheduleItemDetail));
}

compareIgnoreCase(prev, next) {
return prev.toLowerCase().localeCompare(next.toLowerCase());
}

uniqueIgnoreCase(value, index, self) {
const lower = self.map(x => (x || "").toLowerCase());
return lower.indexOf(value.toLowerCase()) === index;
}

normalizeServers(commaSeparatedServers) {
return (commaSeparatedServers || "")
.split(",")
.map(x => x.trim())
.filter(x => !!x)
.filter(this.uniqueIgnoreCase)
.sort(this.compareIgnoreCase)
.join(", ");
}

onServersBlur() {
const { scheduleItemDetail } = this.props;
this.onSettingChange("Servers", {
target: {
value: this.normalizeServers(scheduleItemDetail.Servers)
}
});
}

handleRecommendedServers(callback) {
const { scheduleItemDetail } = this.props;
const recommendedServers = scheduleItemDetail.RecommendedServers || [];

const proceed = () => {
if (callback && typeof(callback) === "function") {
callback();
}
};

if (scheduleItemDetail.Enabled && recommendedServers.length > 0) {
const servers = this.normalizeServers(scheduleItemDetail.Servers);
const recommended = this.normalizeServers(recommendedServers.join(", "));

if (this.compareIgnoreCase(servers, recommended) !== 0) {
const message = util.formatString(resx.get("RecommendServers"), recommended);
const yes = resx.get("Yes");
const no = resx.get("No");
util.utilities.confirm(message, yes, no, () => proceed());
} else {
proceed();
}
} else {
proceed();
}
}

onCancel() {
Expand Down Expand Up @@ -264,6 +319,7 @@ class SchedulerEditor extends Component {
label={resx.get("Servers")}
error={false}
value={this.getValue("Servers") || ""}
onBlur={this.onServersBlur.bind(this)}
onChange={this.onSettingChange.bind(this, "Servers")}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ const utils = {
}
this.utilities = utilities;
},

formatString() {
const format = arguments[0];
const methodsArgs = arguments;
return format.replace(/[{[](\d+)[\]}]/gi, function (_, index) {
let argsIndex = parseInt(index) + 1;
return methodsArgs[argsIndex];
});
},

utilities: null
};
export default utils;
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ namespace Dnn.PersonaBar.TaskScheduler.Components
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;

using DotNetNuke.Abstractions.Application;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Instrumentation;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Scheduling;
using Microsoft.Extensions.DependencyInjection;

public class TaskSchedulerController
{
private static readonly string SchedulersToRunOnSameWebServerKey = "SchedulersToRunOnSameWebServer";
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(TaskSchedulerController));

private string LocalResourcesFile
Expand Down Expand Up @@ -145,5 +148,40 @@ public IEnumerable<ScheduleItem> GetScheduleItems(bool? enabled, string serverNa
return null;
}
}

/// <summary>
/// Gets a list of servers to be recommended for a particular scheduler.
/// </summary>
/// <param name="schedulerId">Scheduler Id.</param>
/// <returns>List of recommended servers for specified <paramref name="schedulerId"/>.</returns>
public IEnumerable<string> GetRecommendedServers(int schedulerId)
{
var hostSettingsService = Globals.DependencyProvider.GetRequiredService<IHostSettingsService>();

var schedulerIds = hostSettingsService.GetString(SchedulersToRunOnSameWebServerKey, string.Empty)
.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Where(x => int.TryParse(x, out var id))
.Select(x => int.Parse(x))
.ToArray();

if (!schedulerIds.Contains(schedulerId))
{
return new string[0];
}

var servers = SchedulingProvider.Instance().GetSchedule()
.Cast<ScheduleItem>()
.Where(x => x.ScheduleID != schedulerId
&& x.Enabled
&& schedulerIds.Contains(x.ScheduleID)
&& !string.IsNullOrWhiteSpace(x.Servers))
.SelectMany(x => x.Servers
.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(s => s.Trim()))
.Distinct(StringComparer.OrdinalIgnoreCase)
.OrderBy(x => x);

return servers;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ public HttpResponseMessage GetScheduleItem(int scheduleId)
try
{
ScheduleItem scheduleItem = SchedulingProvider.Instance().GetSchedule(scheduleId);

var recommendedServers = this._controller.GetRecommendedServers(scheduleItem.ScheduleID);

var response = new
{
Expand All @@ -268,7 +270,8 @@ public HttpResponseMessage GetScheduleItem(int scheduleId)
scheduleItem.AttachToEvent,
scheduleItem.CatchUpEnabled,
scheduleItem.ObjectDependencies,
scheduleItem.Servers
scheduleItem.Servers,
RecommendedServers = recommendedServers,
},
TotalResults = 1
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@
<data name="StopSchedule.Text" xml:space="preserve">
<value>Stop Schedule</value>
</data>
<data name="RecommendServers.Text" xml:space="preserve">
<value>To avoid failures, it is highly recommended to setup this scheduler to run on following web server(s):&lt;br/&gt;&lt;br/&gt;{0}&lt;br/&gt;&lt;br/&gt;Proceed anyway?</value>
</data>
<data name="lblStartDelay.Text" xml:space="preserve">
<value>Schedule Start Delay (mins):</value>
</data>
Expand Down