Skip to content

Commit

Permalink
Prioritize external IP for endpoint selection (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
dann1 committed Nov 7, 2023
1 parent 57e7da0 commit cf6a112
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 66 deletions.
2 changes: 1 addition & 1 deletion share/swagger/api.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openapi: "3.0.0"
info:
version: "0.9.11"
version: "0.9.12"
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.

Expand Down
36 changes: 16 additions & 20 deletions share/swagger/schema_sr.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,24 @@
"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" }]
}
"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"]
},
"required": ["FLAVOUR"]
"ENDPOINT": {
"oneOf": [{ "type": "string" }, { "type": "null" }]
}
},
{ "type": "null" }
]
"required": ["FLAVOUR"],
"minProperties" : 1
},
"SCHEDULING": {
"type": "object",
Expand Down
89 changes: 47 additions & 42 deletions src/server/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ServerlessRuntime < OpenNebula::DocumentJSON
]
}.freeze

# TODO: Load json schema from FS. Distribute schema in the installer to /etc.
SCHEMA_SPECIFICATION = {
:type => 'object',
:properties => {
Expand Down Expand Up @@ -97,49 +98,43 @@ class ServerlessRuntime < OpenNebula::DocumentJSON
:required => ['FLAVOUR']
},
:DAAS => {
'oneOf' => [
{
:type => 'object',
:properties => {
:FLAVOUR => {
: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 => FUNCTION_STATES
},
:ENDPOINT => {
'oneOf' => [
{
:type => 'string'
},
:CPU => {
:type => 'number'
},
:VCPU => {
:type => 'integer'
},
:MEMORY => {
:type => 'integer'
},
:DISK_SIZE => {
:type => 'integer'
},
:VM_ID => {
:type => 'integer'
},
:STATE => {
:type => 'string',
:enum => FUNCTION_STATES
},
:ENDPOINT => {
'oneOf' => [
{
:type => 'string'
},
{
:type => 'null'
}
]
{
:type => 'null'
}
},
:required => ['FLAVOUR']
},
{
:type => 'null'
]
}
]
},
:required => ['FLAVOUR'],
:minProperties => 1
},
:SCHEDULING => {
:type => 'object',
Expand Down Expand Up @@ -416,7 +411,7 @@ def self.to_service(client, specification)
end

['FAAS', 'DAAS'].each do |role|
next unless specification[role]
next unless specification[role] && !specification[role]['FLAVOUR'].empty?

client.logger.info("Requesting #{CVMR} for function #{role}\n#{specification[role]}")

Expand Down Expand Up @@ -453,7 +448,11 @@ def self.to_service(client, specification)

def self.tuple(specification)
tuple = specification['FAAS']['FLAVOUR']
tuple = "#{tuple}-#{specification['DAAS']['FLAVOUR']}" if specification['DAAS']

if specification['DAAS'] && !specification['DAAS']['FLAVOUR'].empty?
tuple = "#{tuple}-#{specification['DAAS']['FLAVOUR']}"
end

tuple
end

Expand All @@ -478,10 +477,16 @@ def self.xaas_template(client, role)
vm = rb
xaas_template = {}
t = '//TEMPLATE/'
nic = "#{t}NIC[NIC_ID=\"0\"]/"

xaas_template['VM_ID'] = vm_id
xaas_template['STATE'] = map_vm_state(vm)
xaas_template['ENDPOINT'] = vm["#{t}NIC[NIC_ID=\"0\"]/IP"]

if vm["#{nic}EXTERNAL_IP"]
xaas_template['ENDPOINT'] = vm["#{nic}EXTERNAL_IP"]
else
xaas_template['ENDPOINT'] = vm["#{nic}IP"]
end

xaas_template['CPU'] = vm["#{t}CPU"].to_f
xaas_template['VCPU'] = vm["#{t}VCPU"].to_i
Expand Down
2 changes: 1 addition & 1 deletion src/server/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
require 'client'
require 'runtime'

VERSION = '0.9.11'
VERSION = '0.9.12'

############################################################################
# Define API Helpers
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def verify_sr_spec(specification, runtime)
expect(response.code.to_i).to eq(200)

['FAAS', 'DAAS'].each do |role|
next unless specification[role]
next unless specification[role] && !specification[role]['FLAVOUR'].empty?

vm = OpenNebula::VirtualMachine.new_with_id(runtime[role]['VM_ID'], @conf[:client][:oned])
raise "Error getting #{SR} VM" if OpenNebula.is_error?(vm.info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"FAAS": {
"FLAVOUR": "Function"
},
"DAAS": null,
"DAAS": {
"FLAVOUR": ""
},
"SCHEDULING": {},
"DEVICE_INFO": {}
}
Expand Down

0 comments on commit cf6a112

Please sign in to comment.