Commit 660eb672 authored by Kevin Di Lallo's avatar Kevin Di Lallo
Browse files

sandbox controller creates app instances at scenario activation

parent b03c3ca1
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -450,13 +450,19 @@ func startRegistrationTicker() {
		registrationSent := false
		subscriptionSent := false
		for range registrationTicker.C {
			// Get Application instance ID if not already available
			// Get Application instance ID
			if serviceAppInstanceId == "" {
				// If global service, request an app instance ID from Sandbox Controller
				// Otherwise use the scenario-provisioned instance ID
				if mepName == defaultMepName {
					var err error
					serviceAppInstanceId, err = getAppInstanceId()
					if err != nil || serviceAppInstanceId == "" {
						continue
					}
				} else {
					serviceAppInstanceId = instanceId
				}
			}

			// Send App Ready message
+12 −0
Original line number Diff line number Diff line
@@ -872,6 +872,18 @@ func flushApps(persist bool) error {

	// Delete App instances
	for _, appInfo := range appInfoList {

		// Ignore persistent apps unless required
		if !persist {
			appPersist, err := strconv.ParseBool(appInfo[fieldPersist])
			if err != nil {
				appPersist = false
			}
			if appPersist {
				continue
			}
		}

		// Get app instance ID
		appId := appInfo[fieldAppId]
		if appId == "" {
+11 −5
Original line number Diff line number Diff line
@@ -405,13 +405,19 @@ func startRegistrationTicker() {
		subscriptionSent := false

		for range registrationTicker.C {
			// Get Application instance ID if not already available
			// Get Application instance ID
			if serviceAppInstanceId == "" {
				// If global service, request an app instance ID from Sandbox Controller
				// Otherwise use the scenario-provisioned instance ID
				if mepName == defaultMepName {
					var err error
					serviceAppInstanceId, err = getAppInstanceId()
					if err != nil || serviceAppInstanceId == "" {
						continue
					}
				} else {
					serviceAppInstanceId = instanceId
				}
			}

			// Send App Ready message
+11 −5
Original line number Diff line number Diff line
@@ -482,13 +482,19 @@ func startRegistrationTicker() {
		registrationSent := false
		subscriptionSent := false
		for range registrationTicker.C {
			// Get Application instance ID if not already available
			// Get Application instance ID
			if serviceAppInstanceId == "" {
				// If global service, request an app instance ID from Sandbox Controller
				// Otherwise use the scenario-provisioned instance ID
				if mepName == defaultMepName {
					var err error
					serviceAppInstanceId, err = getAppInstanceId()
					if err != nil || serviceAppInstanceId == "" {
						continue
					}
				} else {
					serviceAppInstanceId = instanceId
				}
			}

			// Send App Ready message
+44 −5
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import (
	apps "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-applications"
	dataModel "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-data-model"
	log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger"
	mod "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-model"
	mq "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-mq"
	uuid "github.com/google/uuid"
	"github.com/gorilla/mux"
@@ -46,7 +47,8 @@ type AppCtrl struct {
var appCtrl *AppCtrl

// Initialize App Controller
func appCtrlInit(sandboxName string, mqLocal *mq.MsgQueue) (err error) {
func appCtrlInit(sandboxName string, mqLocal *mq.MsgQueue) error {
	var err error

	// Create new App Controller
	appCtrl = new(AppCtrl)
@@ -71,18 +73,55 @@ func appCtrlInit(sandboxName string, mqLocal *mq.MsgQueue) (err error) {
}

// Start App Controller
func appCtrlRun() (err error) {
func appCtrlRun() error {
	return nil
}

// Stop App Controller
func appCtrlStop() (err error) {
func appCtrlStop() error {
	return nil
}

// Flush App instances
func appCtrlFlushAppInstances() (err error) {
func appCtrlResetAppInstances(activeModel *mod.Model) error {
	// Flush non-persistent app instances
	appCtrl.appStore.FlushNonPersistent()

	// Create app instances for scenario processes
	if activeModel != nil {
		// Get active scenario node names
		appNames := activeModel.GetNodeNames(mod.NodeTypeEdgeApp)
		for _, appName := range appNames {
			// Get App Process & context
			appNode := activeModel.GetNode(appName)
			if appNode == nil {
				continue
			}
			appNodeCtx := activeModel.GetNodeContext(appName)
			if appNodeCtx == nil {
				continue
			}
			appProc := appNode.(*dataModel.Process)

			// Determine app type
			appType := apps.TypeUser
			if appCtrl.appStore.IsSysApp(appProc.Image) {
				appType = apps.TypeSystem
			}

			// Create & store app instance
			app := &apps.Application{
				Id:      appProc.Id,
				Name:    appProc.Name,
				Mep:     appNodeCtx.Parents[mod.PhyLoc],
				Type:    appType,
				Persist: false,
			}
			err := appCtrl.appStore.Set(app)
			if err != nil {
				log.Error(err.Error())
			}
		}
	}
	return nil
}

Loading