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

sda-admin cli #1026

Merged
merged 33 commits into from
Sep 18, 2024
Merged

sda-admin cli #1026

merged 33 commits into from
Sep 18, 2024

Conversation

nanjiangshu
Copy link
Contributor

Related issue(s) and PR(s)
This PR closes #1007

Description
The command line tool that can talk to SDA API endpoints. It provides functionalities to list users and files, ingest and set accession IDs for files, and create or release datasets.

How to test

  1. At the root of the repo, start the stack by running
make build-all
PR_NUMBER=$(/usr/bin/date '+%F')  docker compose -f .github/integration/sda-s3-integration.yml run integration_test
  1. Set the ENVs by
export ACCESS_TOKEN=$(curl -s -k http://localhost:8080/tokens | jq -r '.[0]')
export API_HOST=http://localhost:8090
  1. Build the executable in the folder sda-admin by
go build 
  1. Test various functionalities
# list all users
./sda-admin list users  

# list all files for the user [email protected]
./sda-admin list files  

# list all files for the user [email protected]
./sda-admin list files -user [email protected] 

# trigger the ingestion of a given file 
./sda-admin file ingest --filepath requester_demo.org/data/file1.c4gh --user [email protected]  

# assign an accession ID to a file
./sda-admin file accession --filepath requester_demo.org/data/file1.c4gh  --user [email protected]   --accession-id my-id1 

# create a dataset from a list of accession IDs and the dataset ID
./sda-admin dataset create --dataset-id dataset001 my-id1 my-id2 

# # release a dataset for downloading
./sda-admin dataset release --dataset-id dataset001 

@nanjiangshu nanjiangshu force-pushed the feature/sda-admin-cli branch from a3868fd to 76763c9 Compare September 3, 2024 14:04
@nanjiangshu nanjiangshu requested a review from a team September 3, 2024 14:05
Copy link
Collaborator

@jbygdell jbygdell left a comment

Choose a reason for hiding this comment

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

Didn't go through all but added a few pointers that needs to go in overall.
Secondly use the linting function often so you don't end up with simple mistakes.

sda-admin/list/list.go Outdated Show resolved Hide resolved
sda-admin/list/list_test.go Outdated Show resolved Hide resolved
sda-admin/list/list_test.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/dataset/dataset.go Outdated Show resolved Hide resolved
sda-admin/dataset/dataset.go Show resolved Hide resolved
sda-admin/file/file.go Outdated Show resolved Hide resolved
Copy link
Contributor

@MalinAhlberg MalinAhlberg left a comment

Choose a reason for hiding this comment

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

Really well done, @nanjiangshu!
I added some minor comments. Also, shouldn't .github/workflows/test.yml be updated so that the tests are run?

sda-admin/helpers/helpers.go Outdated Show resolved Hide resolved
sda-admin/helpers/helpers.go Outdated Show resolved Hide resolved
sda-admin/helpers/helpers.go Outdated Show resolved Hide resolved
Copy link
Member

@viklund viklund left a comment

Choose a reason for hiding this comment

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

I think commands should either be <verb> <noun> or <noun> <verb>. Currently there's a mix of both.

I suggest not having list as a toplevel command. So refactor list files and list users into files list and users list.

@nanjiangshu nanjiangshu force-pushed the feature/sda-admin-cli branch 2 times, most recently from 8bac427 to ab22a90 Compare September 10, 2024 21:04
@nanjiangshu
Copy link
Contributor Author

Really well done, @nanjiangshu! I added some minor comments. Also, shouldn't .github/workflows/test.yml be updated so that the tests are run?

Good catch @MalinAhlberg , I added in the commit ab22a90

@nanjiangshu
Copy link
Contributor Author

I think commands should either be <verb> <noun> or <noun> <verb>. Currently there's a mix of both.

I suggest not having list as a toplevel command. So refactor list files and list users into files list and users list.

Good suggestion @viklund . The syntax of the commands is now consistent with the format . I use file instead of files and set-accession instead of session.

sda-admin user list
sda-admin file list
sda-admin file ingest
sda-admin file set-accession
sda-admin dataset create
sda-admin dataset release  

Copy link
Collaborator

@jbygdell jbygdell left a comment

Choose a reason for hiding this comment

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

  • Add this folder to the code-linter action
  • Add an option in the Makefile to build the app, both separate and as part of the build-all step
  • Add an option in the Makefile to run the linter for this folder

sda-admin/README.md Outdated Show resolved Hide resolved
sda-admin/README.md Outdated Show resolved Hide resolved
sda-admin/helpers/helpers.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
@MalinAhlberg
Copy link
Contributor

I tested this a bit, and I think it's a really nice way to work with the pipeline! Also, it seems to be a really good way to run into bugs, by being a maybe-not-so-organized user. I quickly ran into bug #1027, and also managed to run into something similar for verify/postgres. They keep logging even though I did not get any error from sda-admin:

postgres  | 2024-09-12 13:36:22.248 UTC [80] ERROR:  duplicate key value violates unique constraint "unique_checksum"
...
verify    | {"level":"error","msg":"SetVerified failed, reason: (pq: duplicate key value violates unique constraint \"unique_checksum\")","time":"2024-09-12T13:36:22Z"}

I'm not sure what I did wrong.
When trying to create a dataset with incorrect file IDs (which could happen if you for example mistype), no error is reported but I was not able to continue after that, all commands returned errors such as

Error: failed to [...], reason: failed to send request, reason: Post "http://localhost:8090/file/accession": EOF

@jbygdell
Copy link
Collaborator

I tested this a bit, and I think it's a really nice way to work with the pipeline! Also, it seems to be a really good way to run into bugs, by being a maybe-not-so-organized user. I quickly ran into bug #1027, and also managed to run into something similar for verify/postgres. They keep logging even though I did not get any error from sda-admin:

postgres  | 2024-09-12 13:36:22.248 UTC [80] ERROR:  duplicate key value violates unique constraint "unique_checksum"
...
verify    | {"level":"error","msg":"SetVerified failed, reason: (pq: duplicate key value violates unique constraint \"unique_checksum\")","time":"2024-09-12T13:36:22Z"}

All of that needs to be solved in the API. There are a few steps we need to double check.

sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/dataset/dataset.go Outdated Show resolved Hide resolved
@MalinAhlberg
Copy link
Contributor

All of that needs to be solved in the API. There are a few steps we need to double check.

I created #1037 and #1038.

@nanjiangshu nanjiangshu force-pushed the feature/sda-admin-cli branch 3 times, most recently from e9e9ac9 to c85480e Compare September 14, 2024 09:04
viklund
viklund previously approved these changes Sep 16, 2024
Copy link
Collaborator

@jbygdell jbygdell left a comment

Choose a reason for hiding this comment

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

In order to test that the messages arrive in the correct stream (stderr or stdout) you can use this: /sda-admin -uri example.com -token fooBar help dataset 2>stderr.log 1>stdout.log

sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
sda-admin/main.go Outdated Show resolved Hide resolved
@jbygdell jbygdell requested a review from a team September 18, 2024 07:27
Copy link
Member

@viklund viklund left a comment

Choose a reason for hiding this comment

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

@jbygdell jbygdell added this pull request to the merge queue Sep 18, 2024
Merged via the queue into main with commit 26fc9fe Sep 18, 2024
26 checks passed
@jbygdell jbygdell deleted the feature/sda-admin-cli branch September 18, 2024 08:08
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.

Migrate the sda-admin script to a go cli tool
4 participants