Commit e96c8f42 authored by Yann Garcia's avatar Yann Garcia
Browse files

Add location support for demo4-ue

parent e585d3b6
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -7,11 +7,13 @@ require (
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-dai-client v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-data-key-mgr v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-http-logger v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-loc-serv-client v0.0.0-20211214133749-f203f7ab4f1c
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-metrics v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sandbox-ctrl-client v0.0.0-20211214133749-f203f7ab4f1c
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-service-mgmt-client v0.0.0-20211214133749-f203f7ab4f1c
	github.com/antihax/optional v1.0.0
	github.com/google/uuid v1.1.2
	github.com/gorilla/handlers v1.5.1
	github.com/gorilla/mux v1.8.0
@@ -23,6 +25,7 @@ replace (
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-dai-client => ../../../../../go-packages/meep-dai-client
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-data-key-mgr => ../../../../../go-packages/meep-data-key-mgr
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-http-logger => ../../../../../go-packages/meep-http-logger
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-loc-serv-client => ../../../../../go-packages/meep-loc-serv-client
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger => ../../../../../go-packages/meep-logger
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-metrics => ../../../../../go-packages/meep-metrics
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis => ../../../../../go-packages/meep-redis
+75 −23
Original line number Diff line number Diff line
@@ -25,14 +25,17 @@ import (
	"strconv"
	"strings"
	"sync"
	"time"

	"github.com/AdvantEDGE/examples/demo4-ue/src/demo-server/backend/util"
	asc "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-app-support-client"
	dai "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-dai-client"
	loc "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-loc-serv-client"
	log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger"
	sbx "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sandbox-ctrl-client"
	smc "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-service-mgmt-client"

	"github.com/antihax/optional"
	uuid "github.com/google/uuid"
	"github.com/gorilla/mux"
)
@@ -56,6 +59,11 @@ var appSupportClientPath string
var sandBoxClient *sbx.APIClient
var sbxCtrlUrl string = "http://meep-sandbox-ctrl"

// Location client
var locServ *loc.APIClient
var locExpiry time.Duration = 5 * time.Second
var locTicker *time.Ticker

// DAI client
var daiClient *dai.APIClient
var daiServiceName string
@@ -74,6 +82,7 @@ var localUrl string
var environment string
var callBackUrl string
var nodeName string
var userInfo loc.UserInfo

// App service & discovered service
var mecServicesMap = make(map[string]string)
@@ -198,17 +207,21 @@ func Init(envPath string, envName string) (port string, err error) {
	// Setup application support client & service management client
	appSupportClientCfg := asc.NewConfiguration()
	srvMgmtClientCfg := smc.NewConfiguration()
	locServerCfg := loc.NewConfiguration()
	if environment == "advantedge" {
		if config.MecPlatform != "" {
			appSupportClientCfg.BasePath = "http://" + mep + "-meep-app-enablement" + "/mec_app_support/v1"
			srvMgmtClientCfg.BasePath = "http://" + mep + "-meep-app-enablement" + "/mec_service_mgmt/v1"
			locServerCfg.BasePath = "http://" + mep + "-meep-loc-serv" + "/location/v2"
		} else {
			appSupportClientCfg.BasePath = "http://meep-app-enablement/mec_app_support/v1"
			srvMgmtClientCfg.BasePath = "http://meep-app-enablement/mec_service_mgmt/v1"
			locServerCfg.BasePath = "http://meep-loc-serv" + "/location/v2"
		}
	} else {
		appSupportClientCfg.BasePath = mecUrl + "/mec_app_support/v1"
		srvMgmtClientCfg.BasePath = mecUrl + "/mec_service_mgmt/v1"
		locServerCfg.BasePath = mecUrl + "/location/v2"
	}

	// Create app enablement client
@@ -231,22 +244,16 @@ func Init(envPath string, envName string) (port string, err error) {
	demoAppInfo.Id = instanceName
	demoAppInfo.Ip = callBackUrl

	// Register to LocationServer
	locServ = loc.NewAPIClient(locServerCfg)
	if locServ == nil {
		return "", errors.New("Failed to create LocationServer REST API client")
	}

	log.Info("Starting Demo 4 instance on Port=", localPort, " using app instance id=", instanceName, " mec platform=", mep)
	return localPort, nil
}

// func setApplicationInfo(appInfo sbx.ApplicationInfo) (appInfoRes sbx.ApplicationInfo, err error) {
// 	log.Info(">>> setApplicationInfo: ", appInfo)
// 	appInfoRes, resp, err := sandBoxClient.ApplicationsApi.ApplicationsPOST(context.TODO(), appInfo)
// 	if err != nil {
// 		log.Error(err.Error())
// 		return appInfoRes, err
// 	}
// 	log.Debug("setApplicationInfo: Receive confirmation acknowlegement ", resp.Status)

// 	return appInfoRes, nil
// }

func getApplicationInfo(appId string) (appInfo sbx.ApplicationInfo, err error) {
	appInfo, resp, err := sandBoxClient.ApplicationsApi.ApplicationsAppInstanceIdGET(context.TODO(), appId)
	if err != nil {
@@ -259,16 +266,6 @@ func getApplicationInfo(appId string) (appInfo sbx.ApplicationInfo, err error) {
	return appInfo, nil
}

// func getAllApplicationInfo() (appInfo []sbx.ApplicationInfo, err error) {
// 	appInfo, resp, err := sandBoxClient.ApplicationsApi.ApplicationsGET(context.TODO(), nil)
// 	if err != nil {
// 		log.Info("Failed to retrieve mec application resource ", err)
// 		return appInfo, err
// 	}

// 	return appInfo, nil
// }

func demo4Register() (err error) {

	mutex.Lock()
@@ -394,6 +391,8 @@ func Run(msg chan bool) {
	if err != nil {
		log.Fatal("Failed to register demo4-ue: ", err.Error())
	}
	startProcessLocTicker()
	log.Info("ProcessLocTicker successfully started")

	done = msg
}
@@ -404,6 +403,8 @@ func Terminate() {
	// Only invoke graceful termination if not terminated (triggerd by mec platform)
	if !terminated {

		stopProcessLocTicker()

		if appEnabled {
			//intervalTicker.Stop()
			log.Info("De-register Demo4 MEC Application")
@@ -1077,3 +1078,54 @@ func appTerminationNotificationCallback(w http.ResponseWriter, r *http.Request)
	demoAppInfo.MecTerminated = true
	Terminate()
}

func startProcessLocTicker() {
	// Make sure ticker is not running
	if locTicker != nil {
		log.Warn("Registration ticker already running")
		return
	}

	// Start registration ticker
	locTicker = time.NewTicker(locExpiry)
	go func() {

		for range locTicker.C {

			// Get UI position
			s := make([]string, 1)
			s[0] = nodeName
			var localVarOptionals loc.UsersGETOpts
			localVarOptionals.Address = optional.NewInterface(s)
			log.Debug("startProcessLocTicker: Call UsersGet with: ", localVarOptionals)
			usersList, _, err := locServ.LocationApi.UsersGET(context.TODO(), &localVarOptionals)
			if err != nil {
				log.Error("UsersGet: Failed: ", err)
				continue // Infinite loop till stopProcessCheckTicker is call
			}
			if usersList.UserList != nil {
				log.Debug("startProcessLocTicker: usersList: ", usersList.UserList)
				log.Debug("startProcessLocTicker: usersList: ", len(usersList.UserList.User))
				if len(usersList.UserList.User) != 0 {
					for _, u := range usersList.UserList.User {
						if u.Address == nodeName && u.LocationInfo != nil {
							userInfo = u
							log.Debug("startProcessLocTicker: New position: ", userInfo.LocationInfo)
							break
						}
					} // End of 'for' statement
				}
			}

			continue // Infinite loop till stopProcessCheckTicker is call
		} // End of 'for' statement
	}()
}

func stopProcessLocTicker() {
	if locTicker != nil {
		log.Info("Stopping App Enablement registration ticker")
		locTicker.Stop()
		locTicker = nil
	}
}
+94 −18
Original line number Diff line number Diff line
@@ -112,14 +112,8 @@ deployment:
                                            id: ce454f4c-16f8-4542-83d8-c8afd45bcfea
                                            name: demo4-ue1
                                            type: EDGE-APP
                                            isExternal: false
                                            userChartLocation: null
                                            userChartAlternateValues: null
                                            userChartGroup: null
                                            image: 'meep-docker-registry:30001/demo4-ue'
                                            environment: ""
                                            commandArguments: ""
                                            commandExe: ""
                                            environment: MEEP_NODE_NAME=10.10.20.01
                                            serviceConfig:
                                                name: demo4-ue1
                                                meSvcName: demo4-ue
@@ -128,17 +122,9 @@ deployment:
                                                        protocol: TCP
                                                        port: 80
                                                        externalPort: 31111
                                            gpuConfig: null
                                            cpuConfig: null
                                            memoryConfig: null
                                            externalConfig: null
                                            netChar:
                                                latency: 0
                                                latencyVariation: 0
                                                throughputDl: 1000
                                                throughputUl: 1000
                                                packetLoss: 0
                                            placementId: ""
                                    netChar:
                                        latencyDistribution: Normal
                                        throughputDl: 1000
@@ -170,14 +156,104 @@ deployment:
                                        location:
                                            type: Point
                                            coordinates:
                                                - 7.423684
                                                - 43.727867
                                                - 7.420433
                                                - 43.729942
                                        path:
                                            type: LineString
                                            coordinates:
                                                -
                                                    - 7.420433
                                                    - 43.729942
                                                -
                                                    - 7.420659
                                                    - 43.73036
                                                -
                                                    - 7.420621
                                                    - 43.731045
                                                -
                                                    - 7.420922
                                                    - 43.73129
                                                -
                                                    - 7.421345
                                                    - 43.731373
                                                -
                                                    - 7.42135
                                                    - 43.73168
                                                -
                                                    - 7.421148
                                                    - 43.73173
                                                -
                                                    - 7.420616
                                                    - 43.731964
                                                -
                                                    - 7.419779
                                                    - 43.732197
                                                -
                                                    - 7.419111
                                                    - 43.732353
                                                -
                                                    - 7.418931
                                                    - 43.732315
                                                -
                                                    - 7.418345
                                                    - 43.731964
                                                -
                                                    - 7.418319
                                                    - 43.73186
                                                -
                                                    - 7.418024
                                                    - 43.73179
                                                -
                                                    - 7.41796
                                                    - 43.731728
                                                -
                                                    - 7.417729
                                                    - 43.731743
                                                -
                                                    - 7.417463
                                                    - 43.731632
                                                -
                                                    - 7.417507
                                                    - 43.73148
                                                -
                                                    - 7.417428
                                                    - 43.731407
                                                -
                                                    - 7.417343
                                                    - 43.731396
                                                -
                                                    - 7.417334
                                                    - 43.731133
                                                -
                                                    - 7.417317
                                                    - 43.73053
                                                -
                                                    - 7.417164
                                                    - 43.7304
                                                -
                                                    - 7.417164
                                                    - 43.72998
                                                -
                                                    - 7.417319
                                                    - 43.729916
                                                -
                                                    - 7.419065
                                                    - 43.730103
                                        eopMode: REVERSE
                                        velocity: 1
                                    connected: true
                                    wireless: true
                                    wirelessType: 'wifi,5g,4g,other'
                                    dataNetwork: {}
                                    dataNetwork:
                                        dnn: ""
                                        ladn: false
                                        ecsp: ""
                                    netChar:
                                        latencyDistribution: Normal
                                        throughputDl: 1000
                                        throughputUl: 1000
                                        latency: 0
                                        latencyVariation: 0
                                        packetLoss: 0
                                    macId: DEADBEEF0001
                                    label: 10.10.20.01
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ echo "mecplatform: ${MEEP_MEP_NAME}" >>app_instance.yaml
echo "appid:" ${MEEP_APP_ID} >>app_instance.yaml
echo "localurl: ${MEEP_POD_NAME}" >>app_instance.yaml
echo "port:" >>app_instance.yaml
echo "nodename: ${MEEP_NODE_NAME}" >>app_instance.yaml

# Start service
exec /demo-server ./app_instance.yaml
+1 −1
Original line number Diff line number Diff line
@@ -312,7 +312,7 @@ func NewDaiMgr(cfg DaiCfg) (am *DaiMgr, err error) {
	if cfg.NotifyAppContextDeletion != nil {
		notifyAppContextDeletion = cfg.NotifyAppContextDeletion
		startProcessCheckTicker()
		log.Info("ProcessCheckTicker successfully stared")
		log.Info("ProcessCheckTicker successfully started")
	}

	daiMgr = am