Commit adca2865 authored by M. Hamza's avatar M. Hamza
Browse files

clean code in MEC015 APIs

parent 55e96cba
Loading
Loading
Loading
Loading
+233 −217
Original line number Diff line number Diff line
@@ -69,11 +69,16 @@ var LinkBuff = make(map[string]uint64)
var maxBuff = uint64(107374182400)
var nextBwAllocIdAvailable uint32 = 1

type sessionFilterListCheck struct {
	sessionBool bool
	SessionList []BwInfoSessionFilter
}

type BwAllocInfoResp struct {
	AppInsId     []string
	AppInstanceId []string
	AllocationId  []string
	AppName       []string
	BwInfoList   []BwInfo
	SessionList   []BwInfo
}
type SessionFilterPostResp struct {
	SessionFilterList []BwInfoSessionFilter
@@ -476,23 +481,25 @@ func mec011AppTerminationPost(w http.ResponseWriter, r *http.Request) {

// bandwidthAllocationDelete removes a specific bandwidthAllocation at /bw_allocations/{allocationId} endpoint
func bandwidthAllocationDelete(w http.ResponseWriter, r *http.Request) {
	log.Info("Delete bwInfo by allocationId")

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	log.Info("bandwidthAllocationDelete")
	vars := mux.Vars(r)
	bwallocIdStr := vars["allocationId"]

	// Information of bandwidth allocation of specific allocationId is fetched
	jsonBwInfo, _ := rc.JSONGetEntry(baseKey+"bw_alloc:"+bwallocIdStr, ".")
	keyName := baseKey + "bw_alloc:" + bwallocIdStr
	jsonBwInfo, err := rc.JSONGetEntry(keyName, ".")

	if jsonBwInfo == "" {
		log.Error("BW Allocation Info not found against the provided allocationId")
		errHandlerProblemDetails(w, "BW Allocation Info not found against the provided allocationId", http.StatusNotFound)
	if err != nil {
		err = errors.New("bwInfo not found against the provided the allocationId")
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusNotFound)
		return
	}

	var bwInfo BwInfo
	err := json.Unmarshal([]byte(jsonBwInfo), &bwInfo)
	err = json.Unmarshal([]byte(jsonBwInfo), &bwInfo)
	if err != nil {
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
@@ -585,7 +592,7 @@ func bandwidthAllocationDelete(w http.ResponseWriter, r *http.Request) {
	}

	// Information of bandwidth allocation of specific allocationId is deleted from redis
	err = rc.JSONDelEntry(baseKey+"bw_alloc:"+bwallocIdStr, ".")
	err = rc.JSONDelEntry(keyName, ".")
	if err != nil {
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusNotFound)
@@ -597,115 +604,92 @@ func bandwidthAllocationDelete(w http.ResponseWriter, r *http.Request) {

// bandwidthAllocationGet retrieves information about a specific bandwidthAllocation at /bw_allocations/{allocationId} endpoint
func bandwidthAllocationGet(w http.ResponseWriter, r *http.Request) {
	log.Info("bandwidthAllocationGet")

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	vars := mux.Vars(r)
	bwallocIdStr := vars["allocationId"]

	// Information of bandwidth allocation of specific allocationId is fetched
	jsonBwInfo, _ := rc.JSONGetEntry(baseKey+"bw_alloc:"+bwallocIdStr, ".")
	keyName := baseKey + "bw_alloc:" + bwallocIdStr
	jsonBwInfo, err := rc.JSONGetEntry(keyName, ".")

	if jsonBwInfo == "" {
		log.Error("BW Allocation Info not found against the provided allocationId")
		errHandlerProblemDetails(w, "BW Allocation Info not found against the provided allocationId", http.StatusNotFound)
	if err != nil {
		err = errors.New("bwInfo not found against the provided the allocationId")
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusNotFound)
		return
	}

	var bwInfo BwInfo
	err := json.Unmarshal([]byte(jsonBwInfo), &bwInfo)

	err = json.Unmarshal([]byte(jsonBwInfo), &bwInfo)
	if err != nil {
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		return
	}

	jsonResponse, err := json.Marshal(bwInfo)
	if err != nil {
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
	} else {
		fmt.Fprint(w, string(jsonResponse))
		w.WriteHeader(http.StatusOK)
	}
	jsonResponse := convertBandwidthInfoToJson(&bwInfo)

	w.WriteHeader(http.StatusOK)
	fmt.Fprint(w, jsonResponse)
}

// bandwidthAllocationListGet retrieves information about a list of bandwidthAllocation resources at /bw_allocations endpoint
func bandwidthAllocationListGet(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	log.Info("bandwidthAllocationListGet")
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

	u, _ := url.Parse(r.URL.String())
	q := u.Query()
	appInsId := q["app_instance_id"]
	appName := q["app_name"]
	allocationId := q["session_id"]

	validQueryParams := []string{"app_instance_id", "app_name", "session_id"}

	//look for all query parameters to reject if any invalid ones
	found := false
	count := 0
	var currentParamValue string
	for queryParam := range q { // fetch query parameter requested one by one
		found = false
		for _, validQueryParam := range validQueryParams { // validate query parameter
			if queryParam == validQueryParam {
				found = true
				currentParamValue = queryParam
				log.Info(currentParamValue, " query parameter is passed")
				break
			}
		}
		if !found {
			log.Error("Query param not valid: ", queryParam)
			errHandlerProblemDetails(w, "Query param is not valid", http.StatusBadRequest)
	validParams := []string{"app_instance_id", "app_name", "allocation_id"}
	err := validateQueryParams(q, validParams)
	if err != nil {
		errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest)
		return
		} else {
			count++
		}
	}

	// In case more than 1 query parameter is passed respond with Bad Request
	if count > 1 {
		log.Error("Single query parameter should passed")
		errHandlerProblemDetails(w, "Single query parameter should passed", http.StatusBadRequest)
		return
	} else if (count == 1) || (count == 0) {
		// In case of [0,1] query parameter, valid query parameter is passed
		log.Info("One/None query parameter is passed")
	appInstanceId := q["app_instance_id"]
	appName := q["app_name"]
	allocationId := q["allocation_id"]

		response := &BwAllocInfoResp{
			AppInsId:     appInsId,
	bwInfoList := &BwAllocInfoResp{
		AppInstanceId: appInstanceId,
		AppName:       appName,
		AllocationId:  allocationId,
			BwInfoList:   make([]BwInfo, 0),
		SessionList:   make([]BwInfo, 0),
	}

		// Get all Bandwidth Allocation Info from DB
		keyMatchStr := baseKey + "bw_alloc:*"
		err := rc.ForEachJSONEntry(keyMatchStr, populateBwInfo, response)
	// Make sure only 1 or none of the following are present: appInstanceId, appName, allocationId
	err = validateMtsSesInfoQueryParams(appInstanceId, appName, allocationId)
	if err != nil {
		errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest)
		return
	}

	// Get all Bandwidth Allocation Info from DB
	keyName := baseKey + "bw_alloc:*"
	err = rc.ForEachJSONEntry(keyName, populateBwInfo, bwInfoList)
	if err != nil {
			log.Error("Unable to retrieve BW allocation info list from DB: ", err.Error())
			errHandlerProblemDetails(w, "Unable to retrieve BW allocation info list from DB", http.StatusBadRequest)
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		return
		} else {
			log.Info("BW allocation info list from DB is retrieved")
			jsonResponse, err := json.Marshal(response.BwInfoList)
	}

	// Prepare & send response
	jsonResponse, err := json.Marshal(bwInfoList.SessionList)
	if err != nil {
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		return
			} else {
	}

	w.WriteHeader(http.StatusOK)
	fmt.Fprint(w, string(jsonResponse))
}
		}
	}
}

// bandwidthAllocationPatch modifies the information about a specific existing bandwidthAllocation by sending updates on the data structure at /bw_allocations/{allocationId} endpoint
// bandwidthAllocationPatch modifies the information about a specific existing bandwidthAllocation
// by sending updates on the data structure at /bw_allocations/{allocationId} endpoint
func bandwidthAllocationPatch(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	log.Info("bandwidthAllocationPut")
@@ -884,39 +868,47 @@ func bandwidthAllocationPatch(w http.ResponseWriter, r *http.Request) {

// bandwidthAllocationPost creates a bandwidthAllocation resource at /bw_allocations endpoint
func bandwidthAllocationPost(w http.ResponseWriter, r *http.Request) {

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	log.Info("bandwidthAllocationPOST")

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	//	Read request body
	var bwInfo BwInfo
	bodyBytes, _ := ioutil.ReadAll(r.Body)
	err := json.Unmarshal(bodyBytes, &bwInfo)
	// Read JSON input stream provided in the Request, and stores it in the buffer of a Decoder object
	decoder := json.NewDecoder(r.Body)
	// Decode function return strings containing the text provided in the request body
	err := decoder.Decode(&bwInfo)
	if err != nil {
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest)
		return
	}

	// verify mandatory attributes
	// Validating mandatory parameters provided in the request body

	if bwInfo.AppInsId == "" {
		log.Error("Mandatory appInsId parameter should be present")
		errHandlerProblemDetails(w, "Mandatory attribute appInsId is missing in the request body.", http.StatusBadRequest)
		return
	}

	// verify RequestType attribute is either 1 or 0
	if bwInfo.RequestType != nil {
		if (*bwInfo.RequestType == 0) || (*bwInfo.RequestType == 1) {
			if (bwInfo.AllocationDirection == "00") || (bwInfo.AllocationDirection == "01") || (bwInfo.AllocationDirection == "10") {
				log.Debug("Valid Mandatory attribute allocationDirection")
			} else {
				log.Error("Invalid Mandatory attribute allocationDirection")
				errHandlerProblemDetails(w, "Invalid Mandatory attribute allocationDirection", http.StatusBadRequest)
				log.Error("Valid allocationDirection value should be present")
				errHandlerProblemDetails(w, "Valid allocationDirection value should be present in the request body", http.StatusBadRequest)
				return
			}
		} else {
			log.Error("Invalid Mandatory attribute requestType")
			errHandlerProblemDetails(w, "Invalid Mandatory attribute requestType", http.StatusBadRequest)
			log.Error("Valid requestType value should be present")
			errHandlerProblemDetails(w, "Valid requestType value should be present in the request body", http.StatusBadRequest)
			return
		}
	} else {
		log.Error("Mandatory attribute requestType is Missing")
		errHandlerProblemDetails(w, "Mandatory attribute requestType is Missing", http.StatusBadRequest)
		log.Error("Mandatory attribute requestType should be present")
		errHandlerProblemDetails(w, "Mandatory attribute requestType is missing in the request body", http.StatusBadRequest)
		return
	}

@@ -941,19 +933,24 @@ func bandwidthAllocationPost(w http.ResponseWriter, r *http.Request) {
			return
		}
	} else {
		log.Error("Mandatory attribute: FixedAllocation is Missing")
		errHandlerProblemDetails(w, "Mandatory attribute: FixedAllocation is Missing", http.StatusBadRequest)
		log.Error("Mandatory fixedAllocation parameter should be present")
		errHandlerProblemDetails(w, "Mandatory attribute fixedAllocation is missing in the request body", http.StatusBadRequest)
		return
	}

	// verify if the RequestType attribute is 1 for session specific allocation
	// then SessionFilter should also provided in requested body
	if *bwInfo.RequestType == 1 {
		if len(bwInfo.SessionFilter) <= 0 {
			log.Error("sessionFilter attribute is Missing.")
			errHandlerProblemDetails(w, "sessionFilter attribute is Missing.", http.StatusBadRequest)
	if *bwInfo.RequestType == 1 && bwInfo.SessionFilter != nil {
		for _, flowFilterVal := range bwInfo.SessionFilter {
			if flowFilterVal.SourceIp == "" && flowFilterVal.SourcePort == nil && flowFilterVal.DstAddress == "" && flowFilterVal.DstPort == nil && flowFilterVal.Protocol == "" {
				log.Error("At least one of sessionFilter subfields shall be included")
				errHandlerProblemDetails(w, "At least one of sessionFilter subfields shall be included in the request body.", http.StatusBadRequest)
				return
		} else {
			}
		}
	}

	if *bwInfo.RequestType == 1 && bwInfo.SessionFilter != nil {
		sessionSlice := make([]BwInfoSessionFilter, 0)
		for index, singleSessionFilter := range bwInfo.SessionFilter {
			if index == 0 {
@@ -967,10 +964,8 @@ func bandwidthAllocationPost(w http.ResponseWriter, r *http.Request) {
			}
		}
	}
	}

	// Get App instance
	if bwInfo.AppInsId != "" {
	appInfo, err := getAppInfo(bwInfo.AppInsId)
	if err != nil {
		errHandlerProblemDetails(w, err.Error(), http.StatusNotFound)
@@ -989,46 +984,37 @@ func bandwidthAllocationPost(w http.ResponseWriter, r *http.Request) {
		}
		return
	}
	} else {
		log.Error("Mandatory attribute: appInsId is Missing")
		errHandlerProblemDetails(w, "Mandatory attribute: appInsId is Missing", http.StatusBadRequest)
		return
	}

	var newBwInfo BwInfo
	var jsonResponse []byte

	// Validate IP Address of UE (dstAddress in downlink, sourceIp in uplink and both is symmetrical
	// options) with existing UE IP(s), if the request type is session specific

	if *bwInfo.RequestType == 1 {

		response := &SessionFilterPostResp{
			SessionMatch:      false,
			SessionFilterList: make([]BwInfoSessionFilter, len(bwInfo.SessionFilter)),
	sessionFilterList := &sessionFilterListCheck{
		sessionBool: false,
		SessionList: bwInfo.SessionFilter,
	}

		response.SessionFilterList = bwInfo.SessionFilter
	keyName := baseKey + "bw_alloc:*"

		// Get all Bandwidth Allocation Info from DB
		keyMatchStr := baseKey + "bw_alloc:*"
		err = rc.ForEachJSONEntry(keyMatchStr, populateSessionFilterPost, response)
	if *bwInfo.RequestType == 1 {
		// Retrieve MTS sessions from redis DB one by one and store in the mtsSessionInfoList array
		err = rc.ForEachJSONEntry(keyName, compareFlowFilters, sessionFilterList)
		if err != nil {
			log.Error("Unable to fetch allocation resource from redis")
			errHandlerProblemDetails(w, "Unable to fetch allocation resource from redis", http.StatusInternalServerError)
			errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
			return
		}
		if response.SessionMatch {
			log.Error("multiple sessions match sessionFilter")
			errHandlerProblemDetails(w, "multiple sessions match sessionFilter", http.StatusBadRequest)
		//check bool here
		if sessionFilterList.sessionBool {
			errHandlerProblemDetails(w, "Provide flowFilter matches an already existing session", http.StatusBadRequest)
			return
		}
	}

		switch bwInfo.AllocationDirection {
	// Validate IP Address of UE (dstAddress in downlink, sourceIp in uplink and both is symmetrical
	// options) with existing UE IP(s), if the request type is session specific

		//downlink
	if *bwInfo.RequestType == 1 {
		switch bwInfo.AllocationDirection {
		case "00":

			// if the provided destination IP range matches with the existing UE IP(s)
			err = checkDstIP(&bwInfo)
			if err != nil {
@@ -1038,9 +1024,7 @@ func bandwidthAllocationPost(w http.ResponseWriter, r *http.Request) {
				newBwInfo.SessionFilter = bwInfo.SessionFilter
			}

		//uplink
		case "01":

			// if the provided source IP range matches with the existing UE IP(s)
			err = checkSrcIP(&bwInfo)
			if err != nil {
@@ -1050,7 +1034,6 @@ func bandwidthAllocationPost(w http.ResponseWriter, r *http.Request) {
				newBwInfo.SessionFilter = bwInfo.SessionFilter
			}

		//symmetrical
		case "10":
			// if the provided source IP range matches with the existing UE IP(s)
			err = checkSrcIP(&bwInfo)
@@ -1078,6 +1061,10 @@ func bandwidthAllocationPost(w http.ResponseWriter, r *http.Request) {
	newBwInfo.FixedAllocation = bwInfo.FixedAllocation
	newBwInfo.FixedBWPriority = bwInfo.FixedBWPriority

	if bwInfo.AppName != "" {
		newBwInfo.AppName = bwInfo.AppName
	}

	seconds := time.Now().Unix()
	nanoseconds := time.Now().UnixNano()
	newBwInfo.TimeStamp = &BwInfoTimeStamp{
@@ -1085,19 +1072,12 @@ func bandwidthAllocationPost(w http.ResponseWriter, r *http.Request) {
		Seconds:     int32(seconds),
	}

	if bwInfo.AppName != "" {
		newBwInfo.AppName = bwInfo.AppName
	}

	// In APPLICATION_SPECIFIC_BW_ALLOCATION OR SESSION_SPECIFIC_BW_ALLOCATION
	// Uplink, Downlink and Symmetrical bandwidth allocation is performed
	if (*bwInfo.RequestType == 0) || (*bwInfo.RequestType == 1) {

		switch bwInfo.AllocationDirection {

		// downlink case
		case "00":

			// getting downlink buffer value from redis to update
			bufferInfo, valBuff, err := getDownlinkBuff()
			if err != nil {
@@ -1143,9 +1123,7 @@ func bandwidthAllocationPost(w http.ResponseWriter, r *http.Request) {
			w.WriteHeader(http.StatusCreated)
			fmt.Fprint(w, string(jsonResponse))

		// uplink case
		case "01":

			// getting uplink buffer value from redis to update
			bufferInfo, valBuff, err := getUplinkBuff()
			if err != nil {
@@ -1192,9 +1170,7 @@ func bandwidthAllocationPost(w http.ResponseWriter, r *http.Request) {
			w.WriteHeader(http.StatusCreated)
			fmt.Fprint(w, string(jsonResponse))

		// symmetrical case
		case "10":

			// getting downlink/uplink buffer value from redis to update
			_, valBuffup, err := getUplinkBuff()
			if err != nil {
@@ -1402,29 +1378,6 @@ func bandwidthAllocationPut(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, string(jsonResponse))
}

func populateSessionFilterPost(key string, jsonInfo string, response interface{}) error {
	resp := response.(*SessionFilterPostResp)
	if resp == nil {
		return errors.New("Response not defined")
	}
	var bwInfo BwInfo
	err := json.Unmarshal([]byte(jsonInfo), &bwInfo)
	if err != nil {
		return err
	}

	if len(resp.SessionFilterList) > 0 {
		for _, singleSessionInput := range resp.SessionFilterList {
			for _, singleSessionStored := range bwInfo.SessionFilter {
				if reflect.DeepEqual(singleSessionInput, singleSessionStored) {
					resp.SessionMatch = true
				}
			}
		}
	}
	return nil
}

func populateSessionFilter(key string, jsonInfo string, response interface{}) error {
	resp := response.(*SessionFilterResp)
	if resp == nil {
@@ -1458,8 +1411,8 @@ func populateSessionFilter(key string, jsonInfo string, response interface{}) er
* @param {*BwAllocInfoResp} response Bandwidth allocation information
* @return {String} error error message
 */
func populateBwInfo(key string, jsonInfo string, response interface{}) error {
	resp := response.(*BwAllocInfoResp)
func populateBwInfo(key string, jsonInfo string, bwInfoList interface{}) error {
	resp := bwInfoList.(*BwAllocInfoResp)
	if resp == nil {
		return errors.New("Response not defined")
	}
@@ -1469,55 +1422,45 @@ func populateBwInfo(key string, jsonInfo string, response interface{}) error {
		return err
	}

	if len(resp.AllocationId) > 0 {
	paramFound := false
		for _, queryAllocationId := range resp.AllocationId {
			if bwInfo.AllocationId == queryAllocationId {
				log.Info("Allocation Id matched")
				resp.BwInfoList = append(resp.BwInfoList, bwInfo)

	if len(resp.AllocationId) > 0 {
		paramFound = false
		for _, QueryAllocationId := range resp.AllocationId {
			if bwInfo.AllocationId == QueryAllocationId {
				paramFound = true
			}
		}

		if !paramFound {
			return nil
		}
	}

	if len(resp.AppInsId) > 0 {
		paramFound := false
		for _, queryAppInsId := range resp.AppInsId {
			if bwInfo.AppInsId == queryAppInsId {
				log.Info("Application Instance Id matched")
				resp.BwInfoList = append(resp.BwInfoList, bwInfo)
	if len(resp.AppInstanceId) > 0 {
		paramFound = false
		for _, QueryAppInstanceId := range resp.AppInstanceId {
			if bwInfo.AppInsId == QueryAppInstanceId {
				paramFound = true
			}
		}

		if !paramFound {
			return nil
		}
	}

	if len(resp.AppName) > 0 {
		paramFound := false
		for _, queryAppNameId := range resp.AppName {
			if bwInfo.AppName == queryAppNameId {
				log.Info("Application name matched")
	if len(resp.AppInstanceId) > 0 {
		paramFound = false
		for _, QueryAppName := range resp.AppName {
			if bwInfo.AppName == QueryAppName {
				paramFound = true
				resp.BwInfoList = append(resp.BwInfoList, bwInfo)
			}
		}

		if !paramFound {
			return nil
		}
	}

	if (len(resp.AppName) == 0) && (len(resp.AppInsId) == 0) && (len(resp.AllocationId) == 0) {
		resp.BwInfoList = append(resp.BwInfoList, bwInfo)
		return nil
	}
	resp.SessionList = append(resp.SessionList, bwInfo)
	return nil
}

@@ -2127,3 +2070,76 @@ func sessionContains(sessionSlice []BwInfoSessionFilter, singleSessionFilter BwI
	}
	return sessionSlice, nil
}

/*
	* validateQueryParams ensures that valid query parameters should be used to retrieve one of the
		app_instance_id or app_name or allocation_id attributes from the user
	* @return {error} error An error will be return if occurs
*/
func validateQueryParams(params url.Values, validParams []string) error {
	for param := range params {
		found := false
		for _, validParam := range validParams {
			if param == validParam {
				found = true
				break
			}
		}
		if !found {
			err := errors.New("Invalid query param: " + param)
			log.Error(err.Error())
			return err
		}
	}
	return nil
}

/*
	* validateMtsSesInfoQueryParams check that either app_instance_id or app_name or allocation_id or
		none should be provided in the request
	* @return {error} error An error will be return if occurs
*/
func validateMtsSesInfoQueryParams(appInstanceId []string, appName []string, allocationId []string) error {
	count := 0
	if len(appInstanceId) != 0 {
		count++
	}
	if len(appName) != 0 {
		count++
	}
	if len(allocationId) != 0 {
		count++
	}
	if count > 1 {
		err := errors.New("Either app_instance_id or app_name or allocation_id or none of them shall be present")
		log.Error(err.Error())
		return err
	}
	return nil
}

func compareFlowFilters(key string, jsonInfo string, sessionFilterList interface{}) error {

	// Get query params & mtsSessionInfo
	data := sessionFilterList.(*sessionFilterListCheck)
	if data == nil {
		return errors.New("mtsSessionInfo list not found")
	}

	// Retrieve mtsSessionInfo from DB
	var sessionFilterInfo BwInfo
	err := json.Unmarshal([]byte(jsonInfo), &sessionFilterInfo)
	if err != nil {
		return err
	}

	for _, flowFilterData := range data.SessionList {
		for _, redisFlowFilterData := range sessionFilterInfo.SessionFilter {
			if reflect.DeepEqual(flowFilterData, redisFlowFilterData) {
				data.sessionBool = true
				return nil
			}
		}
	}
	return nil
}
+2 −2
Original line number Diff line number Diff line
@@ -31,9 +31,9 @@ func convertProblemDetailsToJson(obj *ProblemDetails) string {
	return string(jsonInfo)
}

func convertBandwidthInfoToJson(obj *BwInfo) string {
func convertBandwidthInfoToJson(bwInfo *BwInfo) string {

	jsonInfo, err := json.Marshal(*obj)
	jsonInfo, err := json.Marshal(*bwInfo)
	if err != nil {
		log.Error(err.Error())
		return ""
+7 −3
Original line number Diff line number Diff line
@@ -481,6 +481,7 @@ func storeMtsCapabilityInfoKey() (err error) {

// mtsCapabilityInfoGet is to retrieve mtsCapabilityInfo at /mts_capability_info endpoint
func mtsCapabilityInfoGet(w http.ResponseWriter, r *http.Request) {
	log.Info("mtsCapabilityInfoGet")
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

	keyName := baseKey + "mtsCapabilityInfo"
@@ -538,7 +539,7 @@ func mtsSessionDelete(w http.ResponseWriter, r *http.Request) {

// mtsSessionGet is to retrieve a specific mtsSessionInfo at /mts_sessions/{sessionId} endpoint
func mtsSessionGet(w http.ResponseWriter, r *http.Request) {
	log.Info("Get individual mtsSessionInfo by sessionId")
	log.Info("mtsSessionGet")

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	vars := mux.Vars(r)
@@ -555,7 +556,7 @@ func mtsSessionGet(w http.ResponseWriter, r *http.Request) {
		return
	}

	// Prepare & send mtsCapabilityInfo as a response
	// Prepare & send mtsSessionInfo as a response
	var mtsSessionResp MtsSessionInfo
	err = json.Unmarshal([]byte(mtsSessionJson), &mtsSessionResp)
	if err != nil {
@@ -571,6 +572,8 @@ func mtsSessionGet(w http.ResponseWriter, r *http.Request) {

// mtsSessionPost is to create mtsSessionInfo at /mts_sessions endpoint
func mtsSessionPost(w http.ResponseWriter, r *http.Request) {
	log.Info("mtsSessionPost")

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

	var requestBody MtsSessionInfo
@@ -585,7 +588,7 @@ func mtsSessionPost(w http.ResponseWriter, r *http.Request) {
		return
	}

	// Validating mandatory parameters in request
	// Validating mandatory parameters provided in the request body
	if requestBody.AppInsId == "" {
		log.Error("Mandatory appInsId parameter should be present")
		errHandlerProblemDetails(w, "Mandatory attribute appInsId is missing in the request body.", http.StatusBadRequest)
@@ -1201,6 +1204,7 @@ func mtsSessionPut(w http.ResponseWriter, r *http.Request) {

// mtsSessionsListGet is to retrieve the information about all existing mtsSessionInfo at /mts_sessions endpoint
func mtsSessionsListGet(w http.ResponseWriter, r *http.Request) {
	log.Info("mtsSessionsListGet")
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

	// Validate query parameters