Commit 5ed2736c authored by Yann Garcia's avatar Yann Garcia
Browse files

Enhance demo4-ue

parent eccf6069
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ paths:
      summary: Returns onboarded-demo4 User Application AppContext
      tags:
      - DAI
  /dai/delete:
  /dai/delete/{appcontextid}:
    delete:
      description: Delete the onboarded-demo4 User Application
      operationId: daiDoPingDELETE
@@ -124,7 +124,7 @@ paths:
      summary: Returns onboarded-demo4 User Application AppContext
      tags:
      - DAI
  /dai/doping:
  /dai/doping/{appcontextid}:
    get:
      description: Send a ping to the onboarded-demo4 User Application
      operationId: daiDoPingGET
@@ -147,7 +147,7 @@ paths:
      summary: Returns onboarded-demo4 User Application activity
      tags:
      - DAI
  /dai/availability:
  /dai/availability/{appcontextid}:
    post:
      description: Used to obtain the locations available for instantiation of a specific
        user application in the MEC system.
+65 −15
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ import (
	smc "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-service-mgmt-client"

	uuid "github.com/google/uuid"
	//"github.com/gorilla/mux"
	"github.com/gorilla/mux"
)

const (
@@ -820,39 +820,55 @@ const (

// REST API sends ping request and get response
func demo4DaiDoPingGET(w http.ResponseWriter, r *http.Request) {
	log.Info(">>> demo4DaiDoPingGET: ", r)

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

	// Check if a MEC application context is existing
	var appContextId string
	log.Debug("demo4DaiDoPingGET: appContexts= ", appContexts)
	if len(appContexts) == 0 {
		err := errors.New("No context created, please use POST /dai/instantiate")
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	} else {
		// Use the existing one
	}

	vars := mux.Vars(r)
	contextId := vars["appcontextid"]
	log.Info("demo4DaiDoPingGET: contextId: ", contextId)

	// Retrieve the appContextId
	var appContextId string
	for k := range appContexts {
		if k == contextId {
			log.Debug("demo4DaiDoPingGET: Set appContextId to ", k)
			appContextId = k
			break
		}
	} // End of 'for' statement
	log.Debug("demo4DaiDoPingGET: appContextId: ", appContextId)
	if appContextId == "" { // Not found
		err := errors.New("demo4DaiDoPingGET: Invalid AppContext identifier")
		appActivityLogs = append(appActivityLogs, "demo4DaiDoPingGET: Invalid AppContext identifier")
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}
	appActivityLogs = append(appActivityLogs, "demo4DaiDoPingGET: appContextId: " + appContextId)
	log.Debug("demo4DaiDoPingGET: Reference URL: len(appContexts[appContextId].app.AppInfo.UserAppInstanceInfo): ", len(appContexts[appContextId].app.AppInfo.UserAppInstanceInfo))
	log.Debug("demo4DaiDoPingGET: Reference URL: appContexts[appContextId].app.AppInfo.UserAppInstanceInfo[0].ReferenceURI: ", appContexts[appContextId].app.AppInfo.UserAppInstanceInfo[0].ReferenceURI)

	// Send the ping request
	appActivityLogs = append(appActivityLogs, "demo4DaiDoPingGET: Send ping request: ", strings.TrimSuffix(appContexts[appContextId].app.AppInfo.UserAppInstanceInfo[0].ReferenceURI, "/") + "/ping")
	resp, err := http.Get(strings.TrimSuffix(appContexts[appContextId].app.AppInfo.UserAppInstanceInfo[0].ReferenceURI, "/") + "/ping")
	if err != nil {
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	bodyBytes, _ := ioutil.ReadAll(r.Body)
	log.Debug("demo4DaiDoPingGET: Sent: ", resp.Body)
	bodyBytes, _ := ioutil.ReadAll(resp.Body)
	log.Debug("demo4DaiDoPingGET: resp: ", string(bodyBytes))

	// Send resp
	statusCode, err := strconv.Atoi(resp.Status)
	statusCode, err := strconv.Atoi(strings.Split(resp.Status, " ")[0])
	if err != nil {
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -919,6 +935,8 @@ func demo4DaiDoPingPOST(w http.ResponseWriter, r *http.Request) {

// REST API creates an existing instance of an onboarded MEC application
func demo4DaiDoPingDELETE(w http.ResponseWriter, r *http.Request) {
	log.Info(">>> demo4DaiDoPingDELETE: ", r)

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

	log.Debug("demo4DaiDoPingDELETE: appContexts= ", appContexts)
@@ -930,13 +948,28 @@ func demo4DaiDoPingDELETE(w http.ResponseWriter, r *http.Request) {
		return
	}

	vars := mux.Vars(r)
	contextId := vars["appcontextid"]
	log.Info("demo4DaiDoPingDELETE: contextId: ", contextId)

	// Retrieve the appContextId
	var appContextId string
	for k := range appContexts {
		log.Debug("demo4DaiDoPingPOST: Set appContextId to ", k)
		if k == contextId {
			log.Debug("demo4DaiDoPingDELETE: Set appContextId to ", k)
			appContextId = k
			break
		}
	} // End of 'for' statement
	log.Debug("demo4DaiDoPingDELETE: appContextId: ", appContextId)
	if appContextId == "" { // Not found
		err := errors.New("demo4DaiDoPingDELETE: Invalid AppContext identifier")
		appActivityLogs = append(appActivityLogs, "demo4DaiDoPingDELETE: Invalid AppContext identifier")
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}

	_ /*resp*/, err := daiClient.DevAppApi.DevAppContextDELETE(context.TODO(), appContextId)
	if err != nil {
		err := errors.New("Failed to delete appContextId: " + appContextId)
@@ -955,8 +988,11 @@ func demo4DaiDoPingDELETE(w http.ResponseWriter, r *http.Request) {

// REST API retrieve location constraints of an existing instance of an onboarded MEC application
func demo4DaiAppLocationAvailabilityPOST(w http.ResponseWriter, r *http.Request) {
	log.Info(">>> demo4DaiAppLocationAvailabilityPOST: ", r)

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

	// Check if a MEC application context is existing
	log.Debug("demo4DaiAppLocationAvailabilityPOST: appContexts= ", appContexts)
	if len(appContexts) == 0 {
		err := errors.New("No context created, please use POST /dai/instantiate")
@@ -966,13 +1002,27 @@ func demo4DaiAppLocationAvailabilityPOST(w http.ResponseWriter, r *http.Request)
		return
	}

	vars := mux.Vars(r)
	contextId := vars["appcontextid"]
	log.Info("demo4DaiAppLocationAvailabilityPOST: contextId: ", contextId)

	// Retrieve the appContextId
	var appContextId string
	for k := range appContexts {
		if k == contextId {
			log.Debug("demo4DaiAppLocationAvailabilityPOST: Set appContextId to ", k)
			appContextId = k
			break
		}
	} // End of 'for' statement
	log.Debug("demo4DaiAppLocationAvailabilityPOST: appContextId: ", appContextId)
	if appContextId == "" { // Not found
		err := errors.New("demo4DaiAppLocationAvailabilityPOST: Invalid AppContext identifier")
		appActivityLogs = append(appActivityLogs, "demo4DaiAppLocationAvailabilityPOST: Invalid AppContext identifier")
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}

	// Create a ApplicationLocationAvailability
	var appInfo dai.ApplicationLocationAvailabilityAppInfo
+3 −3
Original line number Diff line number Diff line
@@ -101,14 +101,14 @@ var routes = Routes{
	Route{
		"DaiDoPingDELETE",
		strings.ToUpper("Delete"),
		"/dai/delete/{instance}",
		"/dai/delete/{appcontextid}",
		DaiDoPingDELETE,
	},

	Route{
		"DaiDoPingGET",
		strings.ToUpper("Get"),
		"/dai/doping",
		"/dai/doping/{appcontextid}",
		DaiDoPingGET,
	},

@@ -122,7 +122,7 @@ var routes = Routes{
	Route{
		"DaiAppLocationAvailabilityPOST",
		strings.ToUpper("Post"),
		"/dai/availability",
		"/dai/availability/{appcontextid}",
		DaiAppLocationAvailabilityPOST,
	},

+4 −12
Original line number Diff line number Diff line
@@ -605,8 +605,11 @@ func (am *DaiMgr) DeleteAppContext(appContextId string) (err error) {
	// Un-instantiate the MEC application process
	pid, err := strconv.ParseInt(appContextId, 10, 64) // FIXME To be enhanced to get outputs
	if err != nil {
		log.Error(err.Error())
		return err
	}
	// TODO Check if the process is running

	terminatePidProcess(int(pid))
	log.Debug("Just terminated subprocess ", strconv.Itoa(int(pid)))
	// Delete entries
@@ -1014,19 +1017,8 @@ func (am *DaiMgr) CreateAppContext(appContext *AppContext, remoteUrl string, san
		*app.AppInfo.UserAppInstanceInfo[i].AppInstanceId = *app.ContextId
		app.AppInfo.UserAppInstanceInfo[i].ReferenceURI = new(Uri)
		log.Debug("CreateAppContext: app.AppInfo.AppName: ", app.AppInfo.AppName)
		// p := ":31120"
		// if app.AppInfo.AppName == "onboarded-demo1" { // Hard-coded in charts/meep-dai/values-template.yaml
		// 	p = ":31121"
		// } else if app.AppInfo.AppName == "onboarded-demo2" { // Hard-coded in charts/meep-dai/values-template.yaml
		// 	p = ":31122"
		// } else if app.AppInfo.AppName == "onboarded-demo3" { // Hard-coded in charts/meep-dai/values-template.yaml
		// 	p = ":31123"
		// } else if app.AppInfo.AppName == "onboarded-demo4" { // Hard-coded in charts/meep-dai/values-template.yaml
		// 	p = ":31124"
		// }
		// *app.AppInfo.UserAppInstanceInfo[i].ReferenceURI = Uri("https://"+ targetIp.String() + p)
		*app.AppInfo.UserAppInstanceInfo[i].ReferenceURI = Uri(remoteUrl + "/" + sanboxName + "/" + app.AppInfo.AppName)
		*app.AppInfo.UserAppInstanceInfo[i].ReferenceURI = Uri(strings.Replace(string(*app.AppInfo.UserAppInstanceInfo[i].ReferenceURI), "http:", "https:", 1))
		*app.AppInfo.UserAppInstanceInfo[i].ReferenceURI = Uri(string(*app.AppInfo.UserAppInstanceInfo[i].ReferenceURI))//Uri(strings.Replace(string(*app.AppInfo.UserAppInstanceInfo[i].ReferenceURI), "http:", "https:", 1))
	} // End of 'for' statement
	log.Debug("CreateAppContext: *app.ContextId: ", *app.ContextId)
	log.Debug("CreateAppContext: app.AppInfo: ", app.AppInfo)