Implementation of healthcheck flow 07/11207/1
authorYouhwan Seol <yh.seol@samsung.com>
Wed, 22 Feb 2023 02:26:04 +0000 (11:26 +0900)
committerYouhwan Seol <yh.seol@samsung.com>
Wed, 24 May 2023 10:31:05 +0000 (19:31 +0900)
Change-Id: If8c47e3057805f5f8ecda185e65a0445f806cc06
Signed-off-by: Youhwan Seol <yh.seol@samsung.com>
pkg/api/rest_server.go
pkg/api/v1/healthcheck/healthcheck.go [new file with mode: 0644]
pkg/api/v1/healthcheck/healthcheck_test.go [new file with mode: 0644]

index 6810d9d..781824c 100644 (file)
@@ -24,13 +24,18 @@ import (
 
        "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/api/v1/healthcheck"
        "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/logger"
 )
 
-var deploymentExecutor deployment.Command
+var (
+       deploymentExecutor  deployment.Command
+       healthcheckExecutor healthcheck.Command
+)
 
 func init() {
        deploymentExecutor = deployment.Executor{}
+       healthcheckExecutor = healthcheck.Executor{}
 }
 
 func setupRouter() (router *gin.Engine) {
@@ -46,7 +51,9 @@ func setupRouter() (router *gin.Engine) {
                }
 
                healthcheck := v1.Group(url.Healthcheck())
-               // healthcheck.GET()
+               {
+                       healthcheck.GET("", healthcheckExecutor.Ping)
+               }
 
                revision := v1.Group(url.IPS() + url.Revision())
                // revision.GET()
diff --git a/pkg/api/v1/healthcheck/healthcheck.go b/pkg/api/v1/healthcheck/healthcheck.go
new file mode 100644 (file)
index 0000000..8c2cdb6
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+==================================================================================
+
+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 healthcheck
+
+import (
+       "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 {
+       Ping(c *gin.Context)
+}
+
+type Executor struct {
+       Command
+}
+
+func init() {
+}
+
+func (Executor) Ping(c *gin.Context) {
+       logger.Logging(logger.DEBUG, "IN")
+       defer logger.Logging(logger.DEBUG, "OUT")
+
+       utils.WriteSuccess(c.Writer, http.StatusOK, nil)
+}
diff --git a/pkg/api/v1/healthcheck/healthcheck_test.go b/pkg/api/v1/healthcheck/healthcheck_test.go
new file mode 100644 (file)
index 0000000..411e1ee
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+==================================================================================
+
+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 healthcheck
+
+import (
+       "net/http"
+       "net/http/httptest"
+       "testing"
+
+       "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/commons/url"
+
+       "github.com/gin-gonic/gin"
+)
+
+func TestReceivedPingRequest_ExpectSuccess(t *testing.T) {
+       w := httptest.NewRecorder()
+
+       r, err := http.NewRequest("GET", url.V1()+url.Healthcheck(), nil)
+       if err != nil {
+               t.Errorf("http.NewRequest return Error : %s", err.Error())
+       }
+       r.Header.Set("Content-Type", "application/json")
+
+       c, _ := gin.CreateTestContext(w)
+       c.Request = r
+
+       status := Executor{}
+       status.Ping(c)
+}