Permalink
Browse files

Upgrade procedure for v69.10->v69.11

  • Loading branch information...
1 parent abb6969 commit 35af12ff8d69e8c8809cf1b794cfe78b3fea2cc5 @ferd ferd committed Nov 11, 2013
Showing with 93 additions and 0 deletions.
  1. +93 −0 upgrades/v69.10_v69.11/live_upgrade.erl
View
93 upgrades/v69.10_v69.11/live_upgrade.erl
@@ -0,0 +1,93 @@
+f(UpgradeNode).
+UpgradeNode = fun () ->
+ case logplex_app:config(git_branch) of
+ "v69.10" ->
+ io:format(whereis(user), "at=upgrade_start cur_vsn=69.8~n", []);
+ "v69.11" ->
+ io:format(whereis(user),
+ "at=upgrade type=retry cur_vsn=69.8 old_vsn=69.10~n", []);
+ Else ->
+ io:format(whereis(user),
+ "at=upgrade_start old_vsn=~p abort=wrong_version", [tl(Else)]),
+ erlang:error({wrong_version, Else})
+ end,
+
+ %% stateless
+ l(logplex_drain),
+ l(logplex_http_drain),
+ l(logplex_msg_buffer),
+ l(logplex_tcpsyslog_drain),
+
+
+ application:set_env(logplex, git_branch, "v69.11"),
+ ok
+end.
+
+f(RollbackNode).
+RollbackNode = fun () ->
+ case logplex_app:config(git_branch) of
+ "v69.11" ->
+ io:format(whereis(user),
+ "at=rollback cur_vsn=69.11 old_vsn=69.10~n", []);
+ Else ->
+ io:format(whereis(user),
+ "at=upgrade_start old_vsn=~p abort=wrong_version", [tl(Else)]),
+ erlang:error({wrong_version, Else})
+ end,
+
+ %% stateless
+ l(logplex_tcpsyslog_drain),
+ l(logplex_msg_buffer),
+ l(logplex_http_drain),
+ l(logplex_drain),
+
+ application:set_env(logplex, git_branch, "v69.10"),
+ ok
+end.
+
+f(NodeVersions).
+NodeVersions = fun () ->
+ lists:keysort(3,
+ [ {N,
+ element(2, rpc:call(N, application, get_env, [logplex, git_branch])),
+ rpc:call(N, os, getenv, ["INSTANCE_NAME"])}
+ || N <- [node() | nodes()] ])
+ end.
+
+f(NodesAt).
+NodesAt = fun (Vsn) ->
+ [ N || {N, V, _} <- NodeVersions(), V =:= Vsn ]
+ end.
+
+
+f(RollingUpgrade).
+RollingUpgrade = fun (Nodes) ->
+ lists:foldl(fun (N, {good, Upgraded}) ->
+ case rpc:call(N, erlang, apply, [ UpgradeNode, [] ]) of
+ ok ->
+ {good, [N | Upgraded]};
+ Else ->
+ {{bad, N, Else}, Upgraded}
+ end;
+ (N, {_, _} = Acc) -> Acc
+ end,
+ {good, []},
+ Nodes)
+end.
+
+f(RollingRollback).
+RollingRollback = fun (Nodes) ->
+ lists:foldl(fun (N, {good, Upgraded}) ->
+ case rpc:call(N, erlang, apply, [ RollbackNode, [] ]) of
+ ok ->
+ {good, [N | Upgraded]};
+ Else ->
+ {{bad, N, Else}, Upgraded}
+ end;
+ (N, {_, _} = Acc) -> Acc
+ end,
+ {good, []},
+ Nodes)
+end.
+
+

0 comments on commit 35af12f

Please sign in to comment.