Commit f8959e4d authored by Kevin Di Lallo's avatar Kevin Di Lallo
Browse files

Disconnected status in map UE popup + gis-engine automation trigger cleanup

parent 590400c6
Loading
Loading
Loading
Loading
+35 −29
Original line number Diff line number Diff line
@@ -73,9 +73,8 @@ type Asset struct {
	wirelessType string
}

type PoaInfo struct {
type UeInfo struct {
	poa        string
	distance   float32
	poaInRange []string
	connected  bool
}
@@ -89,7 +88,7 @@ type GisEngine struct {
	sessionMgr     *sm.SessionMgr
	pc             *postgis.Connector
	assets         map[string]*Asset
	uePoaInfo      map[string]*PoaInfo
	ueInfo         map[string]*UeInfo
	automation     map[string]bool
	ticker         *time.Ticker
	updateTime     time.Time
@@ -101,7 +100,7 @@ var ge *GisEngine
func Init() (err error) {
	ge = new(GisEngine)
	ge.assets = make(map[string]*Asset)
	ge.uePoaInfo = make(map[string]*PoaInfo)
	ge.ueInfo = make(map[string]*UeInfo)
	ge.automation = make(map[string]bool)
	resetAutomation()
	startAutomation()
@@ -313,6 +312,13 @@ func setAssets(assetList []string) {
				}
			}
			_ = setUe(asset, pl, geoData)

			// Update stored UE POA Info used in automation updates
			nl := (ge.activeModel.GetNodeParent(assetName)).(*dataModel.NetworkLocation)
			ueInfo, _ := getUeInfo(assetName)
			ueInfo.poa = nl.Name
			ueInfo.connected = pl.Connected

		} else if isPoa(asset.typ) {
			// Set initial geoData only
			nl := (ge.activeModel.GetNode(assetName)).(*dataModel.NetworkLocation)
@@ -776,22 +782,12 @@ func runAutomation() {
		ueMap, err := ge.pc.GetAllUe()
		if err == nil {
			for _, ue := range ueMap {
				// Get stored UE POA info or create new one
				newPoaInfo := false
				poaInfo, found := ge.uePoaInfo[ue.Name]
				if !found {
					poaInfo = new(PoaInfo)
					poaInfo.connected = false
					poaInfo.distance = 0
					poaInfo.poaInRange = []string{}
					poaInfo.poa = ""
					ge.uePoaInfo[ue.Name] = poaInfo
					newPoaInfo = true
				}
				// Get stored UE info
				ueInfo, isNew := getUeInfo(ue.Name)

				// Send mobility event if necessary
				if ge.automation[AutoTypeMobility] {
					if newPoaInfo || (ue.Poa != "" && ue.Poa != poaInfo.poa) || (ue.Poa == "" && poaInfo.connected) {
					if isNew || (ue.Poa != "" && (!ueInfo.connected || ue.Poa != ueInfo.poa)) || (ue.Poa == "" && ueInfo.connected) {
						var event sbox.Event
						var mobilityEvent sbox.EventMobility
						event.Type_ = AutoTypeMobility
@@ -809,23 +805,18 @@ func runAutomation() {
								log.Error(err)
							}
						}()

						// Update sotred data
						poaInfo.poa = ue.Poa
						poaInfo.distance = ue.PoaDistance
						poaInfo.connected = ue.Connected
					}
				}

				// Send POA in range event if necessary
				if ge.automation[AutoTypePoaInRange] {
					updateRequired := false
					if newPoaInfo || len(poaInfo.poaInRange) != len(ue.PoaInRange) {
					if isNew || len(ueInfo.poaInRange) != len(ue.PoaInRange) {
						updateRequired = true
					} else {
						sort.Strings(poaInfo.poaInRange)
						sort.Strings(ueInfo.poaInRange)
						sort.Strings(ue.PoaInRange)
						for i, poa := range poaInfo.poaInRange {
						for i, poa := range ueInfo.poaInRange {
							if poa != ue.PoaInRange[i] {
								updateRequired = true
							}
@@ -847,15 +838,15 @@ func runAutomation() {
						}()

						// Update sotred data
						poaInfo.poaInRange = ue.PoaInRange
						ueInfo.poaInRange = ue.PoaInRange
					}
				}
			}

			// Remove UE Poa info if UEs no longer present
			for ueName := range ge.uePoaInfo {
			// Remove UE info if UE no longer present
			for ueName := range ge.ueInfo {
				if _, found := ueMap[ueName]; !found {
					delete(ge.uePoaInfo, ueName)
					delete(ge.ueInfo, ueName)
				}
			}

@@ -870,6 +861,21 @@ func runAutomation() {
	}
}

func getUeInfo(ueName string) (*UeInfo, bool) {
	// Get stored UE POA info or create new one
	isNew := false
	ueInfo, found := ge.ueInfo[ueName]
	if !found {
		ueInfo = new(UeInfo)
		ueInfo.connected = false
		ueInfo.poaInRange = []string{}
		ueInfo.poa = ""
		ge.ueInfo[ueName] = ueInfo
		isNew = true
	}
	return ueInfo, isNew
}

// ----------------------------  REST API  ------------------------------------

func geGetAutomationState(w http.ResponseWriter, r *http.Request) {
+4 −10
Original line number Diff line number Diff line
@@ -1307,20 +1307,17 @@ func (pc *Connector) refreshUePoa(name string) (err error) {
	// Select POA
	selectedPoa := selectPoa(currentPoa, poaInRange, poaInfoMap, poaTypePrio)
	distance := float32(0)
	connected := false
	if selectedPoa != "" {
		distance = poaInfoMap[selectedPoa].Distance
		connected = true
	}

	// Update POA entries for UE
	query := `UPDATE ` + UeTable + `
		SET poa = $2,
			poa_distance = $3,
			poa_in_range = $4,
			connected = $5
			poa_in_range = $4
		WHERE name = ($1)`
	_, err = pc.db.Exec(query, name, selectedPoa, distance, pq.Array(poaInRange), connected)
	_, err = pc.db.Exec(query, name, selectedPoa, distance, pq.Array(poaInRange))
	if err != nil {
		log.Error(err.Error())
		return err
@@ -1427,20 +1424,17 @@ func (pc *Connector) refreshAllUePoa() (err error) {
		// Select POA
		selectedPoa := selectPoa(uePoaInfo.CurrentPoa, uePoaInfo.PoaInRange, uePoaInfo.PoaInfoMap, uePoaInfo.PoaTypePrio)
		distance := float32(0)
		connected := false
		if selectedPoa != "" {
			distance = uePoaInfo.PoaInfoMap[selectedPoa].Distance
			connected = true
		}

		// Update in DB
		query := `UPDATE ` + UeTable + `
			SET poa = $2,
				poa_distance = $3,
				poa_in_range = $4,
				connected = $5
				poa_in_range = $4
			WHERE name = ($1)`
		_, err = pc.db.Exec(query, ue, selectedPoa, distance, pq.Array(uePoaInfo.PoaInRange), connected)
		_, err = pc.db.Exec(query, ue, selectedPoa, distance, pq.Array(uePoaInfo.PoaInRange))
		if err != nil {
			log.Error(err.Error())
			return err
+26 −17
Original line number Diff line number Diff line
@@ -60,6 +60,8 @@ import {
  FIELD_GEO_LOCATION,
  FIELD_GEO_PATH,
  FIELD_GEO_RADIUS,
  FIELD_CONNECTED,
  FIELD_WIRELESS_TYPE,
  FIELD_META_DISPLAY_MAP_COLOR,
  FIELD_META_DISPLAY_MAP_ICON,
  getElemFieldVal,
@@ -384,7 +386,6 @@ class IDCMap extends Component {
    this.updateCfg({baselayerName: event.name});
  }

  // Get Zones
  getUePoa(ue) {
    var poa = null;
    var table = this.getTable();
@@ -551,13 +552,16 @@ class IDCMap extends Component {
  // UE Marker Event Handler
  updateUePopup(marker) {
    var latlng = marker.getLatLng();
    var poa = this.getUePoa(marker.options.meep.ue.id);
    var poaType = getElemFieldVal(this.getTable().entries[poa], FIELD_TYPE);
    var hasPath = (marker.options.meep.ue.path) ? true : false;
    var msg = '<b>id: ' + marker.options.meep.ue.id + '</b><br>';
    msg += 'velocity: ' + (hasPath ? marker.options.meep.ue.velocity : '0') + ' m/s<br>';
    msg += 'poa: ' + poa + '<br>';
    
    var ue = this.getTable().entries[marker.options.meep.ue.id];
    var connected = getElemFieldVal(ue, FIELD_CONNECTED);
    if (connected) {
      var poa = this.getUePoa(marker.options.meep.ue.id);
      var poaType = getElemFieldVal(this.getTable().entries[poa], FIELD_TYPE);
      msg += 'poa: ' + poa + '<br>';
      switch (poaType) {
      case ELEMENT_TYPE_POA_4G: 
        msg += 'cell: ' + getElemFieldVal(this.getTable().entries[poa], FIELD_CELL_ID) + '<br>';
@@ -572,6 +576,11 @@ class IDCMap extends Component {
        break;
      }
      msg += 'zone: ' + this.getUeZone(marker.options.meep.ue.id) + '<br>';
    } else {
      msg += 'state: <b style="color:red;">DISCONNECTED</b><br>';
      msg += 'types: ' + (getElemFieldVal(ue, FIELD_WIRELESS_TYPE) || 'wifi,5g,4g,other') + '<br>';
    }
    
    msg += 'location: ' + this.getLocationStr(latlng);
    marker.getPopup().setContent(msg);
  }