Commit 2ad15195 authored by Ikram ul Haq's avatar Ikram ul Haq
Browse files

bug fix: mec federation and ingress

parent 4b92ee16
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ image:
    MEEP_SANDBOX_NAME: {{.SandboxName}}
    MEEP_SVC_PATH: /fed_enablement/v1
    MEEP_HOST_URL: {{.HostUrl}}
    MEEP_BROKER: mqtt://172.29.10.56:1883
    MEEP_BROKER: mqtt://try-mec.etsi.org/
    MEEP_TOPIC: ETSI/MEC/Federation
    {{- if .IsMepService }}
    MEEP_MEP_NAME: {{.MepName}}
+6 −3
Original line number Diff line number Diff line
{{- if .Values.ingress.enabled -}}
{{- $serviceName := .Values.service.name -}}
{{- $servicePort := .Values.service.port -}}
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ $serviceName }}
@@ -24,9 +24,12 @@ spec:
        paths:
          {{- range $path := .paths }}
          - path: {{ $path }}
            pathType: Prefix
            backend:
              serviceName: {{ $serviceName }}
              servicePort: {{ $servicePort }}
              service:
                name: {{ $serviceName }}
                port:
                  number: {{ $servicePort }}
          {{- end -}}
      {{- if .name }}
      host: {{ .name }}
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ image:
    MEEP_SANDBOX_NAME: {{.SandboxName}}
    MEEP_SVC_PATH: /vis/v2
    MEEP_HOST_URL: {{.HostUrl}}
    MEEP_BROKER: mqtt://172.29.10.56:1883 #mqtt://broker.emqx.io:1883
    MEEP_BROKER: mqtt://try-mec.etsi.org/ #mqtt://broker.emqx.io:1883
    MEEP_TOPIC: 3gpp/v2x/obu
    MEEP_POA_LIST: poa-5g1
    {{- if .IsMepService }}
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ func main() {

		// Start Location Service REST API Server
		router := server.NewRouter()
		methods := handlers.AllowedMethods([]string{"OPTIONS", "DELETE", "GET", "HEAD", "POST", "PUT"})
		methods := handlers.AllowedMethods([]string{"OPTIONS", "DELETE", "GET", "HEAD", "POST", "PUT", "PATCH"})
		header := handlers.AllowedHeaders([]string{"content-type"})
		log.Fatal(http.ListenAndServe(":80", handlers.CORS(methods, header)(router)))
		run = false
+85 −2
Original line number Diff line number Diff line
@@ -1125,9 +1125,92 @@ func subscriptionPOST(w http.ResponseWriter, r *http.Request) {
func subscriptionPUT(w http.ResponseWriter, r *http.Request) {
	log.Debug(">>> subscriptionPUT: ", r)

	// FIXME FSCOM Todo
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusNotImplemented)

	// Retrieve variable parameters
	vars := mux.Vars(r)
	log.Info("vars: ", vars)
	subscriptionId := vars["subscriptionId"]
	if subscriptionId == "" {
		err := errors.New("Wrong parameters")
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest)
		return
	}
	log.Info("subscriptionId: ", subscriptionId)

	// Read JSON input stream provided in the Request
	var subscription SystemUpdateNotificationSubscription
	bodyBytes, _ := ioutil.ReadAll(r.Body)
	log.Info("subscriptionsPut: bodyBytes: ", string(bodyBytes))

	err := json.Unmarshal(bodyBytes, &subscription)
	if err != nil {
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		return
	}
	log.Info("subscriptionsPut: subscription: ", subscription)

	// Validating mandatory parameters
	if subscription.SubscriptionType == "" {
		log.Error("Mandatory SubscriptionType parameter should be present")
		errHandlerProblemDetails(w, "Mandatory attribute SubscriptionType is missing in the request body.", http.StatusBadRequest)
		return
	}

	if subscription.SubscriptionType != "SystemUpdateNotificationSubscription" {
		log.Error("Invalid SubscriptionType")
		errHandlerProblemDetails(w, "Invalid SubscriptionType", http.StatusBadRequest)
		return
	}

	if subscription.CallbackReference == "" {
		log.Error("CallbackReference shall be present.")
		errHandlerProblemDetails(w, "CallbackReference shall be present.", http.StatusBadRequest)
		return
	}

	if subscription.Links != nil {
		log.Error("Links attribute should not be present in request body")
		errHandlerProblemDetails(w, "Links attribute should not be present in request body", http.StatusBadRequest)
		return
	}

	// Create a self-link for the subscription
	link := new(Links)
	self := new(LinkType)
	self.Href = hostUrl.String() + basePath + "subscriptions/" + subscriptionId
	link.Self = self
	subscription.Links = link

	// Set response header Location
	w.Header().Set("Location", subscription.Links.Self.Href)

	// Convert subscription to JSON
	jsonResponse := convertSystemUpdateNotificationSubscriptionToJson(&subscription)
	if jsonResponse == "" {
		log.Error("Marshalling failure")
		errHandlerProblemDetails(w, "Marshalling failure", http.StatusInternalServerError)
		return
	}

	// update in Redis
	keyName := baseKey + "subscriptions:" + subscriptionId
	log.Info("subscriptionPUT: keyName: ", keyName)
	log.Info("subscriptionPUT: subscription: ", subscription)

	err = rc.JSONSetEntry(keyName, ".", jsonResponse)
	if err != nil {
		log.Error(err.Error())
		errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError)
		return
	}
	log.Info("subscriptionPUT: jsonResponse: ", jsonResponse)

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

func subscriptionsGET(w http.ResponseWriter, r *http.Request) {
Loading