Commit 500f7dc3 authored by Kevin Di Lallo's avatar Kevin Di Lallo
Browse files

migrated loc-serv to new model + added script to start UT redis DB instance

parent 77a1d7f9
Loading
Loading
Loading
Loading
+9 −13
Original line number Diff line number Diff line
@@ -3,29 +3,25 @@ module github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-loc-serv
go 1.12

require (
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-ctrl-engine-model 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-model v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis v0.0.0
	github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6 // indirect
	github.com/flimzy/diff v0.1.5 // indirect
	github.com/flimzy/kivik v1.8.1 // indirect
	github.com/flimzy/testy v0.1.16 // indirect
	github.com/go-kivik/couchdb v1.8.1 // indirect
	github.com/gogo/protobuf v1.2.1 // indirect
	github.com/google/btree v1.0.0 // indirect
	github.com/google/gofuzz v1.0.0 // indirect
	github.com/googleapis/gnostic v0.2.0 // indirect
	github.com/gopherjs/gopherjs v0.0.0-20190411002643-bd77b112433e // indirect
	github.com/gorilla/handlers v1.4.0
	github.com/gorilla/mux v1.7.1
	github.com/gorilla/mux v1.7.3
	github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc // indirect
	github.com/imdario/mergo v0.3.7 // indirect
	github.com/json-iterator/go v1.1.6 // indirect
	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
	github.com/modern-go/reflect2 v1.0.1 // indirect
	github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
	github.com/pkg/errors v0.8.1 // indirect
	github.com/spf13/pflag v1.0.3 // indirect
	golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f // indirect
	golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
@@ -38,10 +34,10 @@ require (
	sigs.k8s.io/yaml v1.1.0 // indirect
)

replace github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-ctrl-engine-model => ../../go-packages/meep-ctrl-engine-model

replace github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-loc-serv-notification-client => ../../go-packages/meep-loc-serv-notification-client

replace github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger => ../../go-packages/meep-logger

replace github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis => ../../go-packages/meep-redis
replace (
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-ctrl-engine-model => ../../go-packages/meep-ctrl-engine-model
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-loc-serv-notification-client => ../../go-packages/meep-loc-serv-notification-client
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger => ../../go-packages/meep-logger
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-model => ../../go-packages/meep-model
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis => ../../go-packages/meep-redis
)
+5 −0
Original line number Diff line number Diff line
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/InterDigitalInc/AdvantEDGE v1.2.0 h1:46Mr4OqKz/6WU/1CziSacw62Z3pc52dgSOLppB5N/Bc=
github.com/KromDaniel/jonson v0.0.0-20180630143114-d2f9c3c389db/go.mod h1:RU+6d0CNIRSp6yo1mXLIIrnFa/3LHhvcDVLVJyovptM=
github.com/KromDaniel/rejonson v0.0.0-20180822072824-00b5bcf2b351 h1:1u1XrfCBnY+GijnyU6O1k4odp5TnqZQTsp5v7+n/E4Y=
github.com/KromDaniel/rejonson v0.0.0-20180822072824-00b5bcf2b351/go.mod h1:HxwfbuElTuGf+/uKZfjJrCnv0BmmpkPJDI7gBwj1KkM=
github.com/RyanCarrier/dijkstra v0.0.0-20190726134004-b51cadb5ae52 h1:trnwuu/Q8T59kgRjXcSDBODnyZP9wes+bnLn0lx4PgM=
github.com/RyanCarrier/dijkstra v0.0.0-20190726134004-b51cadb5ae52/go.mod h1:DdR6ymcLl8+sN/XOVNjnYO1NDYfgHskGjreZUDuQCTY=
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/flimzy/diff v0.1.5/go.mod h1:lFJtC7SPsK0EroDmGTSrdtWKAxOk3rO+q+e04LL05Hs=
@@ -22,6 +25,8 @@ github.com/gorilla/handlers v1.4.0 h1:XulKRWSQK5uChr4pEgSE4Tc/OcmnU9GJuSwdog/tZs
github.com/gorilla/handlers v1.4.0/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
github.com/gorilla/mux v1.7.1 h1:Dw4jY2nghMMRsh1ol8dv1axHkDwMQK2DHerMNJsIpJU=
github.com/gorilla/mux v1.7.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
+8 −0
Original line number Diff line number Diff line
@@ -59,6 +59,14 @@ func main() {
			return
		}

		// Start Location Service Event Handler thread
		err = server.Run()
		if err != nil {
			log.Error("Failed to start Location Service")
			run = false
			return
		}

		// Start Location Service REST API Server
		router := server.NewRouter()
		methods := handlers.AllowedMethods([]string{"OPTIONS", "DELETE", "GET", "HEAD", "POST", "PUT"})
+81 −99
Original line number Diff line number Diff line
@@ -17,63 +17,57 @@
package sbi

import (
	"encoding/json"
	"strings"

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

	ceModel "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-ctrl-engine-model"
	mod "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-model"
)

const moduleCtrlEngine string = "ctrl-engine"
const typeActive string = "active"

const channelCtrlActive string = moduleCtrlEngine + "-" + typeActive

var updateUserInfoCB func(string, string, string)
var updateZoneInfoCB func(string, int, int, int)
var updateAccessPointInfoCB func(string, string, string, string, int)
var cleanUpCB func()

var CTRL_ENGINE_DB = 0
const module string = "loc-serv-sbi"
const redisAddr string = "meep-redis-master:6379"

var rcCtrlEng *redis.Connector
type LocServSbi struct {
	activeModel             *mod.Model
	updateUserInfoCB        func(string, string, string)
	updateZoneInfoCB        func(string, int, int, int)
	updateAccessPointInfoCB func(string, string, string, string, int)
	cleanUpCB               func()
}

const redisAddr string = "meep-redis-master:6379"
var sbi *LocServSbi

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

	rcCtrlEng, err = redis.NewConnector(redisAddr, CTRL_ENGINE_DB)
	if err != nil {
		log.Error("Failed connection to Active ctrl engine DB in Redis. Error: ", err)
		return err
	}
	log.Info("Connected to Active ctrl engine DB in sbi")
	// Create new SBI instance
	sbi = new(LocServSbi)

	// Subscribe to Pub-Sub events for MEEP Controller
	// NOTE: Current implementation is RedisDB Pub-Sub
	err = rcCtrlEng.Subscribe(channelCtrlActive)
	// Create new Model
	sbi.activeModel, err = mod.NewModel(redisAddr, module, "activeScenario")
	if err != nil {
		log.Error("Failed to subscribe to Pub/Sub events. Error: ", err)
		log.Error("Failed to create model: ", err.Error())
		return err
	}

	updateUserInfoCB = updateUserInfo
	updateZoneInfoCB = updateZoneInfo
	updateAccessPointInfoCB = updateAccessPointInfo
	cleanUpCB = cleanUp

	go Run()
	sbi.updateUserInfoCB = updateUserInfo
	sbi.updateZoneInfoCB = updateZoneInfo
	sbi.updateAccessPointInfoCB = updateAccessPointInfo
	sbi.cleanUpCB = cleanUp

	return nil
}

// Run - MEEP Location Service execution
func Run() {
	// Listen for subscribed events. Provide event handler method.
	_ = rcCtrlEng.Listen(eventHandler)
func Run() (err error) {

	// Listen for Model updates
	err = sbi.activeModel.Listen(eventHandler)
	if err != nil {
		log.Error("Failed to listen for model updates: ", err.Error())
		return err
	}
	return nil
}

func eventHandler(channel string, payload string) {
@@ -81,8 +75,8 @@ func eventHandler(channel string, payload string) {
	switch channel {

	// MEEP Ctrl Engine active scenario update Channel
	case channelCtrlActive:
		log.Debug("Event received on channel: ", channelCtrlActive)
	case mod.ActiveScenarioEvents:
		log.Debug("Event received on channel: ", mod.ActiveScenarioEvents)
		processActiveScenarioUpdate()

	default:
@@ -91,69 +85,57 @@ func eventHandler(channel string, payload string) {
}

func processActiveScenarioUpdate() {
	// Retrieve active scenario from DB
	jsonScenario, err := rcCtrlEng.JSONGetEntry(moduleCtrlEngine+":"+typeActive, ".")
	if err != nil {
		log.Error(err.Error())
		//scenario being terminated, we just clear every loc-service entries from the DB controlled by the SBI
		cleanUpCB()
		return
	}
	// Unmarshal Active scenario
	var scenario ceModel.Scenario
	err = json.Unmarshal([]byte(jsonScenario), &scenario)
	if err != nil {
		log.Error(err.Error())
		return
	}

	// Parse scenario
	parseScenario(scenario)

}

func parseScenario(scenario ceModel.Scenario) {
	log.Debug("parseScenario")

	// Store scenario Name
	//scenarioName := scenario.Name

	// Parse Domains
	for _, domain := range scenario.Deployment.Domains {

		// Parse Zones
		for _, zone := range domain.Zones {

			nbZoneUsers := 0
			nbAccessPoints := 0

			// Parse Network Locations
			for _, nl := range zone.NetworkLocations {

				nbApUsers := 0

				// Parse Physical locations
				for _, pl := range nl.PhysicalLocations {

					switch pl.Type_ {
					case "UE":
						updateUserInfoCB(pl.Name, zone.Name, nl.Name)
						nbApUsers++
					default:
					}
				}

				switch nl.Type_ {
				case "POA":
					updateAccessPointInfoCB(zone.Name, nl.Name, "UNKNOWN", "SERVICEABLE", nbApUsers)
					nbAccessPoints++
					nbZoneUsers += nbApUsers
				default:
				}
			}
			if zone.Name != "" && !strings.Contains(zone.Name, "-COMMON") {
				updateZoneInfoCB(zone.Name, nbAccessPoints, 0, nbZoneUsers)
			}
	log.Debug("processActiveScenarioUpdate")
	uePerNetLocMap := make(map[string]int)
	uePerZoneMap := make(map[string]int)
	poaPerZoneMap := make(map[string]int)

	// Update UE info
	ueNameList := sbi.activeModel.GetNodeNames("UE")
	for _, name := range ueNameList {
		ctx := sbi.activeModel.GetNodeContext(name)
		if ctx == nil {
			log.Error("Error getting context for UE: " + name)
			continue
		}
		nodeCtx, ok := ctx.(*mod.NodeContext)
		if !ok {
			log.Error("Error casting context for UE: " + name)
			continue
		}
		zone := nodeCtx.Parents[mod.Zone]
		netLoc := nodeCtx.Parents[mod.NetLoc]

		sbi.updateUserInfoCB(name, zone, netLoc)
		uePerZoneMap[zone]++
		uePerNetLocMap[netLoc]++
	}

	// Update POA info
	poaNameList := sbi.activeModel.GetNodeNames("POA")
	for _, name := range poaNameList {
		ctx := sbi.activeModel.GetNodeContext(name)
		if ctx == nil {
			log.Error("Error getting context for POA: " + name)
			continue
		}
		nodeCtx, ok := ctx.(*mod.NodeContext)
		if !ok {
			log.Error("Error casting context for POA: " + name)
			continue
		}
		zone := nodeCtx.Parents[mod.Zone]
		netLoc := nodeCtx.Parents[mod.NetLoc]

		sbi.updateAccessPointInfoCB(zone, netLoc, "UNKNOWN", "SERVICEABLE", uePerNetLocMap[netLoc])
		poaPerZoneMap[zone]++
	}

	// Update Zone info
	zoneNameList := sbi.activeModel.GetNodeNames("ZONE")
	for _, name := range zoneNameList {
		if name != "" && !strings.Contains(name, "-COMMON") {
			sbi.updateZoneInfoCB(name, poaPerZoneMap[name], 0, uePerZoneMap[name])
		}
	}
}
+6 −2
Original line number Diff line number Diff line
@@ -95,8 +95,12 @@ func Init() (err error) {
	zoneStatusReInit()

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

// Init - Location Service initialization
func Run() (err error) {
	return sbi.Run()
}

func createClient(notifyPath string) (*clientNotifOMA.APIClient, error) {
Loading