Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP CAD-2839 supervisord | ctl: cluster control tool
- Loading branch information
Showing
22 changed files
with
558 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck disable=SC1090,SC2046,SC2206,SC2207 | ||
|
||
set -euo pipefail | ||
|
||
global_ctl_basedir=${global_ctl_basedir:-$(realpath "$(dirname "$0")")} | ||
global_ctl_runsdir=${global_ctl_runsdir:-$(realpath "$global_ctl_basedir/../../runs")} | ||
|
||
. "$global_ctl_basedir"/ctl-lib.sh | ||
. "$global_ctl_basedir"/ctl-profile.sh | ||
. "$global_ctl_basedir"/ctl-run.sh | ||
. "$global_ctl_basedir"/ctl-supervisor.sh | ||
. "$global_ctl_basedir"/ctl-topology.sh | ||
|
||
usage_main() { | ||
__usage "OP" "Main OPs" <<EOF | ||
profile (p) Benchmark profile operations. Default subop is 'list' | ||
run (r) Managing benchmark runs. Default subop is 'list' | ||
topology (t) Topology generation | ||
supervisor (s) Managing local cluster | ||
Options: | ||
--trace / --debug set -x | ||
--help This short help. | ||
--help-full Extended help. | ||
EOF | ||
} | ||
|
||
usage_extra() { | ||
cat >&2 <<EOF | ||
Other OPs: | ||
call ARGS.. Call internal functions with arguments. | ||
Extra options: | ||
--cls Clear screen, before acting further. | ||
--runsdir DIR Set the runs directory. Defaults to $global_ctl_runsdir | ||
EOF | ||
} | ||
|
||
while test $# -gt 0 | ||
do case "$1" in | ||
--runsdir ) | ||
global_ctl_runsdir=$2; shift;; | ||
--cls ) | ||
echo -en "\ec">&2;; | ||
--trace | --debug ) | ||
set -x;; | ||
--help ) | ||
usage_main; exit 1;; | ||
--help-full | --help-all | --help-extra ) | ||
usage_main; usage_extra; exit 1;; | ||
* ) break;; esac; shift; done | ||
|
||
main() { | ||
local op=${1:?$(usage_main)}; shift | ||
|
||
case "${op}" in | ||
profile | profiles | prof | ps | p ) | ||
profile "$@";; | ||
supervisor | sup | sv | s ) | ||
supervisor "$@";; | ||
topology | topo | t ) | ||
topology "$@";; | ||
run | runs | r ) | ||
run "$@";; | ||
call ) | ||
"$@";; | ||
* ) usage_main; exit 1;; esac | ||
} | ||
|
||
main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
to_jsonlist() { | ||
for x in "$@" | ||
do echo "\"$x\"" | ||
done | jq --slurp '.' | ||
} | ||
|
||
__usage() { | ||
local op=$1 desc=$2 | ||
cat >&2 <<EOF | ||
USAGE: $(basename "$0") OPTIONS.. $op SUBOP SUBOP-ARGS.. | ||
$desc: | ||
$(cat) | ||
EOF | ||
} | ||
|
||
usage() { | ||
__usage "$@" | ||
exit 1 | ||
} | ||
|
||
fail() { | ||
echo "$*" >&2 | ||
exit 1 | ||
} | ||
|
||
fatal() { | ||
fail "FATAL: $*" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
usage_profile() { | ||
usage "profile" "Benchmark profile operations" <<EOF | ||
list List profile names (json) | ||
all-profiles | all All profile contents (json) | ||
compose NAME.. Create a profile composed from named profiles | ||
get NAME Get contents of named profile | ||
describe NAME Print a human description of a profile | ||
node-specs NAME PORT-BASE STAGGER-PORTS | ||
Print node specs JSON for the given profile; | ||
If STAGGER-PORTS is true, the assigned ports will | ||
be incrementally distinc for each node spec | ||
EOF | ||
} | ||
|
||
global_profile_eras=( | ||
shelley | ||
allegra | ||
mary | ||
) | ||
|
||
profile() { | ||
local op=${1:-list}; test $# -gt 0 && shift | ||
|
||
case "${op}" in | ||
list | names ) | ||
profile generate-all | jq 'keys' | ||
;; | ||
|
||
all-profiles | generate-all | all ) | ||
(cd "$global_ctl_basedir"; | ||
|
||
jq --argjson eras "$(to_jsonlist ${global_profile_eras[*]})" --null-input ' | ||
include "profiles"; | ||
$eras | ||
| map(profiles(.; null; null; [])) | ||
| add | ||
');; | ||
|
||
compose ) | ||
local profile_names="$@" | ||
|
||
profile generate-all | | ||
jq --argjson profile_names "$(to_jsonlist ${profile_names[*]})" ' | ||
. as $profiles | ||
| $profile_names | debug | ||
| map($profiles[.]) | ||
| add | ||
';; | ||
|
||
get ) | ||
local usage="USAGE: ctl profile get NAME" | ||
local name=${1:?$usage} | ||
|
||
profile generate-all | | ||
jq '.["'$name'"]' | ||
;; | ||
|
||
describe ) | ||
local usage="USAGE: ctl profile describe NAME" | ||
local name=${1:?$usage} | ||
|
||
profile get $name | | ||
(cd "$global_ctl_basedir"; | ||
|
||
jq ' | ||
include "derived"; | ||
profile_pretty_describe(.) | ||
' --raw-output);; | ||
|
||
node-specs ) | ||
local usage="USAGE: ctl profile node-specs NAME PORT-BASE STAGGER-PORTS" | ||
local name=${1:?$usage} | ||
local port_base=${2:?$usage} | ||
local stagger_ports=${3:?$usage} | ||
|
||
args=( | ||
--argjson port_base $port_base | ||
--argjson stagger_ports $stagger_ports | ||
) | ||
profile get $name | | ||
jq '. as $prof | ||
| $prof.composition.n_bft_hosts as $n_bfts | ||
| $prof.composition.n_pool_hosts as $n_pools | ||
| ([range(0; | ||
$n_bfts)] | ||
| map({ i: . | ||
, kind: "bft" | ||
})) | ||
as $bfts | ||
| ([range($n_bfts; | ||
$n_bfts + $n_pools)] | ||
| map({ i: . | ||
, kind: "pool" | ||
})) | ||
as $pools | ||
| ([range($n_bfts + $n_pools; | ||
$n_bfts + $n_pools + | ||
if $prof.composition.with_observer then 1 else 0 end)] | ||
| map({ i: . | ||
, kind: "observer" | ||
})) | ||
as $observers | ||
| ($bfts + $pools + $observers | ||
| map(. + | ||
{ name: "node-\(.["i"])" | ||
, isProducer: ([.kind == "bft", .kind == "pool"] | any) | ||
, port: | ||
(if $stagger_ports | ||
then $port_base + .i | ||
else $port_base | ||
end) | ||
})) | ||
| map({ key: .name, value: .}) | ||
| from_entries | ||
' "${args[@]}";; | ||
|
||
* ) usage_profile;; esac | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
usage_run() { | ||
usage "run" "Managing benchmark runs" <<EOF | ||
list List benchmark runs | ||
mkname Allocate a benchmark run name/id/tag | ||
create Create a benchmark run storage directory | ||
EOF | ||
} | ||
|
||
run() { | ||
local op=${1:-list}; test $# -gt 0 && shift | ||
|
||
case "${op}" in | ||
list ) | ||
(test -d "$global_ctl_runsdir" && cd "$global_ctl_runsdir" && find . -type d) | ||
;; | ||
|
||
mkname ) | ||
local batch=$1 | ||
local profjson=$2 | ||
echo "$(date +'%Y'-'%m'-'%d'-'%H.%M').$batch.$prof" | ||
;; | ||
|
||
create ) | ||
## Assumptions: | ||
## - genesis has been created | ||
## - the cluster is operating | ||
local name=$1 | ||
local batch=$2 | ||
local prof=$3 | ||
|
||
local dir=$runsdir/$name | ||
if test "$(realpath "$dir")" = test "$(realpath "$global_ctl_runsdir")" -o "$name" = '.' | ||
then fatal "bad, bad tag '$name'"; fi | ||
;; | ||
|
||
* ) usage_run;; esac | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
usage_supervisor() { | ||
usage "supervisor" "Managing local cluster" <<EOF | ||
assert-stopped Assert that 'supervisord' is not running | ||
is-running Test if 'supervisord' is running | ||
EOF | ||
} | ||
|
||
supervisor() { | ||
local op=${1:-$(usage_supervisor)}; shift | ||
|
||
case "${op}" in | ||
assert-stopped ) | ||
supervisor is-running && | ||
fail "Supervisord is already running. Please run 'stop-cluster' first!" || | ||
true;; | ||
is-running ) | ||
test "$(netstat -pltn 2>/dev/null | grep ':9001 ' | wc -l)" != "0";; | ||
* ) usage_supervisor;; esac | ||
} |
Oops, something went wrong.