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

FileManager microservice Rust skel #27

Merged
merged 18 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
2d59f66
Manually-written OpenAPI client API definition for filemanager micros…
brainstorm Jun 9, 2023
380130b
Testing postman2openapi conversion via https://joolfe.github.io/postm…
brainstorm Jun 9, 2023
0d89881
Relocate ICAv1 openapi assets
brainstorm Jun 9, 2023
1e05e52
Basic microservices API design workflow outlined
brainstorm Jun 9, 2023
7ba229b
Specify postman collection converter in README, as suggested in offic…
brainstorm Jun 9, 2023
bb0b192
Add first postman-collection outogenerated OpenAPI 3.0.0
brainstorm Jun 9, 2023
27428cb
Backpedaling on crafting OpenAPI definitions by hand, they should com…
brainstorm Jun 12, 2023
0c7cc9e
Add barebones Rust example of an Axum+Utoipa(OpenAPI)+tracing example…
brainstorm Jun 12, 2023
f192536
@reisingerf, test it out with those instructions, let's see if there …
brainstorm Jun 13, 2023
d49d8ff
FileManager->File rename as suggested by Florian
brainstorm Jun 13, 2023
a570ad2
[ci skip] Minor rename fixes
brainstorm Jun 13, 2023
852806c
Restructure openapi folder a bit more to not break docker-compose, ad…
brainstorm Jun 13, 2023
1070df4
Sketch some onboarding docs for rust-api microservices
brainstorm Jun 13, 2023
b77fd6a
FileQuery struct might not be required after all? Simplifying...
brainstorm Jun 13, 2023
c8a276f
Add sqlx types such as datetime for db types matching
brainstorm Jun 13, 2023
ffd6520
First barebones DB query from data_portal's GDSFile table. Needs prop…
brainstorm Jun 13, 2023
ca8e669
Add migrations support, still keeping it ORM-less for now
brainstorm Jun 13, 2023
7915148
Add some Rust tutorial hints for the team
brainstorm Jun 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ cdk.context.json
!.yarn/versions

*.sqlite3

# SQL dumps, data, etc...

data/
35 changes: 23 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,64 +53,75 @@ services:
image: stoplight/prism:4
platform: linux/amd64
container_name: orcabus_wes
command: mock -d -h 0.0.0.0 "/openapi/wes.json"
command: mock -d -h 0.0.0.0 "/openapi/ica/v1/wes.json"
restart: always
ports:
- "4010:4010"
volumes:
- ./openapi:/openapi
- ./openapi/ica:/openapi/ica

tes:
image: stoplight/prism:4
platform: linux/amd64
container_name: orcabus_tes
command: mock -d -h 0.0.0.0 "/openapi/tes.json"
command: mock -d -h 0.0.0.0 "/openapi/ica/v1/tes.json"
restart: always
ports:
- "4011:4010"
volumes:
- ./openapi:/openapi
- ./openapi/ica:/openapi/ica

gds:
image: stoplight/prism:4
platform: linux/amd64
container_name: orcabus_gds
command: mock -d -h 0.0.0.0 "/openapi/gds.json"
command: mock -d -h 0.0.0.0 "/openapi/ica/v1/gds.json"
restart: always
ports:
- "4012:4010"
volumes:
- ./openapi:/openapi
- ./openapi/ica:/openapi/ica

ens:
image: stoplight/prism:4
platform: linux/amd64
container_name: orcabus_ens
command: mock -d -h 0.0.0.0 "/openapi/ens.json"
command: mock -d -h 0.0.0.0 "/openapi/ica/v1/ens.json"
restart: always
ports:
- "4013:4010"
volumes:
- ./openapi:/openapi
- ./openapi/ica:/openapi/ica

console:
image: stoplight/prism:4
platform: linux/amd64
container_name: orcabus_console
command: mock -d -h 0.0.0.0 "/openapi/console.json"
command: mock -d -h 0.0.0.0 "/openapi/ica/v1/console.json"
restart: always
ports:
- "4014:4010"
volumes:
- ./openapi:/openapi
- ./openapi/ica:/openapi/ica

v2:
image: stoplight/prism:4
platform: linux/amd64
container_name: orcabus_ica_v2
command: mock -d -h 0.0.0.0 "/openapi/openapi_public.yaml"
command: mock -d -h 0.0.0.0 "/openapi/ica/v2/openapi_public.yaml"
restart: always
ports:
- "4015:4010"
volumes:
- ./openapi:/openapi
- ./openapi/ica:/openapi/ica

filemanager:
image: stoplight/prism:4
platform: linux/amd64
container_name: orcabus_filemanager
command: mock -d -h 0.0.0.0 "/openapi/orcabus/filemanager.json"
restart: always
ports:
- "4016:4010"
volumes:
- ./openapi/orcabus:/openapi/orcabus
54 changes: 54 additions & 0 deletions docs/developer/RUST_API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Rust API Profile

- Use this profile if your microservice needs: ORM, API, LAMBDA, SQS

## App

- Consider building a microservice: `rust-api`

## Quickstart

Assuming you already have the Rust toolchain installed on your system, otherwise install it via:

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

For development edit and compile loop, use the [`cargo-watch`](https://crates.io/crates/cargo-watch) crate:

```
$ cargo install cargo-watch # if not installed previously
$ cargo watch -c -w src -x run # Watches "src" dir, eXecutes "cargo run"

Compiling rust-api v0.1.0 (/Users/rvalls/dev/umccr/orcabus/skel/rust-api)
Finished dev [unoptimized + debuginfo] target(s) in 1.74s
Running `target/debug/rust-api`
2023-06-13T00:56:41.621002Z INFO rust_api: listening on 0.0.0.0:8080
```

Then:

```
$ curl localhost:8080/file/moo.bam
```

And to access the builtin Swagger playground, visit http://localhost:8080/swagger-ui/ on your browser.

# Database

Since this microservice is reliant on (meta)data present on the former "Data Portal" database, we'll have to load those tables in on the `orcabus_db` container and inner MySQL DB like so:

```bash
aws s3 cp s3://<data-portal-dev-bucket>/data_portal.sql.gz data/
docker cp data/data_portal.sql.gz orcabus_db:/
docker exec -i -e MYSQL_PWD=orcabus orcabus_db mysql -u orcabus -e "DROP DATABASE IF EXISTS orcabus; CREATE DATABASE IF NOT EXISTS orcabus;"
docker exec -i -e MYSQL_PWD=orcabus orcabus_db /bin/bash -c 'zcat data_portal.sql.gz | mysql -uorcabus orcabus'
```

# Rust learning

While at first Rust can seem intimidating (as a language), there's plenty of materials online that can help you get up to speed with this microservice codebase, check this out:

- [Google 3-day Rust course](https://github.com/google/comprehensive-rust)
- [SQLx quickstart](https://www.youtube.com/watch?v=TCERYbgvbq0)
- [Rust Axum full course](https://www.youtube.com/watch?v=XZtlD_m59sM)
18 changes: 4 additions & 14 deletions openapi/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# OpenAPI
# Orcabus microservices OpenAPI client definitions

This directory contains OpenAPI/Swagger JSON files. They are generated/obtained as follows.
Each language implementation should make sure to expose an `api-docs` and `swagger-ui` url routes that expose the APIs for a given microservice, i.e:

## ICA

Sync of https://github.com/umccr-illumina/libica/tree/dev/swagger

```
wget https://raw.githubusercontent.com/umccr-illumina/libica/dev/swagger/console.json -O console.json
wget https://raw.githubusercontent.com/umccr-illumina/libica/dev/swagger/ens.json -O ens.json
wget https://raw.githubusercontent.com/umccr-illumina/libica/dev/swagger/gds.json -O gds.json
wget https://raw.githubusercontent.com/umccr-illumina/libica/dev/swagger/tes.json -O tes.json
wget https://raw.githubusercontent.com/umccr-illumina/libica/dev/swagger/wes.json -O wes.json
wget https://raw.githubusercontent.com/umccr-illumina/libica/main/swagger/openapi_public.yaml -O openapi_public.yaml
```
http://localhost:8080/swagger-ui/
http://localhost:8080/api-docs/filemanager.json
15 changes: 15 additions & 0 deletions openapi/ica/v1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# OpenAPI

This directory contains OpenAPI/Swagger JSON files. They are generated/obtained as follows.

## ICA

Sync of https://github.com/umccr-illumina/libica/tree/dev/swagger

```
wget https://raw.githubusercontent.com/umccr-illumina/libica/dev/swagger/console.json -O console.json
wget https://raw.githubusercontent.com/umccr-illumina/libica/dev/swagger/ens.json -O ens.json
wget https://raw.githubusercontent.com/umccr-illumina/libica/dev/swagger/gds.json -O gds.json
wget https://raw.githubusercontent.com/umccr-illumina/libica/dev/swagger/tes.json -O tes.json
wget https://raw.githubusercontent.com/umccr-illumina/libica/dev/swagger/wes.json -O wes.json
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions openapi/ica/v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is the OpenAPI ICA v2 definition, obtained from upstream:

wget https://raw.githubusercontent.com/umccr-illumina/libica/main/swagger/openapi_public.yaml -O openapi_public.yaml
File renamed without changes.
1 change: 1 addition & 0 deletions openapi/orcabus/filemanager.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"openapi":"3.0.3","info":{"title":"rust-api","description":"","license":{"name":""},"version":"0.1.0"},"paths":{"/file/":{"get":{"tags":["file"],"summary":"Search query","description":"Search query\nSearch files","operationId":"search","parameters":[{"name":"id","in":"query","required":true,"schema":{"type":"integer","format":"int32"}},{"name":"name","in":"query","required":true,"schema":{"type":"string"}},{"name":"size","in":"query","required":true,"schema":{"type":"integer","format":"int64","minimum":0.0}},{"name":"hash","in":"query","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"List matching objects","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/File"}}}}}}}}},"components":{"schemas":{"File":{"type":"object","description":"Item to do.","required":["id","name","size","hash"],"properties":{"hash":{"type":"string"},"id":{"type":"integer","format":"int32"},"name":{"type":"string","example":"foo.bam"},"size":{"type":"integer","format":"int64","minimum":0.0}}},"FileError":{"oneOf":[{"type":"object","required":["NotFound"],"properties":{"NotFound":{"type":"string","description":"File not found by id."}},"example":"id = 1"},{"type":"object","required":["Unauthorized"],"properties":{"Unauthorized":{"type":"string","description":"File operation unauthorized"}},"example":"missing api key"}],"description":"File operation errors"}},"securitySchemes":{"api_key":{"type":"apiKey","in":"header","name":"File_apikey"}}},"tags":[{"name":"File","description":"File manager API"}]}
2 changes: 2 additions & 0 deletions skel/rust-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
*.swp
Loading