Skip to content

Commit

Permalink
Merge pull request #1 from esl/initial_implementation
Browse files Browse the repository at this point in the history
Initial implementation
  • Loading branch information
DenysGonchar authored Jun 9, 2020
2 parents 298665a + 4ca790e commit 59ccffa
Show file tree
Hide file tree
Showing 33 changed files with 2,774 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
*.iml
tmp
_build
13 changes: 13 additions & 0 deletions .travis.yml
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
33 changes: 33 additions & 0 deletions Makefile
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
34 changes: 33 additions & 1 deletion README.md
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)
225 changes: 225 additions & 0 deletions openapi.yaml
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
Loading

0 comments on commit 59ccffa

Please sign in to comment.