Commit d26629ff authored by supermikii's avatar supermikii
Browse files

demo 3 refactor

parent d526fef3
Loading
Loading
Loading
Loading
+57 −33
Original line number Diff line number Diff line
# Demo3

Demo 3 is used to showcase platform capability of 
Application Mobility Service (AMS) API and Edge Application Enablement Service APIs
Demo 3 demonstrates how to use AdvantEDGE mec services showcasing Application Mobility Service (AMS) and Edge Application Enablement Service API.

## Introduction
Demo 3 compose a user MEC application that can be integrated with AdvantEDGE scenarios or MEC Sandbox. 

Edge Application Enablement Service APIs (MEC011) allow MEC applications to:
1. Discover & offer MEC platform services
2. Subscribe for application lifecycle and MEC platform service availability notifications
###  Use-cases

MEC Applications should use the Application Mobility Service (AMS) API to perform MEC-assisted application context transfers.
Using the AMS API, MEC Applications can register for simulated terminal device Mobility Procedure notifications to trigger user application context transfers across MEC Applications
A user can deploy demo 3 as a scenario onto AdvantEDGE or as an external application to use MEC Services APIs from a MEC application

## Getting Started

There are two ways to run Demo3:
1. Running Demo3 as an external MEC Application with requirement to configure details of appInstanceId that has to be generated from the MEC Sandbox frontend along with MEC Service base path. A scenario needs to be deployed on MEC Sandbox prior to running Demo3
2. Use a pre-defined demo 3 scenario to deploy Demo3 application that runs on AdvantEdge as a container within a kubernetes environment 
Demo3 provides a GUI to interact with MEC Service APIs such as:

## Running Demo 3 as an external application with MEC Platform
1. Edge Platform Application Enablement allow MEC Applications to interact with the MEC System allowing Demo 3 to perform the following:

- MEC Application registration/deregistration 
- MEC Service discovery & offering 
- Monitor event notifications about service and application availability 

2. Application Mobility Service provides support for relocation of user context and/or application instance between MEC hosts enabling:

- AMS to trigger and assists the context transfer 
- Demo3 user-context is transferred from one instance to another user-based target mec application



## Getting Started:
Demo 3 can be started on MEC Sandbox or AdvantEDGE

###  Sandbox Procedure

- Demo 3 does not have any prior knowledge or configuration information of the MEC services offered by the MEC platform

The following steps need to be done prior to running demo 3

@@ -26,24 +37,35 @@ The following steps need to be done prior to running demo 3
| ---------  | ------ |
| 1. Login via the MEC Sandbox frontend |  |
| 2. Select a network to deploy in the user sandbox |  |
| 3a. Pre-configure `mep1.yaml` or `mep2.yaml` located in Demo 3 backend directory refer to - [File Structure](#file-structure)  | Add configuration fields <br> `mode:`  "sandbox" |
| 3b. Configure `mep1.yaml` sandbox field with MEC Service base path | Base path format `https://<my-mec-url>/<my-sandbox-key>/mep1` mep1 is an indicator to refer to an edge application running on mep1. MEC Application will learn MEC services availability via mep1 interface
| 3c. Configure `mep1.yaml` mecplatform field with which platform the demo 3 application will be running on | If demo3 will be running on mep1, it would make sense to use `mep1.yaml` as your demo3 configuration file <br> `mecplatform: 'mep1' `| 
| 3d. Obtain an application instance ID using the MEC application startup procedure and configure `mep1.yaml` appid field with application instance ID running on mep1 | `appid: '<app-instance-id>'` | 
| 3e. Pre-configure `localurl` with your I.P address and `port` to indicate port number that demo3 server will run at | `localurl: 'http://<my-ip-address>'` <br> `port: ':<my-port-number>'` 
| 4. Optional: If running a dual mep scenario on MEC sandbox. The above steps needs to be repeated to run a seperate instance of demo 3 application by applying configurations into `mep2.yaml` |  | 

configuration will look like this at the end:
| 3a. Pre-configure MEC Application named `demo3-config.yaml` under Demo 3 backend directory refer to - [File Structure](#file-structure)  | Fill configuration fields <br> `mode:  'sandbox' `| 
| 3b. Pre-configure MEC Application `sandbox` with Application Enablement service endpoints | Example: <br> `sandbox: 'https://try-mec.etsi.org/<my-sandbox-key>/<mep-host>'` <br> MEC Application will learn MEC services availability via mep host interface
| 3c. Pre-configure MEC Application `https` if sandbox url is using https and `mepplatform` with mec platform name demo-3 will run on |  Example: <br> `https: 'false'` <br> `mecplatform: 'mep1' `| 
| 3d. Pre-configure MEC Application `appid` with an Application Instance ID (e.g. appInstanceId) | 
| 3e. Pre-configure MEC Application `localurl` with your I.P address and `port` to indicate port number that demo3 server will run at | `localurl: 'http://<my-ip-address>'` <br> `port: '<my-port-number>'` 
| 4. Optional: If running a dual mep scenario on MEC sandbox. The above steps needs to be repeated to run a seperate instance of demo 3 application by applying configurations into `demo3-config-instance-two.yaml` |  | 

How configuration is expected :
```sh .env
# This file defines the configuration of Demo3 edge application. All fields are required to run demo-3 on MEC Sandbox 

# Set where mec application is running either on MEC Sandbox or AdvantEDGE. Expected fields: sandbox | advantedge
mode: 'sandbox'
sandbox: `https://<my-mec-url>/<my-sandbox-key>/mep1`
mecplatform: 'mep1'
appid: '44a0a575-916d-4cac-874c-514833dc3035'
localurl: 'http://<my-ip-address>'
port: ':8093'
# Set url of mec platform. Example field format: http://{MEC_IP_ADDRESS}/{SANDBOX_NAME}/{MEP_NAME}/ 
sandbox: 'http://{mec-host}/{sandbox-key}/{platform-name}'
# Set if sandbox url uses https. Expected fields: true | false 
https: false 
# Set the mec platform name demo-3 will run on. Example field: mep1
mecplatform: ''
# Set user-application ID that is generated on MEC Sandbox frontend. Example field format: 7930ba6d-4581-444c-b966-3312517f3a51
appid: ''
# Set host address of demo-3. 
localurl: 'http://{local-url}/'
# Set host port number of demo-3. Example field: '8093'
port: '8093'

```

### To Build Demo 3 Server
### Build Demo 3 Server

```shell
# Build demo 3 backend binary 
@@ -52,7 +74,7 @@ go build -o demo-server .
go run demo-server mep1.yaml
```

### To Build Demo 3 Frontend 
### Build Demo 3 Frontend 
1. Change directories to demo 3 frontend
```
cd ~/AdvantEDGE/examples/demo3/src/frontend
@@ -80,13 +102,13 @@ npm run build:dev
npm run build
```

## Running Demo 3 scenario on AdvantEdge
## Demo 3 AdvantEdge Procedure

#### Demo server & Demo frontend 
### Demo server & Demo frontend 

Demo server is a web server that will run internally in AdvantEdge as the backend of demo 3 application. The frontend is a dashboard to provide information on the MEC application instance in the scenario. One capability When the external UE moves in the network and transitions from one edge instance to another, the "UE state" (e.g. the counter value) is transferred using the application state transfer. On the demo server, it maintains a state of external UE as a counter that will continue incrementing (e.g. not reset to zero) when the UE moves in the network.

## Using the scenario


The following steps need to be done prior to using this scenario

@@ -114,7 +136,9 @@ cd ~/AdvantEDGE/examples/demo3/
./dockerize.sh
```

#### Open demo 3 scenario in the AdvantEdge configure tab & save
#### Using the scenario & deploy

Import `demo3-scenario.yaml` under demo3 directory into AdvantEDGE as a scenario process then deploy

#### Start demo 3 frontend

@@ -148,7 +172,7 @@ A quick look at the top-level relevant files and directories in demo 3 project.

3.  **`./backend/util`**: This directory will contain configurations for an external demo 3 application running on MEC sandbox

4.  **`./backend/util.mep1.yaml`**: This file will configurations for an external demo 3 application running on mep1
4.  **`./backend/util.demo3-config.yaml`**: This file will configurations for an external demo 3 application running on mep1

5.  **`./backend/main.go`**: This file is the entry for launching demo 3 backend
   
+20 −28
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ var sbxCtrlUrl string = "http://meep-sandbox-ctrl"
var amsClient *ams.APIClient
var amsResourceId string
var amsTargetId string
var orderedAmsAdded = []string{} // ordered terminal device added
var orderedAmsAdded = []string{}

// Api edge case handling
var svcSubscriptionSent bool
@@ -118,8 +118,6 @@ func startTicker() {
			// Error handling if cannot retrieve mec services
			discoveredServices, err := getMecServices()
			if err != nil {
				intervalTicker.Stop()
				intervalTicker = nil
				log.Error("Error polling mec services")
				// Display on activity log
				appActivityLogs = append(appActivityLogs, "Cannot retrieve mec services app will now shut down, please restart scenario!")
@@ -211,7 +209,7 @@ func Init(envPath string, envName string) (port string, err error) {
	mep = config.MecPlatform

	// If running internally in advantedge create a mec application resource else
	// set configuration variable from mec frontend app id
	// Apply config for app id, mec url path
	if environment == "advantedge" {
		sandBoxClientCfg := sbx.NewConfiguration()
		sandBoxClientCfg.BasePath = sbxCtrlUrl + "/sandbox-ctrl/v1"
@@ -240,7 +238,6 @@ func Init(envPath string, envName string) (port string, err error) {
	} else {
		appSupportClientCfg.BasePath = mecUrl + "/mec_app_support/v1"
		srvMgmtClientCfg.BasePath = mecUrl + "/mec_service_mgmt/v1"
		demoRegisteratonStatus = strconv.Itoa(200)
	}
	// Create app enablement client
	appSupportClient = asc.NewAPIClient(appSupportClientCfg)
@@ -265,6 +262,9 @@ func Init(envPath string, envName string) (port string, err error) {
	// Prepend url & port store in callbackurl
	callBackUrl = localUrl + localPort

	// Store registeration status

	demoRegisteratonStatus = strconv.Itoa(200)
	log.Info("Starting Demo 3 instance on Port=", localPort, " using app instance id=", instanceName, " mec platform=", mep)
	return localPort, nil
}
@@ -559,15 +559,6 @@ func demo3DeleteAmsDevice(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	device := vars["device"]

	// Check if ams is available
	// amsUrl := mecServicesMap["mec021-1"]
	// if amsUrl == "" {
	// 	log.Info("Could not find ams services from available services ")
	// 	w.WriteHeader(http.StatusInternalServerError)
	// 	fmt.Fprintf(w, "Could not find ams services, enable AMS first")
	// 	return
	// }

	// Get AMS Resource
	registerationInfo, _, err := amsClient.AmsiApi.AppMobilityServiceByIdGET(context.TODO(), amsResourceId)
	if err != nil {
@@ -638,7 +629,6 @@ func demo3DeleteAmsDevice(w http.ResponseWriter, r *http.Request) {

// RESP API delete application by deleting all resources
func demo3Deregister(w http.ResponseWriter, r *http.Request) {

	Terminate()
	appEnablementEnabled = false
	w.WriteHeader(http.StatusOK)
@@ -711,6 +701,14 @@ func amsNotificationCallback(w http.ResponseWriter, r *http.Request) {
	amsTargetId = amsNotification.TargetAppInfo.AppInstanceId
	targetDevice := amsNotification.AssociateId[0].Value

	// Find ams target service resource url using mec011
	serviceInfo, _, serviceErr := srvMgmtClient.MecServiceMgmtApi.AppServicesGET(context.TODO(), amsTargetId, nil)
	if serviceErr != nil {
		log.Debug("Failed to get target app mec service resource on mec platform", serviceErr.Error())
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	// Remove device from terminal devices using this instances no longer incrementing state
	for i, v := range trackDevices {
		if v == targetDevice {
@@ -726,14 +724,6 @@ func amsNotificationCallback(w http.ResponseWriter, r *http.Request) {

	counter := strconv.Itoa(terminalDeviceState[targetDevice])

	// Find ams target service resource url using mec011
	serviceInfo, _, serviceErr := srvMgmtClient.MecServiceMgmtApi.AppServicesGET(context.TODO(), amsTargetId, nil)
	if serviceErr != nil {
		log.Debug("Failed to get target app mec service resource on mec platform", serviceErr.Error())
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	// Transfer only if ams target service is found
	// Update Activity Logs
	log.Info("AMS event received for ", amsNotification.AssociateId[0].Value, " moved to app ", amsTargetId)
@@ -1131,8 +1121,7 @@ func subscribeAvailability(appInstanceId string, callbackReference string) (stri
	serAvailabilityNotificationSubscription, resp, err := srvMgmtClient.MecServiceMgmtApi.ApplicationsSubscriptionsPOST(context.TODO(), subscription, appInstanceId)
	status := strconv.Itoa(resp.StatusCode)
	if err != nil {
		log.Error("Failed to send service subscription: ", resp.Status)
		log.Info("line 1114", status)
		log.Error("Failed to send service subscription: ", err)
		appActivityLogs = append(appActivityLogs, "Subscribe to service-availability notification ["+status+"]")
		return "", err
	}
@@ -1159,7 +1148,7 @@ func confirmTerminate(appInstanceId string) {
	resp, err := appSupportClient.MecAppSupportApi.ApplicationsConfirmTerminationPOST(context.TODO(), terminationBody, appInstanceId)
	status := strconv.Itoa(resp.StatusCode)
	if err != nil {
		log.Error("Failed to send confirm termination ", resp.Status)
		log.Error("Failed to send confirm termination ", err)
	} else {
		log.Info("Confirm Terminated")
	}
@@ -1176,7 +1165,7 @@ func subscribeAppTermination(appInstanceId string, callBackReference string) (st
	appTerminationResponse, resp, err := appSupportClient.MecAppSupportApi.ApplicationsSubscriptionsPOST(context.TODO(), appTerminationBody, appInstanceId)
	status := strconv.Itoa(resp.StatusCode)
	if err != nil {
		log.Error("Failed to send termination subscription: ", resp.Status)
		log.Error("Failed to send termination subscription: ", err)
		appActivityLogs = append(appActivityLogs, "Subscribe to app-termination notification ["+status+"]")
		return "", err
	}
@@ -1200,10 +1189,13 @@ func unregisterService(appInstanceId string, serviceId string) error {
	resp, err := srvMgmtClient.MecServiceMgmtApi.AppServicesServiceIdDELETE(context.TODO(), appInstanceId, serviceId)
	status := strconv.Itoa(resp.StatusCode)
	if err != nil {
		log.Error("Failed to send request to delete service resource on mec platform ", err)

		appActivityLogs = append(appActivityLogs, "Delete Demo3 service ["+status+"]")
		log.Debug("Failed to send request to delete service resource on mec platform ", resp.Status)

		return err
	}

	appActivityLogs = append(appActivityLogs, "Delete Demo3 service ["+status+"]")
	return nil
}
+16 −0
Original line number Diff line number Diff line
# This file defines the configuration of Demo3 edge application. All fields are required to run demo-3 on MEC Sandbox 

# Set where mec application is running either on MEC Sandbox or AdvantEDGE. Expected fields: sandbox | advantedge
mode: 'sandbox'
# Set url of mec platform. Example field format: http://{MEC_IP_ADDRESS}/{SANDBOX_NAME}/{MEP_NAME}/ 
sandbox: 'http://'
# Set if sandbox url uses https. Expected fields: true | false 
https: false
# Set the mec platform name demo-3 will run on. Example field: mep1
mecplatform: 'mep2'
# Set user-application ID that is generated on MEC Sandbox frontend. Example field format: 7930ba6d-4581-444c-b966-3312517f3a51
appid: ''
# Set host address of demo-3. 
localurl: 'http://'
# Set host port number of demo-3. Example field: '8093'
port: '8094'
 No newline at end of file
+3 −3
Original line number Diff line number Diff line
@@ -3,9 +3,9 @@
# Set where mec application is running either on MEC Sandbox or AdvantEDGE. Expected fields: sandbox | advantedge
mode: 'sandbox'
# Set url of mec platform. Example field format: http://{MEC_IP_ADDRESS}/{SANDBOX_NAME}/{MEP_NAME}/ 
sandbox: 'https://'
sandbox: 'http://'
# Set if sandbox url uses https. Expected fields: true | false 
https: true 
https: false 
# Set the mec platform name demo-3 will run on. Example field: mep1
mecplatform: ''
# Set user-application ID that is generated on MEC Sandbox frontend. Example field format: 7930ba6d-4581-444c-b966-3312517f3a51
@@ -13,4 +13,4 @@ appid: ''
# Set host address of demo-3. 
localurl: 'http://'
# Set host port number of demo-3. Example field: '8093'
port: ''
port: '8093'