diff --git a/curiosrc/web/api/config/config.go b/curiosrc/web/api/config/config.go index 6f9598f7f..414ee7e6f 100644 --- a/curiosrc/web/api/config/config.go +++ b/curiosrc/web/api/config/config.go @@ -11,12 +11,15 @@ import ( "github.com/BurntSushi/toml" "github.com/gorilla/mux" "github.com/invopop/jsonschema" + logging "github.com/ipfs/go-log/v2" "github.com/filecoin-project/lotus/cmd/curio/deps" "github.com/filecoin-project/lotus/curiosrc/web/api/apihelper" "github.com/filecoin-project/lotus/node/config" ) +var log = logging.Logger("curio/web/config") + type cfg struct { *deps.Deps } @@ -30,9 +33,29 @@ func Routes(r *mux.Router, deps *deps.Deps) { // At edit.html: r.Methods("GET").Path("/schema").HandlerFunc(getSch) r.Methods("GET").Path("/layers/{layer}").HandlerFunc(c.getLayer) + r.Methods("POST").Path("/addlayer").HandlerFunc(c.addLayer) r.Methods("POST").Path("/layers/{layer}").HandlerFunc(c.setLayer) r.Methods("GET").Path("/default").HandlerFunc(c.def) } + +func (c *cfg) addLayer(w http.ResponseWriter, r *http.Request) { + var layer struct { + Name string + } + apihelper.OrHTTPFail(w, json.NewDecoder(r.Body).Decode(&layer)) + ct, err := c.DB.Exec(context.Background(), `INSERT INTO harmony_config (title, config) VALUES ($1, $2)`, layer.Name, "") + apihelper.OrHTTPFail(w, err) + if ct != 1 { + w.WriteHeader(http.StatusConflict) + _, err = w.Write([]byte("Layer already exists")) + if err != nil { + log.Errorf("Failed to write response: %s", err) + } + return + } + w.WriteHeader(200) +} + func getSch(w http.ResponseWriter, r *http.Request) { ref := jsonschema.Reflector{ Mapper: func(i reflect.Type) *jsonschema.Schema { diff --git a/curiosrc/web/hapi/simpleinfo.go b/curiosrc/web/hapi/simpleinfo.go index 11877db15..0e9847c4b 100644 --- a/curiosrc/web/hapi/simpleinfo.go +++ b/curiosrc/web/hapi/simpleinfo.go @@ -13,6 +13,7 @@ import ( "text/template" "time" + "github.com/dustin/go-humanize" "github.com/gorilla/mux" "github.com/samber/lo" "golang.org/x/xerrors" @@ -517,7 +518,10 @@ type machineSummary struct { ID int64 SinceContact string - RecentTasks []*machineRecentTask + RecentTasks []*machineRecentTask + Cpu int + RamHumanized string + Gpu int } type taskSummary struct { @@ -580,7 +584,7 @@ func (a *app) clusterMachineSummary(ctx context.Context) ([]machineSummary, erro } // Then machine summary - rows, err := a.db.Query(ctx, "SELECT id, host_and_port, last_contact FROM harmony_machines order by host_and_port asc") + rows, err := a.db.Query(ctx, "SELECT id, host_and_port, CURRENT_TIMESTAMP - last_contact AS last_contact, cpu, ram, gpu FROM harmony_machines order by host_and_port asc") if err != nil { return nil, err // Handle error } @@ -589,13 +593,14 @@ func (a *app) clusterMachineSummary(ctx context.Context) ([]machineSummary, erro var summaries []machineSummary for rows.Next() { var m machineSummary - var lastContact time.Time + var lastContact time.Duration + var ram int64 - if err := rows.Scan(&m.ID, &m.Address, &lastContact); err != nil { + if err := rows.Scan(&m.ID, &m.Address, &lastContact, &m.Cpu, &ram, &m.Gpu); err != nil { return nil, err // Handle error } - - m.SinceContact = time.Since(lastContact).Round(time.Second).String() + m.SinceContact = lastContact.Round(time.Second).String() + m.RamHumanized = humanize.Bytes(uint64(ram)) // Add recent tasks if ts, ok := taskSummaries[m.Address]; ok { diff --git a/curiosrc/web/hapi/web/cluster_machines.gohtml b/curiosrc/web/hapi/web/cluster_machines.gohtml index 5fb18b52c..6c04b2871 100644 --- a/curiosrc/web/hapi/web/cluster_machines.gohtml +++ b/curiosrc/web/hapi/web/cluster_machines.gohtml @@ -3,6 +3,9 @@ {{.Address}} {{.ID}} + {{.Cpu}} + {{.RamHumanized}} + {{.Gpu}} {{.SinceContact}} {{range .RecentTasks}} {{.TaskName}}:{{.Success}}{{if ne 0 .Fail}}({{.Fail}}){{end}} diff --git a/curiosrc/web/hapi/web/node_info.gohtml b/curiosrc/web/hapi/web/node_info.gohtml index 16f60a475..98e56afd8 100644 --- a/curiosrc/web/hapi/web/node_info.gohtml +++ b/curiosrc/web/hapi/web/node_info.gohtml @@ -1,6 +1,6 @@ {{define "node_info"}}

Info

- +
@@ -22,7 +22,7 @@
Host ID

Storage

- +
@@ -56,7 +56,7 @@

Tasks

Running

-
ID Type
+
@@ -73,7 +73,7 @@ {{end}}
ID Task

Recently Finished

- +
diff --git a/curiosrc/web/hapi/web/root.gohtml b/curiosrc/web/hapi/web/root.gohtml index 114db6462..8fe3ba71a 100644 --- a/curiosrc/web/hapi/web/root.gohtml +++ b/curiosrc/web/hapi/web/root.gohtml @@ -1,10 +1,11 @@ {{define "root"}} +{{.PageTitle}} - - + + diff --git a/curiosrc/web/static/config/index.html b/curiosrc/web/static/config/index.html index 769929e53..28a11f6d9 100644 --- a/curiosrc/web/static/config/index.html +++ b/curiosrc/web/static/config/index.html @@ -22,6 +22,7 @@ this.loadData(); this.message = this.readCookie('message'); this.eraseCookie('message'); + this.addName = ''; } static get styles() { return [css` @@ -46,6 +47,13 @@ `)}
ID Task
+ + +
+ + To delete a layer, use ysqlsh to issue the following command:
+ DELETE FROM curio.harmony_config WHERE title = 'my_layer_name'; +
`; } loadData() { @@ -77,6 +85,26 @@ eraseCookie(name) { document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; } + + updateName(e) { + this.addName = e.target.value; + } + addLayer() { + // get a name + var v = this.addName; + if (v === '') { + alert('Error: Layer name cannot be empty'); + return; + } + + axios.post('/api/config/addlayer', { name: v }) + .then(response => { + window.location.href = '/config/edit.html?layer=' + v; + }) + .catch(error => { + alert('Error adding layer:', error); + }); + } }); diff --git a/curiosrc/web/static/index.html b/curiosrc/web/static/index.html index 0d734d6b7..57c6d4856 100644 --- a/curiosrc/web/static/index.html +++ b/curiosrc/web/static/index.html @@ -60,7 +60,7 @@
-
+

Chain Connectivity

@@ -71,7 +71,7 @@

Chain Connectivity

-
+

Cluster Machines

@@ -79,6 +79,9 @@

Cluster Machines

+ + + @@ -93,7 +96,7 @@

Cluster Machines

Host IDCPUsRAMGPUs Last Contact Tasks (24h)
@@ -120,7 +123,7 @@

PoRep Pipeline

-
+

Actor Summary

@@ -133,7 +136,7 @@

Actor Summary

- + @@ -147,7 +150,7 @@

Actor Summary

-
+

Recently Finished Tasks

Balance Available WorkerWinsWins
@@ -174,7 +177,7 @@

Recently Finished Tasks

-
+

Cluster Tasks

diff --git a/lib/harmony/resources/getGPU_darwin.go b/lib/harmony/resources/getGPU_darwin.go index a9c0a33cd..b977ec638 100644 --- a/lib/harmony/resources/getGPU_darwin.go +++ b/lib/harmony/resources/getGPU_darwin.go @@ -4,5 +4,5 @@ package resources func getGPUDevices() float64 { - return 10000.0 // unserious value intended for non-production use. + return 1.0 // likely-true value intended for non-production use. }