Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: add demo functionality to Reana cli script #19

Merged
merged 1 commit into from
May 4, 2017

Conversation

hjhsalo
Copy link
Contributor

@hjhsalo hjhsalo commented Apr 27, 2017

  • add cli command to run reana-demo-helloworld example easily
    reana run helloworld

Signed-off-by: Harri Hirvonsalo harri.hirvonsalo@cern.ch

@hjhsalo
Copy link
Contributor Author

hjhsalo commented Apr 27, 2017

For now, hardcoded to run only helloworld-workflow with 'atlas' as experiment.

Doesn't follow the run-syntax described in reanahub/reana-demo-helloworld#2 as I feel that this is something we will have to discuss more before implementing it; what is the actual input of reana run (file? folder?) and how to submit the workflow to workflow-controller, etc.

scripts/reana Outdated
@@ -135,6 +222,7 @@ usage () {
echo " install-minikube Installs and starts local minikube instance"
echo " init Initialize REANA system"
echo " down Delete REANA components"
echo " demo helloworld Runs a helloworld demo"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run helloworld so that we are ready for the future run myanalysis without having to change the CLI.

scripts/reana Outdated
#kubectl logs -f $(kubectl get pods | grep -Po 'yadage-atlas-worker[^ ]+')

# Open workflow-monitor web-interface
firefox "http://$controller_url/$workflow_id"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to take commands like firefox out of the script (and use them only in docs).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to open and xdg-open.

.gitignore Outdated
# IntelliJ project files
.idea
*.iml
out
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to check if this is copy-paste error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legit but not needed. I'll remove it.
IntelliJ -specific folder for generated .class files and artifacts

scripts/reana Outdated
# The code to check for flags is from http://stackoverflow.com/q/2875424
# Not sure if this is a good way or not.
flag_verbose=$(echo "$*" | grep -e "--verbose" -o)
flag_devel=$(echo "$*" | grep -e "--devel" -o)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe simple quotes to prevent command execution:

$ echo "$(date)"
Thu 27 Apr 18:40:02 CEST 2017
$ echo '$(date)'
$(date)

or rely on the flag being present last in $3 some place, or use environment variable...

Copy link
Contributor Author

@hjhsalo hjhsalo Apr 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I change this to flag_devel=$(echo $* | grep -e "--devel" -o), shellcheck complains:

  • SC2048: Use "$@" (with quotes) to prevent whitespace problems.
  • SC2086: Double quote to prevent globbing and word splitting.

With flag_devel=$(echo $@ | grep -e "--devel" -o) shellcheck complains:

  • SC2068: Double quote array expansions, otherwise they're like $* and break on spaces.

If I use flag_devel=$(echo "$@" | grep -e "--devel" -o) shellcheck doesn't complain.

I understand your point though.

I don't know enough about shell scripting to be able to say if any of these is good.

Should we change from sh to bash to use if [[ "$@" != *"--devel"* ]]; then if that would be a better alternative?

scripts/reana Outdated
-H "Content-Type: application/json" \
-X POST -d \
"{\"experiment\":\"atlas\",
\"toplevel\":\"github:diegodelemos/reana-demo-helloworld@2-add-helloworld-workflow\",
Copy link
Member

@tiborsimko tiborsimko Apr 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diegodelemos/... image location not needed anymore? Use central one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see reanahub/reana-demo-helloworld#4. Once it is merged \"toplevel\":\"github:diegodelemos/reana-demo-helloworld@2-add-helloworld-workflow\" should be changed for \"toplevel\":\"github:reanahub/reana-demo-helloworld\".

scripts/reana Outdated

if [ "$flag_verbose" != "" ]; then
echo "[INFO] Open http://$controller_url/$workflow_id to see visual representation of your workflow and it's progress."
echo "[INFO] You can 'cat' or 'tail' /reana/atlas/$workflow_id/yadage/helloworld/greetings.txt -file"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of reanahub/reana-workflow-engine-yadage#20 only ATLAS workflows are currently working, however, it would be nice to use something line $(experiment) instead of the string atlas. Since in reana-resources-X we are following the pattern /reana/<experiment> (see here) it would match perfectly

scripts/reana Outdated
echo "[INFO] Open http://$controller_url/$workflow_id to see visual representation of your workflow and it's progress."
echo "[INFO] You can 'cat' or 'tail' /reana/atlas/$workflow_id/yadage/helloworld/greetings.txt -file"
echo " from shared storage of REANA cluster to see how helloworld workflow progresses."
echo "[INFO] (e.g. minikube ssh \"tail -c+1 -F /reana/atlas/$workflow_id/yadage/helloworld/greetings.txt\")"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(experiment) rather than atlas

scripts/reana Outdated
echo ""
echo "Workflow_id: $workflow_id"
echo "Monitor: http://$controller_url/$workflow_id"
echo "Output: /reana/atlas/$workflow_id/yadage/helloworld/greetings.txt"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same about atlas

scripts/reana Outdated
# Tail output-file of the workflow
echo "[INFO] Tailing...hit Ctrl+C when done."
echo ""
minikube ssh "tail -c+1 -F /reana/atlas/$workflow_id/yadage/helloworld/greetings.txt"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same about atlas

scripts/reana Outdated
\"preset_pars\": {\"name\": \"J.Doe\", \"delay\": \"2\"}
}" \
http://"$(reana get reana-workflow-controller)"/yadage \
| grep -oP '(?<="workflow_id": ")[^"]*')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-P option is not available in BSD, so something like grep -oE '"workflow_id"\:[[:space:]]*\"[^\"]*\"'| cut -d ":" -f 2 | tr -d "\"" would support both GNU and BSD

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't update yet. I will look into this next week.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not yet update, it prevents successful execution on Mac

scripts/reana Outdated

if [ "$flag_devel" != "" ]; then
# Start tailing of job-controller logs
#kubectl logs -f $(kubectl get pods | grep -Po 'job-controller[^ ]+')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see more practical to have some developer documentation where we explain which logs would be nice to follow as well as which endpoints should be opened. If you use i3, tmux or something else you have your own setup for doing this kind of things

@hjhsalo hjhsalo force-pushed the demo-option-for-cli branch 2 times, most recently from ee2b97c to 5c8b4ab Compare April 28, 2017 16:41
echo "Output: /reana/$experiment/$workflow_id/yadage/helloworld/greetings.txt"
echo ""

if [ "$flag_devel" != "" ]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I get rid of the whole --devel part of the code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could leave it there if we find it useful for development, all in all it is an option..

scripts/reana Outdated

# The code to check for flags is from http://stackoverflow.com/q/2875424
# Not sure if this is a good way (POSIX compliant?) or not.
flag_verbose=$(echo "$@" | grep -e "--verbose" -o)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I change this to flag_devel=$(echo $* | grep -e "--devel" -o), shellcheck complains:

  • SC2048: Use "$@" (with quotes) to prevent whitespace problems.
  • SC2086: Double quote to prevent globbing and word splitting.

With flag_devel=$(echo $@ | grep -e "--devel" -o) shellcheck complains:

  • SC2068: Double quote array expansions, otherwise they're like $* and break on spaces.

If I use flag_devel=$(echo "$@" | grep -e "--devel" -o) shellcheck doesn't complain.

I understand your point though.

I don't know enough about shell scripting to be able to say if any of these is good.

Should we change from sh to bash to use if [[ "$@" != *"--devel"* ]]; then if that would be a better alternative?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flag_devel=$(echo "$@" | grep -qe "--\<verbose\>")
flag_devel=$(echo "$@" | grep -qe "--\<devel\>")
might be better because current one would allow providing --dev or --verbo. So we could stick to sh which is more standard

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got your point. Have to admit that I'm not sure if I'm actually restricting matches with -o. It should show only the part which matches pattern.
Tested based on suggestion and I couldn't get grep -qe "--\<verbose\>" to work.
How about flag_verbose=$(echo "$@" | grep -oe "--\<verbose\>")?

scripts/reana Outdated
@@ -26,6 +26,8 @@ reana-workflow-monitor
reana-message-broker
reana-workflow-engine-yadage"

experiment_list=$(find ./configuration-manifests/namespaces/ -name \*.yaml -printf '%f\n' | sed -e 's/\.yaml$//')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I just use hardcoded experiment list?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be ok, in the future we can grab it from configuration

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which is what you actually do, sorry about that 🙃

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-printf is not supported on BSD, something like:
find ./configuration-manifests/namespaces/ -name \*.yaml -type f -exec basename {} .yaml ";"
should be more portable

scripts/reana Outdated
if [ "$3" = "-e" ]; then
experiment=$4
else
experiment=${REANA_EXPERIMENT-}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the trailing - necessary? In -h it doesn't include it

Runs a helloworld demo in namespace of
specified experiment (e.g. '-e atlas').
Specify experiment with '-e' flag or 
$REANA_EXPERIMENT environment variable.'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quote from some SO-post:
"${var:-} and ${var-} mean different things. ${var:-} will expand to empty string if var unset or null and ${var-} will expand to empty string only if unset"
BUT now that I think of it, it might be better with ${REANA_EXPERIMENT:-} so it will default to empty string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we warn the user to either set -e <experiment> or the REANA_EXPERIMENT env var? otherwise the request could contain an empty string

@hjhsalo hjhsalo force-pushed the demo-option-for-cli branch 3 times, most recently from 7ba0d4f to d7f22a1 Compare May 3, 2017 12:46
* add cli command to run reana-demo-helloworld example easily
  `reana run helloworld`
* prepare for run syntax ('reana run myworkflow') described in
  reanahub/reana-demo-helloworld/issues/2

Signed-off-by: Harri Hirvonsalo <harri.hirvonsalo@cern.ch>
Copy link
Member

@diegodelemos diegodelemos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@diegodelemos diegodelemos merged commit b37ccfe into reanahub:master May 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants