Skip to content

Commit

Permalink
Merge pull request #533 from molgenis/test/component_projectexplorer_…
Browse files Browse the repository at this point in the history
…view

test: component projectexplorer view
  • Loading branch information
marikaris authored Nov 14, 2023
2 parents 54b402f + 067f13c commit 0c821e8
Show file tree
Hide file tree
Showing 7 changed files with 494 additions and 3 deletions.
2 changes: 1 addition & 1 deletion scripts/ops/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ We source the environment variables to not contaminate our current shell.

```bash
bash -c "source /etc/armadillo/acc.env ; ./test_armadilloctl.bash" || echo FAILED
```
```
176 changes: 176 additions & 0 deletions scripts/ops/armadilloctl.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#!/usr/bin/env zsh

CURL_OPTS=--silent

WARN="\033[33m"
ERR="\033[31m"
B="\033[0m"

function warning() {
echo -e "WARNING: ${WARN}${1}${B}"
}

function error() {
echo -e "ERROR: ${ERR}${1}${B}"
exit 1
}

function is_armadillo_running() {
cmd="${ARMADILLO_URL}"
curl $CURL_OPTS --request "GET" "${cmd}" > /dev/null || (error "Armadillo not running."; exit 1)
}

function get_profiles() {
cmd="$ARMADILLO_URL/ds-profiles"
profile_names=$(curl $CURL_OPTS --user "${CREDENTIALS}" --request "GET" --header "accept: application/json" "${cmd}" | jq -r '.[] | "\(.name)"')
}

function status {
if [ -z "$1" ]; then
error "$0 needs profile name. Or try ${0}All"
fi
name=$1

cmd="${ARMADILLO_URL}/ds-profiles/{$name}"
stats=$(curl $CURL_OPTS --user "${CREDENTIALS}" --request "GET" --header "accept: application/json" "${cmd}" | jq -r '"\(.name) = \(.container.status)"')
echo $stats
}

function start {
if [ -z "$1" ]; then
error "$0 needs profile name. Or try ${0}All"
fi

profile="$1"
cmd="$ARMADILLO_URL/ds-profiles/$profile/start"
echo "Starting '$profile' on $cmd"

curl $CURL_OPTS --user $CREDENTIALS --request "POST" "$cmd" --data ""
}

function stop {
if [ -z "$1" ]; then
error "$0 needs profile name. Or try ${0}All"
fi

profile="$1"
cmd="$ARMADILLO_URL/ds-profiles/$profile/stop"
echo "Stopping '$profile' on $cmd"

curl $CURL_OPTS --user $CREDENTIALS --request "POST" $cmd --data ""
}

function restart {
if [ -z "$1" ]; then
error "$0 needs profile name. Or try ${0}All"
fi

profile=$1
echo "Restarting $profile"
stop "$profile"
sleep 5
start "$profile"
sleep 5
status "$profile"

}

function is_auto_start() {
if [[ $ARMADILLO_PROFILES_AUTOSTART =~ (^|[[:space:]])$1($|[[:space:]]) ]]
then
return 0
else
return 1
fi
}

function doAll {
command=$1
get_profiles

echo "${profile_names}" | while read -r item; do
"$command" "${item}"
done
}

function statusAll() {
doAll status
}

function startAll() {
doAll start
}

function stopAll() {
doAll stop
}

function restartAll {
doAll stop
sleep 5
doAll start
}

function autoStart() {
get_profiles
echo "Auto starting ..."
echo "${profile_names}" | while read -r item
do
if is_auto_start "${item}"
then
start "${item}"
fi
done
}

function check_dependencies() {
if ! which jq > /dev/null ; then
echo "Please install jq for json parsing ... exiting"
exit 1
fi
}

function var_found() {
echo "Variable $1 found ..."
}

function var_empty() {
echo "Variable $1 not set! ... exiting"
exit 1
}

function all_set() {
[[ -n "$ARMADILLO_URL" ]] && var_found ARMADILLO_URL
[[ -z "$ARMADILLO_URL" ]] && var_empty ARMADILLO_URL

[[ -n "$ARMADILLO_ADMIN_USER" ]] && var_found ARMADILLO_ADMIN_USER
[[ -z "$ARMADILLO_ADMIN_USER" ]] && var_empty ARMADILLO_ADMIN_USER

[[ -n "$ARMADILLO_ADMIN_PASSWORD" ]] && var_found ARMADILLO_ADMIN_PASSWORD
[[ -z "$ARMADILLO_ADMIN_PASSWORD" ]] && var_empty ARMADILLO_ADMIN_PASSWORD

# Set to all if not set with value.
[[ -n "${ARMADILLO_PROFILES_AUTOSTART}" ]] && var_found ARMADILLO_PROFILES_AUTOSTART
[[ -z "${ARMADILLO_PROFILES_AUTOSTART}" ]] && ARMADILLO_PROFILES_AUTOSTART="__ALL__"

CREDENTIALS="${ARMADILLO_ADMIN_USER}:${ARMADILLO_ADMIN_PASSWORD}"

echo "\nArmadillo settings:"
echo " URL : ${ARMADILLO_URL}"
echo " ADMIN_USER : ${ARMADILLO_ADMIN_USER}"
echo " PROFILES_AUTOSTART : ${ARMADILLO_PROFILES_AUTOSTART}"
}

check_dependencies || exit

all_set || exit

is_armadillo_running || exit

get_profiles

if [[ "$1" =~ ^(status|start|stop|restart|statusAll|startAll|stopAll|restartAll|autoStart)$ ]]; then
"$@"
else
echo "\nPlease provide one of the following argument: status | start | stop | restart | statusAll | startAll | stopAll | restartAll | autoStart"
fi
2 changes: 1 addition & 1 deletion scripts/ops/env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export ARMADILLO_ADMIN_USER=admin
export ARMADILLO_ADMIN_PASSWORD=admin

# Space separated values between double quotes. Leaving empty falls back to all profiles.
export ARMADILLO_PROFILES_AUTOSTART="default rock"
export ARMADILLO_PROFILES_AUTOSTART="default rock"
67 changes: 67 additions & 0 deletions scripts/ops/test_armadilloctl.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env zsh

OUT=/dev/stdout
if [ -z "$1" ]; then
OUT="/dev/null"
fi

function usage() {
echo 'zsh -c "source dev.env ; ./test_armadilloctl.zsh" || echo FAILED'
}

function colors() {
for c in {0..255}; do
printf "\033[48;5;%sm%3d\033[0m " "$c" "$c"
if (( c == 15 )) || (( c > 15 )) && (( (c-15) % 6 == 0 )); then
printf "\n"
fi
done
}

OK="\033[32m"
WARN="\033[33m"
ERR="\033[31m"
B="\033[0m"

function error() {
echo -e "TEST:: ERROR: ${ERR}${1}${B}"
}

function warning() {
echo -e "TEST:: WARNING: ${WARN}${1}${B}"
}

function success() {
echo -e "TEST:: SUCCES: ${OK}${1}${B}"
}


function failed() {
warn $0
}
function do_sleep() {
warning "Pausing for $1 seconds before '$2'."
sleep "$1"
echo "..."
}

error "NOTE: controller exit values are incomplete ... needs eyes"
warning "Make sure Armadillo is running"

./armadilloctl.zsh > $OUT || success "Needs a command."

./armadilloctl.zsh status > $OUT || success "status needs profile name"
./armadilloctl.zsh statusAll > $OUT && success "statusAll needs running Armadillo"

./armadilloctl.zsh stopAll > $OUT && success "stopAll needs running Armadillo"

do_sleep 5 "autoStart"
./armadilloctl.zsh autoStart > $OUT && success "autoStart needs running Armadillo"

do_sleep 5 "startAll"
./armadilloctl.zsh startAll > $OUT && success "startAll needs running Armadillo"

do_sleep 5 "restartAll"
./armadilloctl.zsh restartAll > $OUT && success "restartAll needs running Armadillo"

# colors
2 changes: 1 addition & 1 deletion ui/src/views/ProjectsExplorer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export default defineComponent({
this.successMessage = `Successfully deleted file [${file}] from directory [${folder}] of project: [${this.projectId}]`;
})
.catch((error) => {
this.errorMessage = error;
this.errorMessage = `${error}`;
});
},
reloadProject(callback: Function | undefined = undefined) {
Expand Down
2 changes: 2 additions & 0 deletions ui/tests/unit/components/SimpleTable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ describe("SimpleTable", () => {
props: {
data: data,
maxWidth: 600,
nCols: Object.keys(data[0]).length,
nRows: data.length
},
});
});
Expand Down
Loading

0 comments on commit 0c821e8

Please sign in to comment.