Martin Polreich | f7a1bb0 | 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]. |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 7 | * ASK_CONFIRMATION Ask confirmation for restore |
Martin Polreich | 721b725 | 2019-01-21 14:42:48 +0100 | [diff] [blame] | 8 | * CHECK_TIME_SYNC Set to true to check time synchronization accross selected nodes. |
Martin Polreich | f7889b5 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 9 | * VERIFICATION_RETRIES Number of restries to verify the restoration. |
Martin Polreich | f7a1bb0 | 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 | 208c487 | 2019-02-15 10:09:10 +0100 | [diff] [blame^] | 15 | def galera = new com.mirantis.mk.Galera() |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 16 | def python = new com.mirantis.mk.Python() |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 17 | def pepperEnv = "pepperEnv" |
| 18 | def resultCode = 99 |
| 19 | |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 20 | askConfirmation = (env.getProperty('ASK_CONFIRMATION') ?: true).toBoolean() |
Martin Polreich | 721b725 | 2019-01-21 14:42:48 +0100 | [diff] [blame] | 21 | checkTimeSync = (env.getProperty('CHECK_TIME_SYNC') ?: true).toBoolean() |
Martin Polreich | 49f16c0 | 2019-02-04 13:14:01 +0100 | [diff] [blame] | 22 | if (common.validInputParam('VERIFICATION_RETRIES') && VERIFICATION_RETRIES.isInteger()) { |
Martin Polreich | f7889b5 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 23 | verificationRetries = VERIFICATION_RETRIES.toInteger() |
| 24 | } else { |
| 25 | verificationRetries = 5 |
| 26 | } |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 27 | |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 28 | timeout(time: 12, unit: 'HOURS') { |
| 29 | node() { |
| 30 | stage('Setup virtualenv for Pepper') { |
| 31 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 32 | } |
| 33 | stage('Verify status') |
Martin Polreich | 208c487 | 2019-02-15 10:09:10 +0100 | [diff] [blame^] | 34 | resultCode = galera.verifyGaleraStatus(pepperEnv, false, checkTimeSync) |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 35 | stage('Restore') { |
| 36 | if (resultCode == 128) { |
| 37 | common.errorMsg("Unable to connect to Galera Master. Trying slaves...") |
Martin Polreich | 208c487 | 2019-02-15 10:09:10 +0100 | [diff] [blame^] | 38 | resultCode = galera.verifyGaleraStatus(pepperEnv, true, checkTimeSync) |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 39 | if (resultCode == 129) { |
| 40 | common.errorMsg("Unable to obtain Galera slave minions list". "Without fixing this issue, pipeline cannot continue in verification and restoration.") |
| 41 | currentBuild.result = "FAILURE" |
Martin Polreich | f7889b5 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 42 | return |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 43 | } else if (resultCode == 130) { |
| 44 | common.errorMsg("Neither master or slaves are reachable. Without fixing this issue, pipeline cannot continue in verification and restoration.") |
| 45 | currentBuild.result = "FAILURE" |
Martin Polreich | f7889b5 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 46 | return |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 47 | } |
| 48 | } |
Martin Polreich | 721b725 | 2019-01-21 14:42:48 +0100 | [diff] [blame] | 49 | if (resultCode == 131) { |
| 50 | common.errorMsg("Time desynced - Click proceed when the issue is fixed or abort.") |
| 51 | currentBuild.result = "FAILURE" |
| 52 | } |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 53 | if (resultCode == 1) { |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 54 | if(askConfirmation){ |
| 55 | common.warningMsg("There was a problem with parsing the status output or with determining it. Do you want to run a restore?") |
| 56 | } else { |
| 57 | common.warningMsg("There was a problem with parsing the status output or with determining it. Try to restore.") |
| 58 | } |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 59 | } else if (resultCode > 1) { |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 60 | if(askConfirmation){ |
| 61 | common.warningMsg("There's something wrong with the cluster, do you want to run a restore?") |
| 62 | } else { |
| 63 | common.warningMsg("There's something wrong with the cluster, try to restore.") |
| 64 | } |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 65 | } else { |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 66 | if(askConfirmation){ |
| 67 | common.warningMsg("There seems to be everything alright with the cluster, do you still want to run a restore?") |
| 68 | } else { |
| 69 | common.warningMsg("There seems to be everything alright with the cluster, do nothing") |
| 70 | } |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 71 | } |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 72 | if(askConfirmation){ |
| 73 | input message: "Are you sure you want to run a restore? Click to confirm" |
| 74 | } |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 75 | try { |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 76 | if((!askConfirmation && resultCode > 0) || askConfirmation){ |
Martin Polreich | 208c487 | 2019-02-15 10:09:10 +0100 | [diff] [blame^] | 77 | galera.restoreGaleraDb(pepperEnv) |
Sergey | 6579de6 | 2019-01-15 17:27:59 +0400 | [diff] [blame] | 78 | } |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 79 | } catch (Exception e) { |
| 80 | common.errorMsg("Restoration process has failed.") |
| 81 | } |
| 82 | } |
Martin Polreich | 7bc654c | 2019-01-18 14:17:52 +0100 | [diff] [blame] | 83 | stage('Verify restoration result') { |
Martin Polreich | f7889b5 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 84 | common.retry(verificationRetries, 15) { |
Martin Polreich | 208c487 | 2019-02-15 10:09:10 +0100 | [diff] [blame^] | 85 | exitCode = galera.verifyGaleraStatus(pepperEnv, false, false) |
Martin Polreich | f7889b5 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 86 | if (exitCode >= 1) { |
Martin Polreich | 49f16c0 | 2019-02-04 13:14:01 +0100 | [diff] [blame] | 87 | 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 15 seconds.") |
Martin Polreich | f7889b5 | 2019-02-01 14:46:10 +0100 | [diff] [blame] | 88 | } else { |
| 89 | common.infoMsg("Restoration procedure seems to be successful. See verification report to be sure.") |
| 90 | currentBuild.result = "SUCCESS" |
| 91 | } |
Martin Polreich | 7bc654c | 2019-01-18 14:17:52 +0100 | [diff] [blame] | 92 | } |
| 93 | } |
Martin Polreich | f7a1bb0 | 2018-12-05 11:12:23 +0100 | [diff] [blame] | 94 | } |
| 95 | } |