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

Swagger #26

Merged
merged 3 commits into from
Oct 18, 2023
Merged
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
241 changes: 241 additions & 0 deletions share/swagger/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
openapi: "3.0.0"
info:
version: "0.9.11"
title: "Provisioning Engine REST API"
description: Provides FaaS capabilities by leveraging features from OpenNebula. Allows to manage Serverless Runtime instances based on a group of Functions defined on request.

components:
schemas:
ServerlessRuntime:
$ref: 'https://raw.githubusercontent.com/SovereignEdgeEU-COGNIT/provisioning-engine/main/share/swagger/schema_sr.json'
securitySchemes:
basicAuth:
type: http
scheme: basic
description: Credentials used to authenticate in OpenNebula

security:
- basicAuth: []

paths:
/serverless-runtimes/schema:
get:
summary: Retrieve the Serverless Runtime schema
tags:
- Serverless Runtimes
security: []
responses:
'200':
description: Serverless Runtime schema retrieved
/serverless-runtimes:
post:
summary: Create a Serverless Runtime
description: Requires a Serverless Runtime defintion with at least a FaaS flavour
tags:
- Serverless Runtimes
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ServerlessRuntime'
example:
SERVERLESS_RUNTIME:
NAME: Function and Data as a Service
FAAS:
CPU: 0.11
VCPU: 2
MEMORY: 133
DISK_SIZE: 1025
FLAVOUR: Function
DAAS:
CPU: 0.33
VCPU: 1
MEMORY: 197
DISK_SIZE: 1337
FLAVOUR: Data
SCHEDULING: {}
DEVICE_INFO: {}
responses:
'201':
description: Serverless Runtime created
content:
application/json:
schema:
$ref: '#/components/schemas/ServerlessRuntime'
example:
SERVERLESS_RUNTIME:
NAME: Function and Data as a Service
ID: 851
FAAS:
CPU: 0.11
VCPU: 2
MEMORY: 133
DISK_SIZE: 1025
FLAVOUR: Function
VM_ID: 592
STATE: PENDING
ENDPOINT:
DAAS:
CPU: 0.33
VCPU: 1
MEMORY: 197
DISK_SIZE: 1337
FLAVOUR: Data
VM_ID: 593
STATE: PENDING
ENDPOINT:
SCHEDULING: {}
DEVICE_INFO: {}
SERVICE_ID: 850
'400':
description: Invalid Serverless Runtime definition
'401':
description: Missing authentication
'403':
description: Permission Denied
'422':
description: Unprocessable Serverless Runtime definition
'500':
description: Failed to create Serverless Runtime
'504':
description: Timeout when creating Serverless Runtime
/serverless-runtimes/{id}:
get:
summary: Retrieve information about a Serverless Runtime
description: Retrieves a JSON representation of the Serverless Runtime. During the retrieval the state of the Serverles Runtime gets updated according to it's underlying components. The document entry in the OpenNebula database will get updated as well.
tags:
- Serverless Runtimes
parameters:
- name: id
in: path
required: true
schema:
type: integer
responses:
'200':
description: Serverless Runtime information retrieved
content:
application/json:
schema:
$ref: '#/components/schemas/ServerlessRuntime'
example:
SERVERLESS_RUNTIME:
NAME: Function and Data as a Service
ID: 851
FAAS:
CPU: 0.11
VCPU: 2
MEMORY: 133
DISK_SIZE: 1025
FLAVOUR: Function
VM_ID: 592
STATE: RUNNING
ENDPOINT:
DAAS:
CPU: 0.33
VCPU: 1
MEMORY: 197
DISK_SIZE: 1337
FLAVOUR: Data
VM_ID: 593
STATE: RUNNING
ENDPOINT:
SCHEDULING: {}
DEVICE_INFO: {}
SERVICE_ID: 850
'401':
description: Missing authentication
'403':
description: Permission Denied
'404':
description: Serverless Runtime not found
'500':
description: Failed to retrieve Serverless Runtime
put:
summary: Update a Serverless Runtime
description: Updates an existing Serverless Runtime with new requirements. Translates into a change on the Virtual Machines containing the Functions requested by the Serverless Runtime.
tags:
- Serverless Runtimes
parameters:
- name: id
in: path
required: true
schema:
type: integer
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ServerlessRuntime'
responses:
'501':
description: Serverless Runtime update not implemented
delete:
summary: Delete a Serverless Runtime
description: Upon success it will trigger a deletion request of the associated services and Virtual Machines in OpenNebula
tags:
- Serverless Runtimes
parameters:
- name: id
in: path
required: true
schema:
type: integer
responses:
'204':
description: Serverless Runtime deleted
'401':
description: Missing authentication
'403':
description: Permission Denied
'404':
description: Serverless Runtime not found
'423':
description: Cannot delete serverless Runtime
'500':
description: Failed to delete Serverless Runtime
/server/version:
get:
summary: Retrieve the Provisioning Engine server version
tags:
- Server
security: []
responses:
'200':
description: Provisioning Engine server version retrieved
content:
application/json:
schema:
type: string
example:
"0.9.11"
/server/config:
get:
summary: Retrieve the Provisioning Engine configuration
tags:
- Server
security: []
responses:
'200':
description: Provisioning Engine server configuration retrieved
content:
application/json:
schema:
type: object
example:
one_xmlrpc: http://localhost:2633/RPC2
oneflow_server: http://localhost:2474
host: 127.0.0.1
port: 1337
capacity:
max:
vcpu_mult: 2
memory_mult: 2
default:
vcpu: 2
memory: 1024
log:
level: 1
system: 'file'
69 changes: 69 additions & 0 deletions share/swagger/schema_sr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"type": "object",
"properties": {
"SERVERLESS_RUNTIME": {
"type": "object",
"properties": {
"NAME": { "type": "string" },
"ID": { "type": "integer" },
"SERVICE_ID": { "type": "integer" },
"FAAS": {
"type": "object",
"properties": {
"FLAVOUR": { "type": "string" },
"CPU": { "type": "number" },
"VCPU": { "type": "integer" },
"MEMORY": { "type": "integer" },
"DISK_SIZE": { "type": "integer" },
"VM_ID": { "type": "integer" },
"STATE": {
"type": "string",
"enum": ["PENDING", "RUNNING", "UPDATING", "ERROR"]
},
"ENDPOINT": { "oneOf": [{ "type": "string" }, { "type": "null" }] }
},
"required": ["FLAVOUR"]
},
"DAAS": {
"oneOf": [
{
"type": "object",
"properties": {
"FLAVOUR": { "type": "string" },
"CPU": { "type": "number" },
"VCPU": { "type": "integer" },
"MEMORY": { "type": "integer" },
"DISK_SIZE": { "type": "integer" },
"VM_ID": { "type": "integer" },
"STATE": {
"type": "string",
"enum": ["PENDING", "RUNNING", "UPDATING", "ERROR"]
},
"ENDPOINT": {
"oneOf": [{ "type": "string" }, { "type": "null" }]
}
},
"required": ["FLAVOUR"]
},
{ "type": "null" }
]
},
"SCHEDULING": {
"type": "object",
"properties": {
"POLICY": { "type": "string" },
"REQUIREMENTS": { "type": "string" }
}
},
"DEVICE_INFO": {
"type": "object",
"properties": {
"LATENCY_TO_PE": { "type": "integer" },
"GEOGRAPHIC_LOCATION": { "type": "string" }
}
}
},
"required": ["FAAS"]
}
}
}
19 changes: 19 additions & 0 deletions src/server/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
require 'client'
require 'runtime'

VERSION = '0.9.11'

############################################################################
# Define API Helpers
############################################################################
RC = 'Response HTTP Return Code'.freeze
SR = 'Serverless Runtime'.freeze
PE = 'Provisioning Engine'.freeze
SRD = "#{SR} definition".freeze
DENIED = 'Permission denied'.freeze
NO_AUTH = 'Failed to authenticate in OpenNebula'.freeze
Expand Down Expand Up @@ -119,6 +122,10 @@ def log_response(level, code, data, message)
end
end

get '/serverless-runtimes/schema' do
json_response(200, ProvisionEngine::ServerlessRuntime::SCHEMA_SPECIFICATION)
end

post '/serverless-runtimes' do
log_request("Create a #{SR}")

Expand Down Expand Up @@ -254,3 +261,15 @@ def log_response(level, code, data, message)
halt 500, json_response(500, rb)
end
end

get '/engine/version' do
json_response(200, VERSION)
end

get '/server/version' do
json_response(200, VERSION)
end

get '/server/config' do
json_response(200, conf)
end