vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Upgrade Stacklight packages and components |
| 4 | * |
| 5 | * Requred parameters: |
| 6 | * SALT_MASTER_URL URL of Salt master |
| 7 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API |
| 8 | * |
| 9 | * STAGE_UPGRADE_SYSTEM_PART Set to True if upgrade of system part (telegraf, fluentd, prometheus-relay) is desired |
| 10 | * STAGE_UPGRADE_ES_KIBANA Set to True if Elasticsearch and Kibana upgrade is desired |
| 11 | * STAGE_UPGRADE_DOCKER_COMPONENTS Set to True if upgrade for components running in Docker Swarm is desired |
| 12 | * |
| 13 | */ |
| 14 | |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 15 | common = new com.mirantis.mk.Common() |
| 16 | salt = new com.mirantis.mk.Salt() |
| 17 | python = new com.mirantis.mk.Python() |
| 18 | command = 'cmd.run' |
| 19 | pepperEnv = "pepperEnv" |
| 20 | errorOccured = false |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 21 | |
| 22 | def upgrade(master, target, service, pckg, state) { |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 23 | stage("Upgrade ${service}") { |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 24 | salt.runSaltProcessStep(master, "${target}", 'saltutil.refresh_pillar', [], null, true, 5) |
| 25 | salt.enforceState(master, "${target}", 'linux.system.repo', true) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 26 | common.infoMsg("Upgrade ${service} package") |
| 27 | try { |
| 28 | salt.runSaltProcessStep(master, "${target}", command, ["apt-get install --only-upgrade ${pckg}"], null, true) |
| 29 | } catch (Exception er) { |
| 30 | errorOccured = true |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 31 | common.errorMsg("[ERROR] ${pckg} package was not upgraded.") |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 32 | return |
| 33 | } |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 34 | common.infoMsg("Run ${state} state on ${target} nodes") |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 35 | try { |
vitalygusev | 2532889 | 2018-10-17 11:40:27 +0400 | [diff] [blame] | 36 | salt.enforceState(master, "${target}", ["${state}"], true) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 37 | } catch (Exception er) { |
| 38 | errorOccured = true |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 39 | common.errorMsg("[ERROR] ${state} state was executed and failed. Please fix it manually.") |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 40 | } |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 41 | common.infoMsg("Check ${service} service status on the target nodes") |
| 42 | salt.runSaltProcessStep(master, "${target}", "service.status", ["${service}"], null, true) |
| 43 | return |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 44 | } |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | def upgrade_es_kibana(master) { |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 48 | stage('Upgrade elasticsearch') { |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 49 | try { |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 50 | common.infoMsg('Upgrade the Elasticsearch package') |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 51 | salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["systemctl stop elasticsearch"], null, true) |
| 52 | salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["apt-get --only-upgrade install elasticsearch"], null, true) |
| 53 | salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["systemctl daemon-reload"], null, true) |
| 54 | salt.runSaltProcessStep(master, 'I@elasticsearch:server', command, ["systemctl start elasticsearch"], null, true) |
| 55 | salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true) |
| 56 | } catch (Exception er) { |
| 57 | errorOccured = true |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 58 | common.errorMsg("[ERROR] Elasticsearch upgrade failed. Please fix it manually.") |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 59 | return |
| 60 | } |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 61 | common.infoMsg('Verify that the Elasticsearch cluster status is green') |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 62 | try { |
| 63 | def retries_wait = 20 |
| 64 | def retries = 15 |
| 65 | def elasticsearch_vip |
vitalygusev | 2532889 | 2018-10-17 11:40:27 +0400 | [diff] [blame] | 66 | def pillar = salt.getPillar(master, "I@elasticsearch:client", 'elasticsearch:client:server:host') |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 67 | if(!pillar['return'].isEmpty()) { |
| 68 | elasticsearch_vip = pillar['return'][0].values()[0] |
| 69 | } else { |
| 70 | errorOccured = true |
| 71 | common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved') |
| 72 | } |
| 73 | pillar = salt.getPillar(master, "I@elasticsearch:client", 'elasticsearch:client:server:port') |
| 74 | def elasticsearch_port |
| 75 | if(!pillar['return'].isEmpty()) { |
| 76 | elasticsearch_port = pillar['return'][0].values()[0] |
| 77 | } else { |
| 78 | errorOccured = true |
| 79 | common.errorMsg('[ERROR] Elasticsearch VIP port could not be retrieved') |
| 80 | } |
| 81 | common.retry(retries,retries_wait) { |
| 82 | common.infoMsg('Waiting for Elasticsearch to become green..') |
| 83 | salt.cmdRun(master, "I@elasticsearch:client", "curl -sf ${elasticsearch_vip}:${elasticsearch_port}/_cat/health | awk '{print \$4}' | grep green") |
| 84 | } |
| 85 | } catch (Exception er) { |
| 86 | errorOccured = true |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 87 | common.errorMsg("[ERROR] Elasticsearch cluster status is not \'green\'. Please fix it manually.") |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 88 | return |
| 89 | } |
| 90 | } |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 91 | stage('Upgrade kibana') { |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 92 | try { |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 93 | common.infoMsg('Upgrade the Kibana package') |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 94 | salt.runSaltProcessStep(master, 'I@kibana:server', command, ["systemctl stop kibana"], null, true) |
| 95 | salt.runSaltProcessStep(master, 'I@kibana:server', command, ["apt-get --only-upgrade install kibana"], null, true) |
| 96 | salt.runSaltProcessStep(master, 'I@kibana:server', command, ["systemctl start kibana"], null, true) |
| 97 | } catch (Exception er) { |
| 98 | errorOccured = true |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 99 | common.errorMsg("[ERROR] Kibana upgrade failed. Please fix it manually.") |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 100 | return |
| 101 | } |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 102 | |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 103 | common.infoMsg("Check kibana status on the target nodes") |
| 104 | salt.runSaltProcessStep(master, "I@kibana:server", "service.status", ["kibana"], null, true) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 105 | return |
| 106 | } |
| 107 | } |
| 108 | timeout(time: 12, unit: 'HOURS') { |
| 109 | node("python") { |
| 110 | |
| 111 | stage('Setup virtualenv for Pepper') { |
| 112 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 113 | } |
| 114 | |
| 115 | if (STAGE_UPGRADE_SYSTEM_PART.toBoolean() == true && !errorOccured) { |
| 116 | upgrade(pepperEnv, "I@telegraf:agent or I@telegraf:remote_agent", "telegraf", "telegraf", "telegraf") |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 117 | upgrade(pepperEnv, "I@fluentd:agent", "td-agent", "td-agent td-agent-additional-plugins", "fluentd") |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 118 | if (salt.testTarget(pepperEnv, "I@prometheus:relay")) { |
| 119 | upgrade(pepperEnv, "I@prometheus:relay", "prometheus-relay", "prometheus-relay", "prometheus") |
| 120 | } |
| 121 | if (salt.testTarget(pepperEnv, "I@prometheus:exporters:libvirt")) { |
| 122 | upgrade(pepperEnv, "I@prometheus:exporters:libvirt", "libvirt-exporter", "libvirt-exporter", "prometheus") |
| 123 | } |
| 124 | if (salt.testTarget(pepperEnv, "I@prometheus:exporters:jmx")) { |
| 125 | upgrade(pepperEnv, "I@prometheus:exporters:jmx", "jmx-exporter", "jmx-exporter", "prometheus") |
| 126 | } |
vitalygusev | 2532889 | 2018-10-17 11:40:27 +0400 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | if (STAGE_UPGRADE_ES_KIBANA.toBoolean() == true && !errorOccured) { |
| 130 | upgrade_es_kibana(pepperEnv) |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | if (STAGE_UPGRADE_DOCKER_COMPONENTS.toBoolean() == true && !errorOccured) { |
| 134 | |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 135 | stage('Upgrade docker components') { |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 136 | |
| 137 | try { |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 138 | common.infoMsg('Disable and remove the previous versions of monitoring services') |
| 139 | salt.runSaltProcessStep(pepperEnv, 'I@docker:swarm:role:master and I@prometheus:server', command, ["docker stack rm monitoring"], null, true) |
| 140 | common.infoMsg('Rebuild the Prometheus configuration') |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 141 | salt.enforceState(pepperEnv, 'I@docker:swarm and I@prometheus:server', 'prometheus') |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 142 | common.infoMsg('Disable and remove the previous version of Grafana') |
| 143 | salt.runSaltProcessStep(pepperEnv, 'I@docker:swarm:role:master and I@prometheus:server', command, ["docker stack rm dashboard"], null, true) |
| 144 | common.infoMsg('Start the monitoring services') |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 145 | salt.enforceState(pepperEnv, 'I@docker:swarm:role:master and I@prometheus:server', 'docker') |
| 146 | salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true) |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 147 | common.infoMsg('Refresh the Grafana dashboards') |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 148 | salt.enforceState(pepperEnv, 'I@grafana:client', 'grafana.client') |
| 149 | } catch (Exception er) { |
| 150 | errorOccured = true |
vitalygusev | 4b331fa | 2018-12-04 19:03:47 +0400 | [diff] [blame^] | 151 | common.errorMsg("[ERROR] Upgrade of docker components failed. Please fix it manually.") |
vitalygusev | 2270137 | 2018-09-25 17:27:35 +0400 | [diff] [blame] | 152 | return |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | } |