Skip to content

Commit

Permalink
WIP CAD-2839 supervisord | ctl: cluster control tool
Browse files Browse the repository at this point in the history
  • Loading branch information
deepfire committed Apr 8, 2021
1 parent d7fc17f commit 7f39497
Show file tree
Hide file tree
Showing 22 changed files with 558 additions and 81 deletions.
6 changes: 3 additions & 3 deletions Makefile
Expand Up @@ -34,16 +34,16 @@ test-chairmans-cluster:
@scripts/chairmans-cluster/cluster-test.sh

profiles:
@jq . $$(nix-build -A profiles)
@./nix/supervisord-cluster/ctl dump-profiles

profile-names:
@jq keys $$(nix-build -A profiles)
@./nix/supervisord-cluster/ctl profile-names

CLUSTER_PROFILE = default-mary
CLUSTER_ARGS_EXTRA =

cluster-shell:
nix-shell --max-jobs 8 --cores 0 --command 'start-cluster; return' --argstr clusterProfile ${CLUSTER_PROFILE} --command 'start-cluster ${CLUSTER_ARGS_EXTRA}; return'
nix-shell --max-jobs 8 --cores 0 --arg 'autoStartCluster' true --argstr clusterProfile ${CLUSTER_PROFILE}

cluster-shell-trace: CLUSTER_ARGS_EXTRA = --trace
large-state-cluster-shell-trace: CLUSTER_ARGS_EXTRA = --trace
Expand Down
3 changes: 1 addition & 2 deletions nix/pkgs.nix
Expand Up @@ -67,8 +67,7 @@ pkgs: _: with pkgs;
inherit (cardanoNodeHaskellPackages.ouroboros-consensus-byron.components.exes) db-converter;
inherit (cardanoNodeHaskellPackages.network-mux.components.exes) cardano-ping;

mkCluster = cfg: callPackage ./supervisord-cluster
(lib.traceValSeqN 2 cfg);
mkCluster = cfg: callPackage ./supervisord-cluster cfg;
cardanolib-py = callPackage ./cardanolib-py {};

clusterTests = import ./supervisord-cluster/tests { inherit pkgs; };
Expand Down
File renamed without changes.
File renamed without changes.
76 changes: 76 additions & 0 deletions nix/supervisord-cluster/ctl/ctl
@@ -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 "$@"
31 changes: 31 additions & 0 deletions nix/supervisord-cluster/ctl/ctl-lib.sh
@@ -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: $*"
}
119 changes: 119 additions & 0 deletions nix/supervisord-cluster/ctl/ctl-profile.sh
@@ -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
}
37 changes: 37 additions & 0 deletions nix/supervisord-cluster/ctl/ctl-run.sh
@@ -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
}
19 changes: 19 additions & 0 deletions nix/supervisord-cluster/ctl/ctl-supervisor.sh
@@ -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
}

0 comments on commit 7f39497

Please sign in to comment.