Skip to content

Commit

Permalink
MEC Fixes (#78)
Browse files Browse the repository at this point in the history
## MEC Fixes
- Fix #77
- Fix bug in Mm5 client adding Headers that allow it to work also if a nginx proxy is used to hidden the MEC Platform Mm5
- Fix MEAO Transport registration during application registration to MEC Platform
  • Loading branch information
gabrik committed May 9, 2019
1 parent ccd924c commit 757aca2
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 45 deletions.
10 changes: 5 additions & 5 deletions src/utils/ocaml/mec_meao_mepmv/meao/Mm1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,19 @@ module Mm1 = struct
p

let make_svc_url prefix id =
prefix ^ "services" ^ id
prefix ^ "services/" ^ id

let make_app_url prefix appid =
prefix ^ "applications" ^ appid
prefix ^ "applications/" ^ appid

let make_plat_url prefix appid =
prefix ^ "platform" ^ appid
prefix ^ "platform/" ^ appid

let make_dns_rule_url prefix appid dnsruleid=
prefix ^ "applications" ^ appid ^ "dns_rules" ^ dnsruleid
prefix ^ "applications/" ^ appid ^ "/dns_rules/" ^ dnsruleid

let make_traffic_rule_url prefix appid tfcruleid =
prefix ^ "applications" ^ appid ^ "traffic_rules" ^ tfcruleid
prefix ^ "applications/" ^ appid ^ "/traffic_rules/" ^ tfcruleid



Expand Down
82 changes: 61 additions & 21 deletions src/utils/ocaml/mec_meao_mepmv/meao/Mm5.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ module Mm5_client = struct


let do_request uri meth header body self =
Logs.debug (fun m -> m "[Mm5 Client]: Request to %s with body %s" uri body );
let sock = Lwt_unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in
let p,c = Lwt.wait () in
let error_handler _ =
Logs.err (fun m -> m "This is a DNS client error");
Logs.err (fun m -> m "[Mm5 Client]: Error processing %s" uri);
Lwt.wakeup c ""
in
let response_handler _ resp_body =
Expand All @@ -56,12 +57,16 @@ module Mm5_client = struct
let headers = Headers.of_list ([
"Content-Length", (string_of_int (String.length body));
"Connection", "keep-alive";
"Content-Type", "application/json";
"User-Agent", "fog05/Mm5/0.0.1";
"Host", Printf.sprintf "%s:%d" self.address self.port;
] @ header)
in
let request_body = Client.request ~error_handler ~response_handler sock (Request.create ~headers meth uri) in
Body.write_string request_body body;
Body.close_writer request_body;
let%lwt res = p in
Logs.debug (fun m -> m "[Mm5 Client]: Request result %s" res );
Lwt.return res

let create address port base_uri =
Expand All @@ -76,32 +81,39 @@ module Mm5_client = struct

let list client =
let uri = client.base_uri ^ "/applications" in
Logs.debug (fun m -> m "[Mm5 Client]: Application list uri http://%s:%d%s" client.address client.port uri );
let%lwt resp = do_request uri `GET [] "" client in
let r = Rest_types.application_info_list_response_of_string resp in
Lwt.return r.application_info

let add appd client =
let uri = client.base_uri ^ "/applications" in
let%lwt resp = do_request uri `POST [] (Rest_types.string_of_app_info appd) client in
let body = Rest_types.string_of_app_info appd in
Logs.debug (fun m -> m "[Mm5 Client]: Application add uri http://%s:%d%s body %s " client.address client.port uri body );
let%lwt resp = do_request uri `POST [] body client in
let _ = Rest_types.application_info_response_of_string resp in
Lwt.return @@ Apero.Option.get appd.app_instance_id


let get appid client =
let uri = client.base_uri ^ "/applications/" ^ appid in
Logs.debug (fun m -> m "[Mm5 Client]: Application get uri http://%s:%d%s" client.address client.port uri );
let%lwt resp = do_request uri `GET [] "" client in
let r = Rest_types.application_info_response_of_string resp in
Lwt.return r.application_info

let remove appid client =
let uri = client.base_uri ^ "/applications/" ^ appid in
Logs.debug (fun m -> m "[Mm5 Client]: Application remove uri http://%s:%d%s" client.address client.port uri );
let%lwt _ = do_request uri `DELETE [] "" client in
Lwt.return appid


let update appid appd client =
let uri = client.base_uri ^ "/applications/" ^ appid in
let%lwt resp = do_request uri `PUT [] (Rest_types.string_of_app_info appd) client in
let body = Rest_types.string_of_app_info appd in
Logs.debug (fun m -> m "[Mm5 Client]: Application update uri http://%s:%d%s body %s" client.address client.port uri body);
let%lwt resp = do_request uri `PUT [] body client in
let _ = Rest_types.application_info_response_of_string resp in
Lwt.return @@ Apero.Option.get appd.app_instance_id

Expand All @@ -110,33 +122,40 @@ module Mm5_client = struct
module DnsRules = struct

let list appid client =
let uri = client.base_uri ^ "/applications/" ^ appid ^ "dns_rules" in
let uri = client.base_uri ^ "/applications/" ^ appid ^ "/dns_rules" in
Logs.debug (fun m -> m "[Mm5 Client]: Dns rule list uri http://%s:%d%s" client.address client.port uri );
let%lwt resp = do_request uri `GET [] "" client in
let r = Rest_types.dns_rule_list_response_of_string resp in
Lwt.return r.dns_rule

let add appid dnsrule client =
let uri = client.base_uri ^ "/applications/" ^ appid ^ "dns_rules" in
let%lwt resp = do_request uri `POST [] (Rest_types.string_of_dns_rule dnsrule) client in
let uri = client.base_uri ^ "/applications/" ^ appid ^ "/dns_rules" in
let body = Rest_types.string_of_dns_rule dnsrule in
Logs.debug (fun m -> m "[Mm5 Client]: Dns rule add uri http://%s:%d%s body %s" client.address client.port uri body);
let%lwt resp = do_request uri `POST [] body client in
let r = Rest_types.dns_rule_response_of_string resp in
Lwt.return @@ r.dns_rule.dns_rule_id


let get appid dns_rule_id client =
let uri = client.base_uri ^ "/applications/" ^ appid ^ "dns_rules/" ^ dns_rule_id in
let uri = client.base_uri ^ "/applications/" ^ appid ^ "/dns_rules/" ^ dns_rule_id in
Logs.debug (fun m -> m "[Mm5 Client]: Dns rule get uri http://%s:%d%s" client.address client.port uri );
let%lwt resp = do_request uri `GET [] "" client in
let r = Rest_types.dns_rule_response_of_string resp in
Lwt.return @@ r.dns_rule

let remove appid dns_rule_id client =
let uri = client.base_uri ^ "/applications/" ^ appid ^ "dns_rules/" ^ dns_rule_id in
let uri = client.base_uri ^ "/applications/" ^ appid ^ "/dns_rules/" ^ dns_rule_id in
Logs.debug (fun m -> m "[Mm5 Client]: Dns rule remove uri http://%s:%d%s" client.address client.port uri );
let%lwt _ = do_request uri `DELETE [] "" client in
Lwt.return dns_rule_id


let update appid dns_rule_id dnsrule client =
let uri = client.base_uri ^ "/applications/" ^ appid ^ "dns_rules/" ^ dns_rule_id in
let%lwt resp = do_request uri `PUT [] (Rest_types.string_of_dns_rule dnsrule) client in
let uri = client.base_uri ^ "/applications/" ^ appid ^ "/dns_rules/" ^ dns_rule_id in
let body = Rest_types.string_of_dns_rule dnsrule in
Logs.debug (fun m -> m "[Mm5 Client]: Dns rule update uri http://%s:%d%s body %s" client.address client.port uri body);
let%lwt resp = do_request uri `PUT [] body client in
let r = Rest_types.dns_rule_response_of_string resp in
Lwt.return @@ r.dns_rule.dns_rule_id

Expand All @@ -145,33 +164,40 @@ module Mm5_client = struct
module TrafficRules = struct

let list appid client =
let uri = client.base_uri ^ "/applications/" ^ appid ^ "traffic_rules" in
let uri = client.base_uri ^ "/applications/" ^ appid ^ "/traffic_rules" in
Logs.debug (fun m -> m "[Mm5 Client]: Traffic rule list uri http://%s:%d%s" client.address client.port uri );
let%lwt resp = do_request uri `GET [] "" client in
let r = Rest_types.traffic_rule_list_response_of_string resp in
Lwt.return r.traffic_rule

let add appid tfcrule client =
let uri = client.base_uri ^ "/applications/" ^ appid ^ "traffic_rules" in
let%lwt resp = do_request uri `POST [] (Rest_types.string_of_traffic_rule tfcrule) client in
let uri = client.base_uri ^ "/applications/" ^ appid ^ "/traffic_rules" in
let body = Rest_types.string_of_traffic_rule tfcrule in
Logs.debug (fun m -> m "[Mm5 Client]: Traffic rule add uri http://%s:%d%s body %s" client.address client.port uri body);
let%lwt resp = do_request uri `POST [] body client in
let r = Rest_types.traffic_rule_response_of_string resp in
Lwt.return @@ r.traffic_rule.traffic_rule_id


let get appid dns_rule_id client =
let uri = client.base_uri ^ "/applications/" ^ appid ^ "traffic_rules/" ^ dns_rule_id in
let uri = client.base_uri ^ "/applications/" ^ appid ^ "/traffic_rules/" ^ dns_rule_id in
Logs.debug (fun m -> m "[Mm5 Client]: Traffic rule get uri http://%s:%d%s" client.address client.port uri );
let%lwt resp = do_request uri `GET [] "" client in
let r = Rest_types.traffic_rule_response_of_string resp in
Lwt.return @@ r.traffic_rule

let remove appid dns_rule_id client =
let uri = client.base_uri ^ "/applications/" ^ appid ^ "traffic_rules/" ^ dns_rule_id in
let uri = client.base_uri ^ "/applications/" ^ appid ^ "/traffic_rules/" ^ dns_rule_id in
Logs.debug (fun m -> m "[Mm5 Client]: Traffic rule remove uri http://%s:%d%s" client.address client.port uri );
let%lwt _ = do_request uri `DELETE [] "" client in
Lwt.return dns_rule_id


let update appid dns_rule_id tfcrule client =
let uri = client.base_uri ^ "/applications/" ^ appid ^ "traffic_rules/" ^ dns_rule_id in
let%lwt resp = do_request uri `PUT [] (Rest_types.string_of_traffic_rule tfcrule) client in
let uri = client.base_uri ^ "/applications/" ^ appid ^ "/traffic_rules/" ^ dns_rule_id in
let body = Rest_types.string_of_traffic_rule tfcrule in
Logs.debug (fun m -> m "[Mm5 Client]: Traffic rule update uri http://%s:%d%s body %s" client.address client.port uri body);
let%lwt resp = do_request uri `PUT [] body client in
let r = Rest_types.traffic_rule_response_of_string resp in
Lwt.return @@ r.traffic_rule.traffic_rule_id

Expand All @@ -182,32 +208,39 @@ module Mm5_client = struct

let list client =
let uri = client.base_uri ^ "/services" in
Logs.debug (fun m -> m "[Mm5 Client]: Service list uri http://%s:%d%s" client.address client.port uri );
let%lwt resp = do_request uri `GET [] "" client in
let r = Rest_types.service_info_list_response_of_string resp in
Lwt.return r.service_info

let add svcd client =
let uri = client.base_uri ^ "/services" in
let%lwt resp = do_request uri `POST [] (Rest_types.string_of_service_info svcd) client in
let body = Rest_types.string_of_service_info svcd in
Logs.debug (fun m -> m "[Mm5 Client]: Service add uri http://%s:%d%s body %s" client.address client.port uri body);
let%lwt resp = do_request uri `POST [] body client in
let _ = Rest_types.service_info_response_of_string resp in
Lwt.return @@ Apero.Option.get (svcd.ser_instance_id)


let get svcid client =
let uri = client.base_uri ^ "/services/" ^ svcid in
Logs.debug (fun m -> m "[Mm5 Client]: Service get uri http://%s:%d%s" client.address client.port uri );
let%lwt resp = do_request uri `GET [] "" client in
let r = Rest_types.service_info_response_of_string resp in
Lwt.return r.service_info

let remove svcid client =
let uri = client.base_uri ^ "/services/" ^ svcid in
Logs.debug (fun m -> m "[Mm5 Client]: Service list remove http://%s:%d%s" client.address client.port uri );
let%lwt _ = do_request uri `DELETE [] "" client in
Lwt.return svcid


let update svcid svcd client =
let uri = client.base_uri ^ "/services/" ^ svcid in
let%lwt resp = do_request uri `PUT [] (Rest_types.string_of_service_info svcd) client in
let body = Rest_types.string_of_service_info svcd in
Logs.debug (fun m -> m "[Mm5 Client]: Service update uri http://%s:%d%s body %s" client.address client.port uri body);
let%lwt resp = do_request uri `PUT [] body client in
let r = Rest_types.service_info_response_of_string resp in
Lwt.return @@ Apero.Option.get (r.service_info.ser_instance_id)
end
Expand All @@ -216,32 +249,39 @@ module Mm5_client = struct

let list client =
let uri = client.base_uri ^ "/transports" in
Logs.debug (fun m -> m "[Mm5 Client]: Transport list uri http://%s:%d%s" client.address client.port uri );
let%lwt resp = do_request uri `GET [] "" client in
let r = Rest_types.transport_info_list_response_of_string resp in
Lwt.return r.transport_info

let add txd client =
let uri = client.base_uri ^ "/transports" in
let%lwt resp = do_request uri `POST [] (Rest_types.string_of_transport_info txd) client in
let body = Rest_types.string_of_transport_info txd in
Logs.debug (fun m -> m "[Mm5 Client]: Transport add uri http://%s:%d%s body %s" client.address client.port uri body);
let%lwt resp = do_request uri `POST [] body client in
let _ = Rest_types.transport_info_response_of_string resp in
Lwt.return @@ txd.id


let get txid client =
let uri = client.base_uri ^ "/transports/" ^ txid in
Logs.debug (fun m -> m "[Mm5 Client]: Transport get uri http://%s:%d%s" client.address client.port uri );
let%lwt resp = do_request uri `GET [] "" client in
let r = Rest_types.transport_info_response_of_string resp in
Lwt.return @@ r.transport_info

let remove txid client =
let uri = client.base_uri ^ "/transports/" ^ txid in
Logs.debug (fun m -> m "[Mm5 Client]: Transport remove uri http://%s:%d%s" client.address client.port uri );
let%lwt _ = do_request uri `DELETE [] "" client in
Lwt.return txid


let update txid txd client =
let uri = client.base_uri ^ "/transports/" ^ txid in
let%lwt resp = do_request uri `PUT [] (Rest_types.string_of_transport_info txd) client in
let body = Rest_types.string_of_transport_info txd in
Logs.debug (fun m -> m "[Mm5 Client]: Transport update uri http://%s:%d%s body %s" client.address client.port uri body);
let%lwt resp = do_request uri `PUT [] body client in
let r = Rest_types.transport_info_response_of_string resp in
Lwt.return @@ (r.transport_info.id)

Expand Down
24 changes: 14 additions & 10 deletions src/utils/ocaml/mec_meao_mepmv/meao/me_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ module MEAO = struct
let dns_rules = List.map (fun d -> MEC_Types.string_of_dns_rule_descriptor d |> Rest_types.dns_rule_of_string |> fun r -> {r with state = `ACTIVE}) appd.dns_rules in
Rest_types.create_app_info ~appd_id ~app_instance_id ~vendor ~soft_verision ~state ~name ~service_produced:[] ~traffic_rules ~dns_rules ()


let transport_info_of_descriptor (txd:MEC_Types.transport_descriptor) =
let id = Apero.Uuid.to_string @@ Apero.Uuid.make () in
let transport_type = transport_types_of_string (MEC_Types.string_of_transport_types txd.transport_type) in
let version = txd.version in
let security = security_info_of_string (MEC_Types.string_of_security_info txd.security) in
let protocol = txd.protocol in
let name = id ^ protocol in
let endpoint = {uris=[]; alternative = Fos_im.JSON.create_empty (); addresses =[] } in
Rest_types.create_transport_info ~id ~transport_type ~version ~security ~protocol ~name ~endpoint ()


(* MEC Platforms *)
Expand Down Expand Up @@ -343,17 +351,13 @@ module MEAO = struct

let app_info = app_info_of_descriptor app_desc in
let app_inst_id = Apero.Option.get app_info.app_instance_id in
let%lwt txs = get_transports plid state in
let rtxs = app_desc.transport_dependencies in
let mtxs = find_matching_transports txs rtxs in
(* let%lwt txs = get_transports plid state in *)
(* let rtxs = app_desc.transport_dependencies in *)
(* let mtxs = find_matching_transports txs rtxs in *)
let svcs =
List.map ( fun (s:MEC_Types.service_descriptor) ->
let rtxs = List.map ( fun (t,_) -> t ) s.transport_supported in
let txs = List.filter (fun ptx -> filter_tx ptx rtxs ) mtxs in
match txs with
| [] -> raise @@ MEException (`TransportNotExisting (`Msg (Printf.sprintf "No required transport found")))
| hd:: _ ->
service_info_of_descriptor s `JSON hd hd.id
let rtxs = List.map ( fun (t,_) -> t ) s.transport_supported |> List.hd |> transport_info_of_descriptor in
service_info_of_descriptor s `JSON rtxs rtxs.id
) app_desc.service_produces in
let app_info = {app_info with service_produced = svcs} in
Mm5_client.Applications.add app_info client
Expand Down
8 changes: 4 additions & 4 deletions src/utils/ocaml/mec_platform/me_platform/Mm5.ml
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ module Mm5 = struct
p

let make_svc_url prefix id =
prefix ^ "services" ^ id
prefix ^ "services/" ^ id

let make_app_url prefix appid =
prefix ^ "applications" ^ appid
prefix ^ "applications/" ^ appid

let make_dns_rule_url prefix appid dnsruleid=
prefix ^ "applications" ^ appid ^ "dns_rules" ^ dnsruleid
prefix ^ "applications/" ^ appid ^ "/dns_rules/" ^ dnsruleid

let make_traffic_rule_url prefix appid tfcruleid =
prefix ^ "applications" ^ appid ^ "traffic_rules" ^ tfcruleid
prefix ^ "applications/" ^ appid ^ "/traffic_rules/" ^ tfcruleid



Expand Down
4 changes: 2 additions & 2 deletions src/utils/ocaml/mec_platform/me_platform/Mp1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ module Mp1 = struct


let make_sub_url prefix appid kind id =
prefix ^ "applications" ^ appid ^ "subscriptions" ^ kind ^ id
prefix ^ "applications/" ^ appid ^ "/subscriptions/" ^ kind ^ id

let make_svc_url prefix id =
prefix ^ "services" ^ id
prefix ^ "services/" ^ id



Expand Down
9 changes: 6 additions & 3 deletions src/utils/python/mec_mm1/fog05mm1/apimm1.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class Mm1(object):
This class allow the interaction with fog05 FIM
'''

def __init__(self, endpoint='127.0.0.1:8071/exampleAPI/mm5/v1',):
def __init__(self, endpoint='127.0.0.1:8071/exampleAPI/mm1/v1',):
self.base_url = 'http://{}'.format(endpoint)
self.applications = self.Applications(self.base_url)
self.dns_rules = self.DnsRules(self.base_url)
self.traffic_rules = self.TrafficRules(self.base_url)
self.services = self.Services(self.base_url)
self.transports = self.Transports(self.base_url)
self.platforms = self.platforms(self.base_url)
self.platforms = self.Platforms(self.base_url)

def check(self):
url = '{}'.format(self.base_url)
Expand All @@ -50,6 +50,9 @@ def close(self):
pass

class Platforms(object):
'''
pl = {'platformId':'platform1', 'endpoint':{'uris':['/exampleAPI/mm5/v1'], 'alternative':{},'addresses':[{'host':'10.212.26.250','port':8091}]}}
'''
def __init__(self, base_url):
self.base_url = base_url

Expand Down Expand Up @@ -118,7 +121,7 @@ def add(self, platformid, applicationid, dns_rule):
return json.loads(requests.post(url, data=json.dumps(dns_rule)).text)

def update(self, platformid, applicationid, dns_rule_id, dns_rule):
url = '{}/platforms/{}/applications/{}/dns_rules/{}'.format(self.base_url platformid, applicationid, dns_rule_id)
url = '{}/platforms/{}/applications/{}/dns_rules/{}'.format(self.base_url, platformid, applicationid, dns_rule_id)
return json.loads(requests.put(url, data=json.dumps(dns_rule)).text)

def get(self, platformid, applicationid, dns_rule_id):
Expand Down

0 comments on commit 757aca2

Please sign in to comment.