Loading go-apps/meep-ams/api/swagger.yaml +1 −1 Original line number Diff line number Diff line Loading @@ -228,7 +228,7 @@ paths: required: true post: tags: - 'amsi' - 'unsupported' summary: ' deregister the individual application mobility service' description: ' deregister the individual application mobility service' operationId: app_mobility_service_derPOST Loading go-apps/meep-ams/server/ams.go +44 −4 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ 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" Loading Loading @@ -99,6 +100,7 @@ var locality []string var basePath string var baseKey string var baseKeyGlobal string var serviceMgmtKey string var mutex sync.Mutex var expiryTicker *time.Ticker Loading Loading @@ -246,6 +248,7 @@ 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) Loading Loading @@ -1643,6 +1646,22 @@ 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) } return } } //new service id newServId := nextServiceIdAvailable nextServiceIdAvailable++ Loading Loading @@ -1785,12 +1804,14 @@ func appMobilityServiceByIdPUT(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, string(jsonResponse)) } /* func appMobilityServiceDerPOST(w http.ResponseWriter, r *http.Request) { //these 2 methods are exactly the same based on spec except that the Deregistration happens on timer expiry //It is not clear why the consumer service should be responsible to send that request rather than letting AMS to take care of it //It looks more like a notification but there is no explanation in the spec regarding that message that enlighten the reason of its existence appMobilityServiceByIdDELETE(w, r) } */ func serviceByIdDelete(serviceId string) (error, int) { key := baseKey + /* ":apps:" + registrationInfo.ServiceConsumerId.AppInstanceId +*/ "services:" + serviceId Loading Loading @@ -1851,7 +1872,7 @@ func appMobilityServiceGET(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } if len(response.RegistrationInfoList) > 0 { // if len(response.RegistrationInfoList) > 0 { jsonResponse, err := json.Marshal(response.RegistrationInfoList) if err != nil { log.Error(err.Error()) Loading @@ -1861,9 +1882,9 @@ func appMobilityServiceGET(w http.ResponseWriter, r *http.Request) { } w.WriteHeader(http.StatusOK) fmt.Fprintf(w, string(jsonResponse)) } else { w.WriteHeader(http.StatusNotFound) } // } else { // w.WriteHeader(http.StatusNotFound) // } } Loading Loading @@ -2001,3 +2022,22 @@ 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, "" } go-apps/meep-ams/server/ams_test.go +19 −19 Original line number Diff line number Diff line Loading @@ -716,7 +716,7 @@ func TestFailServices(t *testing.T) { terminateScenario() } /* func TestServicesDeregister(t *testing.T) { fmt.Println("--- ", t.Name()) log.MeepTextLogInit(t.Name()) Loading Loading @@ -744,7 +744,7 @@ func TestServicesDeregister(t *testing.T) { terminateScenario() } */ func TestServicesListGet(t *testing.T) { fmt.Println("--- ", t.Name()) log.MeepTextLogInit(t.Name()) Loading Loading @@ -1060,30 +1060,30 @@ func testServicesDelete(t *testing.T, serviceId string, expectSuccess bool) { } } } /* func testServicesDeregister(t *testing.T, serviceId string, expectSuccess bool) { /****************************** * expected response section ******************************/ // ****************************** // * expected response section // ****************************** /****************************** * request vars section ******************************/ // ****************************** // * request vars section // ****************************** vars := make(map[string]string) vars["appMobilityServiceId"] = serviceId /****************************** * request body section ******************************/ // ****************************** // * request body section // ****************************** /****************************** * request queries section ******************************/ // ****************************** // * request queries section // ****************************** /****************************** * request execution section ******************************/ // ****************************** // * request execution section // ****************************** if expectSuccess { _, err := sendRequest(http.MethodPost, "/services", nil, vars, nil, http.StatusNoContent, AppMobilityServiceDerPOST) Loading @@ -1097,7 +1097,7 @@ func testServicesDeregister(t *testing.T, serviceId string, expectSuccess bool) } } } */ func testSubscriptionMobilityProcedurePost(t *testing.T) string { /****************************** Loading go-apps/meep-ams/server/api_amsi.go +0 −4 Original line number Diff line number Diff line Loading @@ -39,10 +39,6 @@ func AppMobilityServiceByIdPUT(w http.ResponseWriter, r *http.Request) { appMobilityServiceByIdPUT(w, r) } func AppMobilityServiceDerPOST(w http.ResponseWriter, r *http.Request) { appMobilityServiceDerPOST(w, r) } func AppMobilityServiceGET(w http.ResponseWriter, r *http.Request) { appMobilityServiceGET(w, r) } Loading go-apps/meep-ams/server/api_unsupported.go +5 −0 Original line number Diff line number Diff line Loading @@ -30,3 +30,8 @@ import ( func AdjAppInstGET(w http.ResponseWriter, r *http.Request) { notImplemented(w, r) } func AppMobilityServiceDerPOST(w http.ResponseWriter, r *http.Request) { notImplemented(w, r) } Loading
go-apps/meep-ams/api/swagger.yaml +1 −1 Original line number Diff line number Diff line Loading @@ -228,7 +228,7 @@ paths: required: true post: tags: - 'amsi' - 'unsupported' summary: ' deregister the individual application mobility service' description: ' deregister the individual application mobility service' operationId: app_mobility_service_derPOST Loading
go-apps/meep-ams/server/ams.go +44 −4 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ 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" Loading Loading @@ -99,6 +100,7 @@ var locality []string var basePath string var baseKey string var baseKeyGlobal string var serviceMgmtKey string var mutex sync.Mutex var expiryTicker *time.Ticker Loading Loading @@ -246,6 +248,7 @@ 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) Loading Loading @@ -1643,6 +1646,22 @@ 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) } return } } //new service id newServId := nextServiceIdAvailable nextServiceIdAvailable++ Loading Loading @@ -1785,12 +1804,14 @@ func appMobilityServiceByIdPUT(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, string(jsonResponse)) } /* func appMobilityServiceDerPOST(w http.ResponseWriter, r *http.Request) { //these 2 methods are exactly the same based on spec except that the Deregistration happens on timer expiry //It is not clear why the consumer service should be responsible to send that request rather than letting AMS to take care of it //It looks more like a notification but there is no explanation in the spec regarding that message that enlighten the reason of its existence appMobilityServiceByIdDELETE(w, r) } */ func serviceByIdDelete(serviceId string) (error, int) { key := baseKey + /* ":apps:" + registrationInfo.ServiceConsumerId.AppInstanceId +*/ "services:" + serviceId Loading Loading @@ -1851,7 +1872,7 @@ func appMobilityServiceGET(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } if len(response.RegistrationInfoList) > 0 { // if len(response.RegistrationInfoList) > 0 { jsonResponse, err := json.Marshal(response.RegistrationInfoList) if err != nil { log.Error(err.Error()) Loading @@ -1861,9 +1882,9 @@ func appMobilityServiceGET(w http.ResponseWriter, r *http.Request) { } w.WriteHeader(http.StatusOK) fmt.Fprintf(w, string(jsonResponse)) } else { w.WriteHeader(http.StatusNotFound) } // } else { // w.WriteHeader(http.StatusNotFound) // } } Loading Loading @@ -2001,3 +2022,22 @@ 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, "" }
go-apps/meep-ams/server/ams_test.go +19 −19 Original line number Diff line number Diff line Loading @@ -716,7 +716,7 @@ func TestFailServices(t *testing.T) { terminateScenario() } /* func TestServicesDeregister(t *testing.T) { fmt.Println("--- ", t.Name()) log.MeepTextLogInit(t.Name()) Loading Loading @@ -744,7 +744,7 @@ func TestServicesDeregister(t *testing.T) { terminateScenario() } */ func TestServicesListGet(t *testing.T) { fmt.Println("--- ", t.Name()) log.MeepTextLogInit(t.Name()) Loading Loading @@ -1060,30 +1060,30 @@ func testServicesDelete(t *testing.T, serviceId string, expectSuccess bool) { } } } /* func testServicesDeregister(t *testing.T, serviceId string, expectSuccess bool) { /****************************** * expected response section ******************************/ // ****************************** // * expected response section // ****************************** /****************************** * request vars section ******************************/ // ****************************** // * request vars section // ****************************** vars := make(map[string]string) vars["appMobilityServiceId"] = serviceId /****************************** * request body section ******************************/ // ****************************** // * request body section // ****************************** /****************************** * request queries section ******************************/ // ****************************** // * request queries section // ****************************** /****************************** * request execution section ******************************/ // ****************************** // * request execution section // ****************************** if expectSuccess { _, err := sendRequest(http.MethodPost, "/services", nil, vars, nil, http.StatusNoContent, AppMobilityServiceDerPOST) Loading @@ -1097,7 +1097,7 @@ func testServicesDeregister(t *testing.T, serviceId string, expectSuccess bool) } } } */ func testSubscriptionMobilityProcedurePost(t *testing.T) string { /****************************** Loading
go-apps/meep-ams/server/api_amsi.go +0 −4 Original line number Diff line number Diff line Loading @@ -39,10 +39,6 @@ func AppMobilityServiceByIdPUT(w http.ResponseWriter, r *http.Request) { appMobilityServiceByIdPUT(w, r) } func AppMobilityServiceDerPOST(w http.ResponseWriter, r *http.Request) { appMobilityServiceDerPOST(w, r) } func AppMobilityServiceGET(w http.ResponseWriter, r *http.Request) { appMobilityServiceGET(w, r) } Loading
go-apps/meep-ams/server/api_unsupported.go +5 −0 Original line number Diff line number Diff line Loading @@ -30,3 +30,8 @@ import ( func AdjAppInstGET(w http.ResponseWriter, r *http.Request) { notImplemented(w, r) } func AppMobilityServiceDerPOST(w http.ResponseWriter, r *http.Request) { notImplemented(w, r) }