Loading examples/demo1/src/demo-server/go/README.md +1 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ To see how to make this your own, look here: [README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) - API version: 0.0.1 - Build date: 2021-09-14T17:37:15.009-04:00 - Build date: 2021-10-12T16:48:28.921-04:00 ### Running the server Loading examples/demo1/src/iperf-proxy/go/README.md +1 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ To see how to make this your own, look here: [README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) - API version: 0.0.1 - Build date: 2021-09-14T17:37:16.432-04:00 - Build date: 2021-10-12T16:48:30.368-04:00 ### Running the server Loading go-apps/meep-ams/api/swagger.yaml +19 −21 Original line number Diff line number Diff line Loading @@ -288,9 +288,7 @@ paths: content: application/json: schema: oneOf: - $ref: '#/components/schemas/MobilityProcedureSubscription' - $ref: '#/components/schemas/AdjacentAppInfoSubscription' $ref: '#/components/schemas/InlineSubscription' example: subscriptionType: MobilityProcedureSubscription callbackReference: 'http://my.callback.com/amsi-mobility-procedure/some-id' Loading @@ -307,9 +305,7 @@ paths: content: application/json: schema: oneOf: - $ref: '#/components/schemas/MobilityProcedureSubscription' - $ref: '#/components/schemas/AdjacentAppInfoSubscription' $ref: '#/components/schemas/InlineSubscription' '400': $ref: '#/components/responses/400' '401': Loading Loading @@ -339,14 +335,10 @@ paths: content: application/json: schema: oneOf: - $ref: '#/components/schemas/MobilityProcedureNotification' - $ref: '#/components/schemas/AdjacentAppInfoNotification' $ref: '#/components/schemas/InlineNotification' responses: '204': $ref: '#/components/responses/204' /subscriptions/{subscriptionId}: parameters: - in: path Loading @@ -367,9 +359,7 @@ paths: content: application/json: schema: oneOf: - $ref: '#/components/schemas/MobilityProcedureSubscription' - $ref: '#/components/schemas/AdjacentAppInfoSubscription' $ref: '#/components/schemas/InlineSubscription' '400': $ref: '#/components/responses/400' '401': Loading @@ -393,9 +383,7 @@ paths: content: application/json: schema: oneOf: - $ref: '#/components/schemas/MobilityProcedureSubscription' - $ref: '#/components/schemas/AdjacentAppInfoSubscription' $ref: '#/components/schemas/InlineSubscription' example: subscriptionType: MobilityProcedureSubscription callbackReference: 'http://my.callback.com/amsi-mobility-procedure/some-id' Loading @@ -415,9 +403,7 @@ paths: content: application/json: schema: oneOf: - $ref: '#/components/schemas/MobilityProcedureSubscription' - $ref: '#/components/schemas/AdjacentAppInfoSubscription' $ref: '#/components/schemas/InlineSubscription' '400': $ref: '#/components/responses/400' '401': Loading Loading @@ -1038,6 +1024,18 @@ components: x-etsi-mec-cardinality: 0..1 x-etsi-mec-origin-type: URI type: object InlineSubscription: oneOf: - $ref: '#/components/schemas/MobilityProcedureSubscription' - $ref: '#/components/schemas/AdjacentAppInfoSubscription' discriminator: propertyName: subscriptionType InlineNotification: oneOf: - $ref: '#/components/schemas/MobilityProcedureNotification' - $ref: '#/components/schemas/AdjacentAppInfoNotification' discriminator: propertyName: notificationType responses: 204: description: No Content Loading go-apps/meep-ams/server/README.md +1 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ To see how to make this your own, look here: [README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) - API version: 2.1.1 - Build date: 2021-10-06T15:28:50.114702-04:00[America/Toronto] - Build date: 2021-10-12T16:48:25.500510-04:00[America/Toronto] ### Running the server Loading go-apps/meep-ams/server/ams.go +134 −127 Original line number Diff line number Diff line Loading @@ -98,9 +98,6 @@ const ADJACENT_APP_INFO_SUBSCRIPTION_INT = int32(2) const ADJACENT_APP_INFO_SUBSCRIPTION = "AdjacentAppInfoSubscription" const ADJACENT_APP_INFO_NOTIFICATION = "AdjacentAppInfoNotification" const APP_TERM_NOTIFICATION = "AppTerminationNotification" const TRIGGER_NOTIFICATION = "TriggerNotification" var AMS_DB = 0 var rc *redis.Connector Loading Loading @@ -610,21 +607,9 @@ func unsubscribeAppTermination(appInstanceId string) error { func mec011AppTerminationPost(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") var notificationCommon NotificationCommon bodyBytes, _ := ioutil.ReadAll(r.Body) err := json.Unmarshal(bodyBytes, ¬ificationCommon) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } //extract common body part notificationType := notificationCommon.NotificationType switch notificationType { case APP_TERM_NOTIFICATION: var notification AppTerminationNotification err = json.Unmarshal(bodyBytes, ¬ification) bodyBytes, _ := ioutil.ReadAll(r.Body) err := json.Unmarshal(bodyBytes, ¬ification) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) Loading @@ -639,7 +624,8 @@ func mec011AppTerminationPost(w http.ResponseWriter, r *http.Request) { go func() { //delete any registration it made // cannot unsubscribe otherwise, the app-enablement server fails when receiving the confirm_terminate since it believes it never registered // cannot unsubscribe otherwise, the app-enablement server fails when receiving the confirm_terminate // since it believes it never registered //_ = unsubscribeAppTermination(serviceAppInstanceId) _ = deregisterService(serviceAppInstanceId, appEnablementServiceId) Loading Loading @@ -678,18 +664,6 @@ func mec011AppTerminationPost(w http.ResponseWriter, r *http.Request) { }() } case TRIGGER_NOTIFICATION: var notification TriggerNotification err = json.Unmarshal(bodyBytes, ¬ification) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } log.Info("Manual trigger : ", notification.DestinationMep, "---", notification.AppInstanceId, "---", notification.AssociateId.Value) checkMpNotificationRegisteredSubscriptions(notification.AppInstanceId, ¬ification.AssociateId, notification.DestinationMep) default: } w.WriteHeader(http.StatusNoContent) } Loading Loading @@ -1189,31 +1163,25 @@ func subscriptionsGet(w http.ResponseWriter, r *http.Request) { func subscriptionsPost(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") var subscriptionCommon SubscriptionCommon // Use discriminator to obtain subscription type var discriminator OneOfInlineSubscription bodyBytes, _ := ioutil.ReadAll(r.Body) err := json.Unmarshal(bodyBytes, &subscriptionCommon) err := json.Unmarshal(bodyBytes, &discriminator) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } //extract common body part subscriptionType := subscriptionCommon.SubscriptionType //mandatory parameter if subscriptionCommon.CallbackReference == "" { log.Error("Mandatory CallbackReference parameter not present") http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest) return } subscriptionType := discriminator.SubscriptionType //new subscription id // Get new subscription id newSubsId := nextSubscriptionIdAvailable nextSubscriptionIdAvailable++ subsIdStr := strconv.Itoa(newSubsId) self := new(LinkType) self.Href = hostUrl.String() + basePath + "subscriptions/" + subsIdStr // Process subscription request var jsonResponse []byte switch subscriptionType { Loading @@ -1226,26 +1194,40 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) { return } link := new(AdjacentAppInfoSubscriptionLinks) link.Self = self subscription.Links = link // Validate subscription if subscription.CallbackReference == "" { log.Error("Mandatory CallbackReference parameter not present") http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest) return } if subscription.FilterCriteria == nil { log.Error("FilterCriteria should not be null for this subscription type") http.Error(w, "FilterCriteria should not be null for this subscription type", http.StatusBadRequest) return } // Set resource link link := new(AdjacentAppInfoSubscriptionLinks) link.Self = self subscription.Links = link // populate mobilityStatus if len(subscription.FilterCriteria.MobilityStatus) == 0 { subscription.FilterCriteria.MobilityStatus = append(subscription.FilterCriteria.MobilityStatus, MobilityStatus_INTERHOST_MOVEOUT_TRIGGERED) } //registration // Register subscription registerMp(&subscription, subsIdStr) _ = rc.JSONSetEntry(baseKey+"subscriptions:"+subsIdStr, ".", convertMobilityProcedureSubscriptionToJson(&subscription)) // Prepare response jsonResponse, err = json.Marshal(subscription) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } case ADJACENT_APP_INFO_SUBSCRIPTION: var subscription AdjacentAppInfoSubscription err = json.Unmarshal(bodyBytes, &subscription) Loading @@ -1255,10 +1237,12 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) { return } link := new(AdjacentAppInfoSubscriptionLinks) link.Self = self subscription.Links = link // Validate subscription if subscription.CallbackReference == "" { log.Error("Mandatory CallbackReference parameter not present") http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest) return } if subscription.FilterCriteria == nil { log.Error("FilterCriteria should not be null for this subscription type") http.Error(w, "FilterCriteria should not be null for this subscription type", http.StatusBadRequest) Loading @@ -1270,83 +1254,86 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) { return } //registration // Set resource link link := new(AdjacentAppInfoSubscriptionLinks) link.Self = self subscription.Links = link // Register subscription registerAdj(&subscription, subsIdStr) _ = rc.JSONSetEntry(baseKey+"subscriptions:"+subsIdStr, ".", convertAdjacentAppInfoSubscriptionToJson(&subscription)) // Prepare response jsonResponse, err = json.Marshal(subscription) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } default: nextSubscriptionIdAvailable-- w.WriteHeader(http.StatusBadRequest) return } //processing the error of the jsonResponse if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } // Increment subscription count nextSubscriptionIdAvailable++ w.WriteHeader(http.StatusCreated) fmt.Fprintf(w, string(jsonResponse)) } func subscriptionsPut(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") // Parse query params vars := mux.Vars(r) subIdParamStr := vars["subscriptionId"] var subscriptionCommon SubscriptionCommon // Use discriminator to obtain subscription type var discriminator OneOfInlineSubscription bodyBytes, _ := ioutil.ReadAll(r.Body) err := json.Unmarshal(bodyBytes, &subscriptionCommon) err := json.Unmarshal(bodyBytes, &discriminator) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } //extract common body part subscriptionType := subscriptionCommon.SubscriptionType subscriptionType := discriminator.SubscriptionType //mandatory parameter if subscriptionCommon.CallbackReference == "" { // Process subscription request alreadyRegistered := false var jsonResponse []byte switch subscriptionType { case MOBILITY_PROCEDURE_SUBSCRIPTION: var subscription MobilityProcedureSubscription err = json.Unmarshal(bodyBytes, &subscription) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } // Validate subscription if subscription.CallbackReference == "" { log.Error("Mandatory CallbackReference parameter not present") http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest) return } link := subscriptionCommon.Links link := subscription.Links if link == nil || link.Self == nil { log.Error("Mandatory Link parameter not present") http.Error(w, "Mandatory Link parameter not present", http.StatusBadRequest) return } selfUrl := strings.Split(link.Self.Href, "/") subsIdStr := selfUrl[len(selfUrl)-1] if subsIdStr != subIdParamStr { log.Error("SubscriptionId in endpoint and in body not matching") http.Error(w, "SubscriptionId in endpoint and in body not matching", http.StatusBadRequest) return } alreadyRegistered := false var jsonResponse []byte switch subscriptionType { case MOBILITY_PROCEDURE_SUBSCRIPTION: var subscription MobilityProcedureSubscription err = json.Unmarshal(bodyBytes, &subscription) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } if subscription.FilterCriteria == nil { log.Error("FilterCriteria should not be null for this subscription type") http.Error(w, "FilterCriteria should not be null for this subscription type", http.StatusBadRequest) Loading @@ -1358,13 +1345,14 @@ func subscriptionsPut(w http.ResponseWriter, r *http.Request) { subscription.FilterCriteria.MobilityStatus = append(subscription.FilterCriteria.MobilityStatus, MobilityStatus_INTERHOST_MOVEOUT_TRIGGERED) } //registration // Register subscription if isSubscriptionIdRegisteredMp(subsIdStr) { registerMp(&subscription, subsIdStr) _ = rc.JSONSetEntry(baseKey+"subscriptions:"+subsIdStr, ".", convertMobilityProcedureSubscriptionToJson(&subscription)) alreadyRegistered = true jsonResponse, err = json.Marshal(subscription) } case ADJACENT_APP_INFO_SUBSCRIPTION: var subscription AdjacentAppInfoSubscription err = json.Unmarshal(bodyBytes, &subscription) Loading @@ -1374,6 +1362,25 @@ func subscriptionsPut(w http.ResponseWriter, r *http.Request) { return } // Validate subscription if subscription.CallbackReference == "" { log.Error("Mandatory CallbackReference parameter not present") http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest) return } link := subscription.Links if link == nil || link.Self == nil { log.Error("Mandatory Link parameter not present") http.Error(w, "Mandatory Link parameter not present", http.StatusBadRequest) return } selfUrl := strings.Split(link.Self.Href, "/") subsIdStr := selfUrl[len(selfUrl)-1] if subsIdStr != subIdParamStr { log.Error("SubscriptionId in endpoint and in body not matching") http.Error(w, "SubscriptionId in endpoint and in body not matching", http.StatusBadRequest) return } if subscription.FilterCriteria == nil { log.Error("FilterCriteria should not be null for this subscription type") http.Error(w, "FilterCriteria should not be null for this subscription type", http.StatusBadRequest) Loading @@ -1385,7 +1392,7 @@ func subscriptionsPut(w http.ResponseWriter, r *http.Request) { return } //registration // Register subscription if isSubscriptionIdRegisteredAdj(subsIdStr) { registerAdj(&subscription, subsIdStr) _ = rc.JSONSetEntry(baseKey+"subscriptions:"+subsIdStr, ".", convertAdjacentAppInfoSubscriptionToJson(&subscription)) Loading Loading
examples/demo1/src/demo-server/go/README.md +1 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ To see how to make this your own, look here: [README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) - API version: 0.0.1 - Build date: 2021-09-14T17:37:15.009-04:00 - Build date: 2021-10-12T16:48:28.921-04:00 ### Running the server Loading
examples/demo1/src/iperf-proxy/go/README.md +1 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ To see how to make this your own, look here: [README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) - API version: 0.0.1 - Build date: 2021-09-14T17:37:16.432-04:00 - Build date: 2021-10-12T16:48:30.368-04:00 ### Running the server Loading
go-apps/meep-ams/api/swagger.yaml +19 −21 Original line number Diff line number Diff line Loading @@ -288,9 +288,7 @@ paths: content: application/json: schema: oneOf: - $ref: '#/components/schemas/MobilityProcedureSubscription' - $ref: '#/components/schemas/AdjacentAppInfoSubscription' $ref: '#/components/schemas/InlineSubscription' example: subscriptionType: MobilityProcedureSubscription callbackReference: 'http://my.callback.com/amsi-mobility-procedure/some-id' Loading @@ -307,9 +305,7 @@ paths: content: application/json: schema: oneOf: - $ref: '#/components/schemas/MobilityProcedureSubscription' - $ref: '#/components/schemas/AdjacentAppInfoSubscription' $ref: '#/components/schemas/InlineSubscription' '400': $ref: '#/components/responses/400' '401': Loading Loading @@ -339,14 +335,10 @@ paths: content: application/json: schema: oneOf: - $ref: '#/components/schemas/MobilityProcedureNotification' - $ref: '#/components/schemas/AdjacentAppInfoNotification' $ref: '#/components/schemas/InlineNotification' responses: '204': $ref: '#/components/responses/204' /subscriptions/{subscriptionId}: parameters: - in: path Loading @@ -367,9 +359,7 @@ paths: content: application/json: schema: oneOf: - $ref: '#/components/schemas/MobilityProcedureSubscription' - $ref: '#/components/schemas/AdjacentAppInfoSubscription' $ref: '#/components/schemas/InlineSubscription' '400': $ref: '#/components/responses/400' '401': Loading @@ -393,9 +383,7 @@ paths: content: application/json: schema: oneOf: - $ref: '#/components/schemas/MobilityProcedureSubscription' - $ref: '#/components/schemas/AdjacentAppInfoSubscription' $ref: '#/components/schemas/InlineSubscription' example: subscriptionType: MobilityProcedureSubscription callbackReference: 'http://my.callback.com/amsi-mobility-procedure/some-id' Loading @@ -415,9 +403,7 @@ paths: content: application/json: schema: oneOf: - $ref: '#/components/schemas/MobilityProcedureSubscription' - $ref: '#/components/schemas/AdjacentAppInfoSubscription' $ref: '#/components/schemas/InlineSubscription' '400': $ref: '#/components/responses/400' '401': Loading Loading @@ -1038,6 +1024,18 @@ components: x-etsi-mec-cardinality: 0..1 x-etsi-mec-origin-type: URI type: object InlineSubscription: oneOf: - $ref: '#/components/schemas/MobilityProcedureSubscription' - $ref: '#/components/schemas/AdjacentAppInfoSubscription' discriminator: propertyName: subscriptionType InlineNotification: oneOf: - $ref: '#/components/schemas/MobilityProcedureNotification' - $ref: '#/components/schemas/AdjacentAppInfoNotification' discriminator: propertyName: notificationType responses: 204: description: No Content Loading
go-apps/meep-ams/server/README.md +1 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ To see how to make this your own, look here: [README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) - API version: 2.1.1 - Build date: 2021-10-06T15:28:50.114702-04:00[America/Toronto] - Build date: 2021-10-12T16:48:25.500510-04:00[America/Toronto] ### Running the server Loading
go-apps/meep-ams/server/ams.go +134 −127 Original line number Diff line number Diff line Loading @@ -98,9 +98,6 @@ const ADJACENT_APP_INFO_SUBSCRIPTION_INT = int32(2) const ADJACENT_APP_INFO_SUBSCRIPTION = "AdjacentAppInfoSubscription" const ADJACENT_APP_INFO_NOTIFICATION = "AdjacentAppInfoNotification" const APP_TERM_NOTIFICATION = "AppTerminationNotification" const TRIGGER_NOTIFICATION = "TriggerNotification" var AMS_DB = 0 var rc *redis.Connector Loading Loading @@ -610,21 +607,9 @@ func unsubscribeAppTermination(appInstanceId string) error { func mec011AppTerminationPost(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") var notificationCommon NotificationCommon bodyBytes, _ := ioutil.ReadAll(r.Body) err := json.Unmarshal(bodyBytes, ¬ificationCommon) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } //extract common body part notificationType := notificationCommon.NotificationType switch notificationType { case APP_TERM_NOTIFICATION: var notification AppTerminationNotification err = json.Unmarshal(bodyBytes, ¬ification) bodyBytes, _ := ioutil.ReadAll(r.Body) err := json.Unmarshal(bodyBytes, ¬ification) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) Loading @@ -639,7 +624,8 @@ func mec011AppTerminationPost(w http.ResponseWriter, r *http.Request) { go func() { //delete any registration it made // cannot unsubscribe otherwise, the app-enablement server fails when receiving the confirm_terminate since it believes it never registered // cannot unsubscribe otherwise, the app-enablement server fails when receiving the confirm_terminate // since it believes it never registered //_ = unsubscribeAppTermination(serviceAppInstanceId) _ = deregisterService(serviceAppInstanceId, appEnablementServiceId) Loading Loading @@ -678,18 +664,6 @@ func mec011AppTerminationPost(w http.ResponseWriter, r *http.Request) { }() } case TRIGGER_NOTIFICATION: var notification TriggerNotification err = json.Unmarshal(bodyBytes, ¬ification) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } log.Info("Manual trigger : ", notification.DestinationMep, "---", notification.AppInstanceId, "---", notification.AssociateId.Value) checkMpNotificationRegisteredSubscriptions(notification.AppInstanceId, ¬ification.AssociateId, notification.DestinationMep) default: } w.WriteHeader(http.StatusNoContent) } Loading Loading @@ -1189,31 +1163,25 @@ func subscriptionsGet(w http.ResponseWriter, r *http.Request) { func subscriptionsPost(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") var subscriptionCommon SubscriptionCommon // Use discriminator to obtain subscription type var discriminator OneOfInlineSubscription bodyBytes, _ := ioutil.ReadAll(r.Body) err := json.Unmarshal(bodyBytes, &subscriptionCommon) err := json.Unmarshal(bodyBytes, &discriminator) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } //extract common body part subscriptionType := subscriptionCommon.SubscriptionType //mandatory parameter if subscriptionCommon.CallbackReference == "" { log.Error("Mandatory CallbackReference parameter not present") http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest) return } subscriptionType := discriminator.SubscriptionType //new subscription id // Get new subscription id newSubsId := nextSubscriptionIdAvailable nextSubscriptionIdAvailable++ subsIdStr := strconv.Itoa(newSubsId) self := new(LinkType) self.Href = hostUrl.String() + basePath + "subscriptions/" + subsIdStr // Process subscription request var jsonResponse []byte switch subscriptionType { Loading @@ -1226,26 +1194,40 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) { return } link := new(AdjacentAppInfoSubscriptionLinks) link.Self = self subscription.Links = link // Validate subscription if subscription.CallbackReference == "" { log.Error("Mandatory CallbackReference parameter not present") http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest) return } if subscription.FilterCriteria == nil { log.Error("FilterCriteria should not be null for this subscription type") http.Error(w, "FilterCriteria should not be null for this subscription type", http.StatusBadRequest) return } // Set resource link link := new(AdjacentAppInfoSubscriptionLinks) link.Self = self subscription.Links = link // populate mobilityStatus if len(subscription.FilterCriteria.MobilityStatus) == 0 { subscription.FilterCriteria.MobilityStatus = append(subscription.FilterCriteria.MobilityStatus, MobilityStatus_INTERHOST_MOVEOUT_TRIGGERED) } //registration // Register subscription registerMp(&subscription, subsIdStr) _ = rc.JSONSetEntry(baseKey+"subscriptions:"+subsIdStr, ".", convertMobilityProcedureSubscriptionToJson(&subscription)) // Prepare response jsonResponse, err = json.Marshal(subscription) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } case ADJACENT_APP_INFO_SUBSCRIPTION: var subscription AdjacentAppInfoSubscription err = json.Unmarshal(bodyBytes, &subscription) Loading @@ -1255,10 +1237,12 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) { return } link := new(AdjacentAppInfoSubscriptionLinks) link.Self = self subscription.Links = link // Validate subscription if subscription.CallbackReference == "" { log.Error("Mandatory CallbackReference parameter not present") http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest) return } if subscription.FilterCriteria == nil { log.Error("FilterCriteria should not be null for this subscription type") http.Error(w, "FilterCriteria should not be null for this subscription type", http.StatusBadRequest) Loading @@ -1270,83 +1254,86 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) { return } //registration // Set resource link link := new(AdjacentAppInfoSubscriptionLinks) link.Self = self subscription.Links = link // Register subscription registerAdj(&subscription, subsIdStr) _ = rc.JSONSetEntry(baseKey+"subscriptions:"+subsIdStr, ".", convertAdjacentAppInfoSubscriptionToJson(&subscription)) // Prepare response jsonResponse, err = json.Marshal(subscription) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } default: nextSubscriptionIdAvailable-- w.WriteHeader(http.StatusBadRequest) return } //processing the error of the jsonResponse if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } // Increment subscription count nextSubscriptionIdAvailable++ w.WriteHeader(http.StatusCreated) fmt.Fprintf(w, string(jsonResponse)) } func subscriptionsPut(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") // Parse query params vars := mux.Vars(r) subIdParamStr := vars["subscriptionId"] var subscriptionCommon SubscriptionCommon // Use discriminator to obtain subscription type var discriminator OneOfInlineSubscription bodyBytes, _ := ioutil.ReadAll(r.Body) err := json.Unmarshal(bodyBytes, &subscriptionCommon) err := json.Unmarshal(bodyBytes, &discriminator) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } //extract common body part subscriptionType := subscriptionCommon.SubscriptionType subscriptionType := discriminator.SubscriptionType //mandatory parameter if subscriptionCommon.CallbackReference == "" { // Process subscription request alreadyRegistered := false var jsonResponse []byte switch subscriptionType { case MOBILITY_PROCEDURE_SUBSCRIPTION: var subscription MobilityProcedureSubscription err = json.Unmarshal(bodyBytes, &subscription) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } // Validate subscription if subscription.CallbackReference == "" { log.Error("Mandatory CallbackReference parameter not present") http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest) return } link := subscriptionCommon.Links link := subscription.Links if link == nil || link.Self == nil { log.Error("Mandatory Link parameter not present") http.Error(w, "Mandatory Link parameter not present", http.StatusBadRequest) return } selfUrl := strings.Split(link.Self.Href, "/") subsIdStr := selfUrl[len(selfUrl)-1] if subsIdStr != subIdParamStr { log.Error("SubscriptionId in endpoint and in body not matching") http.Error(w, "SubscriptionId in endpoint and in body not matching", http.StatusBadRequest) return } alreadyRegistered := false var jsonResponse []byte switch subscriptionType { case MOBILITY_PROCEDURE_SUBSCRIPTION: var subscription MobilityProcedureSubscription err = json.Unmarshal(bodyBytes, &subscription) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) return } if subscription.FilterCriteria == nil { log.Error("FilterCriteria should not be null for this subscription type") http.Error(w, "FilterCriteria should not be null for this subscription type", http.StatusBadRequest) Loading @@ -1358,13 +1345,14 @@ func subscriptionsPut(w http.ResponseWriter, r *http.Request) { subscription.FilterCriteria.MobilityStatus = append(subscription.FilterCriteria.MobilityStatus, MobilityStatus_INTERHOST_MOVEOUT_TRIGGERED) } //registration // Register subscription if isSubscriptionIdRegisteredMp(subsIdStr) { registerMp(&subscription, subsIdStr) _ = rc.JSONSetEntry(baseKey+"subscriptions:"+subsIdStr, ".", convertMobilityProcedureSubscriptionToJson(&subscription)) alreadyRegistered = true jsonResponse, err = json.Marshal(subscription) } case ADJACENT_APP_INFO_SUBSCRIPTION: var subscription AdjacentAppInfoSubscription err = json.Unmarshal(bodyBytes, &subscription) Loading @@ -1374,6 +1362,25 @@ func subscriptionsPut(w http.ResponseWriter, r *http.Request) { return } // Validate subscription if subscription.CallbackReference == "" { log.Error("Mandatory CallbackReference parameter not present") http.Error(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest) return } link := subscription.Links if link == nil || link.Self == nil { log.Error("Mandatory Link parameter not present") http.Error(w, "Mandatory Link parameter not present", http.StatusBadRequest) return } selfUrl := strings.Split(link.Self.Href, "/") subsIdStr := selfUrl[len(selfUrl)-1] if subsIdStr != subIdParamStr { log.Error("SubscriptionId in endpoint and in body not matching") http.Error(w, "SubscriptionId in endpoint and in body not matching", http.StatusBadRequest) return } if subscription.FilterCriteria == nil { log.Error("FilterCriteria should not be null for this subscription type") http.Error(w, "FilterCriteria should not be null for this subscription type", http.StatusBadRequest) Loading @@ -1385,7 +1392,7 @@ func subscriptionsPut(w http.ResponseWriter, r *http.Request) { return } //registration // Register subscription if isSubscriptionIdRegisteredAdj(subsIdStr) { registerAdj(&subscription, subsIdStr) _ = rc.JSONSetEntry(baseKey+"subscriptions:"+subsIdStr, ".", convertAdjacentAppInfoSubscriptionToJson(&subscription)) Loading