Implementation of status feature 09/11209/1
authorYouhwan Seol <yh.seol@samsung.com>
Wed, 22 Feb 2023 05:20:00 +0000 (14:20 +0900)
committerYouhwan Seol <yh.seol@samsung.com>
Wed, 24 May 2023 11:38:41 +0000 (20:38 +0900)
Change-Id: I7d5c6aaf3b65dcaea68d6c42ec90f902c195f434
Signed-off-by: Youhwan Seol <yh.seol@samsung.com>
pkg/api/rest_server.go
pkg/api/v1/status/status.go [new file with mode: 0644]
pkg/client/kserve/client.go
pkg/client/kserve/utils.go
pkg/commons/types/values.go
pkg/controller/v1/adapter/controller.go

index 97f86f9..f4e28e6 100644 (file)
@@ -26,6 +26,7 @@ import (
        "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/api/v1/revision"
+       "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/v1/status"
        "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/logger"
 )
 
@@ -33,12 +34,14 @@ var (
        deploymentExecutor  deployment.Command
        healthcheckExecutor healthcheck.Command
        reivisonExecutor    revision.Command
+       statusExecutor      status.Command
 )
 
 func init() {
        deploymentExecutor = deployment.Executor{}
        healthcheckExecutor = healthcheck.Executor{}
        reivisonExecutor = revision.Executor{}
+       statusExecutor = status.Executor{}
 }
 
 func setupRouter() (router *gin.Engine) {
@@ -64,7 +67,9 @@ func setupRouter() (router *gin.Engine) {
                }
 
                status := v1.Group(url.IPS() + url.Status())
-               // status.GET()
+               {
+                       status.GET("", statusExecutor.Get)
+               }
 
                info := v1.Group(url.IPS() + url.Info())
                // info.GET()
diff --git a/pkg/api/v1/status/status.go b/pkg/api/v1/status/status.go
new file mode 100644 (file)
index 0000000..c01e34e
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+==================================================================================
+
+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 status
+
+import (
+       "encoding/json"
+       "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/errors"
+       "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/logger"
+       "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/controller/v1/adapter"
+)
+
+type Command interface {
+       Get(c *gin.Context)
+}
+
+type Executor struct {
+       Command
+}
+
+var ipsAdapter adapter.Command
+
+func init() {
+       ipsAdapter = adapter.Executor{}
+}
+
+func (Executor) Get(c *gin.Context) {
+       logger.Logging(logger.DEBUG, "IN")
+       defer logger.Logging(logger.DEBUG, "OUT")
+
+       name := c.Query("name")
+
+       statusList, err := ipsAdapter.Status(name)
+       if err != nil {
+               utils.WriteError(c.Writer, errors.InternalServerError{Message: err.Error()})
+               return
+       }
+
+       data, err := json.Marshal(statusList)
+       if err != nil {
+               utils.WriteError(c.Writer, err)
+               return
+       }
+
+       utils.WriteSuccess(c.Writer, http.StatusAccepted, data)
+}
index bb5934a..989cf05 100644 (file)
@@ -45,6 +45,7 @@ type Command interface {
        Get(name string) (*api_v1beta1.InferenceService, error)
        Update(values types.Values) (string, error)
        Revision(name string) (revisionList types.Revision, err error)
+       Status(name string) (statusList types.Status, err error)
 }
 
 type Client struct {
@@ -194,3 +195,43 @@ func (c *Client) Revision(name string) (revisionList types.Revision, err error)
 
        return
 }
+
+func (c *Client) Status(name string) (statusList types.Status, err error) {
+       logger.Logging(logger.DEBUG, "IN")
+       defer logger.Logging(logger.DEBUG, "OUT")
+
+       statusList.Status = make(map[string][]types.StatusItem)
+
+       if name == "" {
+               ifsvList, e := c.api.List(v1.ListOptions{})
+               if e != nil {
+                       err = errors.InternalServerError{Message: e.Error()}
+                       return
+               }
+
+               for _, ifsv := range ifsvList.Items {
+                       status, e := makeStatus(ifsv)
+                       if e != nil {
+                               err = errors.InternalServerError{Message: e.Error()}
+                               return
+                       }
+                       statusList.Status[ifsv.Name] = status
+               }
+
+       } else {
+               ifsv, e := c.Get(name)
+               if e != nil {
+                       err = e
+                       return
+               }
+
+               status, e := makeStatus(*ifsv)
+               if e != nil {
+                       err = e
+                       return
+               }
+               statusList.Status[ifsv.Name] = status
+       }
+
+       return
+}
index c755eb8..4e32ec5 100644 (file)
@@ -137,3 +137,28 @@ func makeRevision(ifsv api_v1beta1.InferenceService) (revision types.RevisionIte
        json.Unmarshal(data, &revision)
        return
 }
+
+func makeStatus(ifsv api_v1beta1.InferenceService) (status []types.StatusItem, err error) {
+       logger.Logging(logger.DEBUG, "IN")
+       defer logger.Logging(logger.DEBUG, "OUT")
+
+       if len(ifsv.Status.Conditions) == 0 {
+               logger.Logging(logger.ERROR, "condition is empty")
+               err = errors.InternalServerError{
+                       Message: "condition is empty",
+               }
+               return
+       }
+
+       for _, condition := range ifsv.Status.Conditions {
+               status = append(status, types.StatusItem{
+                       Type:               string(condition.Type),
+                       Status:             string(condition.Status),
+                       Severity:           string(condition.Severity),
+                       Reason:             condition.Reason,
+                       Message:            condition.Message,
+                       LastTransitionTime: condition.LastTransitionTime.Inner.String(),
+               })
+       }
+       return
+}
index d5704d4..3e4a501 100644 (file)
@@ -42,6 +42,19 @@ type RevisionItem struct {
        LatestRolledoutRevision   string `json:"latestRolledoutRevision,omitempty" example:"{revision}" format:"string"`
 }
 
+type StatusItem struct {
+       Type               string `json:"type" example:"{status type}" format:"string"`
+       Status             string `json:"status" example:"{True / False}" format:"string"`
+       Severity           string `json:"severity,omitempty" example:"{severity}" format:"string"`
+       LastTransitionTime string `json:"lastTransitionTime,omitempty" example:"{time stamp}" format:"string"`
+       Reason             string `json:"reason,omitempty" example:"{reason}" format:"string"`
+       Message            string `json:"message,omitempty" example:"{message}" format:"string"`
+}
+
 type Revision struct {
        Revision map[string]RevisionItem `json:"revision"`
 }
+
+type Status struct {
+       Status map[string][]StatusItem `json:"status"`
+}
index 5107713..f88524d 100644 (file)
@@ -35,6 +35,7 @@ type Command interface {
        Delete(name string) error
        Update(name string, version string, canaryTrafficRatio string) (string, error)
        Revision(name string) (revisionList types.Revision, err error)
+       Status(name string) (types.Status, error)
 }
 
 type Executor struct {
@@ -143,3 +144,11 @@ func (Executor) Revision(name string) (result types.Revision, err error) {
        result, err = kserveClient.Revision(name)
        return
 }
+
+func (Executor) Status(name string) (result types.Status, err error) {
+       logger.Logging(logger.DEBUG, "IN")
+       defer logger.Logging(logger.DEBUG, "OUT")
+
+       result, err = kserveClient.Status(name)
+       return
+}