From 1c9147e05181254b695231432d97b071a6305f21 Mon Sep 17 00:00:00 2001 From: "alexey.lazarenko" Date: Fri, 20 Oct 2023 15:21:38 +0300 Subject: [PATCH 1/2] JE-66101 --- .../scripts/promote-master-with-proxy.js | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/addons/promote-new-primary/scripts/promote-master-with-proxy.js b/addons/promote-new-primary/scripts/promote-master-with-proxy.js index 6a876d6f..3bfcfe76 100644 --- a/addons/promote-new-primary/scripts/promote-master-with-proxy.js +++ b/addons/promote-new-primary/scripts/promote-master-with-proxy.js @@ -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() { @@ -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() { @@ -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; }; @@ -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 } @@ -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); }; From a14cc86609ae1a6b2cbf710256570c2a6f70277f Mon Sep 17 00:00:00 2001 From: "alexey.lazarenko" Date: Fri, 20 Oct 2023 16:59:13 +0300 Subject: [PATCH 2/2] JE-66101 --- addons/promote-new-primary/scripts/promote-master.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/promote-new-primary/scripts/promote-master.js b/addons/promote-new-primary/scripts/promote-master.js index 4ba74da7..f8f914bb 100644 --- a/addons/promote-new-primary/scripts/promote-master.js +++ b/addons/promote-new-primary/scripts/promote-master.js @@ -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() { @@ -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); } }