Commit eccf6069 authored by Yann Garcia's avatar Yann Garcia
Browse files

Load onboarded MEC application description from shared folder

parent 763dbf9f
Loading
Loading
Loading
Loading
+18 −13
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import (
	"encoding/json"
	"errors"
	"fmt"
	"io/ioutil"
	"net/http"
	"strconv"
	"strings"
@@ -817,7 +818,7 @@ const (
	simu_appPackageSource = "appPackageSource1"
)

// REST API retrieves the list of the onboarded MEC application
// REST API sends ping request and get response
func demo4DaiDoPingGET(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

@@ -837,24 +838,28 @@ func demo4DaiDoPingGET(w http.ResponseWriter, r *http.Request) {
		} // End of 'for' statement
	}
	appActivityLogs = append(appActivityLogs, "demo4DaiDoPingGET: appContextId: " + appContextId)
	log.Debug("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
	// TODO

	// Send resp
	err := errors.New("Not implemented yet")
	appActivityLogs = append(appActivityLogs, "demo4DaiDoPingGET: "+err.Error())
	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)
	/*jsonResponse, err := json.Marshal(demoAppInfo)
		return
	}
	bodyBytes, _ := ioutil.ReadAll(r.Body)
	log.Debug("demo4DaiDoPingGET: resp: ", string(bodyBytes))

	// Send resp
	statusCode, err := strconv.Atoi(resp.Status)
	if err != nil {
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.WriteHeader(http.StatusOK)
	fmt.Fprintf(w, string(jsonResponse))*/
	w.WriteHeader(statusCode)
	fmt.Fprintf(w, string(bodyBytes))
}

// REST API creates a new instance of an onboarded MEC application
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ import (
)

const (
	port = ":31123"
	port = ":31124"
)

func main() {
+41 −0
Original line number Diff line number Diff line
{
    "appList":
        [
            {
                "appInfoList":
                    [
                        {
                            "appDId": "onboarded-demo4",
                            "appName": "onboarded-demo4",
                            "appProvider": "ETSI",
                            "appSoftVersion": "v0.1.0",
                            "appDVersion": "v0.1.0",
                            "appDescription": "Basic HTTP Ping Pong",
                            "appLocation":
                                [
                                    {
                                        "area": null,
                                        "civicAddressElement": null,
                                        "countryCode": "33"
                                    }
                                ],
                            "appCharcs":
                                [
                                    {
                                        "memory": 1024,
                                        "storage": 1024,
                                        "latency": 1024,
                                        "bandwidth": 1024,
                                        "serviceCont": 0
                                    }
                                ],
                            "cmd": "/onboardedapp/onboarded-demo/onboarded-demo4",
                            "args":null
                        }
                    ],
                    "vendorSpecificExt": {
                        "vendorId": "ETSI"
                    }
            }
        ]
}
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ const ( // FIXME confoguration file required
	sandboxUrl  = "yannsb"
	mep         = "mep1"
	localUrl    = "mec-platform.etsi.org"
	localPort   = ":31123"
	localPort   = ":31124"
	mecUrl      = "sandbox-mec.etsi.org"
	appNameBase = "onboarded-demo4"
)
+19 −15
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ const postgresPwd = "pwd"
type SbiCfg struct {
	ModuleName               string
	SandboxName              string
	HostUrl                  string
	MepName                  string
	RedisAddr                string
	InfluxAddr               string
@@ -60,6 +61,7 @@ type SbiCfg struct {
type DaiSbi struct {
	moduleName      string
	sandboxName     string
	hostUrl         string
	mepName         string
	scenarioName    string
	localityEnabled bool
@@ -88,6 +90,7 @@ func Init(cfg SbiCfg) (err error) {
	sbi = new(DaiSbi)
	sbi.moduleName = cfg.ModuleName
	sbi.sandboxName = cfg.SandboxName
	sbi.hostUrl = cfg.HostUrl
	sbi.mepName = cfg.MepName
	sbi.scenarioName = ""
	sbi.updateAppInfoCB = cfg.AppInfoList
@@ -95,6 +98,7 @@ func Init(cfg SbiCfg) (err error) {
	sbi.cleanUpCB = cfg.CleanUpCb
	redisAddr = cfg.RedisAddr
	influxAddr = cfg.InfluxAddr
	log.Info("SbiCfg: ", *sbi)

	// Fill locality map
	if len(cfg.Locality) > 0 {
@@ -165,7 +169,7 @@ func Init(cfg SbiCfg) (err error) {
	}
	log.Info("Created new DAI DB tables")

	err = sbi.daiMgr.SimulateExistingApplication()
	err = sbi.daiMgr.LoadOnboardedMecApplications()
	if err != nil {
		log.Error("Failed to load simulating data: ", err)
		return err
@@ -376,7 +380,7 @@ func GetApplicationListAppList(appNames []string, appProviders []string, appSoft
	return appListSbi, nil
}

func filterAppNames(appNames []string, appListSbi *map[string]*tm.AppInfoList) (map[string]*tm.AppInfoList) {
func filterAppNames(appNames []string, appListSbi *map[string]*tm.AppInfoList) map[string]*tm.AppInfoList {
	filteredAppListSbi := make(map[string]*tm.AppInfoList)
	for _, appName := range appNames {
		log.Debug("filterAppNames: Processing appName: ", appName)
@@ -396,7 +400,7 @@ func filterAppNames(appNames []string, appListSbi *map[string]*tm.AppInfoList) (
	return filteredAppListSbi
}

func filterAppProviders(appProviders []string, appListSbi *map[string]*tm.AppInfoList) (map[string]*tm.AppInfoList) {
func filterAppProviders(appProviders []string, appListSbi *map[string]*tm.AppInfoList) map[string]*tm.AppInfoList {
	filteredAppListSbi := make(map[string]*tm.AppInfoList)
	for _, appProvider := range appProviders {
		log.Debug("filterAppProviders: Processing appProvider: ", appProvider)
@@ -416,7 +420,7 @@ func filterAppProviders(appProviders []string, appListSbi *map[string]*tm.AppInf
	return filteredAppListSbi
}

func filterAppSoftVersions(appSoftVersions []string, appListSbi *map[string]*tm.AppInfoList) (map[string]*tm.AppInfoList) {
func filterAppSoftVersions(appSoftVersions []string, appListSbi *map[string]*tm.AppInfoList) map[string]*tm.AppInfoList {
	filteredAppListSbi := make(map[string]*tm.AppInfoList)
	for _, appSoftVersion := range appSoftVersions {
		log.Debug("filterAppSoftVersions: Processing appSoftVersion: ", appSoftVersion)
@@ -436,7 +440,7 @@ func filterAppSoftVersions(appSoftVersions []string, appListSbi *map[string]*tm.
	return filteredAppListSbi
}

func filterServiceConts(serviceConts []string, appListSbi *map[string]*tm.AppInfoList) (map[string]*tm.AppInfoList) {
func filterServiceConts(serviceConts []string, appListSbi *map[string]*tm.AppInfoList) map[string]*tm.AppInfoList {
	filteredAppListSbi := make(map[string]*tm.AppInfoList)
	for _, serviceCount := range serviceConts {
		log.Debug("filterServiceConts: Processing serviceCount: ", serviceCount)
@@ -540,7 +544,7 @@ func GetAllListAppList() (appListSbi *map[string]*tm.AppInfoList, err error) {

func CreateAppContext(appContextSbi *tm.AppContext) (appContextSbi_ *tm.AppContext, err error) {

	appContextSbi_, err = sbi.daiMgr.CreateAppContext(appContextSbi)
	appContextSbi_, err = sbi.daiMgr.CreateAppContext(appContextSbi, sbi.hostUrl, sbi.sandboxName)
	if err != nil {
		log.Error(err.Error())
		return nil, err
Loading