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

Enhance DAI testing

parent 914f86a8
Loading
Loading
Loading
Loading
+11 −67
Original line number Diff line number Diff line
@@ -50,74 +50,11 @@ type SbiCfg struct {
	PostgisPort    string
	Locality       []string
	AppInfoList    func(meepdaimgr.AppInfoList)
	NotifyAppContextDeletion func(string, string)
	ScenarioNameCb func(string)
	CleanUpCb      func()
}

// type AppCharcs struct {
// 	Memory      *uint32
// 	Storage     *uint32
// 	Latency     *uint32
// 	Bandwidth   *uint32
// 	ServiceCont *uint32
// }

// type LocationConstraints []LocationConstraintsItem
// type LocationConstraintsItem struct {
// 	Area                *Polygon
// 	CivicAddressElement []CivicAddressElementItem
// 	CountryCode         *string
// }
// type Polygon struct {
// 	Coordinates [][][]float32
// }
// type CivicAddressElementItem struct {
// 	CaType  int32
// 	CaValue string
// }

// type AppInfoSbi struct {
// 	AppDId         string
// 	AppName        string
// 	AppProvider    string
// 	AppSoftVersion string
// 	AppDVersion    string
// 	AppDescription string
// 	AppLocation    LocationConstraints
// 	AppCharcs      []AppCharcs
// }

// type meepdaimgr.AppInfoList struct {
// 	AppList []AppInfoSbi
// }

// type AppContextSbi struct {
// 	AppAutoInstantiation *bool
// 	AppInfo AppContextAppInfo
// 	AppLocationUpdates *bool
// 	AssociateDevAppId string
// 	CallbackReference meepdaimgr.Uri
// 	ContextId string

// }

// type AppContextAppInfo struct {
// 	AppDId string
// 	AppDVersion string
// 	AppDescription string
// 	AppName string
// 	AppProvider string
// 	AppSoftVersion string
// 	AppPackageSource string
// 	UserAppInstanceInfo []AppContextAppInfoUserAppInstanceInfo
// }

// type AppContextAppInfoUserAppInstanceInfo struct {
// 	AppInstanceId string
// 	AppLocation []LocationConstraints
// 	ReferenceURI string
// }

type DaiSbi struct {
	moduleName           string
	sandboxName          string
@@ -215,7 +152,7 @@ func Init(cfg SbiCfg) (err error) {
		log.Error("Failed connection to VIS Traffic Manager: ", err)
		return err
	}
	log.Info("Connected to VIS Traffic Manager")
	log.Info("Connected to DAI Manager")

	// Delete any old tables
	_ = sbi.daiMgr.DeleteTables()
@@ -380,7 +317,7 @@ func processActiveScenarioUpdate() {
func refreshAppList() error {
	sbi.mutex.Lock()
	defer sbi.mutex.Unlock()
	log.Info("Update AppList data struct")
	/*log.Info("Update AppList data struct")

	// Build the list of all application
	appInfo, err := sbi.daiMgr.GetAllAppList()
@@ -388,7 +325,7 @@ func refreshAppList() error {
		log.Error(err.Error())
		return err
	}
	log.Debug("appContextMap: ", appInfo)
	log.Debug("appContextMap: ", appInfo)*/

	// Store it into Redis

@@ -565,6 +502,13 @@ func PutAppContext(appContextSbi meepdaimgr.AppContext) (err error) {
	return nil
}

func notifyAppContextDeletion(appContextSbi meepdaimgr.AppContext) (err error) {
	log.Debug(">>> notifyAppContextDeletion: ", appContextSbi)
	log.Debug(">>> notifyAppContextDeletion: ", *appContextSbi.ContextId)

	return nil
}

func isAppConnected(app string) bool {
	parentNode := sbi.activeModel.GetNodeParent(app)
	if parentNode != nil {
+30 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package server

import (
	"bytes"
	"context"
	"encoding/json"
	"errors"
@@ -68,7 +69,11 @@ var sboxCtrlBasepath = "http://meep-sandbox-ctrl"
var postgresHost string = ""
var postgresPort string = ""

// No notifications
// Notifications
const (
	applicationContextDeleteNotification = "ApplicationContextDeleteNotification"
	applicationContextUpdateNotification = "ApplicationContextUpdateNotification"
)

// No Subscriptions

@@ -217,6 +222,7 @@ func Init() (err error) {
		InfluxAddr:     influxAddr,
		Locality:       locality,
		AppInfoList:    updateAppInfoList,
		NotifyAppContextDeletion: notifyAppContextDeletion,
		ScenarioNameCb: updateStoreName,
		CleanUpCb:      cleanUp,
	}
@@ -811,6 +817,29 @@ func appLocationAvailabilityPOST(w http.ResponseWriter, r *http.Request) {
	w.WriteHeader(http.StatusOK)
}

func notifyAppContextDeletion(notifyUrl string, contextId string) {
	log.Debug(">>> notifyAppContextDeletion: ", notifyUrl)
	log.Debug(">>> notifyAppContextDeletion: ", contextId)

	startTime := time.Now()
	var appContextDeleteNotification = ApplicationContextDeleteNotification{applicationContextDeleteNotification, contextId}
	jsonNotif, err := json.Marshal(appContextDeleteNotification)
	if err != nil {
		log.Error(err.Error())
	}

	resp, err := http.Post(notifyUrl, "application/json", bytes.NewBuffer(jsonNotif))
	duration := float64(time.Since(startTime).Microseconds()) / 1000.0
	_ = httpLog.LogTx(notifyUrl, "POST", string(jsonNotif), resp, startTime)
	if err != nil {
		log.Error(err)
		met.ObserveNotification(sandboxName, serviceName, applicationContextDeleteNotification, notifyUrl, nil, duration)
		return
	}
	met.ObserveNotification(sandboxName, serviceName, applicationContextDeleteNotification, notifyUrl, resp, duration)
	defer resp.Body.Close()
}

func cleanUp() {
	log.Info("Terminate all")
	rc.DBFlush(baseKey)
+14 −14
Original line number Diff line number Diff line
@@ -485,10 +485,10 @@ const (
	callbackReference1 = "callbackReference1"
	//appLocationUpdates1   = true
	//appAutoInstantiation1 = false
	appName1        = "appName1"
	appProvider1    = "appProvider1"
	appDVersion1    = "appDVersion1"
	appDescription1 = "appDescription1"
	appName1        = "onboarded-demo4"
	appProvider1    = "ETSI"
	appDVersion1    = "v0.1.0"
	appDescription1 = "Basic HTTP Ping Pong"

	//associateDevAppId2    = "associateDevAppId2"
	callbackReference2 = "callbackReference2"
@@ -501,9 +501,9 @@ const (
)

var ( // Need to take address
	contextId1        string = "contextId1"
	appDId1           string = "appDId1"
	appSoftVersion1   string = "appSoftVersion1"
	contextId1        string = "onboarded-demo4"
	appDId1           string = "onboarded-demo4"
	appSoftVersion1   string = "v0.1.0"
	appPackageSource1 string = "appPackageSource1"
	//appInstanceId1_1     string         = "appInstanceId1-1"
	//appInstanceId1_2     string         = "appInstanceId1-2"
@@ -512,7 +512,7 @@ var ( // Need to take address
	//referenceURI1_3      meepdaimgr.Uri = "referenceURI1-3"
	area1                       = Polygon{[][][]float32{{{7.420433, 43.729942}, {7.420659, 43.73036}, {7.420621, 43.731045}, {7.420922, 43.73129}}, {{7.420434, 43.729943}, {7.420659, 43.73036}, {7.420621, 43.731045}, {7.420922, 43.73129}}}}
	civicAddressElement1        = []LocationConstraintsCivicAddressElement{{1, "Value1"}, {10, "Value10"}}
	countryCode1         string = "countryCode1"
	countryCode1         string = "33"
	memory1              int32  = 1024
	storage1             int32  = 1024
	latency1             int32  = 1024
@@ -571,9 +571,8 @@ func TestAppListGET(t *testing.T) {
	 * expected response section
	 ******************************/
	// Fill LocationConstraints table
	appLocationConstraints := make([]LocationConstraints, 2)
	appLocationConstraints[0] = LocationConstraints{&area1, make([]LocationConstraintsCivicAddressElement, 0), countryCode1}
	appLocationConstraints[1] = LocationConstraints{nil, civicAddressElement1, ""}
	appLocationConstraints := make([]LocationConstraints, 1)
	appLocationConstraints[0] = LocationConstraints{nil, nil, countryCode1}
	// Fill ApplicationListAppInfo
	var appInfo ApplicationListAppInfo
	appInfo.AppDId = appDId1
@@ -640,8 +639,8 @@ func TestAppListGET(t *testing.T) {
	}
	fmt.Println("respBody: ", respBody)
	receivedAppList = convertJsonToApplicationList(rr)
	appList.AppList = make([]ApplicationListAppList, 0)
	if !validateApplicationList(receivedAppList, appList) {
	var emptyApplicationList ApplicationList
	if !validateApplicationList(receivedAppList, emptyApplicationList) {
		t.Errorf("handler returned unexpected body: got %v want %v", rr, expected_json_response)
	}
	log.Info("Received expected response")
@@ -890,7 +889,6 @@ func initializeVars() {
	redisAddr = redisTestAddr
	influxAddr = influxTestAddr
	sandboxName = testScenarioName
	os.Setenv("MEEP_PREDICT_MODEL_SUPPORTED", "true")
	os.Setenv("MEEP_SANDBOX_NAME", testScenarioName)
	postgresHost = postgresTestHost
	postgresPort = postgresTestPort
@@ -1118,6 +1116,8 @@ func validateApplicationList(appInfoListEntry *ApplicationList, appInfoList Appl
				fmt.Println("appList.AppInfo.AppCharcs != appInfoList.AppList.AppInfo.AppCharcs")
				return false
			}
			fmt.Println("===> len(appList.AppInfo.AppLocation): ", len(appList.AppInfo.AppLocation))
			fmt.Println("===> len(appInfoList.AppList[i].AppInfo.AppLocation): ", len(appInfoList.AppList[i].AppInfo.AppLocation))
			if len(appList.AppInfo.AppLocation) != len(appInfoList.AppList[i].AppInfo.AppLocation) {
				fmt.Println("len(appList.AppInfo.AppLocation) != len(appInfoList.AppList[i].AppInfo.AppLocation)")
				return false
+18 −16
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import (

	log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger"

	//"github.com/lib/pq"
	_ "github.com/lib/pq"
)

@@ -490,15 +489,17 @@ func (am *DaiMgr) CreateTables() (err error) {

// SimulateExistingApplication -- This function simulates an existing onboarded MEC Application on platform. It shall be removed later
func (am *DaiMgr) SimulateExistingApplication() (err error) {
	log.Info("SimulateExistingApplication")

	const (
		//associateDevAppId1    = "associateDevAppId1"
		//callbackReference1    = "callbackReference1"
		//callbackReference1    = "http://`docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 82c1d2d846ce`:8080"
		//appLocationUpdates1   = true
		//appAutoInstantiation1 = false
		appName1        = "appName1"
		appProvider1    = "appProvider1"
		appDVersion1    = "appDVersion1"
		appDescription1 = "appDescription1"
		appName1        = "onboarded-demo4"
		appProvider1    = "ETSI"
		appDVersion1    = "v0.1.0"
		appDescription1 = "Basic HTTP Ping Pong"

		//associateDevAppId2    = "associateDevAppId2"
		//callbackReference2    = "callbackReference2"
@@ -512,17 +513,17 @@ func (am *DaiMgr) SimulateExistingApplication() (err error) {

	var ( // Need to take address
		//contextId1               string = "contextId1"
		appDId1         string = "appDId1"
		appSoftVersion1 string = "appSoftVersion1"
		appDId1         string = "onboarded-demo4"
		appSoftVersion1 string = "v0.1.0"
		//appPackageSource1        string = "appPackageSource1"
		//appInstanceId1_1         string = "appInstanceId1-1"
		//appInstanceId1_2         string = "appInstanceId1-2"
		//appInstanceId1_3         string = "appInstanceId1-3"
		//referenceURI1_1          uri    = "referenceURI1-1"
		//referenceURI1_3          uri    = "referenceURI1-3"
		area1                       = Polygon{[][][]float32{{{7.420433, 43.729942}, {7.420659, 43.73036}, {7.420621, 43.731045}, {7.420922, 43.73129}}, {{7.420434, 43.729943}, {7.420659, 43.73036}, {7.420621, 43.731045}, {7.420922, 43.73129}}}}
		civicAddressElement1        = CivicAddressElement{{1, "Value1"}, {10, "Value10"}}
		countryCode1         string = "countryCode1"
		//area1                       = Polygon{[][][]float32{{{7.420433, 43.729942}, {7.420659, 43.73036}, {7.420621, 43.731045}, {7.420922, 43.73129}}, {{7.420434, 43.729943}, {7.420659, 43.73036}, {7.420621, 43.731045}, {7.420922, 43.73129}}}}
		//civicAddressElement1        = CivicAddressElement{{1, "Value1"}, {10, "Value10"}}
		countryCode1         string = "33"
		memory1              uint32 = 1024
		storage1             uint32 = 1024
		latency1             uint32 = 1024
@@ -546,9 +547,8 @@ func (am *DaiMgr) SimulateExistingApplication() (err error) {
	)

	// Build a complete AppInfoList data structure
	appLocation1 := make([]LocationConstraintsItem, 2)
	appLocation1[0] = LocationConstraintsItem{&area1, nil, &countryCode1}
	appLocation1[1] = LocationConstraintsItem{nil, &civicAddressElement1, nil}
	appLocation1 := make([]LocationConstraintsItem, 1)
	appLocation1[0] = LocationConstraintsItem{nil, nil, &countryCode1}
	appCharcs1 := make([]AppCharcs, 1)
	appCharcs1[0] = AppCharcs{&memory1, &storage1, &latency1, &bandwidth1, &serviceCont1}
	appInfoList1 := AppInfoList{appDId1, appName1, appProvider1, appSoftVersion1, appDVersion1, appDescription1, appLocation1, appCharcs1}
@@ -558,7 +558,7 @@ func (am *DaiMgr) SimulateExistingApplication() (err error) {
		return err
	}

	// Build another complete AppInfoList data structure
	// Build another complete dummy AppInfoList data structure
	appLocation2 := make([]LocationConstraintsItem, 2)
	appLocation2[0] = LocationConstraintsItem{&area2, nil, &countryCode2}
	appLocation2[1] = LocationConstraintsItem{nil, &civicAddressElement2, nil}
@@ -571,7 +571,7 @@ func (am *DaiMgr) SimulateExistingApplication() (err error) {
		return err
	}

	log.Info("Created existing application")
	log.Info("Created onboarded user application")
	return nil
}

@@ -676,6 +676,8 @@ func (am *DaiMgr) DeleteAppContext(appContextId string) (err error) {
		return errors.New("ContextId not found")
	}

	// TODO Add logic to delete applicationListAppList

	// Notify listener
	am.notifyListener(appContextId)