Browse Source

add status api

Zhang Li 2 năm trước cách đây
mục cha
commit
a7815ae204

+ 7 - 1
aihub-dag-jupyter/values.yaml

@@ -12,7 +12,13 @@ jupyterlab:
   nameOverride: ""
   fullnameOverride: ""
   podAnnotations: {}
-  resources: {}
+  resources:
+    limits:
+      cpu: 2000m
+      memory: 4096Mi
+    requests:
+      cpu: 100m
+      memory: 128Mi
   persistence:
     # Enable persistent volume for storing dags
     enabled: true

+ 28 - 0
dag-jupyter/internal/api/helm-wrapper.go

@@ -14,6 +14,12 @@ type Resp struct {
 	Error string      `json:"error,omitempty"`
 }
 
+type StatusResp struct {
+	Code  int                    `json:"code"`
+	Data  []*types.ReleaseStatus `json:"data,omitempty"`
+	Error string                 `json:"error,omitempty"`
+}
+
 const url = "http://localhost:8081"
 
 // const url = "http://192.168.199.109:18080"
@@ -95,3 +101,25 @@ func Upgrade(req *types.CreateJupyterInfo) error {
 
 	return nil
 }
+
+func Status(req *types.ReleaseInfo) ([]*types.ReleaseStatus, error) {
+	var resp StatusResp
+	request := gorequest.New()
+	m := map[string]string{
+		"filter": req.Filter,
+	}
+	_, _, errs := request.Get(fmt.Sprintf("%s/api/namespaces/%s/releases", url, req.Namespace)).SendMap(m).EndStruct(&resp)
+
+	if len(errs) != 0 {
+		return nil, fmt.Errorf("helm status error: %s", errs[0])
+	}
+
+	if resp.Code != 0 {
+		return nil, fmt.Errorf("helm status error: %s", resp.Error)
+	}
+
+	logx.Info("helm status success~~")
+
+	return resp.Data, nil
+
+}

+ 5 - 0
dag-jupyter/internal/handler/routes.go

@@ -47,6 +47,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/helm/ops/upgrade",
 				Handler: UpgradeOpHandler(serverCtx),
 			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/helm/ops/status",
+				Handler: StatusOpHandler(serverCtx),
+			},
 		},
 	)
 }

+ 28 - 0
dag-jupyter/internal/handler/statusophandler.go

@@ -0,0 +1,28 @@
+package handler
+
+import (
+	"net/http"
+
+	"dag-jupyter/internal/logic"
+	"dag-jupyter/internal/svc"
+	"dag-jupyter/internal/types"
+	"github.com/zeromicro/go-zero/rest/httpx"
+)
+
+func StatusOpHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.ReleaseInfo
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewStatusOpLogic(r.Context(), svcCtx)
+		resp, err := l.StatusOp(&req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 41 - 0
dag-jupyter/internal/logic/statusoplogic.go

@@ -0,0 +1,41 @@
+package logic
+
+import (
+	"context"
+	"net/http"
+
+	"dag-jupyter/internal/api"
+	"dag-jupyter/internal/svc"
+	"dag-jupyter/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type StatusOpLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewStatusOpLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatusOpLogic {
+	return &StatusOpLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *StatusOpLogic) StatusOp(req *types.ReleaseInfo) (resp *types.Response, err error) {
+	data, err := api.Status(req)
+	if err != nil {
+		return &types.Response{
+			Data: []*types.ReleaseStatus{},
+			Code: http.StatusBadRequest,
+		}, err
+	}
+
+	return &types.Response{
+		Data: data,
+		Code: http.StatusOK,
+	}, nil
+}

+ 16 - 0
dag-jupyter/internal/types/types.go

@@ -28,3 +28,19 @@ type DeleteJupyterInfo struct {
 	ReleaseName string `json:"release_name"`
 	Namespace   string `json:"namespace"`
 }
+
+type ReleaseInfo struct {
+	Namespace string `json:"namespace"`
+	Filter    string `json:"filter"`
+}
+
+type ReleaseStatus struct {
+	Namespace    string `json:"namespace"`
+	Name         string `json:"name"`
+	Revision     string `json:"revision"`
+	Updated      string `json:"updated"`
+	Status       string `json:"status"`
+	Chart        string `json:"chart"`
+	ChartVersion string `json:"chart_version"`
+	AppVersion   string `json:"app_version"`
+}

+ 2 - 1
docker-compose.yml

@@ -4,7 +4,7 @@ services:
     hostname: aihub-dag-jpt-dev
     container_name: aihub-dag-jpt-dev
     restart: always
-    image: SXKJ:32775/backendhelm:sxkj
+    image: SXKJ:32775/helmbe:sxkj
     privileged: true
     ipc: host
     tty: true
@@ -14,5 +14,6 @@ services:
       - APP_ENV=development
     ports:
       - '18080:8080'
+      - '18081:8081'
     # volumes:
     #   - ./:/app

+ 21 - 0
jupyter.api

@@ -24,6 +24,21 @@ type (
 		ReleaseName string `json:"release_name"`
 		Namespace   string `json:"namespace"`
 	}
+
+	ReleaseInfo {
+		Namespace string `json:"namespace"`
+		Filter    string `json:"filter"`
+	}
+	ReleaseStatus {
+		Namespace    string `json:"namespace"`
+		Name         string `json:"name"`
+		Revision     string `json:"revision"`
+		Updated      string `json:"updated"`
+		Status       string `json:"status"`
+		Chart        string `json:"chart"`
+		ChartVersion string `json:"chart_version"`
+		AppVersion   string `json:"app_version"`
+	}
 )
 
 service jupyter-api {
@@ -54,4 +69,10 @@ service jupyter-api {
 	)
 	@handler UpgradeOpHandler
 	post /helm/ops/upgrade (CreateJupyterInfo) returns (Response)
+	
+	@doc(
+		summary: 查看release状态
+	)
+	@handler StatusOpHandler
+	post /helm/ops/status (ReleaseInfo) returns (Response)
 }