Implementation of IPS deployment interface 46/10946/1
authorYouhwan Seol <yh.seol@samsung.com>
Wed, 8 Feb 2023 06:55:25 +0000 (15:55 +0900)
committerYouhwan Seol <yh.seol@samsung.com>
Tue, 18 Apr 2023 01:22:18 +0000 (10:22 +0900)
Change-Id: Id15e9f4403c95bf5d7bbdef2ff09130546a117f9
Signed-off-by: Youhwan Seol <yh.seol@samsung.com>
pkg/api/commons/utils/utils.go [new file with mode: 0644]
pkg/api/rest_server.go
pkg/api/v1/deployment/deployment.go [new file with mode: 0644]

diff --git a/pkg/api/commons/utils/utils.go b/pkg/api/commons/utils/utils.go
new file mode 100644 (file)
index 0000000..e93ebc6
--- /dev/null
@@ -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
+}
index 71dd4db..51b6de1 100644 (file)
@@ -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 (file)
index 0000000..44a6001
--- /dev/null
@@ -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)
+}