Martin Polreich | 85fa2db | 2019-02-19 10:29:56 +0100 | [diff] [blame] | 1 | def common = new com.mirantis.mk.Common() |
| 2 | def salt = new com.mirantis.mk.Salt() |
| 3 | def galera = new com.mirantis.mk.Galera() |
| 4 | def python = new com.mirantis.mk.Python() |
| 5 | def pepperEnv = "pepperEnv" |
| 6 | |
| 7 | backupNode = "none" |
| 8 | primaryNodes = [] |
| 9 | syncedNodes = [] |
| 10 | galeraMembers = [] |
Valeriy Sakharov | 23b4b04 | 2021-05-31 13:09:34 +0400 | [diff] [blame^] | 11 | maxValue = 0 |
| 12 | masterNode = "none" |
Martin Polreich | 85fa2db | 2019-02-19 10:29:56 +0100 | [diff] [blame] | 13 | |
| 14 | if (common.validInputParam('OVERRIDE_BACKUP_NODE')) { |
| 15 | backupNode = OVERRIDE_BACKUP_NODE |
| 16 | } |
| 17 | |
| 18 | timeout(time: 12, unit: 'HOURS') { |
| 19 | node() { |
| 20 | stage('Setup virtualenv for Pepper') { |
| 21 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 22 | } |
| 23 | if (backupNode.equals("none")) { |
| 24 | stage('Locate Primary component') { |
| 25 | galeraMembers = salt.getMinions(pepperEnv, "I@galera:master or I@galera:slave") |
| 26 | for (member in galeraMembers) { // STEP 1 - Locate all nodes that belong to Primary component |
| 27 | try { |
| 28 | salt.minionsReachable(pepperEnv, "I@salt:master", member) |
| 29 | memberStatus = galera.getWsrepParameters(pepperEnv, member, "wsrep_cluster_status", false) |
| 30 | if (memberStatus.get('wsrep_cluster_status').equals("Primary")) { |
| 31 | primaryNodes.add(member) |
| 32 | common.infoMsg("Adding ${member} as a member of a Primary component.") |
| 33 | } else { |
| 34 | common.warningMsg("Ignoring ${member} node, because it's not part of a Primary component.") |
| 35 | } |
| 36 | } catch (Exception e) { |
| 37 | common.warningMsg("Minion '${member}' is not reachable or is not possible to determine its status.") |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | stage('Choose backup node') { |
Valeriy Sakharov | 23b4b04 | 2021-05-31 13:09:34 +0400 | [diff] [blame^] | 42 | primaryNodes = primaryNodes.sort() |
| 43 | for (node in primaryNodes.reverse()) { // Looking for the node with the highest mysql_queries value |
| 44 | try { |
| 45 | queriesValue = galera.getWsrepParameters(pepperEnv, node, "Queries", false).get('Queries') |
| 46 | common.infoMsg("Queries for ${node} - ${queriesValue}") |
| 47 | if (queriesValue >= maxValue) { |
| 48 | maxValue = queriesValue |
| 49 | masterNode = node |
| 50 | common.infoMsg("Current main node in galera cluster: ${masterNode}") |
| 51 | } |
| 52 | } catch (Exception e) { |
| 53 | common.warningMsg("Minion '${node}' unavailable.") |
| 54 | } |
| 55 | } |
| 56 | if (masterNode.equals("none")) { |
| 57 | backupNode = primaryNodes[-1] // STEP 2 - Use node with highest hostname number (last option if everything previous fails) |
| 58 | } else { |
| 59 | common.infoMsg("Master node is ${masterNode}.") |
| 60 | primaryNodes = primaryNodes.minus(masterNode) |
| 61 | backupNode = primaryNodes[-1] |
| 62 | } |
| 63 | common.infoMsg("Choose backup node as ${backupNode}.") |
| 64 | } |
Martin Polreich | 85fa2db | 2019-02-19 10:29:56 +0100 | [diff] [blame] | 65 | } else { |
| 66 | stage('Choose backup node') { |
| 67 | common.infoMsg("Backup node backup was overriden to ${backupNode}.") |
| 68 | } |
| 69 | } |
| 70 | stage ('Prepare for backup') { |
| 71 | salt.enforceState(pepperEnv, 'I@xtrabackup:server', ['linux.system.repo', 'xtrabackup']) |
| 72 | salt.enforceState(pepperEnv, 'I@xtrabackup:client', ['linux.system.repo', 'openssh.client']) |
| 73 | } |
| 74 | stage('Backup') { |
| 75 | common.infoMsg("Node ${backupNode} was selected as a backup node.") |
| 76 | input: "Please check selected backup node and confirm to run the backup procedure." |
| 77 | salt.cmdRun(pepperEnv, backupNode, "su root -c 'salt-call state.sls xtrabackup'") |
| 78 | salt.cmdRun(pepperEnv, backupNode, "su root -c '/usr/local/bin/innobackupex-runner.sh -s'") |
| 79 | } |
| 80 | stage('Clean-up') { |
| 81 | salt.cmdRun(pepperEnv, backupNode, "su root -c '/usr/local/bin/innobackupex-runner.sh -c'") |
| 82 | } |
Martin Polreich | aceda37 | 2019-08-23 15:55:25 +0200 | [diff] [blame] | 83 | stage('Backup Dogtag') { |
Martin Polreich | 520781e | 2019-09-23 18:08:32 +0200 | [diff] [blame] | 84 | if (!salt.getMinions(pepperEnv, "I@dogtag:server:enabled").isEmpty()) { |
| 85 | dogtagBackupBuild = build(job: 'backupninja_backup', parameters: [ |
Martin Polreich | aceda37 | 2019-08-23 15:55:25 +0200 | [diff] [blame] | 86 | [$class: 'StringParameterValue', name: 'SALT_MASTER_URL', value: SALT_MASTER_URL], |
| 87 | [$class: 'StringParameterValue', name: 'SALT_MASTER_CREDENTIALS', value: SALT_MASTER_CREDENTIALS], |
| 88 | [$class: 'BooleanParameterValue', name: 'ASK_CONFIRMATION', value: "false"], |
| 89 | [$class: 'BooleanParameterValue', name: 'BACKUP_SALTMASTER_AND_MAAS', value: "false"], |
| 90 | [$class: 'BooleanParameterValue', name: 'BACKUP_DOGTAG', value: "true"], |
| 91 | ] |
| 92 | ) |
| 93 | } else { |
| 94 | common.warningMsg("Dogtag pillar not found. This is fine if you are using different Barbican backend.") |
| 95 | } |
| 96 | } |
Martin Polreich | 85fa2db | 2019-02-19 10:29:56 +0100 | [diff] [blame] | 97 | } |
Valeriy Sakharov | 23b4b04 | 2021-05-31 13:09:34 +0400 | [diff] [blame^] | 98 | } |