blob: 443d56b8f5256ce3e85f79a60f5813d6a3d09929 [file] [log] [blame]
vitalygusev22701372018-09-25 17:27:35 +04001/**
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
vitalygusev4b331fa2018-12-04 19:03:47 +040015common = new com.mirantis.mk.Common()
16salt = new com.mirantis.mk.Salt()
17python = new com.mirantis.mk.Python()
18command = 'cmd.run'
19pepperEnv = "pepperEnv"
20errorOccured = false
vitalygusev22701372018-09-25 17:27:35 +040021
22def upgrade(master, target, service, pckg, state) {
vitalygusev4b331fa2018-12-04 19:03:47 +040023 stage("Upgrade ${service}") {
vitalygusev22701372018-09-25 17:27:35 +040024 salt.runSaltProcessStep(master, "${target}", 'saltutil.refresh_pillar', [], null, true, 5)
25 salt.enforceState(master, "${target}", 'linux.system.repo', true)
vitalygusev22701372018-09-25 17:27:35 +040026 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
vitalygusev4b331fa2018-12-04 19:03:47 +040031 common.errorMsg("[ERROR] ${pckg} package was not upgraded.")
vitalygusev22701372018-09-25 17:27:35 +040032 return
33 }
vitalygusev4b331fa2018-12-04 19:03:47 +040034 common.infoMsg("Run ${state} state on ${target} nodes")
vitalygusev22701372018-09-25 17:27:35 +040035 try {
vitalygusev25328892018-10-17 11:40:27 +040036 salt.enforceState(master, "${target}", ["${state}"], true)
vitalygusev22701372018-09-25 17:27:35 +040037 } catch (Exception er) {
38 errorOccured = true
vitalygusev4b331fa2018-12-04 19:03:47 +040039 common.errorMsg("[ERROR] ${state} state was executed and failed. Please fix it manually.")
vitalygusev22701372018-09-25 17:27:35 +040040 }
vitalygusev4b331fa2018-12-04 19:03:47 +040041 common.infoMsg("Check ${service} service status on the target nodes")
42 salt.runSaltProcessStep(master, "${target}", "service.status", ["${service}"], null, true)
43 return
vitalygusev22701372018-09-25 17:27:35 +040044 }
vitalygusev22701372018-09-25 17:27:35 +040045}
46
47def upgrade_es_kibana(master) {
vitalygusev4b331fa2018-12-04 19:03:47 +040048 stage('Upgrade elasticsearch') {
vitalygusev22701372018-09-25 17:27:35 +040049 try {
vitalygusev4b331fa2018-12-04 19:03:47 +040050 common.infoMsg('Upgrade the Elasticsearch package')
vitalygusev22701372018-09-25 17:27:35 +040051 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
vitalygusev4b331fa2018-12-04 19:03:47 +040058 common.errorMsg("[ERROR] Elasticsearch upgrade failed. Please fix it manually.")
vitalygusev22701372018-09-25 17:27:35 +040059 return
60 }
vitalygusev4b331fa2018-12-04 19:03:47 +040061 common.infoMsg('Verify that the Elasticsearch cluster status is green')
vitalygusev22701372018-09-25 17:27:35 +040062 try {
63 def retries_wait = 20
64 def retries = 15
65 def elasticsearch_vip
vitalygusev25328892018-10-17 11:40:27 +040066 def pillar = salt.getPillar(master, "I@elasticsearch:client", 'elasticsearch:client:server:host')
vitalygusev22701372018-09-25 17:27:35 +040067 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
vitalygusev4b331fa2018-12-04 19:03:47 +040087 common.errorMsg("[ERROR] Elasticsearch cluster status is not \'green\'. Please fix it manually.")
vitalygusev22701372018-09-25 17:27:35 +040088 return
89 }
90 }
vitalygusev4b331fa2018-12-04 19:03:47 +040091 stage('Upgrade kibana') {
vitalygusev22701372018-09-25 17:27:35 +040092 try {
vitalygusev4b331fa2018-12-04 19:03:47 +040093 common.infoMsg('Upgrade the Kibana package')
vitalygusev22701372018-09-25 17:27:35 +040094 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
vitalygusev4b331fa2018-12-04 19:03:47 +040099 common.errorMsg("[ERROR] Kibana upgrade failed. Please fix it manually.")
vitalygusev22701372018-09-25 17:27:35 +0400100 return
101 }
vitalygusev22701372018-09-25 17:27:35 +0400102
vitalygusev4b331fa2018-12-04 19:03:47 +0400103 common.infoMsg("Check kibana status on the target nodes")
104 salt.runSaltProcessStep(master, "I@kibana:server", "service.status", ["kibana"], null, true)
vitalygusev22701372018-09-25 17:27:35 +0400105 return
106 }
107}
108timeout(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")
vitalygusev4b331fa2018-12-04 19:03:47 +0400117 upgrade(pepperEnv, "I@fluentd:agent", "td-agent", "td-agent td-agent-additional-plugins", "fluentd")
vitalygusev22701372018-09-25 17:27:35 +0400118 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 }
vitalygusev25328892018-10-17 11:40:27 +0400127 }
128
129 if (STAGE_UPGRADE_ES_KIBANA.toBoolean() == true && !errorOccured) {
130 upgrade_es_kibana(pepperEnv)
vitalygusev22701372018-09-25 17:27:35 +0400131 }
132
133 if (STAGE_UPGRADE_DOCKER_COMPONENTS.toBoolean() == true && !errorOccured) {
134
vitalygusev4b331fa2018-12-04 19:03:47 +0400135 stage('Upgrade docker components') {
vitalygusev22701372018-09-25 17:27:35 +0400136
137 try {
vitalygusev4b331fa2018-12-04 19:03:47 +0400138 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')
vitalygusev22701372018-09-25 17:27:35 +0400141 salt.enforceState(pepperEnv, 'I@docker:swarm and I@prometheus:server', 'prometheus')
vitalygusev4b331fa2018-12-04 19:03:47 +0400142 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')
vitalygusev22701372018-09-25 17:27:35 +0400145 salt.enforceState(pepperEnv, 'I@docker:swarm:role:master and I@prometheus:server', 'docker')
146 salt.runSaltProcessStep(pepperEnv, '*', 'saltutil.sync_all', [], null, true)
vitalygusev4b331fa2018-12-04 19:03:47 +0400147 common.infoMsg('Refresh the Grafana dashboards')
vitalygusev22701372018-09-25 17:27:35 +0400148 salt.enforceState(pepperEnv, 'I@grafana:client', 'grafana.client')
149 } catch (Exception er) {
150 errorOccured = true
vitalygusev4b331fa2018-12-04 19:03:47 +0400151 common.errorMsg("[ERROR] Upgrade of docker components failed. Please fix it manually.")
vitalygusev22701372018-09-25 17:27:35 +0400152 return
153 }
154 }
155 }
156 }
157}