Commit 9894aec8 authored by Simon Pastor's avatar Simon Pastor
Browse files

1st merge

parent d0c7e40c
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -702,7 +702,7 @@ components:
          version: '2.0'
          endpoint:
            uris:
              - 'https://my.callback.com/sandboxname/mep1/rni/v2/'
              - 'https://my.callback.com/sandboxname/rni/v2/'
        serializer: 'JSON'
        scopeOfLocality: 'MEC_SYSTEM'
        isLocal: true
@@ -1031,6 +1031,8 @@ components:
            $ref: '#/components/schemas/SerAvailabilityNotificationSubscription'
          example:
            subscriptionType: 'SerAvailabilityNotificationSubscription'
            callbackReference: "http://my.callback.com/mec_service_mgmt_ser_availabilities/some-id"
            filterCriteria:
              serNames: 
                - 'myRnis'
              states:
@@ -1056,7 +1058,6 @@ components:
          schema:
            $ref: '#/components/schemas/ServiceInfoPost'
          example:
            serInstanceId: 'rnisInstance1'
            serName: 'myRnis'
            serCategory:
              href: 'catItem1'
@@ -1074,7 +1075,7 @@ components:
              version: '2.0'
              endpoint:
                uris:
                  - 'https://my.callback.com/sandboxname/mep1/rni/v2/'
                  - 'https://my.callback.com/sandboxname/rni/v2/'
            serializer: 'JSON'
            scopeOfLocality: 'MEC_SYSTEM'
            isLocal: true
@@ -1181,7 +1182,7 @@ components:
          version: '2.0'
          endpoint:
            uris:
              - 'https://my.callback.com/sandboxname/mep1/rni/v2/'
              - 'https://my.callback.com/sandboxname/rni/v2/'
        serializer: 'JSON'
        scopeOfLocality: 'MEC_SYSTEM'
        isLocal: true
+4 −2
Original line number Diff line number Diff line
@@ -41,7 +41,9 @@ type ServiceInfo struct {

	ScopeOfLocality *LocalityType `json:"scopeOfLocality,omitempty"`
	// Indicate whether the service can only be consumed by the MEC applications located in the same locality (as defined by scopeOfLocality) as this  service instance.
	ConsumedLocalOnly bool `json:"consumedLocalOnly,omitempty"`
	// manually removed the omitempty
	ConsumedLocalOnly bool `json:"consumedLocalOnly"`
	// Indicate whether the service is located in the same locality (as defined by scopeOfLocality) as the consuming MEC application.
	IsLocal bool `json:"isLocal,omitempty"`
	// manually removed the omitempty
	IsLocal bool `json:"isLocal"`
}
+2 −2
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ type ServiceInfoPost struct {

	ScopeOfLocality *LocalityType `json:"scopeOfLocality,omitempty"`
	// Indicate whether the service can only be consumed by the MEC applications located in the same locality (as defined by scopeOfLocality) as this  service instance.
	ConsumedLocalOnly bool `json:"consumedLocalOnly,omitempty"`
	ConsumedLocalOnly bool `json:"consumedLocalOnly"`
	// Indicate whether the service is located in the same locality (as defined by scopeOfLocality) as the consuming MEC application.
	IsLocal bool `json:"isLocal,omitempty"`
	IsLocal bool `json:"isLocal"`
}
+61 −0
Original line number Diff line number Diff line
@@ -219,6 +219,31 @@ func appServicesGET(w http.ResponseWriter, r *http.Request) {
	getServices(w, r, appInstanceId)
}

func validateCategoryRef(categoryRef *CategoryRef) string {
	if categoryRef != nil {
		if categoryRef.Href == "" {
			return "CategoryRef mandatory parameter Href missing."
		}
		if categoryRef.Id == "" {
			return "CategoryRef mandatory parameter Id missing."
		}
		if categoryRef.Name == "" {
			return "CategoryRef mandatory parameter Name missing."
		}
		if categoryRef.Version == "" {
			return "CategoryRef mandatory parameter Version missing."
		}
	}
	return ""
}

func sInfoPostDefaults(sInfoPost *ServiceInfoPost) {
	locality := MEC_HOST
	sInfoPost.ScopeOfLocality = &locality
	sInfoPost.IsLocal = true
	sInfoPost.ConsumedLocalOnly = true
}

func appServicesPOST(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	log.Info("appServicesPOST")
@@ -243,6 +268,8 @@ func appServicesPOST(w http.ResponseWriter, r *http.Request) {

	// Retrieve request parameters from body
	var sInfoPost ServiceInfoPost
	//set default values, if values are omited in json, defaults not be overriden
	sInfoPostDefaults(&sInfoPost)
	decoder := json.NewDecoder(r.Body)
	err = decoder.Decode(&sInfoPost)
	if err != nil {
@@ -282,6 +309,28 @@ func appServicesPOST(w http.ResponseWriter, r *http.Request) {
		http.Error(w, errStr, http.StatusBadRequest)
		return
	}
	if sInfoPost.SerCategory != nil {
		errStr := validateCategoryRef(sInfoPost.SerCategory)
		if errStr != "" {
			log.Error(errStr)
			http.Error(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"
		log.Error(errStr)
		http.Error(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, Porotocl, Version, Endpoint are all mandatory parameters of TransportInfo"
			log.Error(errStr)
			http.Error(w, errStr, http.StatusBadRequest)
			return
		}
	}

	// Create Service
	sInfo := createSInfoFromSInfoPost(&sInfoPost)
@@ -426,6 +475,8 @@ func appServicesByIdPUT(w http.ResponseWriter, r *http.Request) {
	// Current implementation only supports state parameter change
	state := *sInfo.State
	*sInfo.State = *sInfoPrev.State
	//isLocal appears only in query responses and service avail. subs and notif, so not here, make sure both have same value so they are ignored
	sInfo.IsLocal = sInfoPrev.IsLocal
	sInfoJson := convertServiceInfoToJson(&sInfo)
	if sInfoJson != sInfoPrevJson {
		errStr := "Only the ServiceInfo state property may be changed"
@@ -535,6 +586,15 @@ func applicationsSubscriptionsPOST(w http.ResponseWriter, r *http.Request) {
			}
		}
		if subscription.FilteringCriteria.SerCategories != nil {
			for _, categoryRef := range *subscription.FilteringCriteria.SerCategories {
				errStr := validateCategoryRef(&categoryRef)
				if errStr != "" {
					log.Error(errStr)
					http.Error(w, errStr, http.StatusBadRequest)
					return
				}
			}

			if len(*subscription.FilteringCriteria.SerCategories) > 0 {
				nbMutuallyExclusiveParams++
			}
@@ -1259,6 +1319,7 @@ func validateAppInstanceId(appInstanceId string) (error, int, string) {
		problemDetails.Detail = "App Instance not ready. Waiting for AppReadyConfirmation."
		return errors.New("App Instance not ready"), http.StatusForbidden, convertProblemDetailsToJson(&problemDetails)
	}

	return nil, http.StatusOK, ""
}

+2 −2
Original line number Diff line number Diff line
@@ -2338,8 +2338,8 @@ definitions:
        description: "Application Version"
    description: "MEC Application instance information"
    example:
      appInstanceId: "00afec52-f0b6-464e-a660-33568c0975b9"
      appName: "MyAppName"
      id: "00afec52-f0b6-464e-a660-33568c0975b9"
      name: "MyAppName"
      type: "USER"
      state: "INITIALIZED"
      mepName: "mep1"
Loading