From 9b29e50ace5f815a3d1371bf071f08896adf2b8b Mon Sep 17 00:00:00 2001 From: Youhwan Seol Date: Wed, 8 Feb 2023 15:55:25 +0900 Subject: [PATCH] Implementation of IPS deployment interface Change-Id: Id15e9f4403c95bf5d7bbdef2ff09130546a117f9 Signed-off-by: Youhwan Seol --- pkg/api/commons/utils/utils.go | 48 ++++++++++++++++++++++++++++++ pkg/api/rest_server.go | 11 +++++-- pkg/api/v1/deployment/deployment.go | 59 +++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 pkg/api/commons/utils/utils.go create mode 100644 pkg/api/v1/deployment/deployment.go diff --git a/pkg/api/commons/utils/utils.go b/pkg/api/commons/utils/utils.go new file mode 100644 index 0000000..e93ebc6 --- /dev/null +++ b/pkg/api/commons/utils/utils.go @@ -0,0 +1,48 @@ +/* +================================================================================== + +Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +================================================================================== +*/ + +package utils + +import ( + "encoding/json" + "net/http" +) + +func WriteSuccess(w http.ResponseWriter, code int, data []byte) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(code) + w.Write(data) +} + +func WriteError(w http.ResponseWriter, err error) { + data := make(map[string]interface{}) + data["message"] = err.Error() + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusNotFound) + w.Write(ChangeToJson(data)) +} + +func ChangeToJson(src map[string]interface{}) []byte { + dst, err := json.Marshal(src) + if err != nil { + return nil + } + return dst +} diff --git a/pkg/api/rest_server.go b/pkg/api/rest_server.go index 71dd4db..51b6de1 100644 --- a/pkg/api/rest_server.go +++ b/pkg/api/rest_server.go @@ -23,9 +23,16 @@ import ( "github.com/gin-gonic/gin" "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/commons/url" + "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/v1/deployment" "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/logger" ) +var deploymentExecutor deployment.Command + +func init() { + deploymentExecutor = deployment.Executor{} +} + func setupRouter() (router *gin.Engine) { router = gin.Default() @@ -33,7 +40,7 @@ func setupRouter() (router *gin.Engine) { { deployment := v1.Group(url.IPS()) { - // deployment.POST + deployment.POST("", deploymentExecutor.Deploy) // deployment.PUT // deployment.DELETE } @@ -50,7 +57,7 @@ func setupRouter() (router *gin.Engine) { info := v1.Group(url.IPS() + url.Info()) // info.GET() - _, _, _, _, _ = deployment, healthcheck, revision, status, info + _, _, _, _ = healthcheck, revision, status, info } return diff --git a/pkg/api/v1/deployment/deployment.go b/pkg/api/v1/deployment/deployment.go new file mode 100644 index 0000000..44a6001 --- /dev/null +++ b/pkg/api/v1/deployment/deployment.go @@ -0,0 +1,59 @@ +/* +================================================================================== + +Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +================================================================================== +*/ + +package deployment + +import ( + "errors" + "net/http" + + "github.com/gin-gonic/gin" + + "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/commons/utils" + "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/logger" +) + +type Command interface { + Deploy(c *gin.Context) +} + +type Executor struct { + Command +} + +func (Executor) Deploy(c *gin.Context) { + logger.Logging(logger.DEBUG, "IN") + defer logger.Logging(logger.DEBUG, "OUT") + + name := c.Query("name") + if name == "" { + utils.WriteError(c.Writer, errors.New("empty query")) + return + } + + version := c.Query("version") + if version == "" { + utils.WriteError(c.Writer, errors.New("empty query")) + return + } + + // kserve client deploy logic + + utils.WriteSuccess(c.Writer, http.StatusCreated, nil) +} -- 2.16.6