configuremgr "configuremgr"
confdescription "configuremgr/description"
+
// mockconfiguremgr "configuremgr/mock"
- scoringmgr "scoringmgr"
- mockscoringmgr "scoringmgr/mock"
- discoverymgr "discoverymgr"
- securemgr "securemgr"
- servicemgr "servicemgr"
+ discoverymgr "discoverymgr"
+ scoringmgr "scoringmgr"
+ mockscoringmgr "scoringmgr/mock"
+ securemgr "securemgr"
+ servicemgr "servicemgr"
)
+var logPrefixTest = "[orchestrationapi test]"
+
//jaehoon.hyun , jaehoon.hyun
func TestConfigureMgrScoringMgrAlreadyScoring2Library(t *testing.T) {
//release discoverymgr
discoverymgr.ExitChan <- 1
+ if discoverymgr.IsNilServer() == true {
+ discoverymgr.ExitPollingOutBoundCh <- 1
+ }
//waiting resource thread stop
- time.Sleep(time.Duration(100) * time.Millisecond)
+ time.Sleep(time.Duration(1000) * time.Millisecond)
}
//jaehoon.hyun, chacha
orcheMock.IConfiguremgr.Done <- true
//waiting resource thread stop
- time.Sleep(time.Duration(100) * time.Millisecond)
+ time.Sleep(time.Duration(1000) * time.Millisecond)
}
//daemon92-lee, chacha
//release discoverymgr
discoverymgr.ExitChan <- 1
+ if discoverymgr.IsNilServer() == true {
+ discoverymgr.ExitPollingOutBoundCh <- 1
+ }
//waiting resource thread stop
time.Sleep(time.Duration(100) * time.Millisecond)
//release discoverymgr
discoverymgr.ExitChan <- 1
+ if discoverymgr.IsNilServer() == true {
+ discoverymgr.ExitPollingOutBoundCh <- 1
+ }
//waiting resource thread stop
time.Sleep(time.Duration(100) * time.Millisecond)
time.Sleep(time.Duration(100) * time.Millisecond)
//release scoringmgr
- orcheMock.IScoringmgr.IStartResourceService()
+ orcheMock.IScoringmgr.IStopResourceService()
+ orcheMock.IScoringmgr.RemoveAll()
+
+ //release configuremgr
+ orcheMock.IConfiguremgr.Done <- true
+
+ //release discoverymgr
+ discoverymgr.ExitChan <- 1
+ if discoverymgr.IsNilServer() == true {
+ discoverymgr.ExitPollingOutBoundCh <- 1
+ }
+
+ time.Sleep(time.Duration(100) * time.Millisecond)
+}
+
+//jaehoon.hyun, daemon92-lee, chacha, jaehoon.hyun
+func TestOrchestrationInitThreadAndRequestServiceThread(t *testing.T) {
+
+ orcheMock := Init("")
+ ExitTestChan := make(chan int, 2)
+
+ go func() {
+ //init scenario
+ listeningDir := "/tmp/foo"
+ execCommand(fmt.Sprintf("rm -rf %s", listeningDir))
+ execCommand(fmt.Sprintf("mkdir -p %s", listeningDir))
+ time.Sleep(time.Duration(100) * time.Millisecond)
+
+ orcheMock.IScoringmgr = scoringmgr.Init()
+ orcheMock.IConfiguremgr = configuremgr.Init()
+
+ orcheMock.IScoringmgr.IRunningScore = scoringmgr.LoadScoringGeneralInterface
+ orcheMock.IScoringmgr.IStartResourceService = scoringmgr.StartResourceService
+ orcheMock.IScoringmgr.IStopResourceService = scoringmgr.StopResourceService
+ orcheMock.IScoringmgr.IGetScore = scoringmgr.GetScore
+ orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024)
+
+ orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = discoverymgr.AddNewServiceName
+ orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath
+ orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch
+
+ orcheMock.IDiscoverymgr.GetEndpointDevices = discoverymgr.GetDeviceListWithService
+ orcheMock.IServicemgr.ExecuteApp = servicemgr.ExecuteApp
+
+ //1.scoringmgr init
+ orcheMock.IScoringmgr.Listening()
+ orcheMock.IScoringmgr.IStartResourceService()
+
+ //2.configuremgr init
+ go orcheMock.IConfiguremgr.Watch(listeningDir)
+
+ //3.securemgr init
+ securemgr.Init("../securemgr/test/key.txt")
+
+ //4.servicemgr init
+ servicemgr.Init()
+
+ //5.discoverymgr init
+ discoverymgr.InitDiscovery()
+ discoverymgr.GetDeviceList()
+
+ orcheMock.Ready = true
+
+ //user scenario
+ execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
+ time.Sleep(time.Duration(100) * time.Millisecond)
+
+ log.Println(logPrefixTest, "orchestration init done")
+
+ ExitTestChan <- 1
+
+ }()
+
+ go func() {
+ ret := RequestService("ls", []string{"-al"})
+ if ret != -1 {
+ t.Fatal("is it wifi on????? plz off and retry test")
+ } else {
+ log.Println(logPrefixTest, "REEEEEEEEETTTTTTTTT == -1")
+ }
+ time.Sleep(time.Duration(100) * time.Millisecond)
+
+ ExitTestChan <- 1
+ }()
+
+ <-ExitTestChan
+ <-ExitTestChan
+
+ //release scoringmgr
+ orcheMock.IScoringmgr.IStopResourceService()
orcheMock.IScoringmgr.RemoveAll()
//release configuremgr
//release discoverymgr
discoverymgr.ExitChan <- 1
+ if discoverymgr.IsNilServer() == true {
+ discoverymgr.ExitPollingOutBoundCh <- 1
+ }
time.Sleep(time.Duration(100) * time.Millisecond)
}
)
type Orche struct {
+ Ready bool
IScoringmgr *scoringmgr.Handlers
IConfiguremgr *configuremgr.ConfigureMgr
orcheClients = [1024]orcheClient{}
)
+type OrchestrationError int
+
+const (
+ eNotReadyOrchestrationError = ((1 + iota) ^ -1) + 1
+ eTurnOffWifiOrchestrationError
+)
+
+// func (orcheError OrchestrationError) toError() int { return }
+
func Init(settingPath string) *Orche {
orcheEngine = new(Orche)
+ orcheEngine.Ready = false
return orcheEngine
func RequestService(appName string, args []string) (handle int) {
+ if orcheEngine.Ready == false {
+ return eNotReadyOrchestrationError
+ }
+
clientID := atomic.LoadInt32(&orchClientID)
atomic.AddInt32(&orchClientID, 1)
serviceClient := addServiceClient(clientID, appName, args)
go serviceClient.listenNotify()
- endpoints := getEndpointDevices(appName)
+ endpoints, err := getEndpointDevices(appName)
+ if err != nil {
+ return eTurnOffWifiOrchestrationError
+ }
deviceScores := sortByScore(gatheringDevicesScore(endpoints, appName))
if len(deviceScores) > 0 {
return
}
-func getEndpointDevices(appName string) (deviceList []string) {
- deviceList, _ = orcheEngine.IDiscoverymgr.GetEndpointDevices(appName)
- return
+func getEndpointDevices(appName string) (deviceList []string, err error) {
+ return orcheEngine.IDiscoverymgr.GetEndpointDevices(appName)
}
func gatheringDevicesScore(endpoints []string, appName string) (deviceScores []deviceScore) {