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

Merge pull request #272 from pastorsx/sp_dev_mec013-12-28-test

MEC013 (distance, areaCircle) - MEC012 - MEC028 phase 1 testing fixes
parents 36a210b4 af0f2725
Loading
Loading
Loading
Loading
+239 −187
Original line number Diff line number Diff line
@@ -117,12 +117,14 @@ type ZoneStatusCheck struct {

type DistanceCheck struct {
	NextTts             int32 //next time to send, derived from frequency
	NbNotificationsSent int32
	Subscription        *DistanceNotificationSubscription
}

type AreaCircleCheck struct {
	NextTts             int32 //next time to send, derived from frequency
	AddrInArea          map[string]bool
	NbNotificationsSent int32
	Subscription        *CircleNotificationSubscription
}

@@ -384,6 +386,7 @@ func checkNotificationDistancePeriodicTrigger() {
	//check all that applies
	for subsId, distanceCheck := range distanceSubscriptionMap {
		if distanceCheck != nil && distanceCheck.Subscription != nil {
			if distanceCheck.Subscription.Count == 0 || (distanceCheck.Subscription.Count != 0 && distanceCheck.NbNotificationsSent < distanceCheck.Subscription.Count) {
				//decrement the next time to send a message
				distanceCheck.NextTts--
				if distanceCheck.NextTts > 0 {
@@ -430,11 +433,17 @@ func checkNotificationDistancePeriodicTrigger() {
					var distParam gisClient.TargetPoint
					distParam.AssetName = monitoredAddr

				distResp, _, err := gisAppClient.GeospatialDataApi.GetDistanceGeoDataByName(context.TODO(), refAddr, distParam)
					distResp, httpResp, err := gisAppClient.GeospatialDataApi.GetDistanceGeoDataByName(context.TODO(), refAddr, distParam)
					if err != nil {
						//getting distance of an element that is not in the DB (not in scenario, not connected) returns error code 400 (bad parameters) in the API. Using that error code to track that request made it to GIS but no good result, so ignore that address (monitored or ref)
						if httpResp.StatusCode == http.StatusBadRequest {
							//ignore that pair and continue processing
							continue
						} else {
							log.Error("Failed to communicate with gis engine: ", err)
							return
						}
					}

					distance := int32(distResp.Distance)

@@ -469,6 +478,7 @@ func checkNotificationDistancePeriodicTrigger() {
					continue
				}
				if len(returnAddr) > 0 {
					//update nb of notification sent anch check if valid
					subsIdStr := strconv.Itoa(subsId)

					var distanceNotif SubscriptionNotification
@@ -495,24 +505,26 @@ func checkNotificationDistancePeriodicTrigger() {
						terminalLocationList = append(terminalLocationList, terminalLocation)
					}
					distanceNotif.TerminalLocation = terminalLocationList
				distanceNotif.CallbackData = distanceCheck.Subscription.ClientCorrelator
					distanceNotif.CallbackData = distanceCheck.Subscription.CallbackReference.CallbackData
					var inlineDistanceSubscriptionNotification InlineSubscriptionNotification
					inlineDistanceSubscriptionNotification.SubscriptionNotification = &distanceNotif
					distanceCheck.NbNotificationsSent++
					sendSubscriptionNotification(distanceCheck.Subscription.CallbackReference.NotifyURL, inlineDistanceSubscriptionNotification)
					log.Info("Distance Notification"+"("+subsIdStr+") For ", returnAddr)
				}
			}
		}
	}
}

func checkNotificationAreaCircle(addressToCheck string) {

	//only check if there is at least one subscription
	mutex.Lock()
	defer mutex.Unlock()
	//check all that applies
	for subsId, areaCircleCheck := range areaCircleSubscriptionMap {
		if areaCircleCheck != nil && areaCircleCheck.Subscription != nil {
			if areaCircleCheck.Subscription.Count == 0 || (areaCircleCheck.Subscription.Count != 0 && areaCircleCheck.NbNotificationsSent < areaCircleCheck.Subscription.Count) {
				//ignoring the frequency and checkImmediate for this subscription since it is considered event based, not periodic
				/* //decrement the next time to send a message
				if areaCircleCheck.NextTts > 0 {
@@ -532,12 +544,19 @@ func checkNotificationAreaCircle(addressToCheck string) {
					withinRangeParam.Longitude = areaCircleCheck.Subscription.Longitude
					withinRangeParam.Radius = areaCircleCheck.Subscription.Radius

				withinRangeResp, _, err := gisAppClient.GeospatialDataApi.GetWithinRangeByName(context.TODO(), addr, withinRangeParam)
					withinRangeResp, httpResp, err := gisAppClient.GeospatialDataApi.GetWithinRangeByName(context.TODO(), addr, withinRangeParam)
					if err != nil {
						//getting element that is not in the DB (not in scenario, not connected) returns error code 400 (bad parameters) in the API. Using that error code to track that request made it to GIS but no good result, so ignore that address (monitored or ref)
						if httpResp.StatusCode == http.StatusBadRequest {
							//if the UE was within the zone, continue processing to send a LEAVING notification, otherwise, go to next subscription
							if !areaCircleCheck.AddrInArea[addr] {
								continue
							}
						} else {
							log.Error("Failed to communicate with gis engine: ", err)
							return
						}

					}
					//check if there is a change
					var event EnteringLeavingCriteria
					if withinRangeResp.Within {
@@ -586,13 +605,14 @@ func checkNotificationAreaCircle(addressToCheck string) {
					terminalLocationList = append(terminalLocationList, terminalLocation)

					areaCircleNotif.TerminalLocation = terminalLocationList
				areaCircleNotif.CallbackData = areaCircleCheck.Subscription.ClientCorrelator
					areaCircleNotif.CallbackData = areaCircleCheck.Subscription.CallbackReference.CallbackData
					var inlineCircleSubscriptionNotification InlineSubscriptionNotification
					inlineCircleSubscriptionNotification.SubscriptionNotification = &areaCircleNotif
					areaCircleCheck.NbNotificationsSent++
					sendSubscriptionNotification(areaCircleCheck.Subscription.CallbackReference.NotifyURL, inlineCircleSubscriptionNotification)
					log.Info("Area Circle Notification" + "(" + subsIdStr + ") For " + addr + " when " + string(*areaCircleCheck.Subscription.EnteringLeavingCriteria) + " area")
				}

			}
		}
	}
}
@@ -647,8 +667,7 @@ func checkNotificationPeriodicTrigger() {
			periodicNotif.IsFinalNotification = false
			periodicNotif.Link = periodicCheck.Subscription.Link
			subsIdStr := strconv.Itoa(subsId)
			periodicNotif.CallbackData = periodicCheck.Subscription.ClientCorrelator

			periodicNotif.CallbackData = periodicCheck.Subscription.CallbackReference.CallbackData
			periodicNotif.TerminalLocation = terminalLocationList
			var inlinePeriodicSubscriptionNotification InlineSubscriptionNotification
			inlinePeriodicSubscriptionNotification.SubscriptionNotification = &periodicNotif
@@ -680,6 +699,7 @@ func registerDistance(distanceSub *DistanceNotificationSubscription, subsIdStr s
	defer mutex.Unlock()
	var distanceCheck DistanceCheck
	distanceCheck.Subscription = distanceSub
	distanceCheck.NbNotificationsSent = 0
	if distanceSub.CheckImmediate {
		distanceCheck.NextTts = 0 //next time periodic trigger hits, will be forced to trigger
	} else {
@@ -710,6 +730,7 @@ func registerAreaCircle(areaCircleSub *CircleNotificationSubscription, subsIdStr
	defer mutex.Unlock()
	var areaCircleCheck AreaCircleCheck
	areaCircleCheck.Subscription = areaCircleSub
	areaCircleCheck.NbNotificationsSent = 0
	areaCircleCheck.AddrInArea = map[string]bool{}
	//checkImmediate and NextTts apply more to a periodic notification, setting them but ignoring both in notification code because of unclear spec on that matter
	if areaCircleSub.CheckImmediate {
@@ -829,7 +850,7 @@ func checkNotificationRegisteredUsers(oldZoneId string, newZoneId string, oldApI
			timestamp.Seconds = int32(seconds)
			zonal.Timestamp = &timestamp

			zonal.CallbackData = subscription.ClientCorrelator
			zonal.CallbackData = subscription.CallbackReference.CallbackData

			if newZoneId != oldZoneId {
				//process LEAVING events prior to entering ones
@@ -968,7 +989,7 @@ func checkNotificationRegisteredZones(oldZoneId string, newZoneId string, oldApI
						var timestamp TimeStamp
						timestamp.Seconds = int32(seconds)
						zonal.Timestamp = &timestamp
						zonal.CallbackData = subscription.ClientCorrelator
						zonal.CallbackData = subscription.CallbackReference.CallbackData
						var inlineZonal InlineZonalPresenceNotification
						inlineZonal.ZonalPresenceNotification = &zonal
						sendZonalPresenceNotification(subscription.CallbackReference.NotifyURL, inlineZonal)
@@ -996,7 +1017,7 @@ func checkNotificationRegisteredZones(oldZoneId string, newZoneId string, oldApI
							var timestamp TimeStamp
							timestamp.Seconds = int32(seconds)
							zonal.Timestamp = &timestamp
							zonal.CallbackData = subscription.ClientCorrelator
							zonal.CallbackData = subscription.CallbackReference.CallbackData
							var inlineZonal InlineZonalPresenceNotification
							inlineZonal.ZonalPresenceNotification = &zonal
							sendZonalPresenceNotification(subscription.CallbackReference.NotifyURL, inlineZonal)
@@ -1026,7 +1047,7 @@ func checkNotificationRegisteredZones(oldZoneId string, newZoneId string, oldApI
						var timestamp TimeStamp
						timestamp.Seconds = int32(seconds)
						zonal.Timestamp = &timestamp
						zonal.CallbackData = subscription.ClientCorrelator
						zonal.CallbackData = subscription.CallbackReference.CallbackData
						var inlineZonal InlineZonalPresenceNotification
						inlineZonal.ZonalPresenceNotification = &zonal
						sendZonalPresenceNotification(subscription.CallbackReference.NotifyURL, inlineZonal)
@@ -1588,8 +1609,11 @@ func distanceSubPut(w http.ResponseWriter, r *http.Request) {

	_ = rc.JSONSetEntry(baseKey+typeDistanceSubscription+":"+subsIdStr, ".", convertDistanceSubscriptionToJson(distanceSub))

	//store the dynamic states of the subscription
	notifSent := distanceSubscriptionMap[subsId].NbNotificationsSent
	deregisterDistance(subsIdStr)
	registerDistance(distanceSub, subsIdStr)
	distanceSubscriptionMap[subsId].NbNotificationsSent = notifSent

	response.DistanceNotificationSubscription = distanceSub

@@ -1911,8 +1935,13 @@ func areaCircleSubPut(w http.ResponseWriter, r *http.Request) {

	_ = rc.JSONSetEntry(baseKey+typeAreaCircleSubscription+":"+subsIdStr, ".", convertAreaCircleSubscriptionToJson(areaCircleSub))

	//store the dynamic states fo the subscription
	notifSent := areaCircleSubscriptionMap[subsId].NbNotificationsSent
	addrInArea := areaCircleSubscriptionMap[subsId].AddrInArea
	deregisterAreaCircle(subsIdStr)
	registerAreaCircle(areaCircleSub, subsIdStr)
	areaCircleSubscriptionMap[subsId].NbNotificationsSent = notifSent
	areaCircleSubscriptionMap[subsId].AddrInArea = addrInArea

	response.CircleNotificationSubscription = areaCircleSub

@@ -3046,10 +3075,11 @@ func updateAccessPointInfo(zoneId string, apId string, conTypeStr string, opStat
	} else {
		if apInfo.LocationInfo == nil {
			apInfo.LocationInfo = new(LocationInfo)
			apInfo.LocationInfo.Accuracy = 1
		}

		//we only support shape != 7 in locationInfo
		//Accuracy supported for shape 4, 5, 6 only, so ignoring it in our case (only support shape == 2)
		//apInfo.LocationInfo.Accuracy = 1
		apInfo.LocationInfo.Shape = 2
		apInfo.LocationInfo.Longitude = nil
		apInfo.LocationInfo.Longitude = append(apInfo.LocationInfo.Longitude, *longitude)
@@ -3209,6 +3239,7 @@ func distanceReInit() {
			}
			var distanceCheck DistanceCheck
			distanceCheck.Subscription = &distanceSub
			distanceCheck.NbNotificationsSent = 0
			if distanceSub.CheckImmediate {
				distanceCheck.NextTts = 0 //next time periodic trigger hits, will be forced to trigger
			} else {
@@ -3241,6 +3272,7 @@ func areaCircleReInit() {
			}
			var areaCircleCheck AreaCircleCheck
			areaCircleCheck.Subscription = &areaCircleSub
			areaCircleCheck.NbNotificationsSent = 0
			areaCircleCheck.AddrInArea = map[string]bool{}
			if areaCircleSub.CheckImmediate {
				areaCircleCheck.NextTts = 0 //next time periodic trigger hits, will be forced to trigger
@@ -3248,7 +3280,6 @@ func areaCircleReInit() {
				areaCircleCheck.NextTts = areaCircleSub.Frequency
			}
			areaCircleSubscriptionMap[subscriptionId] = &areaCircleCheck

		}
	}
	nextAreaCircleSubscriptionIdAvailable = maxAreaCircleSubscriptionId + 1
@@ -3295,9 +3326,30 @@ func distanceGet(w http.ResponseWriter, r *http.Request) {
	longitudeStr := q.Get("longitude")
	address := q["address"]

	if len(address) == 0 {
		log.Error("Query should have at least 1 'address' parameter")
		http.Error(w, "Query should have at least 1 'address' parameter", http.StatusBadRequest)
		return
	}
	if len(address) > 2 {
		log.Error("Query cannot have more than 2 'address' parameters")
		http.Error(w, "Query cannot have more than 2 'address' parameters", http.StatusBadRequest)
		return
	}
	if len(address) == 2 && (latitudeStr != "" || longitudeStr != "") {
		log.Error("Query cannot have 2 'address' parameters and 'latitude'/'longitude' parameters")
		http.Error(w, "Query cannot have 2 'address' parameters and 'latitude'/'longitude' parameters", http.StatusBadRequest)
		return
	}
	if (latitudeStr != "" && longitudeStr == "") || (latitudeStr == "" && longitudeStr != "") {
		log.Error("Query must provide a latitude and a longitude for a point to be valid")
		http.Error(w, "Query must provide a latitude and a longitude for a point to be valid", http.StatusBadRequest)
		return
	}
	if len(address) == 1 && latitudeStr == "" && longitudeStr == "" {
		log.Error("Query must provide either 2 'address' parameters or 1 'address' parameter and 'latitude'/'longitude' parameters")
		http.Error(w, "Query must provide either 2 'address' parameters or 1 'address' parameter and 'latitude'/'longitude' parameters", http.StatusBadRequest)
		return
	}

	validQueryParams := []string{"requester", "address", "latitude", "longitude"}
+0 −2
Original line number Diff line number Diff line
@@ -229,8 +229,6 @@ func processActiveScenarioUpdate() {

	scenarioName := sbi.activeModel.GetScenarioName()

	sbi.updateScenarioNameCB(scenarioName)

	// Connect to Metric Store
	if scenarioName != sbi.scenarioName {