summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjw_wonny.cha <jw_wonny.cha@samsung.com>2019-04-02 14:59:37 +0900
committerjw_wonny.cha <jw_wonny.cha@samsung.com>2019-04-02 14:59:37 +0900
commit73af3754161eea2b7061f20dd3daeb45589b032d (patch)
tree0999a1b7e411db0c7e75474e10e0143705812064
parent660aca0f325b0aca2ee3c1aa53a4a671ad4000fd (diff)
downloadedge-orchestration-73af3754161eea2b7061f20dd3daeb45589b032d.tar.gz
edge-orchestration-73af3754161eea2b7061f20dd3daeb45589b032d.tar.bz2
edge-orchestration-73af3754161eea2b7061f20dd3daeb45589b032d.zip
- Add rest api that getting scoring
-rw-r--r--src/restapi/v1/restapi.go26
-rw-r--r--src/restapi/v1/routers.go7
2 files changed, 33 insertions, 0 deletions
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,
+ },
}