diff --git a/internal/watchdog/dog.go b/internal/watchdog/dog.go index 3267eec..8a795e1 100644 --- a/internal/watchdog/dog.go +++ b/internal/watchdog/dog.go @@ -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() @@ -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 } diff --git a/internal/watchdog/event.go b/internal/watchdog/event.go index 85f3d51..7e85eed 100644 --- a/internal/watchdog/event.go +++ b/internal/watchdog/event.go @@ -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() @@ -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 } diff --git a/pkg/apiserver/service/v1/handler.go b/pkg/apiserver/service/v1/handler.go index a7dd40b..89e79f6 100644 --- a/pkg/apiserver/service/v1/handler.go +++ b/pkg/apiserver/service/v1/handler.go @@ -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))) } @@ -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))) } @@ -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))) } @@ -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))) } @@ -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))) } diff --git a/pkg/apiserver/service/v1/helper.go b/pkg/apiserver/service/v1/helper.go index 543ce61..e9852d2 100644 --- a/pkg/apiserver/service/v1/helper.go +++ b/pkg/apiserver/service/v1/helper.go @@ -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 } @@ -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 { @@ -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) } @@ -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 { diff --git a/pkg/utils/http_client.go b/pkg/utils/http_client.go index b69b37a..818c106 100644 --- a/pkg/utils/http_client.go +++ b/pkg/utils/http_client.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/golang/glog" "io" "market/internal/constants" "net" @@ -13,6 +12,8 @@ import ( "os" "sync" "time" + + "github.com/golang/glog" ) var ( @@ -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 } @@ -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 }