diff options
author | jaehoon.hyun <jaehoon.hyun@samsung.com> | 2019-04-02 19:09:59 +0900 |
---|---|---|
committer | jaehoon.hyun <jaehoon.hyun@samsung.com> | 2019-04-02 19:09:59 +0900 |
commit | d4e8886494c419d77444ddd4a545028b488c26e1 (patch) | |
tree | ba7f88afeab6dd6feeaa1db46ab026ba37b30435 | |
parent | a36fdca99dc8900d006c38f3394e209add8355b7 (diff) | |
download | edge-orchestration-d4e8886494c419d77444ddd4a545028b488c26e1.tar.gz edge-orchestration-d4e8886494c419d77444ddd4a545028b488c26e1.tar.bz2 edge-orchestration-d4e8886494c419d77444ddd4a545028b488c26e1.zip |
handlers api changed
-rw-r--r-- | src/scoringmgr/handlers.go | 104 |
1 files changed, 6 insertions, 98 deletions
diff --git a/src/scoringmgr/handlers.go b/src/scoringmgr/handlers.go index 0413978..847fa02 100644 --- a/src/scoringmgr/handlers.go +++ b/src/scoringmgr/handlers.go @@ -9,7 +9,9 @@ import "unsafe" import ( + "strings" "time" + confdescription "configuremgr/description" ) @@ -47,8 +49,8 @@ type Handlers struct { Ch chan interface{} - IRunningScore func (uintptr) () - IGetScore func (string, string, chan float64) float64 + IRunningScore func (uintptr) (float64) + IGetScore func (string, string) (float64, error) } var ( @@ -81,18 +83,6 @@ func PushLibPath(libPath string, doc *confdescription.Doc, handlersCh chan<- int return nil } -// GetScore is getting score of device -func GetScore(target string, name string) (scoreValue float64, err error) { - if strings.Compare(target, getOutboundIP()) == 0 || strings.Compare(target, ConstLocalTarget) == 0 { - scoreValue, err = getScoreLocalEnv(name) - } else { - scoreValue, err = getScoreRemoteEnv(target, name) - } - - DLog.Println("scoreValue", scoreValue) - - return -} // Listening function func (handlers *Handlers) Listening() { @@ -114,11 +104,6 @@ func (handlers *Handlers) Listening() { } -func (handlers *Handlers) runScoring(handlerObj *Handler) { - go handlers.IloadScoringLibrary(handlerObj.libPath, handlerObj.intervalMs, handlerObj.scoreValue) - return -} - func (handlers *Handlers) RemoveLib(libName string) { handler := handlers.table[libName] @@ -131,7 +116,7 @@ func (handlers *Handlers) RemoveLib(libName string) { //Close dynamic loader defer C.dlclose(unsafe.Pointer(handler.dl)) - ILog.Println("RemoveLib end") + ILog.Printf("RemoveLib : %s\n", libName) } func (handlers *Handlers) makeHandler(pairObj pair) (handlerObj *Handler) { @@ -146,8 +131,6 @@ func (handlers *Handlers) makeHandler(pairObj pair) (handlerObj *Handler) { handlerObj.endSignal = make(chan bool, 1024) handlerObj.parents = handlers - handlerObj.scoreValue = make(chan float64, 1) - handlers.table[handlerObj.handlerName] = handlerObj return @@ -249,79 +232,4 @@ func getLibName(libPath string) string { libName := strings.Split(name[lastIdx-1], ".") return strings.TrimPrefix(libName[0], "lib") -} - -// func getScore(name string) (score float64, err error) { -// handlerObj := handlers.table[name] - -// if handlerObj == nil { -// err = errors.New("Invalid Service Name") -// return -// } - -// score = handlerObj.scoreValue - -// return -// } - -func getScoreLocalEnv(name string) (scoreValue float64, err error) { - // scoreChan, err := getScore(name) - // if err != nil { - // return - // } - - // select { - // case scoreValue = <-scoreChan: - // DLog.Println(scoreValue) - // } - // return - - handlerObj := handlers.table[name] - - if handlerObj == nil { - err = errors.New("Invalid Service Name") - return - } - - scoreValue = handlerObj.scoreValue - - return -} - -func getScoreRemoteEnv(target string, name string) (scoreValue float64, err error) { - targetURL := ConstPrefixHTTP + target + ":" + strconv.Itoa(ConstWellknownPort) + "/" + name - - respBytes, err := doGet(targetURL) - if checkError(err) == true { - return scoreValue, err - } - - var responseMsg map[string]interface{} - err = json.Unmarshal(respBytes, &responseMsg) - - if err == nil { - scoreValue = responseMsg["ScoreValue"].(float64) - } - - return -} - -func getOutboundIP() string { - conn, err := net.Dial("udp", "8.8.8.8:80") - if err != nil { - log.Fatal(err) - } - defer conn.Close() - - localAddr := conn.LocalAddr().(*net.UDPAddr) - - return localAddr.IP.String() -} - -func checkError(err error) bool { - if err != nil { - log.Println(err.Error()) - return true - } - return false -} +}
\ No newline at end of file |