Skip to content
Open
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
53 changes: 50 additions & 3 deletions addons/promote-new-primary/scripts/promote-master-with-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function promoteNewPrimary() {
let TMP_FILE = "/var/lib/jelastic/promotePrimary";
let session = getParam("session", "");
let CLUSTER_FAILED = 98;
let NOT_RUNNING = 4110;
let WARNING = "warning";

this.run = function() {
Expand Down Expand Up @@ -56,7 +57,7 @@ function promoteNewPrimary() {
};
}

return this.cmdByGroup("touch " + TMP_FILE, PROXY, 3);
return this.cmdByGroup("touch " + TMP_FILE, PROXY, 3, true);
};

this.setContainerVar = function() {
Expand Down Expand Up @@ -135,6 +136,45 @@ function promoteNewPrimary() {
this.failedPrimary = node;
};

this.getAvailableProxy = function() {
return this.availableProxy || "";
};

this.setAvailableProxy = function(nodeid) {
this.availableProxy = nodeid;
};

this.checkNodesAvailability = function(nodeGroup) {
let nodeid;

if (this.getAvailableProxy()) {
return {
result: 0,
nodeid: this.getAvailableProxy()
}
}

let resp = this.cmdByGroup("echo 1", nodeGroup, null, true);
if (resp.result == NOT_RUNNING ||
(resp.responses[0] && resp.responses[0].error && resp.responses[0].error.indexOf("No route to host"))) {
let nodeResp;
for (let i = 0, n = resp.responses.length; i < n; i++) {
nodeResp = resp.responses[i];
if (nodeResp.result == 0) {
nodeid = nodeResp.nodeid;
this.setAvailableProxy(nodeResp.nodeid);
break;
}
}
if (resp.result != 0 && resp.result != NOT_RUNNING) return resp;

return {
result: 0,
nodeid: this.getAvailableProxy()
}
}
};

this.getParsedNodes = function() {
return this.parsedNodes;
};
Expand Down Expand Up @@ -213,7 +253,7 @@ function promoteNewPrimary() {

let command = "bash /usr/local/sbin/jcm.sh newPrimary --server=node" + this.getNewPrimaryNode().id;
this.log("newPrimaryOnProxy command ->" + command);
return this.cmdByGroup(command, PROXY, 20);
return this.cmdByGroup(command, PROXY, 20, true);
}

return { result: 0 }
Expand Down Expand Up @@ -314,11 +354,18 @@ function promoteNewPrimary() {
return { result: 0 }
};

this.cmdByGroup = function(command, nodeGroup, timeout) {
this.cmdByGroup = function(command, nodeGroup, timeout, test) {
if (timeout) {
command = "timeout " + timeout + "s bash -c \"" + command + "\"";
}

if (nodeGroup == PROXY && !test) {
let resp = this.checkNodesAvailability(PROXY);
if (resp.nodeid) {
return this.cmdById(resp.nodeid, command);
}
}

return api.env.control.ExecCmdByGroup(envName, session, nodeGroup, toJSON([{ command: command }]), true, false, ROOT);
};

Expand Down
4 changes: 2 additions & 2 deletions addons/promote-new-primary/scripts/promote-master.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ function promoteNewPrimary() {
};
}

return this.cmdByGroup("touch " + TMP_FILE, PROXY, 3, true);
return this.cmdByGroup("touch " + TMP_FILE, PROXY, 3);
};

this.setContainerVar = function() {
Expand Down Expand Up @@ -579,7 +579,7 @@ function promoteNewPrimary() {

if (this.getAddOnType()) {
let command = "bash /usr/local/sbin/jcm.sh newPrimary --server=node" + this.getNewPrimaryNode().id;
return this.cmdByGroup(command, PROXY, 20, true);
return this.cmdByGroup(command, PROXY, 20);
}
}

Expand Down