Skip to content

Commit

Permalink
MEC Platform Python API Mm5 (#71)
Browse files Browse the repository at this point in the history
## MEC Platfrom
- Fixes in DataModel
- Implemented Mm5 Python API based on REST Mm5
  • Loading branch information
gabrik committed Apr 25, 2019
1 parent 6bf23b6 commit 35c70e4
Show file tree
Hide file tree
Showing 17 changed files with 1,954 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ dune-project
_build
.idea/
.vscode/
*/_build/*
*/_build/*
.coverage
2 changes: 1 addition & 1 deletion fos-plugins/LXD/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ else
sudo cp -r ../LXD/templates /etc/fos/plugins/LXD/
sudo cp ../LXD/__init__.py /etc/fos/plugins/LXD/
sudo cp ../LXD/LXD_plugin /etc/fos/plugins/LXD/
sudo cp ../LXD/LXD_plugin.json /etc/fos/plugins/LXD/
# sudo cp ../LXD/LXD_plugin.json /etc/fos/plugins/LXD/
sudo cp ../LXD/LXDFDU.py /etc/fos/plugins/LXD/
sudo cp ../LXD/README.md /etc/fos/plugins/LXD/
sudo ln -sf /etc/fos/plugins/LXD/LXD_plugin /usr/bin/fos_lxd
Expand Down
642 changes: 642 additions & 0 deletions src/utils/ocaml/mec_platform/me_platform/Mm5.ml

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/utils/ocaml/mec_platform/me_platform/Mm5.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@



module Mm5 : sig

type t

val create : string -> string -> int -> Me_core.MEC_Core.t ->t Lwt.t

val start : t -> unit Lwt.t

val stop : t -> unit Lwt.t

val destroy : t -> unit Lwt.t

end
577 changes: 577 additions & 0 deletions src/utils/ocaml/mec_platform/me_platform/Mp1.ml

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/utils/ocaml/mec_platform/me_platform/Mp1.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@



module Mp1 : sig

type t

val create : string -> string -> int -> Me_core.MEC_Core.t ->t Lwt.t

val start : t -> unit Lwt.t

val stop : t -> unit Lwt.t

val destroy : t -> unit Lwt.t

end
2 changes: 2 additions & 0 deletions src/utils/ocaml/mec_platform/me_platform/me_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module MEC_Core = struct

(* ME Apps and Svcs *)

(* This should add the transports *)
let add_service (ser_desc: service_info ) self =
MVar.read self >>= fun self ->
let serid = Apero.Option.get_or_default ser_desc.ser_instance_id (Apero.Uuid.to_string @@ Apero.Uuid.make ()) in
Expand Down Expand Up @@ -74,6 +75,7 @@ module MEC_Core = struct
| None -> Lwt.fail @@ MEException (`ServiceNotExisting (`Msg (Printf.sprintf "Service with id %s not exist" ser_uuid)))


(* This should add the traffic rules and dns rules *)
let add_application (app_desc: Fos_im.MEC_Types.appd_descriptor ) self =
MVar.read self >>= fun self ->
let appid = app_desc.id in
Expand Down
10 changes: 6 additions & 4 deletions src/utils/ocaml/mec_platform/me_platform/me_platform.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

open Cmdliner
open Me_core
open Rest_api
open Mp1
open Mm5
(* open Lwt.Infix *)
(* open Fos_im *)

Expand Down Expand Up @@ -47,8 +48,9 @@ let run_platform mep_id configuration_path =
try%lwt
ignore mep_id; ignore configuration_path;
let%lwt core = MEC_Core.create (Apero.Option.get @@ Apero_net.Locator.of_string "tcp/127.0.0.1:7887") in
let%lwt mm5 = Mm5.create "127.0.0.1" "/exampleAPI/mm5/v1/" 8091 core in
let%lwt mp1 = Mp1.create "127.0.0.1" "/exampleAPI/mp1/v1/" 8081 core in
Lwt.join [MEC_Core.start core; Mp1.start mp1;]
Lwt.join [MEC_Core.start core; Mp1.start mp1; Mm5.start mm5]
with
(* | YException e ->
Logs_lwt.err (fun m -> m "Exception %s raised:\n%s" (show_yerror e) (Printexc.get_backtrace ())) >> Lwt.return_unit *)
Expand All @@ -61,8 +63,8 @@ let run mep_id configuration_path style_renderer level =
setup_log style_renderer level;
(* Note: by default the Lwt.async_exception_hook do "exit 2" when an exception is raised in a canceled Lwt task.
We rather force it to log and ignore the exception to avoid crashes (as it occurs randomly within cohttp at connection closure). *)
Lwt.async_exception_hook := (fun exn ->
ignore @@ Logs.debug (fun m -> m "Exception caught in Lwt.async_exception_hook: %s\n%s" (Printexc.to_string exn) (Printexc.get_backtrace ())));
(* Lwt.async_exception_hook := (fun exn ->
Logs.debug (fun m -> m "Exception caught in Lwt.async_exception_hook: %s\n%s" (Printexc.to_string exn) (Printexc.get_backtrace ()))); *)
Lwt_main.run @@ run_platform mep_id configuration_path


Expand Down
31 changes: 31 additions & 0 deletions src/utils/ocaml/mec_platform/me_platform/rest_types.atd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* Gabriele Baldoni (gabriele (dot) baldoni (at) adlinktech (dot) com ) -
*********************************************************************************)


type json <ocaml module="Yojson.Safe"> = abstract

(* Errors *)

type problem_details = {
Expand Down Expand Up @@ -115,7 +118,11 @@ type link_type = {
}

type oauth2_info = {
<<<<<<< HEAD
grant_types <json name="grantTypes"> : oauth_grant_types;
=======
grant_types <json name="grantTypes"> : oauth_grant_types list;
>>>>>>> upstream/master
?token_endpoint <json name="tokenEndpoint"> : string option;
}

Expand Down Expand Up @@ -150,7 +157,11 @@ type category_ref = {

type endpoint_info = {
uris : string list;
<<<<<<< HEAD
alternative <json name="alternative"> : json;
=======
alternative : string;
>>>>>>> upstream/master
addresses : address list;
}

Expand All @@ -166,7 +177,11 @@ type traffic_filter = {
dst_port <json name="dstPort"> : string list;
protocol : string list;
token : string list;
<<<<<<< HEAD
src_tunnel_address <json name="srcTunnelAddress"> : string list;
=======
src__tunnel_address <json name="srcATunnelddress"> : string list;
>>>>>>> upstream/master
dst_tunnel_address <json name="dstTunnelAddress"> : string list;
src_tunnel_port <json name="srcTunnelPort"> : string list;
dst_tunnel_port <json name="dstTunnelPort"> : string list;
Expand All @@ -177,7 +192,11 @@ type traffic_filter = {
}

type tunnel_info = {
<<<<<<< HEAD
tunnel_type <json name="tunnelType"> : tunnel_type;
=======
tunnel_type : tunnel_type;
>>>>>>> upstream/master
?tunnel_dst_address <json name="tunnelDstAddress"> : string option;
?tunnel_src_address <json name="tunnelSrcAddress"> : string option;
}
Expand All @@ -203,7 +222,11 @@ type transport_info = {
version : string;
endpoint : endpoint_info;
security : security_info;
<<<<<<< HEAD
?impl_specific_info <json name="implSpecificInfo"> : json option;
=======
?impl_specific_info : string option;
>>>>>>> upstream/master
}


Expand All @@ -220,9 +243,17 @@ type service_info = {

type traffic_rule = {
traffic_rule_id <json name="trafficRuleId"> : string;
<<<<<<< HEAD
filter_type <json name="filterType"> : filter_type;
priority : int;
action : action_type;
traffic_filter <json name="trafficFilter"> : traffic_filter list;
?dst_interface <json name="dstInterface"> : destination_interface option;
=======
filter_type <json name="filterType"> : filter_type list;
action : action_type;
?dst_interface <json name="dstInterface"> : interface_type option;
>>>>>>> upstream/master
state : state_type;
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/ocaml/mec_platform/me_platform/yaks_connector.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ module MakeServiceRegistry(P: sig val prefix: string end) = struct

let get_services connector =
MVar.read connector >>= fun connector ->
let s = get_applications_selector in
let s = get_services_selector in
Yaks.Workspace.get s connector.ws
>>= fun res ->
match res with
Expand All @@ -204,7 +204,7 @@ module MakeServiceRegistry(P: sig val prefix: string end) = struct

let observe_services callback connector =
MVar.guarded connector @@ fun connector ->
let s = get_applications_selector in
let s = get_services_selector in
let%lwt subid = Yaks.Workspace.subscribe ~listener:(sub_cb callback Rest_types.service_info_of_string extract_serviceid_from_path) s connector.ws in
let ls = List.append connector.listeners [subid] in
MVar.return subid {connector with listeners = ls}
Expand Down
17 changes: 17 additions & 0 deletions src/utils/python/mec_mm5/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
all: echo "Nothing to do..."


clean:
rm -rf build dist fog05mm5.egg-info
rm -rf .tox

install:
python setup.py install
rm -rf build dist fog05mm5.egg-info

uninstall:
pip uninstall fog05rest -y

test:
rm -rf .tox
tox
1 change: 1 addition & 0 deletions src/utils/python/mec_mm5/fog05mm5/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from fog05mm5.apimm5 import Mm5
Loading

0 comments on commit 35c70e4

Please sign in to comment.