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

GCBM Simulation API and End-Points for upload #152

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
55 changes: 30 additions & 25 deletions local/rest_api_gcbm/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
# FLINT.Cloud

### GCBM local-run REST API Setup

Run the GCBM local-run container by pushing the following command:
This script follows the pseudocode from Andrew's design to update GCBM configs: https://hackmd.io/@aornugent/B1RluG69c.

## Execution

### End-Point

* Endpoints supported: `/gcbm/upload`
* Categories supported: `disturbances, classifiers, miscellaneous`

```bash
docker-compose up
# This uploads a classifier, disturbance and a miscellaneous file
curl -F disturbances="@disturbances/disturbances_2011_moja.tiff" -F classifiers="@classifiers/Classifier1_moja.tiff" http://localhost:8080/gcbm/upload

# Try skipping disturbance file, and it will still work :)
```

Navigate to http://localhost:8080/ in the browser. You can stop the running container by pushing the following command:
**Expected Output:**

```bash
docker-compose down
{
"error": "Missing files for categories: ['config_files', 'input'], they are required for the simulation to run"
}
```

Currently the REST API has the following endpoints available for access:-

| Endpoint | Functionality | Method |
| :----------------: | :----------------: | :----------------: |
| **\help\all** | This endpoint produces a help message with information on all options for moja.CLI | `GET`
| **\help\arg** | This endpoint produces a help message with information on option arg for moja.CLI. | `GET`
| **\gcbm\new** | This endpoint creates a new directory to store input and output files of the simulation. Parameter to be passed in the body is the title of the new simulation or default value simulation will be used. | `POST` |
| **\gcbm\upload** | This endpoint is used to upload the input files: config_files, input and database. Remember to upload the files in the body from the GCBM folder which is available in the root of this repository for setup and use. A directory /input will be created to store the specified files. | `POST` |
| **\gcbm\dynamic** | This endpoint runs simulation in a thread and generates an output zip file in /output directory. The process may take a while. Parameter is the title of the simulation. | `POST` |
| **\gcbm\status** | This endpoint is employed to check the status of the simulation. It sends a message 'Output is ready to download' to notify that the output zip file is generated. Parameter is the title of the simulation. | `POST`
| **\gcbm\download** | This endpoint is used to download the output zip file. Parameter is the title of the simulation. | `POST`
| **\gcbm\list** | This endpoint retrieves the complete list of simulations that are created using /new. | `GET`
The outputs for classifier file and disturbance file will be stored in "templates/config/" folder.

The inputs are contained in `GCBM_Demo_Run.zip`, present in the root of the directory. This file must be unzipped for further usage.
### GCBM Pre-Processing

<h3> Once the container is up and running, the following methods can be used to interact with the endpoints </h3>
Run: `python3 gcbm.py disturbances/disturbances_2011_moja.tiff` and a folder will be generated with the output config file (JSON)

Script:

```bash
pip install -r requirements.txt
python3 gcbm.py disturbances/disturbances_2011_moja.tiff
cat templates/config/disturbances_2011_moja.json
```

1. A sample Postman collection is available [here](https://github.com/nynaalekhya/FLINT.Cloud/blob/local-gcbm-run/rest_local_run/local_run.postman_collection). Import the collection to Postman and run the endpoints.
Please see the `main` function in the `gcbm.py` file for more info. A payload is manually added, which checks if it has year and then the `has_year` key is set to `True`

2. The endpoints can be interacted with using `cURL`.
curl is used in command lines or scripts to transfer data. Find out more about curl [here](https://curl.se/). Commands using cURL can be found [here](curl.md)
## TODOs

There are a lot of in-line TODOs, this is the first draft to see how we can implement this the most pythonic way.
Loading