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

Add AppContext deletion

parent 879d3534
Loading
Loading
Loading
Loading
+24 −9
Original line number Diff line number Diff line
@@ -1170,15 +1170,30 @@ func demo4DaiDoPingDELETE(w http.ResponseWriter, r *http.Request) {
		appActivityLogs = append(appActivityLogs, "demo4DaiDoPingDELETE: " + err.Error())
		log.Error(err.Error())
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	// Send resp
	err := errors.New("Not implemented yet")
	appActivityLogs = append(appActivityLogs, "demo4DaiDoPingDELETE: " + err.Error())
	log.Error(err.Error())
	// Retrieve the appContextId
	var appContextId string
	for k := range appContexts {
		log.Debug("demo4DaiDoPingPOST: Set appContextId to ", k)
		appContextId = k
	} // End of 'for' statement
	log.Debug("demo4DaiDoPingDELETE: appContextId: ", appContextId)
	_/*resp*/, err := daiClient.DevAppApi.DevAppContextDELETE(context.TODO(), appContextId)
	if err != nil {
		err := errors.New("Failed to delete appContextId: " + appContextId)
		appActivityLogs = append(appActivityLogs, "demo4DaiDoPingDELETE: Failed to delete appContextId [" + err.Error() + "]")
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	// Remove it from appContexts
	delete(appContexts, appContextId)
	log.Debug("demo4DaiDoPingDELETE: Updated appContexts= ", appContexts)

	//w.WriteHeader(http.StatusNoContent)
	// Send resp
	w.WriteHeader(http.StatusNoContent)
}

// Rest API handle user-app termination call-back notification
+6 −1
Original line number Diff line number Diff line
@@ -51,8 +51,13 @@ func cmdExec(cli string) (int, error) {
	return pid, nil
}

func terminatePidProcess(pid int) {
	str := "kill " + strconv.Itoa(pid) // SIGTERM  
	_, _ = cmdExec(str)
}

func deletePidProcess(pid int) {
	str := "kill -9 " + strconv.Itoa(pid)
	str := "kill -9 " + strconv.Itoa(pid) // SIGKILL
	_, _ = cmdExec(str)
}

+19 −10
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ package meepdaimgr
import (
	"database/sql"
	"os"

	//"encoding/json"
	"errors"
	//"sort"
@@ -640,6 +641,17 @@ func (am *DaiMgr) DeleteAppContext(appContextId string) (err error) {
		return err
	}

	// TODO Add logic to delete applicationListAppList
	// Whe deleting the context, un-instantiate the application
	// TODO meep-dai-mgr could be partially enhanced with MEC-10-2 Clauses 6.2.1.2 Type: AppD and Lifecycle Mgmt
	// Un-instantiate the MEC application process
	pid, err := strconv.ParseInt(appContextId, 10, 64) // FIXME To be enhanced to get outputs
	if err != nil {
		return err
	}
	terminatePidProcess(int(pid))
	log.Debug("Just terminated subprocess ", strconv.Itoa(int(pid)))

	result, err := am.db.Exec(`DELETE FROM `+AppContextTable+` WHERE contextId = ($1)`, appContextId)
	if err != nil {
		log.Error(err.Error())
@@ -654,17 +666,14 @@ func (am *DaiMgr) DeleteAppContext(appContextId string) (err error) {
		return errors.New("ContextId not found")
	}

	// TODO Add logic to delete applicationListAppList
	// Whe deleting the context, un-instantiate the application
	// TODO meep-dai-mgr could be partially enhanced with MEC-10-2 Clauses 6.2.1.2 Type: AppD and Lifecycle Mgmt
	_, err = DockerTerminate(appContextId, 3*time.Second)
	// Notify listener
	am.notifyListener(appContextId)

	process, err := os.FindProcess(pid)
	if err != nil {
		log.Error(err.Error())
		return err
	}

	// Notify listener
	am.notifyListener(appContextId)
	log.Debug("Process info: ", *process)

	if profiling {
		now := time.Now()
@@ -1073,7 +1082,7 @@ func (am *DaiMgr) CreateAppContext(appContext *AppContext) (app *AppContext, err

	// TODO Add logic to instanciate applicationListAppList
	// Whe creating the context, instantiate the application
	pid, err := cmdExec(fullPathApp)
	pid, err := cmdExec(fullPathApp) // FIXME To be enhanced to get outputs
	if err != nil {
		log.Error(err.Error())
		return nil, err
+10 −4
Original line number Diff line number Diff line
@@ -6,7 +6,8 @@ DESC="AdvantEDGE platform"
TIMEOUT=7
IS_RUNNING=`kubectl get pods --all-namespaces | grep "meep-virt-engine" | awk '{print $2}'`
ADV_PATH=~/AdvantEDGE
BUILD_EX=$1
DO_NOT_BUILD_EX=$1

stop_advantedge() {
    if [ -n $IS_RUNNING ]; then
    	meepctl delete core
@@ -21,7 +22,7 @@ build_advantedge() {
    meepctl deploy dep
    sleep $TIMEOUT
    rm -fr $ADV_PATH/bin/meep-*
    if [ "$BUILD_EX" = "-e" ]; then
    if [ "$DO_NOT_BUILD_EX" != "--noexamplesbuilt" ]; then
        build_examples
    fi
    meepctl build all --nolint
@@ -42,11 +43,16 @@ build_examples() {
}

usage() {
    echo "Usage: $0 {-e}" >&2
    echo "       -e To include building examples"
    echo "Usage: $0 [--noexamplesbuilt]" >&2
    echo "       --noexamplesbuilt: To exclude examples from build process (optional)"
    exit 1
}

if [ "$DO_NOT_BUILD_EX" != "" ]; then
    if [ "$DO_NOT_BUILD_EX" != "--noexamplesbuilt" ]; then
        usage
    fi
fi
stop_advantedge
sleep $TIMEOUT
build_advantedge