Commit 28194290 authored by Ikram Haq's avatar Ikram Haq
Browse files

Implement logic to Update(PUT) a service via CAPIF

parent 7ddc7f3d
Loading
Loading
Loading
Loading
+74 −21
Original line number Diff line number Diff line
@@ -411,8 +411,8 @@ func appServicesByIdPUT(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	log.Info("appServicesByIdPUT")
	vars := mux.Vars(r)
	appId := vars["appInstanceId"]
	svcId := vars["serviceId"]
	svcId := vars["serviceApiId"]
	appId := vars["apfId"]

	mutex.Lock()
	defer mutex.Unlock()
@@ -454,10 +454,12 @@ func appServicesByIdPUT(w http.ResponseWriter, r *http.Request) {
	}
	// NOTE: Set default values for omitted fields
	locality := MEC_HOST_LocalityType
	sInfo := ServiceInfo{
	sInfo := ServiceApiDescription{
		VendorSpecificUrnetsimeccapifextserviceInfo: &MecServiceInfoCapifExt{
			ScopeOfLocality:   &locality,
			IsLocal:           true,
			ConsumedLocalOnly: true,
		},
	}
	decoder := json.NewDecoder(r.Body)
	err = decoder.Decode(&sInfo)
@@ -467,13 +469,64 @@ func appServicesByIdPUT(w http.ResponseWriter, r *http.Request) {
		return
	}

	aefProfile := &AefProfile{
		AefId:                 sInfo.AefProfiles[0].AefId,
		Versions:              sInfo.AefProfiles[0].Versions,
		InterfaceDescriptions: sInfo.AefProfiles[0].InterfaceDescriptions,
		VendorSpecificUrnetsimeccapifexttransportInfo: &MecTransportInfoCapifExt{
			Name:     sInfo.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Name,
			Type_:    sInfo.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Type_,
			Protocol: sInfo.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Protocol,
			Version:  sInfo.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Version,
			Security: sInfo.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Security,
		},
	}
	dsInfo := &ServiceApiDescription{
		ApiName:     sInfo.ApiName,
		ApiId:       uuid.New().String(),
		AefProfiles: []AefProfile{*aefProfile},
		VendorSpecificUrnetsimeccapifextserviceInfo: &MecServiceInfoCapifExt{
			Serializer:        sInfo.VendorSpecificUrnetsimeccapifextserviceInfo.Serializer,
			State:             sInfo.VendorSpecificUrnetsimeccapifextserviceInfo.State,
			ScopeOfLocality:   sInfo.VendorSpecificUrnetsimeccapifextserviceInfo.ScopeOfLocality,
			ConsumedLocalOnly: sInfo.VendorSpecificUrnetsimeccapifextserviceInfo.ConsumedLocalOnly,
			IsLocal:           sInfo.VendorSpecificUrnetsimeccapifextserviceInfo.IsLocal,
			Category:          sInfo.VendorSpecificUrnetsimeccapifextserviceInfo.Category,
		},
	}

	transportInfo_ := TransportInfo{
		Id:       sInfo.AefProfiles[0].AefId,
		Name:     sInfo.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Name,
		Type_:    sInfo.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Type_,
		Protocol: sInfo.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Protocol,
		Version:  sInfo.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Version,
		Endpoint: sInfo.AefProfiles[0].InterfaceDescriptions,
		Security: sInfo.AefProfiles[0].VendorSpecificUrnetsimeccapifexttransportInfo.Security,
	}

	// Create Service
	_sInfo := ServiceInfo{
		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,
		IsLocal:           dsInfo.VendorSpecificUrnetsimeccapifextserviceInfo.IsLocal,
		LivenessInterval:  0,
	}

	// Current implementation only supports state parameter change;
	// Make sure none of the other service information fields have changed
	state := *sInfo.State
	*sInfo.State = *sInfoPrev.State
	state := *_sInfo.State
	*_sInfo.State = *sInfoPrev.State
	// isLocal is only set in responses, subscriptions and notifications;
	// Ignore this field while comparing the previous & new service info structs
	sInfo.IsLocal = sInfoPrev.IsLocal
	_sInfo.IsLocal = sInfoPrev.IsLocal

	// Compare service information as JSON strings
	/* FSCOM: It is not specified that only the ServiceInfo state property may be changed in ETSI GS MEC 011 V3.2.1 (2024-04)
@@ -486,9 +539,9 @@ func appServicesByIdPUT(w http.ResponseWriter, r *http.Request) {
	}*/

	// Compare service info states & update DB if necessary
	*sInfo.State = state
	if *sInfo.State != *sInfoPrev.State {
		err, retCode := setService(appId, &sInfo, STATE_CHANGED_ServiceAvailabilityNotificationChangeType)
	*_sInfo.State = state
	if *_sInfo.State != *sInfoPrev.State {
		err, retCode := setService(appId, &_sInfo, STATE_CHANGED_ServiceAvailabilityNotificationChangeType)
		if err != nil {
			log.Error(err.Error())
			errHandlerProblemDetails(w, err.Error(), retCode)
@@ -497,24 +550,24 @@ func appServicesByIdPUT(w http.ResponseWriter, r *http.Request) {
	}

	// Compare LivenessInterval
	if sInfo.LivenessInterval != sInfoPrev.LivenessInterval {
		if _, ok := livenessTimerList[sInfo.SerInstanceId]; ok { // An entry already exist
			if sInfo.LivenessInterval != 0 { // update it
				updateLivenessTicker(sInfo)
	if _sInfo.LivenessInterval != sInfoPrev.LivenessInterval {
		if _, ok := livenessTimerList[_sInfo.SerInstanceId]; ok { // An entry already exist
			if _sInfo.LivenessInterval != 0 { // update it
				updateLivenessTicker(_sInfo)
			} else {
				deleteLivenessTicker(sInfo.SerInstanceId)
				deleteLivenessTicker(_sInfo.SerInstanceId)
			}
		} else { // No entry
			if sInfo.LivenessInterval != 0 { // Create a new entry
				createLivenessTicker(sInfo)
			if _sInfo.LivenessInterval != 0 { // Create a new entry
				createLivenessTicker(_sInfo)
			}
		}
	} // else, nothing to do
	sInfo.LivenessInterval = sInfoPrev.LivenessInterval
	_sInfo.LivenessInterval = sInfoPrev.LivenessInterval

	// Send response
	w.WriteHeader(http.StatusOK)
	fmt.Fprint(w, convertServiceInfoToJson(&sInfo))
	fmt.Fprint(w, convertServiceInfoToJson_1(dsInfo))
}

func appServicesByIdDELETE(w http.ResponseWriter, r *http.Request) {
+7 −0
Original line number Diff line number Diff line
@@ -364,6 +364,13 @@ var routes = Routes{
		capifMgmt.AppServicesServiceIdGET,
	},

	Route{
		"AppServicesServiceIdPUT",
		strings.ToUpper("Put"),
		"/published-apis/v1/{apfId}/service-apis/{serviceApiId}",
		capifMgmt.AppServicesServiceIdPUT,
	},

	Route{
		"Index",
		"GET",