Skip to content

Commit

Permalink
Update to YAKS API 0.2.7 and initial MEC Platform contibution (#70)
Browse files Browse the repository at this point in the history
## Update requirements YAKS API
- Using latest version 0.2.7

## MEC Platform
Initial code for the MEC Platform exposing standard ETSI MEC Mp1 interface [see specs](http://www.etsi.org/deliver/etsi_gs/MEC/001_099/011/01.01.01_60/gs_mec011v010101p.pdf)
Uses YAKS as Service Registry, httpaf for implementing the REST API
  • Loading branch information
gabrik committed Apr 24, 2019
1 parent 059d34e commit 6bf23b6
Show file tree
Hide file tree
Showing 18 changed files with 2,219 additions and 102 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ endif
sudo id -u fos >/dev/null 2>&1 || sudo useradd -r -s /bin/false fos
sudo usermod -aG sudo fos
ifeq ($(shell uname -m), x86_64)
curl -L -o /tmp/yaks.tar.gz https://www.dropbox.com/s/nz1onkzai6jhkc5/yaksd.tar.gz
curl -L -o /tmp/yaks.tar.gz https://www.dropbox.com/s/g4tnzvjwlx3zcr2/yaksd.tar.gz
else ifeq ($(shell uname -m), armv7l)
curl -L -o /tmp/yaks.tar.gz https://www.dropbox.com/s/q1x3zoqmpftjcxn/yaks_armv7l.tar.gz
curl -L -o /tmp/yaks.tar.gz https://www.dropbox.com/s/lo4s72rc5uoowxw/yaksd_armv7l.tar.gz
else ifeq ($(shell uname -m), aarch64)
curl -L -o /tmp/yaks.tar.gz https://www.dropbox.com/s/o8rr3y652iwb9gy/yaks_arm64.tar.gz
curl -L -o /tmp/yaks.tar.gz https://www.dropbox.com/s/j29g35zb9cy28ph/yaksd_arm64.tar.gz
endif
tar -xzvf /tmp/yaks.tar.gz -C /etc/fos
rm -rf /tmp/yaks.tar.gz
Expand Down
72 changes: 43 additions & 29 deletions src/api/python/api/fog05/fimapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,26 +453,43 @@ def cb(fdu_info):
return res

def onboard(self, descriptor, wait=True):
'''
Onboard the FDU descriptor in the Catalog
:param descriptor: the fdu descriptor
:param wait: make the call wait for completio
:return the fdu uuid
'''
fduid = descriptor.get('uuid')
if fduid is None:
fduid = '{}'.format(uuid.uuid4())
res = self.connector.glob.desired.add_fdu_info(
self.connector.glob.desired.add_fdu_info(
self.sysid, self.tenantid, fduid, descriptor)
if wait:
self.__wait_fdu(fduid)
return res
return fduid

def offload(self, fdu_uuid, wait=True):
'''
Offload the FDU descriptor from the Catalog
:param fdu_uuid: fdu uuid you want to remove
:param wait: make the call wait for completion
:return the fdu uuid
'''
res = self.connector.glob.desired.remove_fdu_info(
self.sysid, self.tenantid, fdu_uuid)
return fdu_uuid

def define(self, fduid, node_uuid, wait=True):
'''
Defines an FDU instance in a node, this method will check
the descriptor before sending the definition to the node
:param manifest: dictionary representing the atomic entity manifest
:param fduid: id of the fdu you want to instantiate
:param node_uuid: destination node uuid
:param wait: if wait that the definition is complete before
returning
Expand Down Expand Up @@ -675,7 +692,7 @@ def resume(self, instanceid, wait=True):
def migrate(self, instanceid, destination_node_uuid, wait=True):
'''
Live migrate an atomic entity instance between two nodes
Live migrate an instance between two nodes
The migration is issued when this command is sended,
there is a little overhead for the copy of the base image and the disk image
Expand Down Expand Up @@ -718,12 +735,26 @@ def migrate(self, instanceid, destination_node_uuid, wait=True):


def instantiate(self, fduid, nodeid, wait=True):
'''
Instantiate (define, configure, start) an fdu in a node
:param fduid: id of the fdu to instantiate
:param nodeid: node where instantiate
:return instance uuid
'''
instance_id = self.define(fduid, nodeid)
self.configure(instance_id)
self.start(instance_id)
return instance_id

def terminate(self, instanceid, wait=True):
'''
Terminate (stop, clean, undefine) an instance
:param instanceid: instance you want to terminate
:return instance uuid
'''

self.stop(instanceid)
self.clean(instanceid)
return self.undefine(instanceid)
Expand All @@ -747,6 +778,14 @@ def info(self, fdu_uuid):
return self.connector.glob.actual.get_fdu_info(self.sysid, self.tenantid, fdu_uuid)

def instance_info(self, instanceid):
'''
Information about an instance
:param instanceid: instance id
:return dict containing the fdu record and hypervisor informations
'''
return self.connector.glob.actual.get_node_fdu_instance(self.sysid, self.tenantid, "*", instanceid)

def get_nodes(self, fdu_uuid):
Expand Down Expand Up @@ -799,31 +838,6 @@ def list(self, node_uuid='*'):
:param node_uuid: optional node uuid
:return: dictionary {node uuid: {entity uuid: instance list} list}
'''

# if node_uuid is not None:
# entity_list = {}
# uri = '{}/{}/runtime/*/entity/**'.format(self.store.aroot, node_uuid)
# response = self.store.actual.resolveAll(uri)
# for i in response:
# rid = i[0]
# en_uuid = rid.split('/')[7]
# if en_uuid not in entity_list:
# entity_list.update({en_uuid: []})
# if len(rid.split('/')) == 8 and en_uuid in entity_list:
# pass
# if len(rid.split('/')) == 10:
# entity_list.get(en_uuid).append(rid.split('/')[9])

# return {node_uuid: entity_list}

# entities = {}
# uri = '{}/*/runtime/*/entity/**'.format(self.store.aroot)
# response = self.store.actual.resolveAll(uri)
# for i in response:
# node_id = i[0].split('/')[3]
# elist = self.list(node_id)
# entities.update({node_id: elist.get(node_id)})
# return entities
return self.connector.glob.actual.get_all_fdus(self.sysid, self.tenantid)


Expand Down
2 changes: 1 addition & 1 deletion src/api/python/api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
url='https://github.com/eclipse/fog05',
authon_email='gabriele.baldoni@adlinktech.com',
license='Apache 2.O or EPL 2.0',
install_requires=['yaks==0.2.6', 'jsonschema','mvar'],
install_requires=['yaks==0.2.7', 'jsonschema','mvar'],
scripts=[],
include_package_data=True
)
113 changes: 75 additions & 38 deletions src/api/python/rest_api/fog05rest/fimapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import json
import os
import tempfile
import uuid


def save_file(content, filename):
Expand Down Expand Up @@ -43,7 +44,6 @@ def __init__(self, locator='127.0.0.1:8080',):
self.image = self.Image(self.base_url)
self.flavor = self.Flavor(self.base_url)


def check(self):
url = '{}'.format(self.base_url)
return json.loads(str(requests.get(url).content))
Expand Down Expand Up @@ -86,7 +86,6 @@ class Plugin(object):
def __init__(self, base_url):
self.base_url = base_url


def info(self, node_uuid, pluginid):
url = '{}/plugin/info/{}/{}'.format(self.base_url, pluginid, node_uuid)
return json.loads(str(requests.get(url).content))
Expand Down Expand Up @@ -118,7 +117,6 @@ def delete_connection_point(self, cp_uuid):
url = '{}/connection_point/remove/{}'.format(self.base_url, cp_uuid)
return json.loads(str(requests.delete(url).content))


def list(self):
url = '{}/network/list'.format(self.base_url)
return json.loads(str(requests.get(url).content))
Expand All @@ -134,7 +132,6 @@ class FDU(object):
def __init__(self, base_url):
self.base_url = base_url


def onboard(self, descriptor):
url = '{}/fdu/onboard'.format(self.base_url)
return json.loads(str(requests.post(url, data=json.dumps(descriptor)).content))
Expand All @@ -147,36 +144,75 @@ def define(self, fduid, node_uuid):
url = '{}/fdu/define/{}/{}'.format(self.base_url, fduid, node_uuid)
return json.loads(str(requests.post(url).content))

def undefine(self, fduid, node_uuid):
url = '{}/fdu/undefine/{}/{}'.format(self.base_url, fduid, node_uuid)
return json.loads(str(requests.delete(url).content))

def configure(self, fduid, node_uuid):
url = '{}/fdu/configure/{}/{}'.format(self.base_url, fduid, node_uuid)
return json.loads(str(requests.post(url).content))

def clean(self, fduid, node_uuid):
url = '{}/fdu/clean/{}/{}'.format(self.base_url, fduid, node_uuid)
return json.loads(str(requests.post(url).content))

def run(self, fduid, node_uuid):
url = '{}/fdu/run/{}/{}'.format(self.base_url, fduid, node_uuid)
return json.loads(str(requests.post(url).content))

def stop(self, fduid, node_uuid):
url = '{}/fdu/stop/{}/{}'.format(self.base_url, fduid, node_uuid)
return json.loads(str(requests.post(url).content))

def pause(self, fduid, node_uuid):
url = '{}/fdu/pause/{}/{}'.format(self.base_url, fduid, node_uuid)
return json.loads(str(requests.post(url).content))

def resume(self, fduid, node_uuid):
url = '{}/fdu/resume/{}/{}'.format(self.base_url, fduid, node_uuid)
return json.loads(str(requests.post(url).content))

def migrate(self, fduid, node_uuid, destination_node_uuid):
pass
def undefine(self, instanceid):
url = '{}/fdu/undefine/{}'.format(self.base_url, instanceid)
res = json.loads(str(requests.delete(url).content))
if 'error' in res:
raise ValueError(res['error'])
return res['result']

def configure(self, instanceid):
url = '{}/fdu/configure/{}'.format(self.base_url, instanceid)
res = json.loads(str(requests.post(url).content))
if 'error' in res:
raise ValueError(res['error'])
return res['result']

def clean(self, instanceid):
url = '{}/fdu/clean/{}'.format(self.base_url, instanceid)
res = json.loads(str(requests.post(url).content))
if 'error' in res:
raise ValueError(res['error'])
return res['result']

def start(self, instanceid):
url = '{}/fdu/start/{}'.format(self.base_url, instanceid)
res = json.loads(str(requests.post(url).content))
if 'error' in res:
raise ValueError(res['error'])
return res['result']

def stop(self, instanceid):
url = '{}/fdu/stop/{}'.format(self.base_url, instanceid)
res = json.loads(str(requests.post(url).content))
if 'error' in res:
raise ValueError(res['error'])
return res['result']

def pause(self, instanceid):
url = '{}/fdu/pause/{}'.format(self.base_url, instanceid)
res = json.loads(str(requests.post(url).content))
if 'error' in res:
raise ValueError(res['error'])
return res['result']

def resume(self, instanceid):
url = '{}/fdu/resume/{}'.format(self.base_url, instanceid)
res = json.loads(str(requests.post(url).content))
if 'error' in res:
raise ValueError(res['error'])
return res['result']

def migrate(self, instanceid, destination_node_uuid):
url = '{}/fdu/migrate/{}/{}'.format(self.base_url, instanceid, destination_node_uuid)
res = json.loads(str(requests.post(url).content))
if 'error' in res:
raise ValueError(res['error'])
return res['result']

def instantiate(self, fduid, nodeid):
url = '{}/fdu/instantiate/{}/{}'.format(self.base_url, fduid, nodeid)
res = json.loads(str(requests.post(url).content))
if 'error' in res:
raise ValueError(res['error'])
return res['result']

def terminate(self, instanceid):
url = '{}/fdu/terminate/{}'.format(self.base_url, instanceid)
res = json.loads(str(requests.post(url).content))
if 'error' in res:
raise ValueError(res['error'])
return res['result']

def get_nodes(self, fdu_uuid, node_uuid):
url = '{}/fdu/get_nodes/{}'.format(self.base_url, fdu_uuid)
Expand All @@ -186,13 +222,16 @@ def list_node(self, node_uuid):
url = '{}/fdu/list_node/{}'.format(self.base_url, node_uuid)
return json.loads(str(requests.get(url).content))

def instance_list(self, fduid):
url = '{}/fdu/instance_list/{}'.format(self.base_url, fduid)
return json.loads(str(requests.get(url).content))

def info(self, fdu_uuid):
url = '{}/fdu/info/{}'.format(self.base_url, fdu_uuid)
return json.loads(str(requests.get(url).content))

def instance_info(self, fdu_uuid, node_uuid):
url = '{}/fdu/instance_info/{}/{}'.format(self.base_url, fdu_uuid, node_uuid)
def instance_info(self, instanceid):
url = '{}/fdu/instance_info/{}'.format(self.base_url, instanceid)
return json.loads(str(requests.get(url).content))

def list(self):
Expand Down Expand Up @@ -230,12 +269,10 @@ def get(self, image_uuid):
url = '{}/image/{}'.format(self.base_url, image_uuid)
return json.loads(str(requests.get(url).content))


def remove(self, image_uuid):
url = '{}/image/{}'.format(self.base_url, image_uuid)
return json.loads(str(requests.delete(url).content))


def list(self):
url = '{}/image/list'.format(self.base_url)
return json.loads(str(requests.get(url).content))
Expand Down
2 changes: 1 addition & 1 deletion src/api/python/rest_api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

setup(
name='fog05rest',
version='0.0.1',
version='0.0.2',
author='ADLINK',
packages=['fog05rest',],
install_requires=['requests'],
Expand Down
6 changes: 3 additions & 3 deletions src/im/ocaml/fos-im/fos_im.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* Gabriele Baldoni (gabriele (dot) baldoni (at) adlinktech (dot) com ) - OCaml implementation
*********************************************************************************)

module IM_Types = Im
module IM_Json = Im
module IM_Validator = Im_v
module MEC_Types = Im
module MEC_Json = Im
module MEC_Validator = Im_v

module FAgentTypes = Agent_types
(* module FAgentTypesJson = Agent_types *)
Expand Down
18 changes: 18 additions & 0 deletions src/utils/ocaml/mec_platform/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
all: atd
dune build

atd:
atdgen -t me_platform/rest_types.atd
atdgen -j-std me_platform/rest_types.atd
atdgen -v me_platform/rest_types.atd

clean:
rm -rf me_platform/rest_types*.ml me_platform/rest_types*.mli
dune clean
rm -rf ./_build

install:
opam install .

# uninstall:
# opam remove me-platform
Loading

0 comments on commit 6bf23b6

Please sign in to comment.