Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Verify and restore Galera cluster |
| 3 | * |
| 4 | * Expected parameters: |
| 5 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API. |
| 6 | * SALT_MASTER_URL Full Salt API address [http://10.10.10.1:8000]. |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 7 | * ASK_CONFIRMATION Ask confirmation for restore |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 8 | * VERIFICATION_RETRIES Number of restries to verify the restoration. |
Martin Polreich | 2aa7440 | 2019-01-21 14:42:48 +0100 | [diff] [blame] | 9 | * CHECK_TIME_SYNC Set to true to check time synchronization accross selected nodes. |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 10 | * |
| 11 | **/ |
| 12 | |
| 13 | def common = new com.mirantis.mk.Common() |
| 14 | def salt = new com.mirantis.mk.Salt() |
Martin Polreich | 71a08db | 2019-02-15 10:09:10 +0100 | [diff] [blame] | 15 | def galera = new com.mirantis.mk.Galera() |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 16 | def python = new com.mirantis.mk.Python() |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 17 | def pepperEnv = "pepperEnv" |
| 18 | def resultCode = 99 |
| 19 | |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 20 | askConfirmation = (env.getProperty('ASK_CONFIRMATION') ?: true).toBoolean() |
Martin Polreich | 2aa7440 | 2019-01-21 14:42:48 +0100 | [diff] [blame] | 21 | checkTimeSync = (env.getProperty('CHECK_TIME_SYNC') ?: true).toBoolean() |
Sergey | c8a8a79 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 22 | |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 23 | if (common.validInputParam(VERIFICATION_RETRIES) && VERIFICATION_RETRIES.isInteger()) { |
| 24 | verificationRetries = VERIFICATION_RETRIES.toInteger() |
| 25 | } else { |
| 26 | verificationRetries = 5 |
| 27 | } |
| 28 | |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 29 | timeout(time: 12, unit: 'HOURS') { |
| 30 | node() { |
| 31 | stage('Setup virtualenv for Pepper') { |
| 32 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 33 | } |
| 34 | stage('Verify status') |
Martin Polreich | 71a08db | 2019-02-15 10:09:10 +0100 | [diff] [blame] | 35 | resultCode = galera.verifyGaleraStatus(pepperEnv, false, checkTimeSync) |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 36 | stage('Restore') { |
| 37 | if (resultCode == 128) { |
| 38 | common.errorMsg("Unable to connect to Galera Master. Trying slaves...") |
Martin Polreich | 71a08db | 2019-02-15 10:09:10 +0100 | [diff] [blame] | 39 | resultCode = galera.verifyGaleraStatus(pepperEnv, true, checkTimeSync) |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 40 | if (resultCode == 129) { |
| 41 | common.errorMsg("Unable to obtain Galera slave minions list". "Without fixing this issue, pipeline cannot continue in verification and restoration.") |
| 42 | currentBuild.result = "FAILURE" |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 43 | return |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 44 | } else if (resultCode == 130) { |
| 45 | common.errorMsg("Neither master or slaves are reachable. Without fixing this issue, pipeline cannot continue in verification and restoration.") |
| 46 | currentBuild.result = "FAILURE" |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 47 | return |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 48 | } |
| 49 | } |
Martin Polreich | 2aa7440 | 2019-01-21 14:42:48 +0100 | [diff] [blame] | 50 | if (resultCode == 131) { |
Martin Polreich | 323ffde | 2019-05-07 15:56:38 +0200 | [diff] [blame^] | 51 | common.errorMsg("Time desynced - Please fix this issue and rerun the pipeline.") |
Martin Polreich | 2aa7440 | 2019-01-21 14:42:48 +0100 | [diff] [blame] | 52 | currentBuild.result = "FAILURE" |
Martin Polreich | 323ffde | 2019-05-07 15:56:38 +0200 | [diff] [blame^] | 53 | return |
| 54 | } |
| 55 | if (resultCode == 140 || resultCode == 141) { |
| 56 | common.errorMsg("Disk utilization check failed - Please fix this issue and rerun the pipeline.") |
| 57 | currentBuild.result = "FAILURE" |
| 58 | return |
Martin Polreich | 2aa7440 | 2019-01-21 14:42:48 +0100 | [diff] [blame] | 59 | } |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 60 | if (resultCode == 1) { |
Sergey | c8a8a79 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 61 | if(askConfirmation){ |
| 62 | common.warningMsg("There was a problem with parsing the status output or with determining it. Do you want to run a restore?") |
| 63 | } else { |
| 64 | common.warningMsg("There was a problem with parsing the status output or with determining it. Try to restore.") |
| 65 | } |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 66 | } else if (resultCode > 1) { |
Sergey | c8a8a79 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 67 | if(askConfirmation){ |
| 68 | common.warningMsg("There's something wrong with the cluster, do you want to run a restore?") |
| 69 | } else { |
| 70 | common.warningMsg("There's something wrong with the cluster, try to restore.") |
| 71 | } |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 72 | } else { |
Sergey | c8a8a79 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 73 | if(askConfirmation){ |
| 74 | common.warningMsg("There seems to be everything alright with the cluster, do you still want to run a restore?") |
| 75 | } else { |
| 76 | common.warningMsg("There seems to be everything alright with the cluster, do nothing") |
| 77 | } |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 78 | } |
Sergey | c8a8a79 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 79 | if(askConfirmation){ |
| 80 | input message: "Are you sure you want to run a restore? Click to confirm" |
| 81 | } |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 82 | try { |
Sergey | c8a8a79 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 83 | if((!askConfirmation && resultCode > 0) || askConfirmation){ |
Martin Polreich | 71a08db | 2019-02-15 10:09:10 +0100 | [diff] [blame] | 84 | galera.restoreGaleraDb(pepperEnv) |
Sergey | c8a8a79 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 85 | } |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 86 | } catch (Exception e) { |
| 87 | common.errorMsg("Restoration process has failed.") |
| 88 | } |
| 89 | } |
Martin Polreich | c9466c7 | 2019-01-18 14:17:52 +0100 | [diff] [blame] | 90 | stage('Verify restoration result') { |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 91 | common.retry(verificationRetries, 15) { |
Martin Polreich | 71a08db | 2019-02-15 10:09:10 +0100 | [diff] [blame] | 92 | exitCode = galera.verifyGaleraStatus(pepperEnv, false, false) |
Martin Polreich | 0d53826 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 93 | if (exitCode >= 1) { |
| 94 | error("Verification attempt finished with an error. This may be caused by cluster not having enough time to come up or to sync. Next verification attempt in 5 seconds.") |
| 95 | } else { |
| 96 | common.infoMsg("Restoration procedure seems to be successful. See verification report to be sure.") |
| 97 | currentBuild.result = "SUCCESS" |
| 98 | } |
Martin Polreich | c9466c7 | 2019-01-18 14:17:52 +0100 | [diff] [blame] | 99 | } |
| 100 | } |
Martin Polreich | aae1b9d | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 101 | } |
| 102 | } |