From: jaehoon.hyun Date: Tue, 2 Apr 2019 06:26:42 +0000 (+0900) Subject: orchestration api changed X-Git-Tag: submit/tizen/20190409.085658~6^2~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f17ebed9ed9bf643c10bd0676828827d873dc3ba;p=platform%2Fcore%2Fsystem%2Fedge-orchestration.git orchestration api changed --- diff --git a/src/orchestrationapi/orchestration_api_test.go b/src/orchestrationapi/orchestration_api_test.go index d1113dd..2b8cbba 100644 --- a/src/orchestrationapi/orchestration_api_test.go +++ b/src/orchestrationapi/orchestration_api_test.go @@ -8,89 +8,97 @@ import ( "fmt" configuremgr "configuremgr" - mockconfiguremgr "configuremgr/mock" + confdescription "configuremgr/description" + + // mockconfiguremgr "configuremgr/mock" scoringmgr "scoringmgr" mockscoringmgr "scoringmgr/mock" - + // discoverymgr "discoverymgr" // servicemgr "servicemgr" - mockorchestrationapi "orchestrationapi/mock" ) + //jaehoon.hyun , jaehoon.hyun func TestConfigureMgrScoringMgr(t *testing.T){ - //copy event environment - watchDir := "/tmp/foo" - src := "../configuremgr/mock/mysum" - dst := watchDir + //make orche + orcheMock := new(Orche) + + orcheMock.IScoringmgr = scoringmgr.Init() + orcheMock.IConfiguremgr = configuremgr.Init() + + orcheMock.IScoringmgr.IRunningScore = mockscoringmgr.LoadScoringAddInterface + orcheMock.IScoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock + orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024) - //mock function linking - scoringHandlers := scoringmgr.Init() - scoringHandlers.IloadScoringLibrary = mockscoringmgr.LoadScoringAdd - scoringHandlers.Ch = make(chan interface{}, 1024) + orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = pushConfPathDiscoveryDeviceMock + orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath + orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch - configuremgrObj := configuremgr.Init() - configuremgrObj.IDiscoveryMgr.PushConfPath = mockconfiguremgr.PushConfPathDiscoveryDeviceMock - configuremgrObj.IScoringMgr.PushLibPath = scoringmgr.PushLibPath - configuremgrObj.IScoringMgr.Ch = scoringHandlers.Ch + orcheMock.IDiscoverymgr.GetEndpointDevices = getEndpointDevicesMock + orcheMock.IServicemgr.ExecuteApp = executeAppMock - scoringHandlers.Listening() - go configuremgrObj.Watch(watchDir) + //start module function + orcheMock.IScoringmgr.Listening() + go orcheMock.IConfiguremgr.Watch("/tmp/foo") + + //init scenario + execCommand("rm -rf /tmp/foo/mysum") time.Sleep(time.Duration(1) * time.Second) //user scenario - command := fmt.Sprintf("cp -ar %s %s", src, dst) - configuremgr.DLog.Println(command) - cmd := exec.Command("sh", "-c", command) - stdoutStderr, err := cmd.CombinedOutput() - configuremgr.DLog.Printf("%s", stdoutStderr) - if err != nil { - configuremgr.ELog.Fatal(err) - } + execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/mysum/", "/tmp/foo")) + time.Sleep(time.Duration(5) * time.Second) - time.Sleep(time.Duration(5) * time.Second) + orcheMock.IScoringmgr.RemoveLib("/tmp/foo/mysum/libmysum.so") - configuremgrObj.Done <- true + orcheMock.IConfiguremgr.Done <- true } //jaehoon.hyun, damon92-lee func TestConfigureMgrDiscoveryMgr(t *testing.T) { - orcheEngine = new(Iorche) +} - orcheEngine.IScoringmgr = scoringmgr.Init() - orcheEngine.IConfiguremgr = configuremgr.Init() +//jaehoon.hyun, chacha +func TestRequestServiceFunctionServiceMgr(t *testing.T){ - orcheEngine.IScoringmgr.IloadScoringLibrary = mockscoringmgr.LoadScoringAdd - orcheEngine.IScoringmgr.GetScore = mockorchestrationapi.GetScore - orcheEngine.IScoringmgr.Ch = make(chan interface{}, 1024) + //make orche + // orcheMock := new(Orche) - orcheEngine.IConfiguremgr.IDiscoveryMgr.PushConfPath = mockorchestrationapi.PushConfPathDiscoveryDeviceMock - orcheEngine.IConfiguremgr.IScoringMgr.PushLibPath = mockorchestrationapi.PushLibPathScoringAppMock - orcheEngine.IConfiguremgr.IScoringMgr.Ch = orcheEngine.IScoringmgr.Ch + // orcheMock.IScoringmgr = scoringmgr.Init() + // orcheMock.IConfiguremgr = configuremgr.Init() - orcheEngine.IDiscoverymgr.GetEndpointDevices = mockorchestrationapi.GetEndpointDevices - orcheEngine.IServicemgr.InitServiceMgr = mockorchestrationapi.InitServiceMgr - orcheEngine.IServicemgr.ExecuteApp = mockorchestrationapi.ExecuteApp + // orcheMock.IScoringmgr.IRunningScore = mockscoringmgr.LoadScoringAddInterface + // orcheMock.IScoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock + // orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024) - orcheEngine.IScoringmgr.Listening() + // orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = pushConfPathDiscoveryDeviceMock + // orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath + // orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch - //TODO : get watch path of attribute in settingpath - go orcheEngine.IConfiguremgr.Watch("/tmp/foo") + // orcheMock.IDiscoverymgr.GetEndpointDevices = getEndpointDevicesMock + // orcheMock.IServicemgr.ExecuteApp = executeAppMock -} + // //scoringmgr init + // orcheMock.IScoringmgr.Listening() -//jaehoon.hyun, chacha -func TestScoringMgrServiceMgr(t *testing.T){ + // //configuremgr init + // go orcheMock.IConfiguremgr.Watch("/tmp/foo") + + // //servicemgr init + // servicemgr.InitServiceMap() + + // //user scenario + // RequestService("mysum", "ls", []string{"-al"}) - //I can do that , anyone have a idea, implement please or ask for jaehoon } //daemon92-lee, chacha @@ -120,3 +128,39 @@ func TestConfigureMgrDiscoveryMgrScoringMgrServiceMgr(t *testing.T){ } + + +func pushConfPathDiscoveryDeviceMock (doc *confdescription.Doc) (err error) { + ILog.Println("pushConfPathDiscoveryDeviceMock") + ILog.Println(*doc) + return +} + +func pushLibPathScoringAppMock(libPath string, doc *confdescription.Doc, handlersCh chan<- interface{}) (err error) { + ILog.Println("pushLibPathScoringAppMock") + ILog.Println(libPath) + return +} + +func getEndpointDevicesMock(serviceName string) []string { + return []string{"localhost", "localhost"} +} + +func executeAppMock(target string, name string, args []string, notiChan chan string) (serviceID uint64, err error) { + ILog.Println("ExecuteApp") + ILog.Println(target) + ILog.Println(name) + ILog.Println(args) + return +} + + +func execCommand(command string) { + configuremgr.DLog.Println(command) + cmd := exec.Command("sh", "-c", command) + stdoutStderr, err := cmd.CombinedOutput() + configuremgr.DLog.Printf("%s", stdoutStderr) + if err != nil { + configuremgr.ELog.Fatal(err) + } +} \ No newline at end of file diff --git a/src/orchestrationapi/orchstration_api.go b/src/orchestrationapi/orchstration_api.go index 455ebb1..901226f 100644 --- a/src/orchestrationapi/orchstration_api.go +++ b/src/orchestrationapi/orchstration_api.go @@ -10,16 +10,14 @@ import ( configuremgr "configuremgr" scoringmgr "scoringmgr" - mockscoringmgr "scoringmgr/mock" - mockorchestrationapi "orchestrationapi/mock" // discoverymgr "discoverymgr" // servicemgr "servicemgr" ) -type Iorche struct { +type Orche struct { IScoringmgr *scoringmgr.Handlers IConfiguremgr *configuremgr.ConfigureMgr @@ -29,69 +27,73 @@ type Iorche struct { } IServicemgr struct { - InitServiceMgr func()() ExecuteApp func(target string, name string, args []string, notiChan chan string) (serviceID uint64, err error) } } -var orcheEngine *Iorche +var orcheEngine *Orche -func Init(settingPath string) { - orcheEngine = new(Iorche) +type deviceScore struct{ + endpoint string + score float64 +} - orcheEngine.IScoringmgr = scoringmgr.Init() - orcheEngine.IConfiguremgr = configuremgr.Init() - orcheEngine.IScoringmgr.IloadScoringLibrary = mockscoringmgr.LoadScoringAdd - orcheEngine.IScoringmgr.GetScore = mockorchestrationapi.GetScore - orcheEngine.IScoringmgr.Ch = make(chan interface{}, 1024) +type orcheClient struct { - orcheEngine.IConfiguremgr.IDiscoveryMgr.PushConfPath = mockorchestrationapi.PushConfPathDiscoveryDeviceMock - orcheEngine.IConfiguremgr.IScoringMgr.PushLibPath = mockorchestrationapi.PushLibPathScoringAppMock - orcheEngine.IConfiguremgr.IScoringMgr.Ch = orcheEngine.IScoringmgr.Ch + libName string + serviceName string + args []string + notiChan chan string +} - orcheEngine.IDiscoverymgr.GetEndpointDevices = mockorchestrationapi.GetEndpointDevices - orcheEngine.IServicemgr.InitServiceMgr = mockorchestrationapi.InitServiceMgr - orcheEngine.IServicemgr.ExecuteApp = mockorchestrationapi.ExecuteApp +var orchClientId int32 +var orcheClients = [1024]orcheClient{} - orcheEngine.IScoringmgr.Listening() +func Init(settingPath string) { - //TODO : get watch path of attribute in settingpath - go orcheEngine.IConfiguremgr.Watch("/tmp/foo") + orcheEngine = new(Orche) return } -type deviceScore struct{ - endpoint string - score float64 +func RequestService(libName string, serviceName string, args []string) (handle int){ + + clientId := atomic.LoadInt32(&orchClientId) + atomic.AddInt32(&orchClientId, 1) + + serviceClient := addServiceClient(clientId, libName, serviceName, args) + serviceClient.listenNotify() + endpoints := getEndpointDevices(serviceName) + deviceScores := sortByScore(gatheringDevicesScore(endpoints, libName)) + executeApp(deviceScores[0].endpoint, serviceName, args, serviceClient.notiChan) + + + + ILog.Println(deviceScores) + return } -type orcheClient struct { +func Close(handle uint64) { - path string - serviceName string - args []string - notiChan chan string } + func (client *orcheClient) listenNotify(){ select { case str := <-client.notiChan: - ILog.Printf("service status changed [path:%s][serviceName:%s][status:%s]\n", client.path, client.serviceName, str) + ILog.Printf("service status changed [path:%s][serviceName:%s][status:%s]\n", client.libName, client.serviceName, str) } } -var orchClientId int32 -var orcheClients = [1024]orcheClient{} -func addServiceClient(clientId int32, path string, serviceName string, args []string) (client *orcheClient){ - orcheClients[clientId].path = path +func addServiceClient(clientId int32, libName string, serviceName string, args []string) (client *orcheClient){ + orcheClients[clientId].libName = libName orcheClients[clientId].args = args orcheClients[clientId].serviceName = serviceName @@ -103,10 +105,10 @@ func getEndpointDevices(serviceName string) []string{ return orcheEngine.IDiscoverymgr.GetEndpointDevices(serviceName) } -func gatheringDevicesScore(endpoints []string) (deviceScores []deviceScore){ +func gatheringDevicesScore(endpoints []string, libName string) (deviceScores []deviceScore){ for _ , endpoint := range endpoints { - score := orcheEngine.IScoringmgr.GetScore(endpoint) + score := orcheEngine.IScoringmgr.IGetScore(endpoint, libName) deviceScores = append(deviceScores, deviceScore{endpoint, score}) } @@ -124,26 +126,4 @@ func sortByScore(deviceScores []deviceScore) ( []deviceScore ){ func executeApp(endpoint string, serviceName string, args []string, notiChan chan string) { orcheEngine.IServicemgr.ExecuteApp(endpoint, serviceName, args, notiChan) -} - -func RequestService(path string, serviceName string, args []string) (handle int){ - - clientId := atomic.LoadInt32(&orchClientId) - atomic.AddInt32(&orchClientId, 1) - - serviceClient := addServiceClient(clientId, path, serviceName, args) - serviceClient.listenNotify() - endpoints := getEndpointDevices(serviceName) - deviceScores := sortByScore(gatheringDevicesScore(endpoints)) - executeApp(deviceScores[0].endpoint, serviceName, args, serviceClient.notiChan) - - - - ILog.Println(deviceScores) - return -} - - -func Close(handle uint64) { - -} +} \ No newline at end of file