Newer
Older
/*
* Copyright (c) 2020 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 (
"net/http"
"net/url"
"os"
"reflect"
"strconv"
"strings"
"time"
sbi "github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-wais/sbi"
Kevin Di Lallo
committed
asc "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-app-support-client"
dkm "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-data-key-mgr"
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"
const waisBasePath = "wai/v2/"
const waisKey = "wais"
Kevin Di Lallo
committed
const serviceName = "WAI Service"
const defaultMepName = "global"
const defaultScopeOfLocality = "MEC_SYSTEM"
const defaultConsumedLocalOnly = true
const appTerminationPath = "notifications/mec011/appTermination"
Kevin Di Lallo
committed
const (
Simon Pastor
committed
notifAssocSta = "AssocStaNotification"
notifStaDataRate = "StaDataRateNotification"
notifExpiry = "ExpiryNotification"
notifTest = "TestNotification"
Kevin Di Lallo
committed
)
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"
const assocStaSubscriptionType = "AssocStaSubscription"
Simon Pastor
committed
const staDataRateSubscriptionType = "StaDataRateSubscription"
Simon Pastor
committed
const STA_DATA_RATE_SUBSCRIPTION = "StaDataRateSubscription"
Simon Pastor
committed
const STA_DATA_RATE_NOTIFICATION = "StaDataRateNotification"
const MEASUREMENT_REPORT_SUBSCRIPTION = "MeasurementReportSubscription"
Simon Pastor
committed
const TEST_NOTIFICATION = "TestNotification"
var assocStaSubscriptionInfoMap = map[int]*AssocStaSubscriptionInfo{}
var staDataRateSubscriptionInfoMap = map[int]*StaDataRateSubscriptionInfo{}
Simon Pastor
committed
var rc *redis.Connector
var hostUrl *url.URL
Kevin Di Lallo
committed
var instanceId string
var instanceName string
var mepName string = defaultMepName
var scopeOfLocality string = defaultScopeOfLocality
var consumedLocalOnly bool = defaultConsumedLocalOnly
var locality []string
var expiryTicker *time.Ticker
var nextSubscriptionIdAvailable int
type ApInfoComplete struct {
ApId ApIdentity
ApLocation ApLocation
StaMacIds []string
}
type ApInfoCompleteResp struct {
ApInfoCompleteList []ApInfoComplete
}
type StaDataRateSubscriptionInfo struct {
NextTts int32 //next time to send, derived from notificationPeriod
NotificationCheckReady bool
Subscription *StaDataRateSubscription
Triggered bool
}
type AssocStaSubscriptionInfo struct {
NextTts int32 //next time to send, derived from notificationPeriod
NotificationCheckReady bool
Subscription *AssocStaSubscription
Triggered bool
Simon Pastor
committed
type StaData struct {
Simon Pastor
committed
}
type StaInfoResp struct {
StaInfoList []StaInfo
}
type ApInfoResp struct {
ApInfoList []ApInfo
}
const serviceAppVersion = "2.1.1"
var serviceAppInstanceId string
var appEnablementUrl string
var appEnablementServiceId string
Kevin Di Lallo
committed
var appSupportClient *asc.APIClient
var svcMgmtClient *smc.APIClient
var sbxCtrlClient *scc.APIClient
var registrationTicker *time.Ticker
Simon Pastor
committed
func notImplemented(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusNotImplemented)
}
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
Kevin Di Lallo
committed
instanceNameEnv := strings.TrimSpace(os.Getenv("MEEP_POD_NAME"))
if instanceNameEnv != "" {
instanceName = instanceNameEnv
}
log.Info("MEEP_POD_NAME: ", instanceName)
// Retrieve Sandbox name from environment variable
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())
return err
}
log.Info("MEEP_SANDBOX_NAME: ", sandboxName)
// hostUrl is the url of the node serving the resourceURL
// Retrieve public url address where service is reachable, if not present, use Host URL environment variable
hostUrl, err = url.Parse(strings.TrimSpace(os.Getenv("MEEP_PUBLIC_URL")))
if err != nil || hostUrl == nil || hostUrl.String() == "" {
hostUrl, err = url.Parse(strings.TrimSpace(os.Getenv("MEEP_HOST_URL")))
if err != nil {
hostUrl = new(url.URL)
}
}
log.Info("MEEP_HOST_URL: ", hostUrl)
// Get MEP name
mepNameEnv := strings.TrimSpace(os.Getenv("MEEP_MEP_NAME"))
if mepNameEnv != "" {
Loading
Loading full blame…