--- /dev/null
+!mock/mysum/libmysum.so
\ No newline at end of file
--- /dev/null
+libmysum.so.1.0.1
\ No newline at end of file
--- /dev/null
+package orchestrationapi
+
+import (
+ "log"
+ "os"
+)
+
+var ILog *log.Logger = log.New(os.Stdout, "[orchestrationapi] INFO : ", log.LstdFlags)
+var ELog *log.Logger = log.New(os.Stdout, "[orchestrationapi] ERROR : ", log.LstdFlags)
+var DLog *log.Logger = log.New(os.Stdout, "[orchestrationapi] DEBUG : ", log.LstdFlags)
\ No newline at end of file
--- /dev/null
+package mockorchestrationapi
+
+import (
+ "time"
+ "math/rand"
+ "log"
+ "os"
+
+ confdescription "configuremgr/description"
+)
+
+
+var ILog *log.Logger = log.New(os.Stdout, "[mockorchestrationapi] INFO : ", log.LstdFlags)
+var ELog *log.Logger = log.New(os.Stdout, "[mockorchestrationapi] ERROR : ", log.LstdFlags)
+var DLog *log.Logger = log.New(os.Stdout, "[mockorchestrationapi] DEBUG : ", log.LstdFlags)
+
+func PushConfPathDiscoveryDeviceMock (doc *confdescription.Doc) (err error) {
+ ILog.Println("pushConfPathDiscoveryDeviceMock")
+ ILog.Println(*doc)
+ return
+}
+
+func PushConfPathAppExecuteMock(doc *confdescription.Doc) (err error) {
+ ILog.Println("pushConfPathAppExecuteMock")
+ ILog.Println(*doc)
+ return
+}
+
+func PushLibPathScoringAppMock(libPath string) (err error) {
+ ILog.Println("pushLibPathScoringAppMock")
+ ILog.Println(libPath)
+ return
+}
+
+func GetEndpointDevices(serviceName string) []string {
+ return []string{"localhost", "localhost"}
+}
+
+func GetScore(endpoint string) float64{
+ seed := rand.NewSource(time.Now().UnixNano())
+ random := rand.New(seed)
+
+ return random.Float64() * 100
+}
+
+func ExecuteApp(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
+}
--- /dev/null
+package orchestrationapi
+
+
+import (
+ "testing"
+ "time"
+ "os/exec"
+ "fmt"
+
+ configuremgr "configuremgr"
+ 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
+
+ //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
+ 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)
+ }
+
+
+ time.Sleep(time.Duration(5) * time.Second)
+
+ configuremgrObj.Done <- true
+
+}
+
+//jaehoon.hyun, damon92-lee
+func TestConfigureMgrDiscoveryMgr(t *testing.T) {
+
+ orcheEngine := new(orchestrationapi.Iorche)
+
+ orcheEngine.IScoringmgr = scoringmgr.Init()
+ orcheEngine.IConfiguremgr = configuremgr.Init()
+
+ orcheEngine.IScoringmgr.IloadScoringLibrary = mockscoringmgr.LoadScoringAdd
+ orcheEngine.IScoringmgr.GetScore = mockscoringmgr.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.IDiscoverymgr.GetEndpointDevices = mockorchestrationapi.GetEndpointDevices
+ orcheEngine.IServicemgr.InitServiceMgr = mockorchestrationapi.InitServiceMgr
+ orcheEngine.IServicemgr.ExecuteApp = mockorchestrationapi.ExecuteApp
+
+ orcheEngine.IScoringmgr.Listening()
+ go orcheEngine.IConfiguremgr.Watch(watchDir)
+
+
+}
+
+//jaehoon.hyun, chacha
+func TestScoringMgrServiceMgr(t *testing.T){
+
+ //I can do that , anyone have a idea, implement please or ask for jaehoon
+}
+
+//daemon92-lee, chacha
+func TestDiscoveryMgrServiceMgr(t *testing.T){
+
+
+}
+
+//jaehoon.hyun, daemon92-lee, jaehoon.hyun
+func TestConfigureMgrDiscoveryMgrScoringMgr(t *testing.T){
+
+}
+
+//jaehoon.hyun, daemon92-lee, chacha
+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
+func TestConfigureMgrDiscoveryMgrScoringMgrServiceMgr(t *testing.T){
+
+
+}
--- /dev/null
+package orchestrationapi
+
+
+import (
+
+ "sort"
+
+ // "time"
+ // "os/exec"
+
+ // configuremgr "configuremgr"
+ // mockconfiguremgr "configuremgr/mock"
+
+ // scoringmgr "scoringmgr"
+ // mockscoringmgr "scoringmgr/mock"
+
+ // discoverymgr "discoverymgr"
+ // servicemgr "servicemgr"
+
+
+)
+
+type Iorche struct {
+
+ IScoringmgr *scoringHandlers.Handlers
+ IConfiguremgr *configuremgr.ConfigureMgr
+
+ IDiscoverymgr struct {
+ GetEndpointDevices func(serviceName string) []string
+ }
+
+ IServicemgr struct {
+ InitServiceMgr func()()
+ ExecuteApp func(target string, name string, args []string, notiChan chan string) (serviceID uint64, err error)
+ }
+
+}
+
+var orcheEngine *Iorche
+
+func Init(settingPath string) {
+
+ orcheEngine = new(Iorche)
+
+ orcheEngine.IScoringmgr = scoringmgr.Init()
+ orcheEngine.IConfiguremgr = configuremgr.Init()
+
+ orcheEngine.IScoringmgr.IloadScoringLibrary = mockscoringmgr.LoadScoringAdd
+ 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.IDiscoverymgr.GetEndpointDevices = mockorchestrationapi.GetEndpointDevices
+ orcheEngine.IServicemgr.InitServiceMgr = mockorchestrationapi.InitServiceMgr
+ orcheEngine.IServicemgr.ExecuteApp = mockorchestrationapi.ExecuteApp
+
+ orcheEngine.IScoringmgr.Listening()
+ go orcheEngine.IConfiguremgr.Watch(watchDir)
+
+ return
+
+
+}
+
+type deviceScore struct{
+ endpoint string
+ score float64
+}
+
+
+type orcheClient struct {
+
+ path string
+ serviceName 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)
+ }
+}
+
+var orchClientId int
+var orcheClients = [1024]orcheClient
+
+func addServiceClient(clientId int, path string, serviceName string, args []string) (client *orcheClient){
+ orcheClients[clientId].path = path
+ orcheClients[clientId].args = args
+ orcheClients[clientId].serviceName = serviceName
+
+ client = &orcheClients[clientId]
+ return
+}
+
+func getEndpointDevices(serviceName string) []string{
+ return orcheEngine.IDiscoverymgr.GetEndpointDevices(serviceName)
+}
+
+func gatheringDevicesScore(endpoints []string) (deviceScores []deviceScore{}){
+
+ for _ , endpoint := endpoints {
+ score := orcheEngine.IScoringmgr.GetScore(endpoint)
+ deviceScores = append(deviceScores, deviceScore{endpoint, score})
+ }
+}
+
+func sortByScore(deviceScores []deviceScore) ( []deviceScore ){
+ sort.Slice(deviceScores, func(i, j int) bool {
+ return deviceScores[i].score > deviceScores[j].score
+ })
+
+ return deviceScores
+
+}
+
+func RequestService(path string, serviceName string, args []string) (handle int){
+
+ clientId = atomic.LoadInt(&orchClientId)
+ atomic.AddInt(&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)
+
+ ILog.Println(deviceScores)
+ return
+}
+
+
+func Close(handle uint64) {
+
+}