Skip to content

Commit

Permalink
Merge pull request #27 from umccr/filemanager
Browse files Browse the repository at this point in the history
FileManager microservice
  • Loading branch information
brainstorm authored Jun 15, 2023
2 parents ce5b82a + 7915148 commit 94d72e7
Show file tree
Hide file tree
Showing 22 changed files with 2,617 additions and 26 deletions.
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

0 comments on commit 94d72e7

Please sign in to comment.