From: wansuyoo Date: Wed, 20 Mar 2019 10:37:00 +0000 (+0900) Subject: update restapi function X-Git-Tag: submit/tizen/20190409.085658~21^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7864eb224b45f4fe28c4ac934e21742bf6a23b65;p=platform%2Fcore%2Fsystem%2Fedge-orchestration.git update restapi function --- diff --git a/.gitignore b/.gitignore index 5d0f86b..ebc62b8 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ bin/* pkg/* vendor/src +doc/generate-api/* # Test binary, build with `go test -c` *.test diff --git a/doc/README.md b/doc/README.md index 32c2797..03ad8a4 100644 --- a/doc/README.md +++ b/doc/README.md @@ -10,5 +10,5 @@ Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode) ``` ### 2. Code generate ``` -$ java -jar swagger-codegen-cli.jar generate -i ../edge-orchestration-api.json -l go-server +$ java -jar swagger-codegen-cli.jar generate -i edge-orchestration-api.json -l go-server ``` diff --git a/doc/edge-orchestration-api.json b/doc/edge-orchestration-api.json index 7bd3287..e058a7d 100644 --- a/doc/edge-orchestration-api.json +++ b/doc/edge-orchestration-api.json @@ -341,6 +341,37 @@ } } } + }, + "/api/v1/servicemgr/services/{appname}": { + "get": { + "tags": [ + "Service Manager" + ], + "description": "Get information of app", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "appname", + "in": "path", + "description": "Name of executed app", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "Successful operation", + "schema": { + "$ref": "#/definitions/ServiceInfo" + } + } + } + } } }, "definitions": { diff --git a/doc/generate-api/api/swagger.yaml b/doc/generate-api/api/swagger.yaml index c5ef1b4..05f3174 100644 --- a/doc/generate-api/api/swagger.yaml +++ b/doc/generate-api/api/swagger.yaml @@ -235,6 +235,27 @@ paths: description: "Successful operation" schema: $ref: "#/definitions/APIResponse" + /api/v1/servicemgr/services/{appname}: + get: + tags: + - "Service Manager" + description: "Get information of app" + consumes: + - "application/json" + produces: + - "application/json" + parameters: + - name: "appname" + in: "path" + description: "Name of executed app" + required: true + type: "string" + x-exportParamName: "Appname" + responses: + 200: + description: "Successful operation" + schema: + $ref: "#/definitions/ServiceInfo" definitions: EdgeResource: type: "string" @@ -400,6 +421,9 @@ definitions: description: "Name of requested user service" serviceList: $ref: "#/definitions/MicroServiceList" + example: + appName: "GreetWorldApp" + serviceList: "" ServiceList: type: "array" items: diff --git a/doc/generate-api/go/api_service_manager.go b/doc/generate-api/go/api_service_manager.go index 11cdb89..368b813 100644 --- a/doc/generate-api/go/api_service_manager.go +++ b/doc/generate-api/go/api_service_manager.go @@ -13,6 +13,11 @@ import ( "net/http" ) +func ApiV1ServicemgrServicesAppnameGet(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + func ApiV1ServicemgrServicesDelete(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusOK) diff --git a/doc/generate-api/go/routers.go b/doc/generate-api/go/routers.go index ca2e5b3..0d53db1 100644 --- a/doc/generate-api/go/routers.go +++ b/doc/generate-api/go/routers.go @@ -98,6 +98,13 @@ var routes = Routes{ }, Route{ + "ApiV1ServicemgrServicesAppnameGet", + strings.ToUpper("Get"), + "/api/v1/servicemgr/services/{appname}", + ApiV1ServicemgrServicesAppnameGet, + }, + + Route{ "ApiV1ServicemgrServicesDelete", strings.ToUpper("Delete"), "/api/v1/servicemgr/services", diff --git a/doc/generate-api/swagger-codegen-cli.jar b/doc/swagger-codegen-cli.jar similarity index 100% rename from doc/generate-api/swagger-codegen-cli.jar rename to doc/swagger-codegen-cli.jar diff --git a/src/restapi/v1/restapi.go b/src/restapi/v1/restapi.go index 0df85e0..304cf9b 100644 --- a/src/restapi/v1/restapi.go +++ b/src/restapi/v1/restapi.go @@ -71,11 +71,6 @@ func APIV1ServicemgrServicesDelete(w http.ResponseWriter, r *http.Request) { log.Printf("[%s] APIV1ServicemgrServicesDelete", logPrefix) } -// APIV1ServicemgrServicesGet function -func APIV1ServicemgrServicesGet(w http.ResponseWriter, r *http.Request) { - log.Printf("[%s] APIV1ServicemgrServicesGet", logPrefix) -} - // APIV1ServicemgrServicesPost function func APIV1ServicemgrServicesPost(w http.ResponseWriter, r *http.Request) { log.Printf("[%s] APIV1ServicemgrServicesPost", logPrefix) @@ -117,21 +112,13 @@ func APIV1ServicemgrEventServiceIDPost(w http.ResponseWriter, r *http.Request) { id, err := strconv.ParseUint(serviceID, 10, 64) if len(serviceID) == 0 || err != nil { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusBadRequest) + writeJSONResponse(w, nil, http.StatusBadRequest) } else { servicemgr.DataPathHandler(w, r, id) - - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) + writeJSONResponse(w, nil, http.StatusOK) } } -// APIV1ServicemgrServicesServiceIDGet function -func APIV1ServicemgrServicesServiceIDGet(w http.ResponseWriter, r *http.Request) { - log.Printf("[%s] APIV1ServicemgrServicesServiceIDGet", logPrefix) -} - // APIV1ServicemgrServicesServiceIDPost function func APIV1ServicemgrServicesServiceIDPost(w http.ResponseWriter, r *http.Request) { log.Printf("[%s] APIV1ServicemgrServicesServiceIDPost", logPrefix) @@ -160,72 +147,58 @@ func APIV1ServicemgrServicesGet(w http.ResponseWriter, r *http.Request) { ret, err := servicemgr.ServiceList() if err != nil { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") writeJSONResponse(w, nil, http.StatusBadRequest) - return } json, err := json.Marshal(ret) if err == nil { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") writeJSONResponse(w, json, http.StatusOK) } else { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") writeJSONResponse(w, nil, http.StatusBadRequest) } } -// APIV1ServicemgrServicesGetByAppName function -func APIV1ServicemgrServicesGetByAppName(w http.ResponseWriter, r *http.Request) { - log.Printf("[%s] APIV1ServicemgrServicesGetByAppName", logPrefix) +// APIV1ServicemgrServicesAppnameGet function +func APIV1ServicemgrServicesAppnameGet(w http.ResponseWriter, r *http.Request) { + log.Printf("[%s] APIV1ServicemgrServicesAppnameGet", logPrefix) vars := mux.Vars(r) appName := vars["appname"] ret, err := servicemgr.FindServiceByName(appName) if err != nil { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") writeJSONResponse(w, nil, http.StatusBadRequest) - return } json, err := json.Marshal(ret) if err == nil { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") writeJSONResponse(w, json, http.StatusOK) } else { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") writeJSONResponse(w, nil, http.StatusBadRequest) } } -// APIV1ServicemgrServicesGetByServiceID function -func APIV1ServicemgrServicesGetByServiceID(w http.ResponseWriter, r *http.Request) { - log.Printf("[%s] APIV1ServicemgrServicesGetByServiceID", logPrefix) +// APIV1ServicemgrServicesServiceIDGet function +func APIV1ServicemgrServicesServiceIDGet(w http.ResponseWriter, r *http.Request) { + log.Printf("[%s] APIV1ServicemgrServicesServiceIDGet", logPrefix) vars := mux.Vars(r) serviceID := vars["serviceid"] id, err := strconv.ParseUint(serviceID, 10, 64) if err != nil { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") writeJSONResponse(w, nil, http.StatusBadRequest) - return } ret, err := servicemgr.FindServiceByID(id) if err != nil { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") writeJSONResponse(w, nil, http.StatusBadRequest) - return } json, err := json.Marshal(ret) if err == nil { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") writeJSONResponse(w, json, http.StatusOK) } else { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") writeJSONResponse(w, nil, http.StatusBadRequest) } } diff --git a/src/restapi/v1/routers.go b/src/restapi/v1/routers.go index 8ab65f6..c31eac2 100644 --- a/src/restapi/v1/routers.go +++ b/src/restapi/v1/routers.go @@ -102,6 +102,13 @@ var routes = Routes{ }, Route{ + "APIV1ServicemgrServicesAppnameGet", + strings.ToUpper("Get"), + "/api/v1/servicemgr/services/{appname}", + APIV1ServicemgrServicesAppnameGet, + }, + + Route{ "APIV1ServicemgrServicesDelete", strings.ToUpper("Delete"), "/api/v1/servicemgr/services", @@ -142,25 +149,4 @@ var routes = Routes{ "/api/v1/servicemgr/services/{serviceid}", APIV1ServicemgrServicesServiceIDPost, }, - - Route{ - "APIV1ServicemgrServicesGet", - strings.ToUpper("Get"), - "/api/v1/servicemgr/services", - APIV1ServicemgrServicesGet, - }, - - Route{ - "APIV1ServicemgrServicesGetByAppName", - strings.ToUpper("Get"), - "/api/v1/servicemgr/services/{appname}", - APIV1ServicemgrServicesGetByAppName, - }, - - Route{ - "APIV1ServicemgrServicesGetByServiceID", - strings.ToUpper("Get"), - "/api/v1/servicemgr/services/{serviceid}", - APIV1ServicemgrServicesGetByServiceID, - }, }