This repository has been archived by the owner on Dec 6, 2022. It is now read-only.
/
app_cluster_upgrade.mc
78 lines (65 loc) · 2.3 KB
/
app_cluster_upgrade.mc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# validate the input....
if empty($backend) { fail('Please specify a backend to manage using $backend') }
if empty($revision) { fail('Please specify a revision to manage using $revision') }
if empty($cluster) { fail('Please specify a cluster to manage using $cluster') }
# find a load balancer and list of worker nodes
$load_balancer = discover({"class" => haproxy})
$servers = discover(appmgr, {fact => "cluster=${cluster}"})
if empty($load_balancer) { fail("Could not find any loadbalancers to manage") }
if empty($servers) { fail("Could not find any servers to manage") }
$server_count = size($servers)
$msg = "${id} updated ${server_count} node cluster ${cluster} to revision ${revision}"
app::update{$cluster:
backend => $backend,
revision => $revision,
load_balancer => $load_balancer,
nodes => $servers
} ->
angelia{$cluster:
msg => $msg,
recipient => "boxcar://rip@devco.net"
} ->
mco::say{"done":
msg => $msg
}
# Given an array or nodes, a revision, a list of nodes to update and
# a load balancer that fronts the nodes this will:
#
# - disable all the nodes on the load balancer
# - update them to a new revision in a 2 per batch series
# - make sure their load average is ok for up to 100 seconds
# - enable all the nodes in the load balancer
define app::update($backend, $revision, $nodes, $load_balancer) {
if is_string($nodes) {
$workers = [$nodes]
} elsif is_array($nodes) {
$workers = $nodes
} else {
fail("Don't know how to deploy to nodes: ${nodes}")
}
# makes sure they are all up, cached discovery
mco::ping{"${name}-lb": identity_filter => $load_balancer} ->
mco::ping{"${name}-workers": identity_filter => $nodes} ->
haproxy::disable{$name:
server => join($workers, ","),
backend => $backend,
identity_filter => $load_balancer
} ->
mcollective{"update_${name}":
agent => appmgr,
action => upgrade,
arguments => {revision => $revision},
identity_filter => $workers,
tries => 2,
batch_size => 2
} ->
nrpe::runcommand{"check_load":
tries => 10,
identity_filter => $workers
} ->
haproxy::enable{$name:
server => join($workers, ","),
backend => $backend,
identity_filter => $load_balancer
}
}