Newer
Older
* Copyright (c) 2019 InterDigital Communications, Inc
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
package server
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
Kevin Di Lallo
committed
"os"
"time"
sbi "github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-loc-serv/sbi"
Kevin Di Lallo
committed
asc "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-app-support-client"
Kevin Di Lallo
committed
dkm "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-data-key-mgr"
gisClient "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-gis-engine-client"
httpLog "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-http-logger"
log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger"
Kevin Di Lallo
committed
met "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-metrics"
redis "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis"
Kevin Di Lallo
committed
scc "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sandbox-ctrl-client"
smc "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-service-mgmt-client"
Simon Pastor
committed
"github.com/gorilla/mux"
)
const LocServBasePath = "location/v2/"
const locServKey = "loc-serv"
Kevin Di Lallo
committed
const logModuleLocServ = "meep-loc-serv"
const serviceName = "Location Service"
const defaultMepName = "global"
const defaultScopeOfLocality = "MEC_SYSTEM"
const defaultConsumedLocalOnly = true
const typeZone = "zone"
const typeAccessPoint = "accessPoint"
const typeUser = "user"
const typeZonalSubscription = "zonalsubs"
const typeUserSubscription = "usersubs"
const typeZoneStatusSubscription = "zonestatus"
const typeDistanceSubscription = "distance"
const typeAreaCircleSubscription = "areacircle"
Kevin Di Lallo
committed
const (
notifZonalPresence = "ZonalPresenceNotification"
notifZoneStatus = "ZoneStatusNotification"
Kevin Di Lallo
committed
)
Kevin Di Lallo
committed
type UeUserData struct {
queryZoneId []string
queryApId []string
queryAddress []string
Kevin Di Lallo
committed
}
type ApUserData struct {
queryInterestRealm string
apList *AccessPointList
}
var nextZonalSubscriptionIdAvailable int
var nextUserSubscriptionIdAvailable int
Simon Pastor
committed
var nextZoneStatusSubscriptionIdAvailable int
var nextDistanceSubscriptionIdAvailable int
var nextAreaCircleSubscriptionIdAvailable int
var zonalSubscriptionEnteringMap = map[int]string{}
var zonalSubscriptionLeavingMap = map[int]string{}
var zonalSubscriptionTransferringMap = map[int]string{}
var zonalSubscriptionMap = map[int]string{}
var userSubscriptionEnteringMap = map[int]string{}
var userSubscriptionLeavingMap = map[int]string{}
var userSubscriptionTransferringMap = map[int]string{}
var userSubscriptionMap = map[int]string{}
Simon Pastor
committed
var zoneStatusSubscriptionMap = map[int]*ZoneStatusCheck{}
var periodicSubscriptionMap = map[int]*PeriodicCheck{}
Simon Pastor
committed
type ZoneStatusCheck struct {
ZoneId string
Serviceable bool
Unserviceable bool
Unknown bool
Simon Pastor
committed
}
NextTts int32 //next time to send, derived from frequency
NbNotificationsSent int32
NotificationCheckReady bool
Subscription *DistanceNotificationSubscription
NextTts int32 //next time to send, derived from frequency
AddrInArea map[string]bool
NbNotificationsSent int32
NotificationCheckReady bool
Subscription *CircleNotificationSubscription
type PeriodicCheck struct {
NextTts int32 //next time to send, derived from frequency
Subscription *PeriodicNotificationSubscription
}
Kevin Di Lallo
committed
var LOC_SERV_DB = 0
var redisAddr string = "meep-redis-master.default.svc.cluster.local:6379"
var influxAddr string = "http://meep-influxdb.default.svc.cluster.local:8086"
Kevin Di Lallo
committed
var sbxCtrlUrl string = "http://meep-sandbox-ctrl"
Kevin Di Lallo
committed
var hostUrl *url.URL
Kevin Di Lallo
committed
var instanceId string
var instanceName string
Kevin Di Lallo
committed
var sandboxName string
var mepName string = defaultMepName
var scopeOfLocality string = defaultScopeOfLocality
var consumedLocalOnly bool = defaultConsumedLocalOnly
Kevin Di Lallo
committed
var basePath string
Kevin Di Lallo
committed
var baseKey string
Simon Pastor
committed
var gisAppClientUrl string = "http://meep-gis-engine"
const serviceAppVersion = "2.1.1"
var serviceAppInstanceId string
var appEnablementUrl string
var appEnablementEnabled bool
Kevin Di Lallo
committed
var appSupportClient *asc.APIClient
var svcMgmtClient *smc.APIClient
var sbxCtrlClient *scc.APIClient
var registrationTicker *time.Ticker
// Init - Location Service initialization
func Init() (err error) {
Kevin Di Lallo
committed
// Retrieve Instance ID from environment variable if present
instanceIdEnv := strings.TrimSpace(os.Getenv("MEEP_INSTANCE_ID"))
if instanceIdEnv != "" {
instanceId = instanceIdEnv
}
log.Info("MEEP_INSTANCE_ID: ", instanceId)
// Retrieve Instance Name from environment variable
instanceNameEnv := strings.TrimSpace(os.Getenv("MEEP_POD_NAME"))
if instanceNameEnv != "" {
instanceName = instanceNameEnv
}
log.Info("MEEP_POD_NAME: ", instanceName)
sandboxNameEnv := strings.TrimSpace(os.Getenv("MEEP_SANDBOX_NAME"))
if sandboxNameEnv != "" {
sandboxName = sandboxNameEnv
}
if sandboxName == "" {
Loading
Loading full blame…