Skip to content

Commit 7255838

Browse files
committed
Adding serial checking to avoid configuration conflict writing (Dashboard - Worker group configuration UI)
1 parent d51866a commit 7255838

2 files changed

Lines changed: 39 additions & 9 deletions

File tree

mrq/dashboard/app.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ def get_workers():
129129
def get_workergroups():
130130
collection = connections.mongodb_jobs.mrq_workergroups
131131
data = {"workergroups": {str(row.pop("_id")): row for row in collection.find(sort=[("_id", 1)])}}
132+
for workergroup_id in data["workergroups"]:
133+
if "serial" not in data["workergroups"][workergroup_id]:
134+
data["workergroups"][workergroup_id]["serial"] = str(int(time.time()))
132135
return jsonify(data)
133136

134137

@@ -144,9 +147,16 @@ def post_workergroups():
144147
for workergroup_id in workergroup_to_delete_list:
145148
connections.mongodb_jobs.mrq_workergroups.delete_one({"_id": workergroup_id})
146149

150+
outdated_wgcs = []
147151
for k, v in workergroups.iteritems():
148-
connections.mongodb_jobs.mrq_workergroups.update_one({"_id": k}, {"$set": v}, upsert=True)
149-
return jsonify({"status": "ok"})
152+
if ("serial" not in v or v["serial"] == connections.mongodb_jobs.mrq_workergroups.find_one({"_id": k})["serial"]):
153+
v["serial"] = str(int(time.time()))
154+
connections.mongodb_jobs.mrq_workergroups.update_one({"_id": k}, {"$set": v}, upsert=True)
155+
else:
156+
outdated_wgcs.append(k)
157+
158+
return jsonify({"status": "outdated" if len(outdated_wgcs) else "ok",
159+
"outdated_wgcs": outdated_wgcs})
150160

151161

152162
def build_api_datatables_query(req):

mrq/dashboard/static/js/views/workergroups.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ define(["jquery", "underscore", "models", "views/generic/page", "quicksettings"]
5656
this.workergroupPanels.push(workerPanel);
5757
if (workergroup != null)
5858
{
59+
this.serials[workergroupName] = workergroup["serial"]
5960
_.forEach(workergroup["profiles"], function(profile, profileName) {
6061
this.addProfileToPanel(workerPanel, profile, profileName);
6162
}, this);
@@ -79,19 +80,21 @@ define(["jquery", "underscore", "models", "views/generic/page", "quicksettings"]
7980
remove_profile: function() {
8081
},
8182

82-
reload: function() {
83-
if (confirm('It will discard every changes that hasn\'t be saved. Are you sure?')) {
83+
reload: function(force = false) {
84+
if (force || confirm('It will discard every changes that hasn\'t be saved. Are you sure?')) {
8485
_.forEach(this.workergroupPanels, function(panel) {
85-
if (panel != null && panel != undefined)
86+
if (panel !== null && panel !== undefined)
8687
panel.destroy();
8788
delete panel;
8889
})
8990
this.render();
9091
}
9192
},
9293

94+
9395
// Check for "continue" usage instead of nested ifs
9496
save: function() {
97+
var _this = this;
9598
this.commandPanel._controls["Status"].setValue("<font color=\"orange\">Saving...</font>");
9699

97100
data = {};
@@ -106,9 +109,12 @@ define(["jquery", "underscore", "models", "views/generic/page", "quicksettings"]
106109
"profiles" : {},
107110
"process_termination_timeout": parseInt(panelJSON["Process Termination Timeout"], 10)
108111
}
112+
113+
if (panelJSON["Workgroup Name"] in _this.serials)
114+
workergroup["serial"] = _this.serials[panelJSON["Workgroup Name"]];
115+
109116
_.forEach(_.range(1, panel.profilesNumber + 1), function(index) {
110117
header = "Profile " + String(index) + " - ";
111-
console.log(panelJSON[header + "Profile Name"])
112118
if ($.inArray(panelJSON[header + "Profile Name"], [null, ""]) == -1)
113119
{
114120
profile = {};
@@ -124,21 +130,35 @@ define(["jquery", "underscore", "models", "views/generic/page", "quicksettings"]
124130
}
125131
}
126132
})
127-
console.log(data)
128133

129134
$.post("/api/workergroups", {"workergroups": JSON.stringify(data)}).done(function(result) {
130-
if (result.status != "ok") {
135+
if (result.status === "ok")
136+
{
137+
_this.commandPanel._controls["Status"].setValue("<font color=\"green\">Saved</font>");
138+
_this.reload(true);
139+
}
140+
else if (result.status === "outdated")
141+
{
142+
string = "";
143+
_.forEach(result.outdated_wgcs, function(wgc) {
144+
string += "- " + wgc + "<br>";
145+
})
146+
_this.commandPanel._controls["Status"].setValue("<font color=\"red\">These configurations were outdated and were not saved:<br>" + string + "</font><br>The others were saved.");
147+
}
148+
else
149+
{
150+
_this.commandPanel._controls["Status"].setValue("<font color=\"red\">FAILED</font>");
131151
return alert("There was an error while saving!");
132152
}
133153
});
134-
this.commandPanel._controls["Status"].setValue("<font color=\"green\">Saved</font>");
135154
},
136155

137156
render: function() {
138157
var _this = this;
139158

140159
this.workergroupPanels = [];
141160
this.addCommandPanel();
161+
this.serials = {};
142162

143163
$.get("/api/workergroups").done(function(data) {
144164
_.forEach(data["workergroups"], function(workergroup, workergroupName) {

0 commit comments

Comments
 (0)