Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:app list no progress #43

Merged
merged 5 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions internal/watchdog/dog.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ func checkHaveProgress(installOp, cfgType string) bool {
return false
}

func (w *ModelManager) GetProgress(uid string) string {

manager, exists := w.ModelManagerMap[uid]
if !exists || manager == nil {
glog.Info("GetProgress:", uid, "not found or nil")
return ""
}

glog.Info("GetProgress:", uid, manager.progress)
return manager.progress
}

func (w *ModelManager) NewWatchDog(installOp, appName, uid, token, from, cfgType string, info *models.ApplicationInfo) *CommonWatchDog {
w.mu.Lock()
defer w.mu.Unlock()
Expand Down Expand Up @@ -79,6 +91,7 @@ func (w *ModelManager) NewWatchDog(installOp, appName, uid, token, from, cfgType
clear: w.DeleteWatchDog,
}
w.ModelManagerMap[uid] = wd
glog.Info("NewWatchDog:", uid)

return wd
}
Expand Down
13 changes: 13 additions & 0 deletions internal/watchdog/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ func NewWatchDogManager() *Manager {
return &Manager{ManagerMap: make(ManagerMap)}
}

func (w *Manager) GetProgress(uid string) string {

manager, exists := w.ManagerMap[uid]
if !exists || manager == nil {
glog.Info("GetProgress-Event:", uid, "not found or nil")
return ""
}

glog.Info("GetProgress-Event:", uid, manager.progress)
return manager.progress
}

func (w *Manager) NewWatchDog(installOp, appname, uid, token, from, cfgType string, info *models.ApplicationInfo) *InstallationWatchDog {
w.mu.Lock()
defer w.mu.Unlock()
Expand Down Expand Up @@ -119,6 +131,7 @@ func (w *Manager) NewWatchDog(installOp, appname, uid, token, from, cfgType stri
clear: w.DeleteWatchDog,
}
w.ManagerMap[uid] = wd
glog.Info("NewWatchDog-Event:", uid)

return wd
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/apiserver/service/v1/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (h *Handler) list(req *restful.Request, resp *restful.Response) {
workflowMap, _ := getWorkflowsMap(token)
middlewareMap, _ := getMiddlewaresMap(token)

appWithStatusList := parseAppInfos(res, appsMap, workflowMap, middlewareMap)
appWithStatusList := parseAppInfos(h, res, appsMap, workflowMap, middlewareMap)

resp.WriteEntity(models.NewResponse(api.OK, api.Success, models.NewListResultWithCount(appWithStatusList, res.TotalCount)))
}
Expand Down Expand Up @@ -247,7 +247,8 @@ func (h *Handler) listTop(req *restful.Request, resp *restful.Response) {
workflowMap, _ := getWorkflowsMap(token)
middlewareMap, _ := getMiddlewaresMap(token)

appWithStatusList := parseAppInfos(res, appsMap, workflowMap, middlewareMap)
appWithStatusList := parseAppInfos(h, res, appsMap, workflowMap, middlewareMap)

resp.WriteEntity(models.NewResponse(api.OK, api.Success, models.NewListResultWithCount(appWithStatusList, res.TotalCount)))
}

Expand Down Expand Up @@ -281,7 +282,7 @@ func (h *Handler) listLatest(req *restful.Request, resp *restful.Response) {
workflowMap, _ := getWorkflowsMap(token)
middlewareMap, _ := getMiddlewaresMap(token)

appWithStatusList := parseAppInfos(res, appsMap, workflowMap, middlewareMap)
appWithStatusList := parseAppInfos(h, res, appsMap, workflowMap, middlewareMap)

resp.WriteEntity(models.NewResponse(api.OK, api.Success, models.NewListResultWithCount(appWithStatusList, res.TotalCount)))
}
Expand Down Expand Up @@ -360,7 +361,7 @@ func (h *Handler) search(req *restful.Request, resp *restful.Response) {
workflowMap, _ := getWorkflowsMap(token)
middlewareMap, _ := getMiddlewaresMap(token)

appWithStatusList := parseAppInfos(res, appsMap, workflowMap, middlewareMap)
appWithStatusList := parseAppInfos(h, res, appsMap, workflowMap, middlewareMap)

_ = resp.WriteEntity(models.NewResponse(api.OK, api.Success, models.NewListResultWithCount(appWithStatusList, res.TotalCount)))
}
Expand Down Expand Up @@ -402,7 +403,7 @@ func (h *Handler) searchPost(req *restful.Request, resp *restful.Response) {
workflowMap, _ := getWorkflowsMap(token)
middlewareMap, _ := getMiddlewaresMap(token)

appWithStatusList := parseAppInfos(res, appsMap, workflowMap, middlewareMap)
appWithStatusList := parseAppInfos(h, res, appsMap, workflowMap, middlewareMap)

resp.WriteEntity(models.NewResponse(api.OK, api.Success, models.NewListResultWithCount(appWithStatusList, res.TotalCount)))
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/apiserver/service/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func getRunningModelList(token string) ([]*models.ModelStatusResponse, error) {
}

jsonStr, _, err := appservice.LlmStatusList(token)
glog.Infof("LlmStatusList:res:%s", jsonStr)
// glog.Infof("LlmStatusList:res:%s", jsonStr)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -161,7 +161,7 @@ func parseAppTypes(res *models.ListResultD) []string {
return stringItems
}

func parseAppInfos(res *models.ListResultD, appsMap map[string]appservice.Application, workflowMap map[string]*models.StatusData, middlewareMap map[string]*models.StatusData) []*models.ApplicationInfo {
func parseAppInfos(h *Handler, res *models.ListResultD, appsMap map[string]appservice.Application, workflowMap map[string]*models.StatusData, middlewareMap map[string]*models.StatusData) []*models.ApplicationInfo {

var appWithStatusList []*models.ApplicationInfo
for _, item := range res.Items {
Expand All @@ -184,6 +184,10 @@ func parseAppInfos(res *models.ListResultD, appsMap map[string]appservice.Applic
continue
}

// merge app info
info.Progress = h.commonWatchDogManager.GetProgress(info.Name)
info.Progress = h.watchDogManager.GetProgress(info.Name)

appWithStatusList = append(appWithStatusList, info)
}

Expand Down Expand Up @@ -329,7 +333,7 @@ func upgradeByType(info *models.ApplicationInfo, token string) (string, error) {
}

func respJsonWithOriginBody(resp *restful.Response, body string) {
glog.Info("body:", body)
// glog.Info("body:", body)
info := make(map[string]interface{})
err := json.Unmarshal([]byte(body), &info)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions pkg/utils/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/golang/glog"
"io"
"market/internal/constants"
"net"
"net/http"
"os"
"sync"
"time"

"github.com/golang/glog"
)

var (
Expand Down Expand Up @@ -120,7 +121,7 @@ func SendHttpRequest(req *http.Request) (string, error) {
if len(debugBody) > 256 {
debugBody = debugBody[:256]
}
glog.Infof("url:%s, method:%s, resp.StatusCode:%d, body:%s", req.URL, req.Method, resp.StatusCode, debugBody)
// glog.Infof("url:%s, method:%s, resp.StatusCode:%d, body:%s", req.URL, req.Method, resp.StatusCode, debugBody)

return string(body), nil
}
Expand Down Expand Up @@ -153,7 +154,7 @@ func SendHttpRequestByte(req *http.Request) ([]byte, error) {
if len(debugBody) > 256 {
debugBody = debugBody[:256]
}
glog.Infof("url:%s, method:%s, resp.StatusCode:%d, body:%s", req.URL, req.Method, resp.StatusCode, debugBody)
// glog.Infof("url:%s, method:%s, resp.StatusCode:%d, body:%s", req.URL, req.Method, resp.StatusCode, debugBody)

return body, nil
}
Expand Down
Loading