scoringmgr "scoringmgr"
mockscoringmgr "scoringmgr/mock"
- discoverymgr "discoverymgr"
- servicemgr "servicemgr"
+ // discoverymgr "discoverymgr"
+ // servicemgr "servicemgr"
mockorchestrationapi "orchestrationapi/mock"
)
//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")
}
//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
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"
type Iorche struct {
- IScoringmgr *scoringHandlers.Handlers
+ IScoringmgr *scoringmgr.Handlers
IConfiguremgr *configuremgr.ConfigureMgr
IDiscoverymgr struct {
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
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
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 ){
}
+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