Unverified Commit 4f7156ef authored by Kevin Di Lallo's avatar Kevin Di Lallo Committed by GitHub
Browse files

Merge pull request #88 from pastorsx/sp_dev_loc-serv_test

Location service UT testing
parents ee7b274f 2f186b5e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ require (
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-http-logger v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-loc-serv-notification-client v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-metric-store v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-model v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-mq v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis v0.0.0
+21 −14
Original line number Diff line number Diff line
@@ -19,15 +19,12 @@ package sbi
import (
	"strings"

	httpLog "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-http-logger"
	log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger"
	mod "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-model"
	mq "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-mq"
)

const moduleName string = "meep-loc-serv-sbi"
const redisAddr string = "meep-redis-master.default.svc.cluster.local:6379"
const influxAddr string = "http://meep-influxdb.default.svc.cluster.local:8086"

type LocServSbi struct {
	sandboxName             string
@@ -37,14 +34,20 @@ type LocServSbi struct {
	updateUserInfoCB        func(string, string, string)
	updateZoneInfoCB        func(string, int, int, int)
	updateAccessPointInfoCB func(string, string, string, string, int)
	updateScenarioNameCB    func(string)
	cleanUpCB               func()
}

var sbi *LocServSbi

// Init - Location Service SBI initialization
func Init(sandboxName string, updateUserInfo func(string, string, string), updateZoneInfo func(string, int, int, int),
	updateAccessPointInfo func(string, string, string, string, int), cleanUp func()) (err error) {
func Init(sandboxName string,
	redisAddr string,
	updateUserInfo func(string, string, string),
	updateZoneInfo func(string, int, int, int),
	updateAccessPointInfo func(string, string, string, string, int),
	updateScenarioName func(string),
	cleanUp func()) (err error) {

	// Create new SBI instance
	sbi = new(LocServSbi)
@@ -75,6 +78,7 @@ func Init(sandboxName string, updateUserInfo func(string, string, string), updat
	sbi.updateUserInfoCB = updateUserInfo
	sbi.updateZoneInfoCB = updateZoneInfo
	sbi.updateAccessPointInfoCB = updateAccessPointInfo
	sbi.updateScenarioNameCB = updateScenarioName
	sbi.cleanUpCB = cleanUp

	// Initialize service
@@ -128,16 +132,14 @@ func processActiveScenarioUpdate() {

	// Sync with active scenario store
	sbi.activeModel.UpdateScenario()
	if sbi.activeModel.GetScenarioName() == "" {
		return
	}

	scenarioName := sbi.activeModel.GetScenarioName()
	sbi.updateScenarioNameCB(scenarioName)

	uePerNetLocMap := make(map[string]int)
	uePerZoneMap := make(map[string]int)
	poaPerZoneMap := make(map[string]int)

	_ = httpLog.ReInit(moduleName, sbi.sandboxName, sbi.activeModel.GetScenarioName(), redisAddr, influxAddr)

	// Update UE info
	ueNameList := sbi.activeModel.GetNodeNames("UE")
	for _, name := range ueNameList {
@@ -159,17 +161,17 @@ func processActiveScenarioUpdate() {
		uePerNetLocMap[netLoc]++
	}

	// Update POA info
	poaNameList := sbi.activeModel.GetNodeNames("POA")
	// Update POA-CELL info
	poaNameList := sbi.activeModel.GetNodeNames("POA-CELL")
	for _, name := range poaNameList {
		ctx := sbi.activeModel.GetNodeContext(name)
		if ctx == nil {
			log.Error("Error getting context for POA: " + name)
			log.Error("Error getting context for POA-CELL: " + name)
			continue
		}
		nodeCtx, ok := ctx.(*mod.NodeContext)
		if !ok {
			log.Error("Error casting context for POA: " + name)
			log.Error("Error casting context for POA-CELL: " + name)
			continue
		}
		zone := nodeCtx.Parents[mod.Zone]
@@ -187,3 +189,8 @@ func processActiveScenarioUpdate() {
		}
	}
}

func Stop() (err error) {
	sbi.mqLocal.UnregisterHandler(sbi.handlerId)
	return nil
}
+37 −22
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import (

const LocServBasePath = "/location/v1/"
const locServKey string = "loc-serv:"
const logModuleLocServ string = "meep-loc-serv"

const typeZone = "zone"
const typeAccessPoint = "accessPoint"
@@ -77,8 +78,10 @@ type ZoneStatusCheck struct {
}

var LOC_SERV_DB = 5
var currentStoreName = ""

const redisAddr string = "meep-redis-master.default.svc.cluster.local:6379"
var redisAddr string = "meep-redis-master.default.svc.cluster.local:6379"
var influxAddr string = "http://meep-influxdb.default.svc.cluster.local:8086"

var rc *redis.Connector
var hostUrl *url.URL
@@ -89,8 +92,10 @@ var baseKey string
// Init - Location Service initialization
func Init() (err error) {

	// Retrieve Sandbox name from environment variable
	sandboxName = strings.TrimSpace(os.Getenv("MEEP_SANDBOX_NAME"))
	sandboxNameEnv := strings.TrimSpace(os.Getenv("MEEP_SANDBOX_NAME"))
	if sandboxNameEnv != "" {
		sandboxName = sandboxNameEnv
	}
	if sandboxName == "" {
		err = errors.New("MEEP_SANDBOX_NAME env variable not set")
		log.Error(err.Error())
@@ -124,7 +129,7 @@ func Init() (err error) {
	zoneStatusReInit()

	//sbi is the sole responsible of updating the userInfo, zoneInfo and apInfo structures
	return sbi.Init(sandboxName, updateUserInfo, updateZoneInfo, updateAccessPointInfo, cleanUp)
	return sbi.Init(sandboxName, redisAddr, updateUserInfo, updateZoneInfo, updateAccessPointInfo, updateStoreName, cleanUp)
}

// Run - Start Location Service
@@ -132,6 +137,11 @@ func Run() (err error) {
	return sbi.Run()
}

// Stop - Stop RNIS
func Stop() (err error) {
	return sbi.Stop()
}

func createClient(notifyPath string) (*clientNotifOMA.APIClient, error) {
	// Create & store client for App REST API
	subsAppClientCfg := clientNotifOMA.NewConfiguration()
@@ -376,20 +386,18 @@ func sendNotification(notifyUrl string, ctx context.Context, subscriptionId stri
		return
	}

	resp, err := client.NotificationsApi.PostTrackingNotification(ctx, subscriptionId, notification)
	if err != nil {
		log.Error(err)
		return
	}
	defer resp.Body.Close()

	jsonNotif, err := json.Marshal(notification)
	if err != nil {
		log.Error(err.Error())
	}

	resp, err := client.NotificationsApi.PostTrackingNotification(ctx, subscriptionId, notification)
	_ = httpLog.LogTx(notifyUrl, "POST", string(jsonNotif), resp, startTime)

	if err != nil {
		log.Error(err)
		return
	}
	defer resp.Body.Close()
}

func sendStatusNotification(notifyUrl string, ctx context.Context, subscriptionId string, notification clientNotifOMA.ZoneStatusNotification) {
@@ -401,20 +409,18 @@ func sendStatusNotification(notifyUrl string, ctx context.Context, subscriptionI
		return
	}

	resp, err := client.NotificationsApi.PostZoneStatusNotification(ctx, subscriptionId, notification)
	if err != nil {
		log.Error(err)
		return
	}
	defer resp.Body.Close()

	jsonNotif, err := json.Marshal(notification)
	if err != nil {
		log.Error(err.Error())
	}

	resp, err := client.NotificationsApi.PostZoneStatusNotification(ctx, subscriptionId, notification)
	_ = httpLog.LogTx(notifyUrl, "POST", string(jsonNotif), resp, startTime)

	if err != nil {
		log.Error(err)
		return
	}
	defer resp.Body.Close()
}

func checkNotificationRegisteredZones(oldZoneId string, newZoneId string, oldApId string, newApId string, userId string) {
@@ -1115,9 +1121,9 @@ func zoneStatusGetById(w http.ResponseWriter, r *http.Request) {
func zoneStatusPost(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

	var response ResponseZoneStatusSubscription
	var response ResponseZoneStatusSubscription2
	zoneStatusSub := new(ZoneStatusSubscription)
	response.ZonalTrafficSubscription = zoneStatusSub
	response.ZoneStatusSubscription = zoneStatusSub

	decoder := json.NewDecoder(r.Body)
	err := decoder.Decode(&zoneStatusSub)
@@ -1233,6 +1239,15 @@ func cleanUp() {
	userSubscriptionMap = map[int]string{}

	zoneStatusSubscriptionMap = map[int]*ZoneStatusCheck{}

	updateStoreName("")
}

func updateStoreName(storeName string) {
	if currentStoreName != storeName {
		currentStoreName = storeName
		_ = httpLog.ReInit(logModuleLocServ, sandboxName, storeName, redisAddr, influxAddr)
	}
}

func updateUserInfo(address string, zoneId string, accessPointId string) {
+2246 −0

File added.

Preview size limit exceeded, changes collapsed.

+4 −2
Original line number Diff line number Diff line
@@ -758,6 +758,8 @@ func cleanUp() {
}

func updateStoreName(storeName string) {
	if currentStoreName != storeName {
		currentStoreName = storeName
		_ = httpLog.ReInit(logModuleRNIS, sandboxName, storeName, redisAddr, influxAddr)
	}
}
Loading