This commit is contained in:
root 2025-02-18 11:18:39 +08:00
parent 61136b7f0c
commit 9f64055191
3 changed files with 26 additions and 3 deletions

View File

@ -1,4 +1,4 @@
title "ContextOS 研发平台"
title "ContextOS-Cluster"
refer `
网址 https://dev.shylinux.com
`

View File

@ -0,0 +1 @@
export ctx_dev={{.Option "domain"}}{{.Option "ctx_env"}}; {{.Option "ctx_cli"}} binary {{.Option "ctx_arg"}}

View File

@ -1,9 +1,13 @@
package travel
import (
"path"
"shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/tcp"
"shylinux.com/x/icebergs/base/web"
"shylinux.com/x/icebergs/core/code"
kit "shylinux.com/x/toolkits"
@ -12,16 +16,32 @@ import (
type travel struct {
ice.Space
script string `name:"create name*=2025-cluster port*=40000 count*=3" icon:"bi bi-terminal"`
list string `name:"list space auto" help:"集群管理"`
foreach string `name:"foreach" help:"遍历" icon:"bi bi-card-list"`
}
func (s travel) Script(m *ice.Message, arg ...string) {
for i := 0; i < kit.Int(m.Option(mdb.COUNT)); i++ {
m.Option(cli.CTX_ENV, cli.CTX_NAME, m.Option(mdb.NAME)+kit.Format(i))
m.Option(cli.CTX_ARG, kit.JoinCmdArgs(ice.DEV, m.Option(ice.MSG_USERHOST), tcp.NODENAME, m.Option(mdb.NAME)+kit.Format(i), tcp.PORT, kit.Format(kit.Int(m.Option(tcp.PORT))+i)))
m.Cmdy(code.PUBLISH, nfs.BINARY)
}
m.Action(s.Foreach, s.Script)
}
func (s travel) List(m *ice.Message, arg ...string) {
if len(arg) == 0 {
stat := map[string]int{}
m.SpaceListServer().Table(func(value ice.Maps) { stat[value[nfs.MODULE]]++ })
kit.For([]string{
"2025-dev.shylinux.com/x/20250213-machine",
"2025-dev.shylinux.com/x/20250211-service",
}, func(key string) {
m.Push(path.Base(key), stat[key])
})
m.Push(nfs.VERSION, ice.Info.Make.Version)
m.Push(mdb.TIME, ice.Info.Make.Time)
m.Cmdy(code.PUBLISH, nfs.BINARY)
m.Action(s.Foreach)
m.Cmdy("", s.Script)
} else {
m.Cmdy(web.SPACE, arg[0], m.PrefixKey())
}
@ -34,9 +54,11 @@ func (s travel) Upgrade(m *ice.Message, arg ...string) {
}
func (s travel) Concurrent(m *ice.Message, arg ...string) {
m.SpaceListServer().TableGo(func(value ice.Maps, lock *task.Lock) { s.pushRecord(m, value, arg...) })
m.SortStrR(web.SPACE)
}
func (s travel) Sequential(m *ice.Message, arg ...string) {
m.SpaceListServer().Table(func(value ice.Maps) { s.pushRecord(m, value, arg...) })
m.SortStrR(web.SPACE)
}
func (s travel) pushRecord(m *ice.Message, value ice.Maps, arg ...string) {
if value[nfs.MODULE] == arg[0] {