Commit eacab7d6 authored by Simon Pastor's avatar Simon Pastor
Browse files

appinfoMap usage

parent a5ad3a5d
Loading
Loading
Loading
Loading
+16 −46
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ import (
const moduleName = "meep-ams"
const amsBasePath = "amsi/v1/"
const amsKey = "ams"
const appEnablementKey = "app-enablement"
const serviceName = "App Mobility Service"
const serviceCategory = "AMS"
const defaultMepName = "global"
@@ -100,7 +99,6 @@ var locality []string
var basePath string
var baseKey string
var baseKeyGlobal string
var serviceMgmtKey string
var mutex sync.Mutex

var expiryTicker *time.Ticker
@@ -248,7 +246,6 @@ func Init() (err error) {
	// Set base storage key
	baseKey = dkm.GetKeyRoot(sandboxName) + amsKey + ":mep:" + mepName + ":"
	baseKeyGlobal = dkm.GetKeyRoot(sandboxName) + amsKey + ":mep:*:"
	serviceMgmtKey = dkm.GetKeyRoot(sandboxName) + appEnablementKey + ":mep:" + mepName

	// Connect to Redis DB (AMS_DB)
	rc, err = redis.NewConnector(redisAddr, AMS_DB)
@@ -1648,19 +1645,11 @@ func appMobilityServicePOST(w http.ResponseWriter, r *http.Request) {

	//validate if the appInstanceId exists
	// Validate App Instance ID
	if registrationInfo.ServiceConsumerId.AppInstanceId != "" {
		err, code, problemDetails := validateAppInstanceId(registrationInfo.ServiceConsumerId.AppInstanceId)
		if err != nil {
			log.Error(err.Error())
			if problemDetails != "" {
				w.WriteHeader(code)
				fmt.Fprintf(w, problemDetails)
			} else {
				http.Error(w, err.Error(), code)
			}
	if registrationInfo.ServiceConsumerId.AppInstanceId != "" && appInfoMap[registrationInfo.ServiceConsumerId.AppInstanceId] == nil {
		log.Error("App Instance Id does not exist.")
		http.Error(w, "App Instance Id does not exist.", http.StatusBadRequest)
		return
	}
	}

	//new service id
	newServId := nextServiceIdAvailable
@@ -2022,22 +2011,3 @@ func populateAppInstanceIds(key string, fields map[string]string, response inter
	//response = &resp
	return nil
}

func validateAppInstanceId(appInstanceId string) (error, int, string) {
	// Get application instance
	key := serviceMgmtKey + ":app:" + appInstanceId + ":info"
	fields, err := rc.GetEntry(key)
	if err != nil || len(fields) == 0 {
		return errors.New("App Instance not found"), http.StatusNotFound, ""
	}

	// Make sure App is in ready state
	if fields["state"] != "READY" {
		var problemDetails ProblemDetails
		problemDetails.Status = http.StatusForbidden
		problemDetails.Detail = "App Instance not ready. Waiting for AppReadyConfirmation."
		return errors.New("App Instance not ready"), http.StatusForbidden, convertProblemDetailsToJson(&problemDetails)
	}

	return nil, http.StatusOK, ""
}
+6 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import (
	//met "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-metrics"
	mod "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-model"
	mq "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-mq"
        scc "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sandbox-ctrl-client"

	"github.com/gorilla/mux"
)
@@ -716,6 +717,7 @@ func TestFailServices(t *testing.T) {

	terminateScenario()
}

/*
func TestServicesDeregister(t *testing.T) {
	fmt.Println("--- ", t.Name())
@@ -901,6 +903,7 @@ func testServicesPost(t *testing.T) string {

	rr, err := sendRequest(http.MethodPost, "/services", bytes.NewBuffer(body), nil, nil, http.StatusCreated, AppMobilityServicePOST)
	if err != nil {
	
		t.Fatalf("Failed to get expected response")
	}

@@ -1060,6 +1063,7 @@ func testServicesDelete(t *testing.T, serviceId string, expectSuccess bool) {
		}
	}
}

/*
func testServicesDeregister(t *testing.T, serviceId string, expectSuccess bool) {

@@ -1843,6 +1847,8 @@ func initializeVars() {
	redisAddr = redisTestAddr
	influxAddr = influxTestAddr
	sandboxName = testScenarioName
	var appInfo scc.ApplicationInfo
	appInfoMap["myapp"] = &appInfo
}

func initialiseScenario(testScenario string) {
+1 −2
Original line number Diff line number Diff line
@@ -34,4 +34,3 @@ func AdjAppInstGET(w http.ResponseWriter, r *http.Request) {
func AppMobilityServiceDerPOST(w http.ResponseWriter, r *http.Request) {
	notImplemented(w, r)
}
+0 −9
Original line number Diff line number Diff line
@@ -89,12 +89,3 @@ func convertRegistrationInfoToJson(obj *RegistrationInfo) string {

	return string(jsonInfo)
}

func convertProblemDetailsToJson(problemDetails *ProblemDetails) string {
	jsonInfo, err := json.Marshal(*problemDetails)
	if err != nil {
		log.Error(err.Error())
		return ""
	}
	return string(jsonInfo)
}