11package historyserver
22
33import (
4+ "context"
45 "encoding/json"
6+ "fmt"
57 "io"
68 "net/http"
79 "os"
810 "path"
911 "path/filepath"
1012 "sort"
13+ "time"
1114
1215 "github.com/emicklei/go-restful/v3"
1316 "github.com/ray-project/kuberay/historyserver/utils"
@@ -17,14 +20,83 @@ import (
1720func (s * ServerHandler ) listClusters (limit int ) []utils.ClusterInfo {
1821 // 初始的继续标记
1922 logrus .Debugf ("Prepare to get list clusters info ..." )
23+ ctx := context .Background ()
24+ liveClusters , _ := s .clientManager .ListRayClusters (ctx )
25+ liveClusterNames := []string {}
26+ liveClusterInfos := []utils.ClusterInfo {}
27+ for _ , liveCluster := range liveClusters {
28+ liveClusterInfo := utils.ClusterInfo {
29+ Name : liveCluster .Name ,
30+ Namespace : liveCluster .Namespace ,
31+ CreateTime : liveCluster .CreationTimestamp .String (),
32+ CreateTimeStamp : liveCluster .CreationTimestamp .Unix (),
33+ SessionName : "live" ,
34+ }
35+ liveClusterInfos = append (liveClusterInfos , liveClusterInfo )
36+ liveClusterNames = append (liveClusterNames , liveCluster .Name )
37+ }
38+ logrus .Infof ("live clusters: %v" , liveClusterNames )
2039 clusters := s .reader .List ()
2140 sort .Sort (utils .ClusterInfoList (clusters ))
2241 if limit > 0 {
2342 clusters = clusters [:limit ]
2443 }
44+ clusters = append (liveClusterInfos , clusters ... )
2545 return clusters
2646}
2747
48+ func (s * ServerHandler ) _getNodeLogs (rayClusterNameID , sessionId , nodeId , dir string ) ([]byte , error ) {
49+ logPath := path .Join (sessionId , "logs" , nodeId )
50+ if dir != "" {
51+ logPath = path .Join (logPath , dir )
52+ }
53+ files := s .reader .ListFiles (rayClusterNameID , logPath )
54+ ret := map [string ]interface {}{
55+ "data" : map [string ]interface {}{
56+ "result" : map [string ]interface {}{
57+ "padding" : files ,
58+ },
59+ },
60+ }
61+ return json .Marshal (ret )
62+ }
63+
64+ func (s * ServerHandler ) GetNodes (rayClusterNameID , sessionId string ) ([]byte , error ) {
65+ logPath := path .Join (sessionId , "logs" )
66+ nodes := s .reader .ListFiles (rayClusterNameID , logPath )
67+ templ := map [string ]interface {}{
68+ "result" : true ,
69+ "msg" : "Node summary fetched." ,
70+ "data" : map [string ]interface {}{
71+ "summary" : []map [string ]interface {}{},
72+ },
73+ }
74+ nodeSummary := []map [string ]interface {}{}
75+ for _ , node := range nodes {
76+ nodeSummary = append (nodeSummary , map [string ]interface {}{
77+ "raylet" : map [string ]interface {}{
78+ "nodeId" : path .Clean (node ),
79+ "state" : "ALIVE" ,
80+ },
81+ "ip" : "UNKNOWN" ,
82+ })
83+ }
84+ templ ["data" ].(map [string ]interface {})["summary" ] = nodeSummary
85+ return json .Marshal (templ )
86+ }
87+
88+ func (s * ServerHandler ) ClusterInfo (rayClusterNameID string ) []byte {
89+ templ := `{
90+ "result": true,
91+ "msg": "Got formatted cluster status.",
92+ "data": {
93+ "clusterStatus": "======== Autoscaler status: %f ========\nNode status\n---------------------------------------------------------------\nActive:\n (no active nodes)\nIdle:\n 0 headgroup\nPending:\n (no pending nodes)\nRecent failures:\n (no failures)\n\nResources\n---------------------------------------------------------------\nTotal Usage:\n 0B/0B memory\n 0B/0B object_store_memory\n\nFrom request_resources:\n (none)\nPending Demands:\n (no resource demands)"
94+ }
95+ }`
96+ afterRender := fmt .Sprintf (templ , time .Now ().Format ("2006-01-02 15:04:05.000000" ))
97+ return []byte (afterRender )
98+ }
99+
28100func (s * ServerHandler ) MetaKeyInfo (rayClusterNameID , key string ) []byte {
29101 baseObject := path .Join (utils .GetMetaDirByNameID (s .rootDir , rayClusterNameID ), key )
30102 logrus .Infof ("Prepare to get object %s info ..." , baseObject )
@@ -37,8 +109,8 @@ func (s *ServerHandler) MetaKeyInfo(rayClusterNameID, key string) []byte {
37109 return data
38110}
39111
40- func (s * ServerHandler ) LogKeyInfo (rayClusterNameID , nodeID , key string , lines int64 ) []byte {
41- baseObject := path .Join (utils .GetLogDirByNameID (s .rootDir , rayClusterNameID , nodeID ), key )
112+ func (s * ServerHandler ) LogKeyInfo (rayClusterNameID , nodeID , sessionId , key string , lines int64 ) []byte {
113+ baseObject := path .Join (utils .GetLogDirByNameID (s .rootDir , rayClusterNameID , nodeID , sessionId ), key )
42114 logrus .Infof ("Prepare to get object %s info ..." , baseObject )
43115 body := s .reader .GetContent (rayClusterNameID , baseObject )
44116 data , err := io .ReadAll (body )
@@ -56,8 +128,22 @@ func (s *ServerHandler) staticFileHandler(req *restful.Request, resp *restful.Re
56128 // Get the path parameter
57129 path := req .PathParameter ("path" )
58130
131+ isHomePage := true
132+ _ , err := req .Request .Cookie (COOKIE_CLUSTER_NAME_KEY )
133+ isHomePage = err != nil
134+ prefix := ""
135+ if isHomePage {
136+ prefix = "homepage"
137+ } else {
138+ version := "v2.51.0"
139+ if versionCookie , err := req .Request .Cookie (COOKIE_DASHBOARD_VERSION_KEY ); err == nil {
140+ version = versionCookie .Value
141+ }
142+ prefix = version + "/client/build"
143+ }
144+
59145 // Construct the full path to the static directory
60- fullPath := filepath .Join (s .dashboardDir , "static" , path )
146+ fullPath := filepath .Join (s .dashboardDir , prefix , "static" , path )
61147 logrus .Infof ("staticFileHandler fullpath %s" , fullPath )
62148
63149 // Check if the full path exists
0 commit comments