-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from esl/initial_implementation
Initial implementation
- Loading branch information
Showing
33 changed files
with
2,774 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea | ||
*.iml | ||
tmp | ||
_build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
sudo: false | ||
|
||
language: erlang | ||
|
||
otp_release: | ||
- 22.3 | ||
- 21.3 | ||
|
||
branches: | ||
only: | ||
- master | ||
|
||
script: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.PHONY: all test generate validate compile console dialyzer xref | ||
|
||
OutputDir ?= tmp | ||
|
||
define openapi-generator | ||
docker run --rm -v "${PWD}:/local" -w "/local" \ | ||
openapitools/openapi-generator-cli:v4.3.1 | ||
endef | ||
|
||
all: compile | ||
|
||
test: validate compile dialyzer xref generate | ||
diff -sq priv/openapi.json "$(OutputDir)/priv/openapi.json" | ||
|
||
generate: | ||
$(openapi-generator) generate \ | ||
-g erlang-server -i openapi.yaml -o "$(OutputDir)" \ | ||
--additional-properties=packageName=amoc_rest | ||
|
||
validate: | ||
$(openapi-generator) validate -i openapi.yaml | ||
|
||
compile: | ||
./rebar3 compile | ||
|
||
console: | ||
./rebar3 shell --apps=amoc_rest | ||
|
||
dialyzer: | ||
./rebar3 dialyzer | ||
|
||
xref: | ||
./rebar3 xref |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,34 @@ | ||
# amoc_rest | ||
# amoc_rest [![Build Status](https://travis-ci.org/esl/amoc_rest.svg?branch=master)](https://travis-ci.org/esl/amoc_rest) | ||
|
||
The generated server code for AMOC REST API | ||
|
||
## initial generation | ||
* initial version of the project is generated using openapi-generator. | ||
|
||
```bash | ||
make generate | ||
``` | ||
|
||
## compilation and execution of the project | ||
* compilation of the project can be done using this command: | ||
|
||
```bash | ||
make compile | ||
``` | ||
|
||
* to test the project you can run: | ||
|
||
```bash | ||
make console | ||
``` | ||
|
||
and then, execute in the erlang shell: | ||
|
||
```erlang | ||
ServerParams = #{ip => {0, 0, 0, 0}, port => 4000, net_opts => []}. | ||
amoc_rest_server:start(http_server, ServerParams). | ||
``` | ||
|
||
## swagger-ui integration | ||
* the `dist` version of the swagger-ui is integrated under `/api-docs/` path (e.g. http://localhost:4000/api-docs/) | ||
* the online version of the documentation is also available [here](https://esl.github.io/amoc_rest/?v=7890862) (w/o possibility of execution) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
openapi: 3.0.1 | ||
info: | ||
title: API-DOCS | ||
version: 1.0.0 | ||
servers: | ||
- url: / | ||
paths: | ||
/nodes: | ||
get: | ||
tags: | ||
- node | ||
description: List all AMOC nodes in a cluster. | ||
responses: | ||
'200': | ||
description: response object | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/NodesKV' | ||
/scenarios: | ||
get: | ||
tags: | ||
- scenarios | ||
description: List all available scenarios | ||
responses: | ||
'200': | ||
description: response object | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ScenarioList' | ||
'/scenarios/{id}': | ||
get: | ||
tags: | ||
- scenario | ||
description: Get scenario status | ||
parameters: | ||
- name: id | ||
in: path | ||
description: Scenario name | ||
required: true | ||
schema: | ||
type: string | ||
responses: | ||
'200': | ||
description: response object | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ScenarioStatus' | ||
'404': | ||
description: no scenarion with such name | ||
patch: | ||
tags: | ||
- scenario | ||
description: Start scenario | ||
parameters: | ||
- name: id | ||
in: path | ||
description: Scenario name | ||
required: true | ||
schema: | ||
type: string | ||
requestBody: | ||
description: request body (as json) | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ScenarioExecution' | ||
required: true | ||
responses: | ||
'200': | ||
description: response object | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ScenarioExecutionResp' | ||
'404': | ||
description: no scenarion with such name | ||
/status: | ||
get: | ||
tags: | ||
- status | ||
description: 'Get AMOC app status, whether it is running or not.' | ||
responses: | ||
'200': | ||
description: response object | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/AmocStatus' | ||
/scenarios/upload: | ||
put: | ||
tags: | ||
- upload | ||
description: >- | ||
Uploads new scenario, you can run the next command to upload a file | ||
using curl utility | ||
`curl -s -H "Content-Type: text/plain" -T <filename> | ||
http://<amoc_host>/upload` | ||
requestBody: | ||
content: | ||
application/octet-stream: | ||
schema: | ||
$ref: '#/components/schemas/UploadBody' | ||
text/plain: | ||
schema: | ||
$ref: '#/components/schemas/UploadBody' | ||
example: Past module source code here!!! | ||
responses: | ||
'200': | ||
description: response object | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/UploadResp' | ||
'400': | ||
description: response object | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Error' | ||
components: | ||
schemas: | ||
NodesKV: | ||
required: | ||
- nodes | ||
type: object | ||
properties: | ||
nodes: | ||
type: object | ||
additionalProperties: | ||
type: string | ||
enum: | ||
- up | ||
- down | ||
example: | ||
amoc@host1: up | ||
amoc@host2: up | ||
ScenarioList: | ||
required: | ||
- scenarios | ||
type: object | ||
properties: | ||
scenarios: | ||
type: array | ||
items: | ||
type: string | ||
example: | ||
- some_scenario | ||
- another_scenario | ||
ScenarioStatus: | ||
required: | ||
- scenario_status | ||
type: object | ||
properties: | ||
scenario_status: | ||
type: string | ||
enum: | ||
- loaded | ||
- running | ||
- finished | ||
- error | ||
ScenarioExecution: | ||
required: | ||
- users | ||
type: object | ||
properties: | ||
users: | ||
type: integer | ||
description: Number of users to start | ||
example: 1000 | ||
settings: | ||
type: object | ||
description: Scenario parameters | ||
additionalProperties: | ||
type: string | ||
example: | ||
atom_parameter: atom1 | ||
list_parameter: '[atom1, atom2]' | ||
tuple_parameter: '{atom1, atom2}' | ||
string_parameter: '"some_string"' | ||
binary_parameter: <<"some_binary">> | ||
ScenarioExecutionResp: | ||
required: | ||
- scenario | ||
type: object | ||
properties: | ||
scenario: | ||
type: string | ||
enum: | ||
- started | ||
- error | ||
AmocStatus: | ||
required: | ||
- node_status | ||
type: object | ||
properties: | ||
node_status: | ||
type: string | ||
enum: | ||
- up | ||
- down | ||
UploadBody: | ||
type: string | ||
format: binary | ||
UploadResp: | ||
required: | ||
- compile | ||
type: object | ||
properties: | ||
compile: | ||
type: string | ||
description: ok | CompilationError | ||
example: ok | ||
Error: | ||
required: | ||
- error | ||
type: object | ||
properties: | ||
error: | ||
type: string | ||
example: error description |
Oops, something went wrong.