orchestration compile error fix
authorjaehoon.hyun <jaehoon.hyun@samsung.com>
Fri, 29 Mar 2019 10:01:00 +0000 (19:01 +0900)
committerjaehoon.hyun <jaehoon.hyun@samsung.com>
Fri, 29 Mar 2019 10:01:00 +0000 (19:01 +0900)
src/orchestrationapi/mock/simulation.go
src/orchestrationapi/orchestration_api_test.go
src/orchestrationapi/orchstration_api.go

index a3ea4b2..7ee0f16 100644 (file)
@@ -26,7 +26,7 @@ func PushConfPathAppExecuteMock(doc *confdescription.Doc) (err error) {
   return
 }
 
-func PushLibPathScoringAppMock(libPath string) (err error) {
+func PushLibPathScoringAppMock(libPath string, doc *confdescription.Doc, handlersCh chan<- interface{}) (err error) {
   ILog.Println("pushLibPathScoringAppMock")
   ILog.Println(libPath)
   return
@@ -50,3 +50,7 @@ func ExecuteApp(target string, name string, args []string, notiChan chan string)
   ILog.Println(args)
   return
 }
+
+func InitServiceMgr() () {
+  
+}
\ No newline at end of file
index cff52fe..d1113dd 100644 (file)
@@ -13,8 +13,8 @@ import (
   scoringmgr       "scoringmgr"
   mockscoringmgr   "scoringmgr/mock"
 
-  discoverymgr     "discoverymgr"
-  servicemgr       "servicemgr"
+  // discoverymgr     "discoverymgr"
+  // servicemgr       "servicemgr"
 
   mockorchestrationapi "orchestrationapi/mock"
 )
@@ -62,26 +62,27 @@ func TestConfigureMgrScoringMgr(t *testing.T){
 //jaehoon.hyun, damon92-lee
 func TestConfigureMgrDiscoveryMgr(t *testing.T) {
 
-  orcheEngine := new(orchestrationapi.Iorche)
+  orcheEngine = new(Iorche)
 
   orcheEngine.IScoringmgr    = scoringmgr.Init()
-  orcheEngine.IConfiguremgr  = configuremgr.Init()
+  orcheEngine.IConfiguremgr    = configuremgr.Init()
 
   orcheEngine.IScoringmgr.IloadScoringLibrary = mockscoringmgr.LoadScoringAdd
-  orcheEngine.IScoringmgr.GetScore            = mockscoringmgr.GetScore
+  orcheEngine.IScoringmgr.GetScore            = mockorchestrationapi.GetScore
   orcheEngine.IScoringmgr.Ch                  = make(chan interface{}, 1024)
 
   orcheEngine.IConfiguremgr.IDiscoveryMgr.PushConfPath  = mockorchestrationapi.PushConfPathDiscoveryDeviceMock
-  orcheEngine.IConfiguremgr.IAppExecuteMgr.PushConfPath = mockorchestrationapi.PushConfPathAppExecuteMock
-  orcheEngine.IConfiguremgr.IScoringMgr.PushLibPath     = mockorchestrationapi.PushLibPath
-  orcheEngine.IConfiguremgr.IScoringMgr.Ch              = IScoringmgr.Ch
+  orcheEngine.IConfiguremgr.IScoringMgr.PushLibPath     = mockorchestrationapi.PushLibPathScoringAppMock
+  orcheEngine.IConfiguremgr.IScoringMgr.Ch              = orcheEngine.IScoringmgr.Ch
 
   orcheEngine.IDiscoverymgr.GetEndpointDevices = mockorchestrationapi.GetEndpointDevices
   orcheEngine.IServicemgr.InitServiceMgr       = mockorchestrationapi.InitServiceMgr
   orcheEngine.IServicemgr.ExecuteApp           = mockorchestrationapi.ExecuteApp
 
   orcheEngine.IScoringmgr.Listening()
-  go orcheEngine.IConfiguremgr.Watch(watchDir)
+
+  //TODO :  get watch path of attribute in settingpath
+  go orcheEngine.IConfiguremgr.Watch("/tmp/foo")
 
 
 }
@@ -112,35 +113,6 @@ func TestConfigureMgrDiscoveryMgrServiceMgr(t *testing.T){
 //jaehoon.hyun, chacha, jaehoon.hyun
 func TestConfigureMgrServiceMgrScoringMgr(t *testing.T){
 
-
-  //mock function linking
-  scoringHandlers := scoringmgr.Init()
-  scoringHandlers.IloadScoringLibrary = mockscoringmgr.LoadScoringAdd
-  scoringHandlers.Ch                  = make(chan interface{}, 1024)
-
-  configuremgrObj  := configuremgr.Init()
-  configuremgrObj.IDiscoveryMgr.PushConfPath  = mockconfiguremgr.PushConfPathDiscoveryDeviceMock
-  configuremgrObj.IScoringMgr.PushLibPath     = scoringmgr.PushLibPath
-  configuremgrObj.IScoringMgr.Ch              = scoringHandlers.Ch
-
-  scoringHandlers.Listening()
-  go configuremgrObj.Watch(watchDir)
-
-  time.Sleep(time.Duration(1) * time.Second)
-
-  //user scenario
-  targetLocalAddr := "localhost"
-  serviceName     := "ls"
-  args            := []string{"-al"}
-  notiChan        := make(chan string)
-  servicemgr.ExecuteApp(targetLocalAddr, serviceName, args, notiChan)
-
-  <- notiChan
-
-
-  time.Sleep(time.Duration(5) * time.Second)
-
-  configuremgrObj.Done <- true
 }
 
 //jaehoon.hyun, daemon92-lee, chacha, jaehoon.hyun
index 68a0037..455ebb1 100644 (file)
@@ -3,17 +3,16 @@ package orchestrationapi
 
 import (
   
+  "sync/atomic"
   "sort"
-
   // "time"
   // "os/exec"
 
-  // configuremgr     "configuremgr"
-  // mockconfiguremgr "configuremgr/mock"
-
-  // scoringmgr       "scoringmgr"
-  // mockscoringmgr   "scoringmgr/mock"
+  configuremgr     "configuremgr"
+  scoringmgr       "scoringmgr"
+  mockscoringmgr       "scoringmgr/mock"
 
+  mockorchestrationapi "orchestrationapi/mock"
   // discoverymgr     "discoverymgr"
   // servicemgr       "servicemgr"
 
@@ -22,7 +21,7 @@ import (
 
 type Iorche struct {
   
-  IScoringmgr *scoringHandlers.Handlers
+  IScoringmgr   *scoringmgr.Handlers
   IConfiguremgr *configuremgr.ConfigureMgr
 
   IDiscoverymgr struct {
@@ -46,20 +45,21 @@ func Init(settingPath string) {
   orcheEngine.IConfiguremgr    = configuremgr.Init()
 
   orcheEngine.IScoringmgr.IloadScoringLibrary = mockscoringmgr.LoadScoringAdd
+  orcheEngine.IScoringmgr.GetScore            = mockorchestrationapi.GetScore
   orcheEngine.IScoringmgr.Ch                  = make(chan interface{}, 1024)
-  orcheEngine.IScoringmgr.GetScore            = mockscoringmgr.GetScore
 
   orcheEngine.IConfiguremgr.IDiscoveryMgr.PushConfPath  = mockorchestrationapi.PushConfPathDiscoveryDeviceMock
-  orcheEngine.IConfiguremgr.IAppExecuteMgr.PushConfPath = mockorchestrationapi.PushConfPathAppExecuteMock
-  orcheEngine.IConfiguremgr.IScoringMgr.PushLibPath     = mockorchestrationapi.PushLibPath
-  orcheEngine.IConfiguremgr.IScoringMgr.Ch              = IScoringmgr.Ch
+  orcheEngine.IConfiguremgr.IScoringMgr.PushLibPath     = mockorchestrationapi.PushLibPathScoringAppMock
+  orcheEngine.IConfiguremgr.IScoringMgr.Ch              = orcheEngine.IScoringmgr.Ch
 
   orcheEngine.IDiscoverymgr.GetEndpointDevices = mockorchestrationapi.GetEndpointDevices
   orcheEngine.IServicemgr.InitServiceMgr       = mockorchestrationapi.InitServiceMgr
   orcheEngine.IServicemgr.ExecuteApp           = mockorchestrationapi.ExecuteApp
 
   orcheEngine.IScoringmgr.Listening()
-  go orcheEngine.IConfiguremgr.Watch(watchDir)
+
+  //TODO :  get watch path of attribute in settingpath
+  go orcheEngine.IConfiguremgr.Watch("/tmp/foo")
 
   return
 
@@ -76,20 +76,21 @@ type orcheClient struct {
 
   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", path, serviceName, str)
+      ILog.Printf("service status changed [path:%s][serviceName:%s][status:%s]\n", client.path, client.serviceName, str)
        }
 }
 
-var orchClientId int
-var orcheClients = [1024]orcheClient
+var orchClientId int32
+var orcheClients = [1024]orcheClient{}
 
-func addServiceClient(clientId int, path string, serviceName string, args []string) (client *orcheClient){
+func addServiceClient(clientId int32, path string, serviceName string, args []string) (client *orcheClient){
   orcheClients[clientId].path        = path
   orcheClients[clientId].args        = args
   orcheClients[clientId].serviceName = serviceName
@@ -102,12 +103,14 @@ func getEndpointDevices(serviceName string) []string{
   return orcheEngine.IDiscoverymgr.GetEndpointDevices(serviceName)
 }
 
-func gatheringDevicesScore(endpoints []string) (deviceScores []deviceScore{}){
+func gatheringDevicesScore(endpoints []string) (deviceScores []deviceScore){
 
-  for _ , endpoint := endpoints {
+  for _ , endpoint := range endpoints {
       score := orcheEngine.IScoringmgr.GetScore(endpoint)
       deviceScores = append(deviceScores, deviceScore{endpoint, score})
   }
+
+  return
 }
 
 func sortByScore(deviceScores []deviceScore) ( []deviceScore ){
@@ -119,16 +122,22 @@ 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.LoadInt(&orchClientId)
-  atomic.AddInt(&orchClientId, 1)
+  clientId := atomic.LoadInt32(&orchClientId)
+  atomic.AddInt32(&orchClientId, 1)
 
   serviceClient := addServiceClient(clientId, path, serviceName, args)
   serviceClient.listenNotify()
   endpoints := getEndpointDevices(serviceName)
   deviceScores := sortByScore(gatheringDevicesScore(endpoints))
-  iorche.IServicemgr.ExecuteApp(deviceScores[0].endpoint, serviceName, args, serviceClient.notiChan)
+  executeApp(deviceScores[0].endpoint, serviceName, args, serviceClient.notiChan)
+
+  
 
   ILog.Println(deviceScores)
   return