Newer
Older
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# How to develop a MEC application using the MEC Sandbox HTTP REST API\n",
"\n",
"## Table of contents\n",
"\r\n",
" .[ What is a MEC applicationn](what_is_a_mec_applicationn)2\n",
".[ The basics of developing a MEC applicationh](the_basics_of_developing_a_mec_application)\n",
"3. [Use the MEC Sandbox HTTP REST API models and code](#use_the_mec_sandbox_http_rest_api_models_and_code)\n",
"4. [Create our first MEC application](#create_our_first_mec_application)\n",
" 4.1. [The login function](#the_login_function)\n",
" 4.2. [The logout function](#the_logout_function)\n",
"5. [Second step: Retrieve the list of network scenarios](#second_step_retrieve_the_list_of_network_scenarios)\n",
"6. [Third step: Activate and deactivate a network scenario](#third_step_activate_and_deactivate_a_network_scenario)\n",
" 6.1. [The activate function](#the_activate_function)\n",
" 6.2. [The deactivate function](#thedeactivate_function)\n",
"7. [Fourth step: Create and delete an appliction instance id](#fourth_step_create_and_delete_an_appliction_instance_id)\n",
"8. [MEC Registration and the READY indication](#mec_registration_and_the_ready_indication)\n",
"9. [Annexes](#annexes)\n",
"10. [Bibliography](#bibliograhypt\n"
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## What is a MEC application\n",
"\n",
"See [The Wiki MEC web site](https://www.etsi.org/technologies/multi-access-edge-computing)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The basics of developing a MEC application\n",
"\n",
"The developement of a MEC application follows a strict process in order to access the ETSI MEC services and provides valueable services to the customers.\n",
"Mainly, this process can be split in several steps:\n",
"1. Global initializations (constant, variables...)\n",
"2. Create of a new instance of a MEC Sandbox (Note that using an existing one could be a solution too (see Annex A)\n",
"3. Activate a network scenario in order to access the ETSI MEC services\n",
"4. Create a new application identifier\n",
"5. Register our MEC application and subscribe to service termination (see MEC 011)\n",
"6. Use MEC services in order to provide valueable services to the customers\n",
" 6.1. Apply MEC services required subscriptions (e.g. MEC 013 location subscription)\n",
"7. Terminate the MEC application\n",
" 7.1. Remove MEC services subscriptions\n",
" 7.2. Deactivate the current network scenario\n",
" 7.3. Delete the instance of the MEC Sandbox\n",
"8. Release all the MEC application resources\n",
"\n",
"## Use the MEC Sandbox HTTP REST API models and code\n",
"\n",
"The MEC sandbox provides a piece of code (the python sub) that shall be used to develop the MEC applicationand interact with the MEC Sandbox. This piece of code mainly contains swagger models to serialize/deserialize JSON data structures and HTTP REST API call functions.\n",
"The openApi file is availabe [here](https://forge.etsi.org/rep/mec/AdvantEDGE/-/blob/Task2_PoC/go-apps/meep-sandbox-api/api/swagger.yaml) and the [Swagger editor](https://editor-next.swagger.io/) is used to generate the python sub.\n",
"\n",
"The project architecture is describe [here](images/project_arch.jpg).\n",
"\n",
"The api folder contains the python implementation of the HTTP REST API definitions introduced by the openApi [file](https://forge.etsi.org/rep/mec/AdvantEDGE/-/blob/Task2_PoC/go-apps/meep-sandbox-api/api/swagger.yaml).\n",
"The model folder contains the python implementation of the data type definitions introduced by the openApi [file](https://forge.etsi.org/rep/mec/AdvantEDGE/-/blob/Task2_PoC/go-apps/meep-sandbox-api/api/swagger.yaml).\n",
"irectory:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before to create our MEC ap[plication skeleton, the following steps shall be done:\n",
"1) Change the working directory (see the project architecture)"
]
},
{
"cell_type": "code",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/home/yann/dev/jupyter/Sandbox/mecapp\n"
]
}
],
"source": [
"import os\n",
"os.chdir(os.path.join(os.getcwd(), '../mecapp'))\n",
"print(os.getcwd())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2) Do the python import"
]
},
{
"cell_type": "code",
"metadata": {},
"outputs": [],
"source": [
"from __future__ import division # Import floating-point division (1/4=0.25) instead of Euclidian division (1/4=0)\n",
"\n",
"import os\n",
"import sys\n",
"import logging\n",
"import time\n",
"import json\n",
"import uuid\n",
"\n",
"from pprint import pprint\n",
"\n",
"import swagger_client\n",
"from swagger_client.rest import ApiException\n",
"\n",
"from http import HTTPStatus\n",
"from http.server import BaseHTTPRequestHandler, HTTPServer\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"3) to initialize the global constants (cell 3)"
]
},
{
"cell_type": "code",
"MEC_SANDBOX_URL = 'https://mec-platform.etsi.org' # MEC Sandbox host/base URL\n",
"MEC_SANDBOX_API_URL = 'https://mec-platform.etsi.org/sandbox-api/v1' # MEC Sandbox API host/base URL\n",
"PROVIDER = 'Jupyter2024' # Login provider value\n",
"MEC_PLTF = 'mep1' # MEC plateform name. Linked to the network scenario\n",
"LOGGER_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' # Logging format\n",
"STABLE_TIME_OUT = 6 # Timer to wait for MEC Sndbox reaches its stable state (K8S pods in running state)\n",
"LOGIN_TIMEOUT = 3 #30 # Timer to wait for user to authorize from GITHUB\n",
"LISTENER_IP = '0.0.0.0' # Listener IPv4 address for notification callback calls\n",
"LISTENER_PORT = 32100 # Listener IPv4 port for notification callback calls\n",
"CALLBACK_URI = \"/jupyter/sandbox/demo6/v1/\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"4) to setup a logger instance and initialize the global variables (cell 4)"
]
},
{
"cell_type": "code",
"metadata": {},
"outputs": [],
"source": [
"# Initialize the logger\n",
"logger = logging.getLogger(__name__)\n",
"logger.setLevel(logging.DEBUG)\n",
"logging.basicConfig(filename='/tmp/' + time.strftime(\"%Y%m%d-%H%M%S\") + '.log')\n",
"l = logging.StreamHandler()\n",
"l.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))\n",
"logger.addHandler(l)\n",
"\n",
"# Setup the HTTP REST API configuration\n",
"configuration = swagger_client.Configuration()\n",
"configuration.verify_ssl = False\n",
"configuration.debug = True\n",
"configuration.logger_format = LOGGER_FORMAT\n",
"\n",
"# Create an instance of ApiClient to be used before each request\n",
"api = swagger_client.ApiClient(configuration, 'Content-Type', 'application/json')\n",
"\n",
"# Initialize the global variables\n",
"nw_scenarios = [] # The list of available network scenarios\n",
"nw_scenario_idx = -1 # The network scenario idx to activate (deactivate)\n",
"app_inst_id = None # The requested application instance identifier\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create our first MEC application\n",
"\n",
"The first step to develop a MEC application is to create the application skeleton which contains the minimum steps below:\n",
" \n",
"- Login to instanciate a MEC Sandbox\n",
"- Logout to delete a existing MEC Sandbox"
Loading
Loading full blame…