Loading go-apps/meep-app-enablement/server/capif-mgmt/service-mgmt.go +86 −40 Original line number Diff line number Diff line Loading @@ -214,7 +214,7 @@ func appServicesPOST(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") vars := mux.Vars(r) appId := vars["appInstanceId"] appId := vars["apfId"] mutex.Lock() defer mutex.Unlock() Loading Loading @@ -247,10 +247,15 @@ func appServicesPOST(w http.ResponseWriter, r *http.Request) { } // NOTE: Set default values for omitted fields locality := MEC_HOST_LocalityType sInfoPost := ServiceInfo{ sInfoPost := ServiceApiDescription{ VendorSpecificUrnetsimeccapifextserviceInfo: &MecServiceInfoCapifExt{ ScopeOfLocality: &locality, IsLocal: true, ConsumedLocalOnly: true, }, // ScopeOfLocality: &locality, // IsLocal: true, // ConsumedLocalOnly: true, } decoder := json.NewDecoder(r.Body) err = decoder.Decode(&sInfoPost) Loading @@ -261,85 +266,126 @@ func appServicesPOST(w http.ResponseWriter, r *http.Request) { } // Check for mandatory properties if sInfoPost.SerInstanceId != "" { if sInfoPost.ApiId != "" { errStr := "Service instance ID must not be present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if sInfoPost.SerName == "" { if sInfoPost.ApiName == "" { errStr := "Mandatory Service Name parameter not present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if sInfoPost.Version == "" { if len(sInfoPost.AefProfiles) == 0 || len(sInfoPost.AefProfiles[0].Versions) == 0 { errStr := "Mandatory Service Version parameter not present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if sInfoPost.State == nil { if sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.State == nil { errStr := "Mandatory Service State parameter not present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if sInfoPost.Serializer == nil { if sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.Serializer == nil { errStr := "Mandatory Serializer parameter not present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if sInfoPost.SerCategory != nil { errStr := validateCategoryRef(sInfoPost.SerCategory) if sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.Category != nil { errStr := validateCategoryRef(sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.Category) if errStr != "" { log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } } if (sInfoPost.TransportId != "" && sInfoPost.TransportInfo != nil) || (sInfoPost.TransportId == "" && sInfoPost.TransportInfo == nil) { errStr := "Either transportId or transportInfo but not both shall be present" if len(sInfoPost.AefProfiles) == 0 || sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo == nil { errStr := "Mandatory TransportInfo (VendorSpecificUrnetsimeccapifexttransportInfo) not present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if len(sInfoPost.AefProfiles) == 0 || sInfoPost.AefProfiles[0].InterfaceDescriptions == nil { errStr := "Mandatory AefProfiles (InterfaceDescriptions) not present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if sInfoPost.Links != nil { errStr := "Links parameter should not be present in request" if len(sInfoPost.AefProfiles) == 0 || sInfoPost.AefProfiles[0].AefId == "" { errStr := "Mandatory AefProfiles (AefId) not present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if sInfoPost.TransportInfo != nil { if sInfoPost.TransportInfo.Id == "" || sInfoPost.TransportInfo.Name == "" || string(*sInfoPost.TransportInfo.Type_) == "" || sInfoPost.TransportInfo.Protocol == "" || sInfoPost.TransportInfo.Version == "" || sInfoPost.TransportInfo.Endpoint == nil { errStr := "Id, Name, Type, Protocol, Version, Endpoint are all mandatory parameters of TransportInfo" transportInfo := sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo // if sInfoPost.TransportInfo != nil { if transportInfo.Name == "" || string(*transportInfo.Type_) == "" || transportInfo.Protocol == "" || transportInfo.Version == "" { errStr := "Id, Name, Type, Protocol, Version, are all mandatory parameters of TransportInfo" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } // } aefProfile := &AefProfile{ AefId: sInfoPost.AefProfiles[0].AefId, Versions: sInfoPost.AefProfiles[0].Versions, InterfaceDescriptions: sInfoPost.AefProfiles[0].InterfaceDescriptions, VendorSpecificUrnetsimeccapifexttransportInfo: &MecTransportInfoCapifExt{ Name: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Name, Type_: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Type_, Protocol: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Protocol, Version: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Version, Security: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Security, }, } dsInfo := &ServiceApiDescription{ ApiName: sInfoPost.ApiName, ApiId: uuid.New().String(), AefProfiles: []AefProfile{*aefProfile}, VendorSpecificUrnetsimeccapifextserviceInfo: &MecServiceInfoCapifExt{ Serializer: sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.Serializer, State: sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.State, ScopeOfLocality: sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.ScopeOfLocality, ConsumedLocalOnly: sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.ConsumedLocalOnly, IsLocal: sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.IsLocal, Category: sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.Category, }, } transportInfo_ := TransportInfo{ Id: sInfoPost.AefProfiles[0].AefId, // Set this appropriately or generate it Name: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Name, Type_: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Type_, Protocol: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Protocol, Version: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Version, Endpoint: sInfoPost.AefProfiles[0].InterfaceDescriptions, // Set the endpoint as required Security: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Security, } // Create Service sInfo := &ServiceInfo{ SerInstanceId: uuid.New().String(), SerName: sInfoPost.SerName, SerCategory: sInfoPost.SerCategory, Version: sInfoPost.Version, State: sInfoPost.State, TransportInfo: sInfoPost.TransportInfo, Serializer: sInfoPost.Serializer, ScopeOfLocality: sInfoPost.ScopeOfLocality, ConsumedLocalOnly: sInfoPost.ConsumedLocalOnly, SerInstanceId: dsInfo.ApiId, SerName: dsInfo.ApiName, SerCategory: dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.Category, Version: dsInfo.AefProfiles[0].Versions[0], State: dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.State, TransportInfo: &transportInfo_, Serializer: dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.Serializer, ScopeOfLocality: dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.ScopeOfLocality, ConsumedLocalOnly: dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.ConsumedLocalOnly, // although IsLocal is reevaluated when a query is replied to, value stored in sInfo as is for now IsLocal: sInfoPost.IsLocal, LivenessInterval: sInfoPost.LivenessInterval, IsLocal: dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.IsLocal, LivenessInterval: 0, } sInfo.Links = &ServiceInfoLinks{ Self: &LinkType{ Loading Loading
go-apps/meep-app-enablement/server/capif-mgmt/service-mgmt.go +86 −40 Original line number Diff line number Diff line Loading @@ -214,7 +214,7 @@ func appServicesPOST(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") vars := mux.Vars(r) appId := vars["appInstanceId"] appId := vars["apfId"] mutex.Lock() defer mutex.Unlock() Loading Loading @@ -247,10 +247,15 @@ func appServicesPOST(w http.ResponseWriter, r *http.Request) { } // NOTE: Set default values for omitted fields locality := MEC_HOST_LocalityType sInfoPost := ServiceInfo{ sInfoPost := ServiceApiDescription{ VendorSpecificUrnetsimeccapifextserviceInfo: &MecServiceInfoCapifExt{ ScopeOfLocality: &locality, IsLocal: true, ConsumedLocalOnly: true, }, // ScopeOfLocality: &locality, // IsLocal: true, // ConsumedLocalOnly: true, } decoder := json.NewDecoder(r.Body) err = decoder.Decode(&sInfoPost) Loading @@ -261,85 +266,126 @@ func appServicesPOST(w http.ResponseWriter, r *http.Request) { } // Check for mandatory properties if sInfoPost.SerInstanceId != "" { if sInfoPost.ApiId != "" { errStr := "Service instance ID must not be present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if sInfoPost.SerName == "" { if sInfoPost.ApiName == "" { errStr := "Mandatory Service Name parameter not present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if sInfoPost.Version == "" { if len(sInfoPost.AefProfiles) == 0 || len(sInfoPost.AefProfiles[0].Versions) == 0 { errStr := "Mandatory Service Version parameter not present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if sInfoPost.State == nil { if sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.State == nil { errStr := "Mandatory Service State parameter not present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if sInfoPost.Serializer == nil { if sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.Serializer == nil { errStr := "Mandatory Serializer parameter not present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if sInfoPost.SerCategory != nil { errStr := validateCategoryRef(sInfoPost.SerCategory) if sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.Category != nil { errStr := validateCategoryRef(sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.Category) if errStr != "" { log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } } if (sInfoPost.TransportId != "" && sInfoPost.TransportInfo != nil) || (sInfoPost.TransportId == "" && sInfoPost.TransportInfo == nil) { errStr := "Either transportId or transportInfo but not both shall be present" if len(sInfoPost.AefProfiles) == 0 || sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo == nil { errStr := "Mandatory TransportInfo (VendorSpecificUrnetsimeccapifexttransportInfo) not present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if len(sInfoPost.AefProfiles) == 0 || sInfoPost.AefProfiles[0].InterfaceDescriptions == nil { errStr := "Mandatory AefProfiles (InterfaceDescriptions) not present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if sInfoPost.Links != nil { errStr := "Links parameter should not be present in request" if len(sInfoPost.AefProfiles) == 0 || sInfoPost.AefProfiles[0].AefId == "" { errStr := "Mandatory AefProfiles (AefId) not present" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } if sInfoPost.TransportInfo != nil { if sInfoPost.TransportInfo.Id == "" || sInfoPost.TransportInfo.Name == "" || string(*sInfoPost.TransportInfo.Type_) == "" || sInfoPost.TransportInfo.Protocol == "" || sInfoPost.TransportInfo.Version == "" || sInfoPost.TransportInfo.Endpoint == nil { errStr := "Id, Name, Type, Protocol, Version, Endpoint are all mandatory parameters of TransportInfo" transportInfo := sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo // if sInfoPost.TransportInfo != nil { if transportInfo.Name == "" || string(*transportInfo.Type_) == "" || transportInfo.Protocol == "" || transportInfo.Version == "" { errStr := "Id, Name, Type, Protocol, Version, are all mandatory parameters of TransportInfo" log.Error(errStr) errHandlerProblemDetails(w, errStr, http.StatusBadRequest) return } // } aefProfile := &AefProfile{ AefId: sInfoPost.AefProfiles[0].AefId, Versions: sInfoPost.AefProfiles[0].Versions, InterfaceDescriptions: sInfoPost.AefProfiles[0].InterfaceDescriptions, VendorSpecificUrnetsimeccapifexttransportInfo: &MecTransportInfoCapifExt{ Name: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Name, Type_: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Type_, Protocol: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Protocol, Version: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Version, Security: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Security, }, } dsInfo := &ServiceApiDescription{ ApiName: sInfoPost.ApiName, ApiId: uuid.New().String(), AefProfiles: []AefProfile{*aefProfile}, VendorSpecificUrnetsimeccapifextserviceInfo: &MecServiceInfoCapifExt{ Serializer: sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.Serializer, State: sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.State, ScopeOfLocality: sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.ScopeOfLocality, ConsumedLocalOnly: sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.ConsumedLocalOnly, IsLocal: sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.IsLocal, Category: sInfoPost.VendorSpecificUrnetsimeccapifextserviceInfo.Category, }, } transportInfo_ := TransportInfo{ Id: sInfoPost.AefProfiles[0].AefId, // Set this appropriately or generate it Name: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Name, Type_: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Type_, Protocol: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Protocol, Version: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Version, Endpoint: sInfoPost.AefProfiles[0].InterfaceDescriptions, // Set the endpoint as required Security: sInfoPost.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Security, } // Create Service sInfo := &ServiceInfo{ SerInstanceId: uuid.New().String(), SerName: sInfoPost.SerName, SerCategory: sInfoPost.SerCategory, Version: sInfoPost.Version, State: sInfoPost.State, TransportInfo: sInfoPost.TransportInfo, Serializer: sInfoPost.Serializer, ScopeOfLocality: sInfoPost.ScopeOfLocality, ConsumedLocalOnly: sInfoPost.ConsumedLocalOnly, SerInstanceId: dsInfo.ApiId, SerName: dsInfo.ApiName, SerCategory: dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.Category, Version: dsInfo.AefProfiles[0].Versions[0], State: dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.State, TransportInfo: &transportInfo_, Serializer: dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.Serializer, ScopeOfLocality: dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.ScopeOfLocality, ConsumedLocalOnly: dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.ConsumedLocalOnly, // although IsLocal is reevaluated when a query is replied to, value stored in sInfo as is for now IsLocal: sInfoPost.IsLocal, LivenessInterval: sInfoPost.LivenessInterval, IsLocal: dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.IsLocal, LivenessInterval: 0, } sInfo.Links = &ServiceInfoLinks{ Self: &LinkType{ Loading