From: jw_wonny.cha Date: Tue, 2 Apr 2019 05:59:37 +0000 (+0900) Subject: - Add rest api that getting scoring X-Git-Tag: submit/tizen/20190409.085658~6^2~6^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=73af3754161eea2b7061f20dd3daeb45589b032d;p=platform%2Fcore%2Fsystem%2Fedge-orchestration.git - Add rest api that getting scoring --- diff --git a/src/restapi/v1/restapi.go b/src/restapi/v1/restapi.go index d022836..fc3c1ca 100644 --- a/src/restapi/v1/restapi.go +++ b/src/restapi/v1/restapi.go @@ -18,8 +18,11 @@ import ( "net" "net/http" "os/exec" + "scoringmgr" "servicemgr" "strconv" + + "github.com/gorilla/mux" ) // APIV1DeviceResourceUsageCPUGet function @@ -122,6 +125,29 @@ func APIV1ServicemgrServicesNotificationServiceIDPost(w http.ResponseWriter, r * } } +// APIV1ScoringmgrScoreLibnameGet function +func APIV1ScoringmgrScoreLibnameGet(w http.ResponseWriter, r *http.Request) { + log.Printf("[%s] APIV1ScoringmgrScoreLibnameGet", logPrefix) + + vars := mux.Vars(r) + libName := vars["libname"] + + name := libName + target := scoringmgr.ConstLocalTarget + + scoreValue, err := scoringmgr.GetScore(target, name) + + respInfo := make(map[string]interface{}) + respInfo["ScoreValue"] = scoreValue + respBytes, err := json.Marshal(respInfo) + + if err != nil { + w.WriteHeader(http.StatusBadRequest) + } else { + writeJSONResponse(w, respBytes, http.StatusOK) + } +} + func writeJSONResponse(w http.ResponseWriter, data []byte, status int) { log.Printf("[%s] writeJSONResponse: %s", logPrefix, data) w.Header().Set("Content-Type", "application/json; charset=UTF-8") diff --git a/src/restapi/v1/routers.go b/src/restapi/v1/routers.go index 5834c11..cfddada 100644 --- a/src/restapi/v1/routers.go +++ b/src/restapi/v1/routers.go @@ -114,4 +114,11 @@ var routes = Routes{ "/api/v1/servicemgr/services/notification/{serviceid}", APIV1ServicemgrServicesNotificationServiceIDPost, }, + + Route{ + "APIV1ScoringmgrScoreLibnameGet", + strings.ToUpper("Get"), + "/api/v1/scoringmgr/score/{libname}", + APIV1ScoringmgrScoreLibnameGet, + }, }