From 1074912fbab3ae4175c7365928d7e3229ce74d8c Mon Sep 17 00:00:00 2001 From: Youhwan Seol Date: Wed, 22 Feb 2023 11:26:04 +0900 Subject: [PATCH] Implementation of healthcheck flow Change-Id: If8c47e3057805f5f8ecda185e65a0445f806cc06 Signed-off-by: Youhwan Seol --- pkg/api/rest_server.go | 11 +++++-- pkg/api/v1/healthcheck/healthcheck.go | 47 ++++++++++++++++++++++++++++++ pkg/api/v1/healthcheck/healthcheck_test.go | 46 +++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 pkg/api/v1/healthcheck/healthcheck.go create mode 100644 pkg/api/v1/healthcheck/healthcheck_test.go diff --git a/pkg/api/rest_server.go b/pkg/api/rest_server.go index 6810d9d..781824c 100644 --- a/pkg/api/rest_server.go +++ b/pkg/api/rest_server.go @@ -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 index 0000000..8c2cdb6 --- /dev/null +++ b/pkg/api/v1/healthcheck/healthcheck.go @@ -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 index 0000000..411e1ee --- /dev/null +++ b/pkg/api/v1/healthcheck/healthcheck_test.go @@ -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) +} -- 2.16.6