From 2a5a133cf7abb005c6180aef8a221b59a497ede9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20D=C3=ADaz?= Date: Mon, 8 Apr 2019 19:21:09 +0200 Subject: [PATCH] Update startup scripts to support new cli options --- tests/start_agent | 92 ++++++++++++++++++++++++++ tests/start_all_xterm | 26 ++++++++ tests/start_server | 149 +++++++++++++++++------------------------- 3 files changed, 179 insertions(+), 88 deletions(-) create mode 100755 tests/start_agent create mode 100755 tests/start_all_xterm diff --git a/tests/start_agent b/tests/start_agent new file mode 100755 index 000000000..3dc8b2977 --- /dev/null +++ b/tests/start_agent @@ -0,0 +1,92 @@ +#!/bin/bash + +# Copyright 2018-2019 Banco Bilbao Vizcaya Argentaria, S.A. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +CGO_LDFLAGS_ALLOW='.*' +QED="go run $GOPATH/src/github.com/bbva/qed/main.go" + +# Agent options +AGENT_CONFIG=() +AGENT_CONFIG+=('--log debug') +AGENT_CONFIG+=('--bind-addr 127.0.0.1:810${i}') +AGENT_CONFIG+=('--metrics-addr 127.0.0.2:1810${i}') +AGENT_CONFIG+=('--start-join 127.0.0.1:8400') + +# Notifier options +NOTIFIER_CONFIG=() +NOTIFIER_CONFIG+=('--notifier-servers http://127.0.0.1:8888') + +# Snapshot store options +STORE_CONFIG=() +STORE_CONFIG+=('--store-servers http://127.0.0.1:8888') + +# Task manager options +TASKS_CONFIG=() +TASKS_CONFIG+=("") + +# QED client options +QED_CONFIG=() +QED_CONFIG+=("--qed-endpoints http://127.0.0.1:8800") + + +MONITOR_CONFIG=("${AGENT_CONFIG[@]}" "${NOTIFIER_CONFIG[@]}" "${STORE_CONFIG[@]}" "${TASKS_CONFIG[@]}" "${QED_CONFIG[@]}") +MONITOR_CONFIG+=("--role monitor") +MONITOR_CONFIG+=("--node-name monitor${i}") + +PUBLISHER_CONFIG=("${AGENT_CONFIG[@]}" "${NOTIFIER_CONFIG[@]}" "${STORE_CONFIG[@]}" "${TASKS_CONFIG[@]}" ) +PUBLISHER_CONFIG+=("--role publisher") +PUBLISHER_CONFIG+=("--node-name publisher${i}") + +AUDITOR_CONFIG=("${AGENT_CONFIG[@]}" "${NOTIFIER_CONFIG[@]}" "${STORE_CONFIG[@]}" "${TASKS_CONFIG[@]}" ) +AUDITOR_CONFIG+=("--role auditor") +AUDITOR_CONFIG+=("--node-name auditor${i}") + +start() { + local type="$1" + local id="$2" + + case "$type" in + "monitor") + conf=$(echo "${MONITOR_CONFIG[@]}"| i=$id envsubst ) + ;; + "publisher") + conf=$(echo "${PUBLISHER_CONFIG[@]}"| i=$id envsubst ) + ;; + "auditor") + conf=$(echo "${AUDITOR_CONFIG[@]}"| i=$id envsubst ) + ;; + *) + echo Unknown agent type. Please choose monitor, publisher or auditor + return -1 + ;; + esac + echo CONFIG $conf + $QED agent $type $conf & + pids+=($!) +} + +pids=() + +count=0 +for agent in "$@" +do + echo Starting "$agent" "$count" + start "$agent" "$count" + count=$((count+1)) +done + +for pid in ${pids[*]}; do + echo waiting for pid $pid + wait $pid +done diff --git a/tests/start_all_xterm b/tests/start_all_xterm new file mode 100755 index 000000000..c67cf2c8a --- /dev/null +++ b/tests/start_all_xterm @@ -0,0 +1,26 @@ +#!/bin/bash + +# Copyright 2018-2019 Banco Bilbao Vizcaya Argentaria, S.A. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# Starts a local test setup + +xterm -hold -e "go run test_service.go" & + +xterm -hold -e "bash start_server" & + +sleep 3s + +xterm -hold -e "bash start_agent monitor publisher" & + diff --git a/tests/start_server b/tests/start_server index ca180976b..856d08ee3 100755 --- a/tests/start_server +++ b/tests/start_server @@ -1,90 +1,63 @@ -#!/usr/bin/env sh - -# Copyright 2018-2019 Banco Bilbao Vizcaya Argentaria, S.A. - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -echo "export CLUSTER_SIZE=N [2|4] env variable to execute the benchmark in replica mode. N number of folowers" -echo "export PROFILING=true env variable to enable go profiling" -echo "export TLS=true to allow https" - -tdir=$(mktemp -d /var/tmp/demo.XXX) -certs="/var/tmp/certs" - -LOCAL_IP=127.0.0.1 -if [ ! -z "$PROFILING" ]; then - echo "PROFILING=enabled" - mkdir -p results - PROFILING=--profiling -else - echo PROFILING=disabled +#!/bin/bash + +# Copyright 2018-2019 Banco Bilbao Vizcaya Argentaria, S.A. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Deployment options +keyFile="/var/tmp/id_ed25519" + +if [ ! -f "$keyFile" ]; then + echo Create id_ed25519 key + echo -e 'y\n' | ssh-keygen -t ed25519 -N '' -f /var/tmp/id_ed25519 fi -if [ ! -z "$TLS" ]; then - TLS="--certificate ${certs}/server.crt \ --certificate-key ${certs}/server.key" -else - echo "TLS=disabled" -fi - -leader() { - mkdir -p ${tdir}/0/ - - go run ../main.go start \ - -k test_key \ - -p ${tdir}/0/ \ - --node-id leader \ - --http-addr ${LOCAL_IP}:8800 \ - --keypath ${certs}/id_ed25519 \ - --gossip-addr ${LOCAL_IP}:8400 \ - -l error \ - $TLS \ - $PROFILING \ - & -} - -follower() { - mkdir -p ${tdir}/$1 - - go run ../main.go start \ - -k test_key \ - --node-id follower_$1 \ - -p ${tdir}/$1 \ - --keypath ${certs}/id_ed25519 \ - -l error \ - --http-addr ${LOCAL_IP}:880$1 \ - --mgmt-addr ${LOCAL_IP}:870$1 \ - --metrics-addr ${LOCAL_IP}:860$1 \ - --raft-addr ${LOCAL_IP}:850$1 \ - --gossip-addr ${LOCAL_IP}:840$1 \ - --join-addr ${LOCAL_IP}:8700 \ - --gossip-join-addr ${LOCAL_IP}:8400 \ - $TLS \ - $PROFILING \ - & -} - -if [ -z "$CLUSTER_SIZE" ] -then - echo '>>>> Starting single node...' - leader -else - echo '>>>> Starting cluster mode...' - leader - sleep 5 - echo '>>>> Starting followers' - for i in $(seq 1 $CLUSTER_SIZE); do - follower ${i} - done -fi -sleep 10 -echo '>>>> done.' +CGO_LDFLAGS_ALLOW='.*' +QED="go run $GOPATH/src/github.com/bbva/qed/main.go" + +# Server options +LEADER_CONFIG=() +LEADER_CONFIG+=('--log debug') +LEADER_CONFIG+=('--api-key key') +LEADER_CONFIG+=('--db-path /var/tmp/qed${i}/db') +LEADER_CONFIG+=('--gossip-addr 127.0.0.1:840${i}') +LEADER_CONFIG+=('--http-addr 127.0.0.1:880${i}') +LEADER_CONFIG+=('--metrics-addr 127.0.0.1:860${i}') +LEADER_CONFIG+=('--mgmt-addr 127.0.0.1:870${i}') +LEADER_CONFIG+=('--node-id server${i}') +LEADER_CONFIG+=('--private-key-path /var/tmp/id_ed25519') +LEADER_CONFIG+=('--raft-addr 127.0.0.1:850${i}') +LEADER_CONFIG+=('--raft-path /var/tmp/qed${i}/wal') + +FOLLOWER_CONFIG=("${LEADER_CONFIG[@]}") +FOLLOWER_CONFIG+=("--gossip-join-addr 127.0.0.1:8400") + +pids=() + +mkdir -p /var/tmp/qed0/server.log +leader=$(echo ${LEADER_CONFIG[@]} | i=0 envsubst ) +$QED server start $leader 2>&1 | tee /var/tmp/qed0/server.log & +pids+=($!) +sleep 3s + +for id in $(seq 1 1 $1); do + mkdir -p /var/tmp/qed${id} + follower=$(echo ${FOLLOWER_CONFIG[@]} | i=$id envsubst ) + $QED server start $follower 2>&1 | tee /var/tmp/qed${id}/server.log & + pids+=($!) + sleep 3s +done + +for pid in ${pids[*]}; do + echo waiting for pid $pid + wait $pid +done