Commit 4550ce0d authored by Kevin Di Lallo's avatar Kevin Di Lallo
Browse files

loc-serv env var updates

parent ac9c918f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -20,6 +20,12 @@ image:
  env:
    MEEP_SANDBOX_NAME: {{.SandboxName}}
    MEEP_HOST_URL: {{.HostUrl}}
    {{- if .IsMepService }}
    MEEP_MEP_NAME: {{.MepName}}
    {{- end }}
    {{- range .Env}}
    {{.}}
    {{- end}}

service:
  {{- if .IsMepService }}
+48 −13
Original line number Diff line number Diff line
@@ -44,10 +44,13 @@ import (
	"github.com/gorilla/mux"
)

const LocServBasePath = "/location/v2/"
const locServKey = "loc-serv:"
const LocServBasePath = "location/v2/"
const locServKey = "loc-serv"
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"
@@ -149,6 +152,10 @@ var influxAddr string = "http://meep-influxdb.default.svc.cluster.local:8086"
var rc *redis.Connector
var hostUrl *url.URL
var sandboxName string
var mepName string = defaultMepName
var scopeOfLocality string = defaultScopeOfLocality
var consumedLocalOnly bool = defaultConsumedLocalOnly
var locality []string = []string{}
var basePath string
var baseKey string
var mutex sync.Mutex
@@ -171,16 +178,10 @@ var retryAppEnablementTicker *time.Ticker

//MEC011 section end

/*
func notImplemented(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusNotImplemented)
}
*/

// Init - Location Service initialization
func Init() (err error) {

	// Get Sandbox name
	sandboxNameEnv := strings.TrimSpace(os.Getenv("MEEP_SANDBOX_NAME"))
	if sandboxNameEnv != "" {
		sandboxName = sandboxNameEnv
@@ -203,11 +204,45 @@ func Init() (err error) {
	}
	log.Info("resource URL: ", hostUrl)

	// Set base path
	basePath = "/" + sandboxName + LocServBasePath
	// Get MEP name
	mepNameEnv := strings.TrimSpace(os.Getenv("MEEP_MEP_NAME"))
	if mepNameEnv != "" {
		mepName = mepNameEnv
	}
	log.Info("MEEP_MEP_NAME: ", mepName)

	// Get scope of locality
	scopeOfLocalityEnv := strings.TrimSpace(os.Getenv("MEEP_SCOPE_OF_LOCALITY"))
	if scopeOfLocalityEnv != "" {
		scopeOfLocality = scopeOfLocalityEnv
	}
	log.Info("MEEP_SCOPE_OF_LOCALITY: ", scopeOfLocality)

	// Get base storage key
	baseKey = dkm.GetKeyRoot(sandboxName) + locServKey
	// Get local consumption
	consumedLocalOnlyEnv := strings.TrimSpace(os.Getenv("MEEP_CONSUMED_LOCAL_ONLY"))
	if consumedLocalOnlyEnv != "" {
		value, err := strconv.ParseBool("true")
		if err == nil {
			consumedLocalOnly = value
		}
	}
	log.Info("MEEP_CONSUMED_LOCAL_ONLY: ", consumedLocalOnly)

	// Get locality
	localityEnv := strings.TrimSpace(os.Getenv("MEEP_LOCALITY"))
	if localityEnv != "" {
		locality = strings.Split(localityEnv, ":")
	}
	log.Info("MEEP_LOCALITY: ", locality)

	// Set base path & base storage key
	if mepName != "" {
		basePath = "/" + sandboxName + "/" + mepName + "/" + LocServBasePath
		baseKey = dkm.GetKeyRoot(sandboxName) + locServKey + ":mep:" + mepName + ":"
	} else {
		basePath = "/" + sandboxName + "/" + LocServBasePath
		baseKey = dkm.GetKeyRoot(sandboxName) + locServKey + ":mep-global:"
	}

	// Connect to Redis DB
	rc, err = redis.NewConnector(redisAddr, LOC_SERV_DB)
+13 −3
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ type SandboxTemplate struct {
	AuthEnabled    bool
	IsMepService   bool
	MepName        string
	Env            []string
}

// Deploy - Generate charts & deploy single process or entire scenario
@@ -247,6 +248,9 @@ func generateScenarioCharts(sandboxName string, procName string, model *mod.Mode
		} else if mepService := getMepService(proc); mepService != "" {
			log.Debug("Processing MEP Service chart for element[", proc.Name, "]")

			// Get MEP Name
			mepName := ctx.Parents[mod.PhyLoc]

			// Create Sandbox template
			var sandboxTemplate SandboxTemplate
			sandboxTemplate.SandboxName = sandboxName
@@ -255,11 +259,17 @@ func generateScenarioCharts(sandboxName string, procName string, model *mod.Mode
			sandboxTemplate.HttpsOnly = ve.httpsOnly
			sandboxTemplate.AuthEnabled = ve.authEnabled
			sandboxTemplate.IsMepService = true

			// Get MEP Name
			mepName := ctx.Parents[mod.PhyLoc]
			sandboxTemplate.MepName = mepName

			// Set environment variables in template
			if proc.Environment != "" {
				allVar := strings.Split(proc.Environment, ",")
				for _, oneVar := range allVar {
					nameValue := strings.Split(oneVar, "=")
					sandboxTemplate.Env = append(sandboxTemplate.Env, strings.TrimSpace(nameValue[0])+": "+strings.TrimSpace(nameValue[1]))
				}
			}

			// Create chart
			chartName := proc.Name
			chartLocation, _, err := createChart(chartName, sandboxName, scenarioName, mepService, sandboxTemplate)