diff --git a/.gitignore b/.gitignore index 8d08402..8356ea9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ iam test.go inagent/daemon/ssh.go go.sum +todo.md +*.pb.rs +*.pb.thunks.cc diff --git a/Makefile b/Makefile index c784b36..08ee5e5 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ PROTOC_CMD = protoc -PROTOC_ARGS = --proto_path=./inapi --go_opt=paths=source_relative --go_out=./inapi --go-grpc_out=./inapi ./inapi/*.proto -PROTOC_RUST_ARGS = --proto_path=./inapi --rust_out=experimental-codegen=enabled,kernel=cpp:./inapi ./inapi/*.proto +PROTOC_ARGS = --proto_path=./api --go_opt=paths=source_relative --go_out=./inapi --go-grpc_out=./inapi ./api/*.proto +PROTOC_RUST_ARGS = --proto_path=./api --rust_out=experimental-codegen=enabled,kernel=cpp:./inapi ./api/*.proto HTOML_TAG_FIX_CMD = htoml-tag-fix HTOML_TAG_FIX_ARGS = ./inapi @@ -22,7 +22,7 @@ endif .PHONY: api api: $(QUIET_BUILD)$(PROTOC_CMD) $(PROTOC_ARGS) $(CCLINK) - $(QUIET_BUILD)$(PROTOC_CMD) $(PROTOC_RUST_ARGS) $(CCLINK) + # $(QUIET_BUILD)$(PROTOC_CMD) $(PROTOC_RUST_ARGS) $(CCLINK) $(QUIET_BUILD)$(HTOML_TAG_FIX_CMD) $(HTOML_TAG_FIX_ARGS) $(CCLINK) .PHONY: api-in-runc diff --git a/inapi/app.proto b/api/app.proto similarity index 100% rename from inapi/app.proto rename to api/app.proto diff --git a/inapi/cluster.proto b/api/cluster.proto similarity index 100% rename from inapi/cluster.proto rename to api/cluster.proto diff --git a/inapi/config.proto b/api/config.proto similarity index 100% rename from inapi/config.proto rename to api/config.proto diff --git a/inapi/inapi.proto b/api/inapi.proto similarity index 100% rename from inapi/inapi.proto rename to api/inapi.proto diff --git a/inapi/mail.proto b/api/mail.proto similarity index 100% rename from inapi/mail.proto rename to api/mail.proto diff --git a/inapi/operator.proto b/api/operator.proto similarity index 100% rename from inapi/operator.proto rename to api/operator.proto diff --git a/inapi/pod.proto b/api/pod.proto similarity index 100% rename from inapi/pod.proto rename to api/pod.proto diff --git a/inapi/stats.proto b/api/stats.proto similarity index 100% rename from inapi/stats.proto rename to api/stats.proto diff --git a/config/config.go b/config/config.go index fee85cf..7aa7a9b 100644 --- a/config/config.go +++ b/config/config.go @@ -30,7 +30,8 @@ import ( "github.com/hooto/htoml4g/htoml" iamcfg "github.com/hooto/iam/config" "github.com/lessos/lessgo/crypto/idhash" - "github.com/lynkdb/kvgo" + // "github.com/lynkdb/kvgo" + kvclient "github.com/lynkdb/kvgo/v2/pkg/client" "github.com/sysinner/incore/inapi" ) @@ -98,7 +99,11 @@ type ConfigCommon struct { Zone ZoneConfig `json:"zone" toml:"zone"` ZoneMain *ZoneMainConfig `json:"zone_main,omitempty" toml:"zone_main,omitempty"` IamService *iamcfg.ConfigCommon `json:"iam_service,omitempty" toml:"iam_service,omitempty"` - ZoneData *kvgo.Config `json:"zone_data,omitempty" toml:"zone_data,omitempty"` + // ZoneData *kvgo.Config `json:"zone_data,omitempty" toml:"zone_data,omitempty"` + + GlobDatabase *kvclient.Config `json:"glob_database,omitempty" toml:"glob_database,omitempty"` + ZoneDatabase *kvclient.Config `json:"zone_database,omitempty" toml:"zone_database,omitempty"` + PackDatabase *kvclient.Config `json:"pack_database,omitempty" toml:"pack_database,omitempty"` /** DelZoneIamAccessKey *hauth.AccessKey `json:"zone_iam_access_key,omitempty" toml:"zone_iam_access_key,omitempty"` diff --git a/data/data.go b/data/data.go index fb0fc0b..c5e1003 100644 --- a/data/data.go +++ b/data/data.go @@ -16,24 +16,38 @@ package data import ( "errors" - "strings" + "github.com/hooto/hauth/go/hauth/v1" "github.com/hooto/hlog4g/hlog" - "github.com/lynkdb/kvgo" - kv2 "github.com/lynkdb/kvspec/v2/go/kvspec" + "github.com/hooto/htoml4g/htoml" + // "github.com/lynkdb/kvgo" + kvclient "github.com/lynkdb/kvgo/v2/pkg/client" + "github.com/lynkdb/kvgo/v2/pkg/kvapi" + "github.com/lynkdb/kvgo/v2/pkg/kvrep" + "github.com/lynkdb/kvgo/v2/pkg/storage" + // kv2 "github.com/lynkdb/kvspec/v2/go/kvspec" "github.com/sysinner/incore/config" - "github.com/sysinner/incore/inapi" + // "github.com/sysinner/incore/inapi" ) var ( - dbLocal kv2.Client - dbZone kv2.Client - DataLocal kv2.ClientTable - DataZone kv2.ClientTable - DataGlobal kv2.ClientTable - DataInpack kv2.ClientTable - err error + // dbLocal kv2.Client + // dbZone kv2.Client + + // prevDataLocal kv2.ClientTable + DataLocal kvapi.Client + + // prevDataZone kv2.ClientTable + DataZone kvapi.Client + + // prevDataPack kv2.ClientTable + DataPack kvapi.Client + + // prevDataGlobal kv2.ClientTable + DataGlobal kvapi.Client + + err error ) func Setup() error { @@ -47,23 +61,33 @@ func Setup() error { func setupLocal() error { - if DataLocal == nil { + //// if prevDataLocal == nil { + + //// cfgLocal := &kvgo.Config{ + //// Storage: kvgo.ConfigStorage{ + //// DataDirectory: config.Prefix + "/var/db_local", + //// }, + //// } + + //// cn, err := kvgo.Open(cfgLocal) + //// if err != nil { + //// return err + //// } + //// dbLocal, err = cn.NewClient() + //// if err != nil { + //// return err + //// } + //// prevDataLocal = dbLocal.OpenTable("main") + //// } - cfgLocal := &kvgo.Config{ - Storage: kvgo.ConfigStorage{ - DataDirectory: config.Prefix + "/var/db_local", - }, - } - - cn, err := kvgo.Open(cfgLocal) - if err != nil { - return err - } - dbLocal, err = cn.NewClient() - if err != nil { + if DataLocal == nil { + if c, err := kvrep.NewReplica(&storage.Options{ + DataDirectory: config.Prefix + "/var/inlocal", + }); err != nil { return err + } else { + DataLocal = c } - DataLocal = dbLocal.OpenTable("main") } return nil @@ -79,157 +103,346 @@ func setupZone() error { return errors.New("no zone setup") } - if config.Config.ZoneData == nil { + //// if config.Config.ZoneData == nil { + + //// config.Config.ZoneData = &kvgo.Config{ + //// Storage: kvgo.ConfigStorage{ + //// DataDirectory: config.Prefix + "/var/db_zone", + //// }, + //// } + + //// if err = config.Config.Flush(); err != nil { + //// return err + //// } + //// } + + //// cn, err := kvgo.Open(config.Config.ZoneData) + //// if err != nil { + //// return err + //// } + + //// dbZone, err = cn.NewClient() + //// if err != nil { + //// return err + //// } + + //// dbinit := func(name string) error { + //// req := kv2.NewSysCmdRequest("TableSet", &kv2.TableSetRequest{ + //// Name: name, + //// Desc: "innerstack " + name, + //// }) + + //// rs := dbZone.Connector().SysCmd(req) + //// if !rs.OK() { + //// return rs.Error() + //// } + //// hlog.Printf("info", "db init table setup %s ok", name) + //// return nil + //// } - config.Config.ZoneData = &kvgo.Config{ - Storage: kvgo.ConfigStorage{ - DataDirectory: config.Prefix + "/var/db_zone", - }, + flush := false + + // + //// if prevDataGlobal == nil { + //// if config.Config.ZoneMain.DataTableGlobal == "" { + //// if err := dbinit("global"); err != nil { + //// return err + //// } + //// config.Config.ZoneMain.DataTableGlobal = "global" + //// flush = true + //// } + //// prevDataGlobal = dbZone.OpenTable(config.Config.ZoneMain.DataTableGlobal) + //// UpgradeGlobalData(prevDataGlobal) + //// } + + //// // + //// if prevDataZone == nil { + //// if config.Config.ZoneMain.DataTableZone == "" { + //// if err := dbinit("zone"); err != nil { + //// return err + //// } + //// config.Config.ZoneMain.DataTableZone = "zone" + //// flush = true + //// } + //// prevDataZone = dbZone.OpenTable(config.Config.ZoneMain.DataTableZone) + //// } + + //// // + //// if prevDataPack == nil { + //// if config.Config.ZoneMain.DataTableInpack == "" { + //// if err := dbinit("inpack"); err != nil { + //// return err + //// } + //// config.Config.ZoneMain.DataTableInpack = "inpack" + //// flush = true + //// } + //// prevDataPack = dbZone.OpenTable(config.Config.ZoneMain.DataTableInpack) + //// } + + // auto init database setting + if config.Config.GlobDatabase == nil || + config.Config.ZoneDatabase == nil || + config.Config.PackDatabase == nil { + + var kvConfig struct { + Server struct { + Bind string `toml:"bind"` + AccessKey *hauth.AccessKey `toml:"access_key"` + } `toml:"server"` } - if err = config.Config.Flush(); err != nil { + if err := htoml.DecodeFromFile("/opt/lynkdb/kvgo/etc/kvgo-server.toml", &kvConfig); err != nil { return err } - } - - cn, err := kvgo.Open(config.Config.ZoneData) - if err != nil { - return err - } - - dbZone, err = cn.NewClient() - if err != nil { - return err - } - dbinit := func(name string) error { - req := kv2.NewSysCmdRequest("TableSet", &kv2.TableSetRequest{ - Name: name, - Desc: "innerstack " + name, - }) + if kvConfig.Server.AccessKey == nil { + return errors.New("kv database config not setup") + } - rs := dbZone.Connector().SysCmd(req) - if !rs.OK() { - return rs.Error() + cc := &kvclient.Config{ + Addr: kvConfig.Server.Bind, + AccessKey: &hauth.AccessKey{ + Id: kvConfig.Server.AccessKey.Id, + Secret: kvConfig.Server.AccessKey.Secret, + }, } - hlog.Printf("info", "db init table setup %s ok", name) - return nil - } - flush := false + ac, err := cc.NewAdminClient() + if err != nil { + return err + } - // - if DataZone == nil { - if config.Config.ZoneMain.DataTableZone == "" { - if err := dbinit("zone"); err != nil { - return err + if config.Config.GlobDatabase == nil { + if rs := ac.DatabaseCreate(&kvapi.DatabaseCreateRequest{ + Name: "inglob", + }); !rs.OK() && rs.StatusCode != kvapi.Status_Conflict { + return rs.Error() + } + config.Config.GlobDatabase = &kvclient.Config{ + Database: "inglob", + Addr: kvConfig.Server.Bind, + AccessKey: kvConfig.Server.AccessKey, } - config.Config.ZoneMain.DataTableZone = "zone" - flush = true } - DataZone = dbZone.OpenTable(config.Config.ZoneMain.DataTableZone) - } - // - if DataGlobal == nil { - if config.Config.ZoneMain.DataTableGlobal == "" { - if err := dbinit("global"); err != nil { - return err + if config.Config.ZoneDatabase == nil { + if rs := ac.DatabaseCreate(&kvapi.DatabaseCreateRequest{ + Name: "inzone", + }); !rs.OK() && rs.StatusCode != kvapi.Status_Conflict { + return rs.Error() + } + config.Config.ZoneDatabase = &kvclient.Config{ + Database: "inzone", + Addr: kvConfig.Server.Bind, + AccessKey: kvConfig.Server.AccessKey, } - config.Config.ZoneMain.DataTableGlobal = "global" - flush = true } - DataGlobal = dbZone.OpenTable(config.Config.ZoneMain.DataTableGlobal) - UpgradeGlobalData(DataGlobal) - } - // - if DataInpack == nil { - if config.Config.ZoneMain.DataTableInpack == "" { - if err := dbinit("inpack"); err != nil { - return err + if config.Config.PackDatabase == nil { + if rs := ac.DatabaseCreate(&kvapi.DatabaseCreateRequest{ + Name: "inpack", + }); !rs.OK() && rs.StatusCode != kvapi.Status_Conflict { + return rs.Error() + } + config.Config.PackDatabase = &kvclient.Config{ + Database: "inpack", + Addr: kvConfig.Server.Bind, + AccessKey: kvConfig.Server.AccessKey, } - config.Config.ZoneMain.DataTableInpack = "inpack" - flush = true } - DataInpack = dbZone.OpenTable(config.Config.ZoneMain.DataTableInpack) - } - if flush { - if err = config.Config.Flush(); err != nil { - return err - } + flush = true } - return nil -} - -func UpgradeGlobalData(data kv2.ClientTable) error { - - if data == nil { - return errors.New("Upgrade Global Data kv2.ClientConnector Not Found") + // upgrade ... + if DataGlobal, err = config.Config.GlobDatabase.NewClient(); err != nil { + hlog.Printf("info", "glob database new client err %s", err.Error()) + return err + } else { + hlog.Printf("info", "glob database client setup ok") } - rs := data.NewReader(nil).KeyRangeSet( - inapi.NsGlobalAppSpec(""), inapi.NsGlobalAppSpec("zzzz")). - LimitNumSet(200).Query() - - for _, v := range rs.Items { - - var spec inapi.AppSpec - if err := v.Decode(&spec); err != nil { - continue - } - var specPrev inapi.AppSpecPrev - if err := v.Decode(&specPrev); err != nil { - continue - } - - prekey := inapi.NsKvGlobalAppSpecVersion(spec.Meta.ID, "") - - rs2 := data.NewReader(nil).KeyRangeSet( - prekey, append(prekey, 0xff)).LimitNumSet(200).Query() - if rs2.OK() { - - for _, v2 := range rs2.Items { + if DataZone, err = config.Config.ZoneDatabase.NewClient(); err != nil { + hlog.Printf("info", "zone database new client err %s", err.Error()) + return err + } else { + hlog.Printf("info", "zone database client setup ok") + } - k := strings.TrimPrefix(string(v2.Meta.Key), string(prekey)) - if len(k) > 24 { - continue - } + if DataPack, err = config.Config.PackDatabase.NewClient(); err != nil { + hlog.Printf("info", "inpack database new client err %s", err.Error()) + return err + } else { + hlog.Printf("info", "inpack database client setup ok") + } - var pspec inapi.AppSpec - if err := v2.Decode(&pspec); err != nil { - continue - } + // upgrade ... + if true { + // dataTransfer(DataGlobal, prevDataGlobal, "inglob") + } - if rs3 := data.NewWriter(inapi.NsKvGlobalAppSpecVersion(spec.Meta.ID, pspec.Meta.Version), pspec).Commit(); rs3.OK() { + if true { + // dataTransfer(DataZone, prevDataZone, "inzone") + } - data.NewWriter(v2.Meta.Key, nil, nil).ModeDeleteSet(true).Commit() - } - } - } + if true { + // go dataTransfer(DataPack, prevDataPack, "inpack") + } - if specPrev.Meta.Version != spec.Meta.Version { - data.NewWriter(inapi.NsGlobalAppSpec(spec.Meta.ID), spec).Commit() - hlog.Printf("info", "AppSpec %s version %s -> %s", - spec.Meta.ID, specPrev.Meta.Version, spec.Meta.Version) + if flush { + if err = config.Config.Flush(); err != nil { + return err } } return nil } +//// func UpgradeGlobalData(data kv2.ClientTable) error { +//// +//// if data == nil { +//// return errors.New("Upgrade Global Data kv2.ClientConnector Not Found") +//// } +//// +//// rs := data.NewReader(nil).KeyRangeSet( +//// inapi.NsGlobalAppSpec(""), inapi.NsGlobalAppSpec("zzzz")). +//// LimitNumSet(200).Query() +//// +//// for _, v := range rs.Items { +//// +//// var spec inapi.AppSpec +//// if err := v.Decode(&spec); err != nil { +//// continue +//// } +//// var specPrev inapi.AppSpecPrev +//// if err := v.Decode(&specPrev); err != nil { +//// continue +//// } +//// +//// prekey := inapi.NsKvGlobalAppSpecVersion(spec.Meta.ID, "") +//// +//// rs2 := data.NewReader(nil).KeyRangeSet( +//// prekey, append(prekey, 0xff)).LimitNumSet(200).Query() +//// if rs2.OK() { +//// +//// for _, v2 := range rs2.Items { +//// +//// k := strings.TrimPrefix(string(v2.Meta.Key), string(prekey)) +//// if len(k) > 24 { +//// continue +//// } +//// +//// var pspec inapi.AppSpec +//// if err := v2.Decode(&pspec); err != nil { +//// continue +//// } +//// +//// if rs3 := data.NewWriter(inapi.NsKvGlobalAppSpecVersion(spec.Meta.ID, pspec.Meta.Version), pspec).Commit(); rs3.OK() { +//// +//// data.NewWriter(v2.Meta.Key, nil, nil).ModeDeleteSet(true).Commit() +//// } +//// } +//// } +//// +//// if specPrev.Meta.Version != spec.Meta.Version { +//// data.NewWriter(inapi.NsGlobalAppSpec(spec.Meta.ID), spec).Commit() +//// hlog.Printf("info", "AppSpec %s version %s -> %s", +//// spec.Meta.ID, specPrev.Meta.Version, spec.Meta.Version) +//// } +//// } +//// +//// return nil +//// } + func Close() error { - for _, db := range []kv2.Client{ - dbLocal, - dbZone, - } { - if db != nil { - db.Close() - } - } + // for _, db := range []kv2.Client{ + // dbLocal, + // dbZone, + // } { + // if db != nil { + // db.Close() + // } + // } return nil } + +//// func dataTransfer(dst kvapi.Client, src kv2.ClientTable, desc string) error { +//// +//// var ( +//// offset = []byte{0x00} +//// cutset = []byte{0xff} +//// +//// tn = time.Now().UnixNano() / 1e6 +//// +//// statsReqN int +//// statsTtlN int +//// statsIncN int +//// statsHitN int +//// statsHitOK int +//// statsHitER int +//// +//// statsSize int64 +//// ) +//// +//// for { +//// rs := src.NewReader(nil).KeyRangeSet(offset, cutset). +//// LimitNumSet(200).Query() +//// statsReqN += 1 +//// for _, v := range rs.Items { +//// +//// offset = v.Meta.Key +//// statsHitN += 1 +//// +//// if len(v.Data.Value) <= 1 || (v.Data.Value[0] != 0 && v.Data.Value[0] != 2) { +//// statsHitER += 1 +//// continue +//// } +//// +//// statsSize += int64(len(v.Data.Value)) +//// +//// wr := dst.NewWriter(v.Meta.Key, v.Data.Value[1:]).SetCreateOnly(true) +//// +//// if v.Meta.Expired > 0 { +//// +//// statsTtlN += 1 +//// +//// ttl := int64(v.Meta.Expired) - tn +//// +//// if ttl > 0 { +//// wr.SetTTL(ttl) +//// } +//// +//// hlog.Printf("info", "transfer %s, key %s, val %d, TTL %d sec", +//// desc, string(v.Meta.Key), len(v.Data.Value), ttl/1e3) +//// } +//// +//// if v.Meta.IncrId > 0 { +//// wr.SetIncr(v.Meta.IncrId, "") +//// statsIncN += 1 +//// +//// hlog.Printf("info", "transfer %s, key %s, val %d, Incr %d", +//// desc, string(v.Meta.Key), len(v.Data.Value), v.Meta.IncrId) +//// } +//// +//// if rs2 := wr.Exec(); rs2.OK() { +//// statsHitOK += 1 +//// hlog.Printf("info", "transfer %s, key %s, val %d, version %d", +//// desc, string(v.Meta.Key), len(v.Data.Value), rs2.Meta().Version) +//// } else { +//// statsHitER += 1 +//// hlog.Printf("info", "transfer %s, key %s, err %s", desc, string(v.Meta.Key), rs2.ErrorMessage()) +//// } +//// } +//// +//// if len(rs.Items) < 1 { +//// break +//// } +//// } +//// +//// hlog.Printf("info", "transfer %s, reqs %d, keyd %d/%d/%d, ttl %d, incr %d, size %d", +//// desc, statsReqN, statsHitOK, statsHitER, statsHitN, statsTtlN, statsIncN, statsSize) +//// +//// return nil +//// } diff --git a/data/data_util.go b/data/data_util.go index bc24b8e..a393de9 100644 --- a/data/data_util.go +++ b/data/data_util.go @@ -22,13 +22,13 @@ func SysHostUpdate(zoneId string, host *inapi.ResHost) error { if zoneId == host.Operate.ZoneId { if rs := DataZone.NewWriter( - inapi.NsZoneSysHost(zoneId, host.Meta.Id), host).Commit(); !rs.OK() { + inapi.NsZoneSysHost(zoneId, host.Meta.Id), host).Exec(); !rs.OK() { return rs.Error() } } if rs := DataGlobal.NewWriter( - inapi.NsGlobalSysHost(host.Operate.ZoneId, host.Meta.Id), host).Commit(); !rs.OK() { + inapi.NsGlobalSysHost(host.Operate.ZoneId, host.Meta.Id), host).Exec(); !rs.OK() { return rs.Error() } @@ -40,25 +40,23 @@ func SysHostDelete(zoneId string, host *inapi.ResHost) error { if zoneId == host.Operate.ZoneId { if rs := DataZone.NewWriter( - inapi.NsKvZoneSysHostDestroyed(host.Operate.ZoneId, host.Meta.Id), host).Commit(); !rs.OK() { + inapi.NsKvZoneSysHostDestroyed(host.Operate.ZoneId, host.Meta.Id), host).Exec(); !rs.OK() { return rs.Error() } - if rs := DataZone.NewWriter( - inapi.NsZoneSysHost(host.Operate.ZoneId, host.Meta.Id), nil). - ModeDeleteSet(true).Commit(); !rs.OK() { + if rs := DataZone.NewDeleter( + inapi.NsZoneSysHost(host.Operate.ZoneId, host.Meta.Id)).Exec(); !rs.OK() { return rs.Error() } } if rs := DataGlobal.NewWriter( - inapi.NsKvGlobalSysHostDestroyed(host.Operate.ZoneId, host.Meta.Id), host).Commit(); !rs.OK() { + inapi.NsKvGlobalSysHostDestroyed(host.Operate.ZoneId, host.Meta.Id), host).Exec(); !rs.OK() { return rs.Error() } - if rs := DataGlobal.NewWriter( - inapi.NsGlobalSysHost(host.Operate.ZoneId, host.Meta.Id), nil). - ModeDeleteSet(true).Commit(); !rs.OK() { + if rs := DataGlobal.NewDeleter( + inapi.NsGlobalSysHost(host.Operate.ZoneId, host.Meta.Id)).Exec(); !rs.OK() { return rs.Error() } @@ -69,13 +67,13 @@ func SysCellUpdate(zoneId string, cell *inapi.ResCell) error { if zoneId == cell.ZoneId { if rs := DataZone.NewWriter( - inapi.NsZoneSysCell(zoneId, cell.Meta.Id), cell).Commit(); !rs.OK() { + inapi.NsZoneSysCell(zoneId, cell.Meta.Id), cell).Exec(); !rs.OK() { return rs.Error() } } if rs := DataGlobal.NewWriter( - inapi.NsGlobalSysCell(cell.ZoneId, cell.Meta.Id), cell).Commit(); !rs.OK() { + inapi.NsGlobalSysCell(cell.ZoneId, cell.Meta.Id), cell).Exec(); !rs.OK() { return rs.Error() } @@ -89,23 +87,23 @@ func SysCellDelete(zoneId string, cell *inapi.ResCell) error { if zoneId == cell.ZoneId { if rs := DataZone.NewWriter( - inapi.NsKvZoneSysCellDestroyed(cell.ZoneId, cell.Meta.Id), cell).Commit(); !rs.OK() { + inapi.NsKvZoneSysCellDestroyed(cell.ZoneId, cell.Meta.Id), cell).Exec(); !rs.OK() { return rs.Error() } - if rs := DataZone.NewWriter( - inapi.NsZoneSysCell(cell.ZoneId, cell.Meta.Id), nil).ModeDeleteSet(true).Commit(); !rs.OK() { + if rs := DataZone.NewDeleter( + inapi.NsZoneSysCell(cell.ZoneId, cell.Meta.Id)).Exec(); !rs.OK() { return rs.Error() } } if rs := DataGlobal.NewWriter( - inapi.NsKvGlobalSysCellDestroyed(cell.ZoneId, cell.Meta.Id), cell).Commit(); !rs.OK() { + inapi.NsKvGlobalSysCellDestroyed(cell.ZoneId, cell.Meta.Id), cell).Exec(); !rs.OK() { return rs.Error() } - if rs := DataGlobal.NewWriter( - inapi.NsGlobalSysCell(cell.ZoneId, cell.Meta.Id), nil).ModeDeleteSet(true).Commit(); !rs.OK() { + if rs := DataGlobal.NewDeleter( + inapi.NsGlobalSysCell(cell.ZoneId, cell.Meta.Id)).Exec(); !rs.OK() { return rs.Error() } @@ -116,13 +114,13 @@ func SysZoneUpdate(zoneId string, zone *inapi.ResZone) error { if zoneId == zone.Meta.Id { if rs := DataZone.NewWriter( - inapi.NsZoneSysZone(zone.Meta.Id), zone).Commit(); !rs.OK() { + inapi.NsZoneSysZone(zone.Meta.Id), zone).Exec(); !rs.OK() { return rs.Error() } } if rs := DataGlobal.NewWriter( - inapi.NsGlobalSysZone(zone.Meta.Id), zone).Commit(); !rs.OK() { + inapi.NsGlobalSysZone(zone.Meta.Id), zone).Exec(); !rs.OK() { return rs.Error() } @@ -135,18 +133,18 @@ func SysZoneDelete(zoneId string, zone *inapi.ResZone) error { if zoneId == zone.Meta.Id { if rs := DataZone.NewWriter( - inapi.NsZoneSysZone(zone.Meta.Id), zone).Commit(); !rs.OK() { + inapi.NsZoneSysZone(zone.Meta.Id), zone).Exec(); !rs.OK() { return rs.Error() } } if rs := DataGlobal.NewWriter( - inapi.NsKvGlobalSysZoneDestroyed(zone.Meta.Id), zone).Commit(); !rs.OK() { + inapi.NsKvGlobalSysZoneDestroyed(zone.Meta.Id), zone).Exec(); !rs.OK() { return rs.Error() } - if rs := DataGlobal.NewWriter( - inapi.NsGlobalSysZone(zone.Meta.Id), nil).ModeDeleteSet(true).Commit(); !rs.OK() { + if rs := DataGlobal.NewDeleter( + inapi.NsGlobalSysZone(zone.Meta.Id)).Exec(); !rs.OK() { return rs.Error() } diff --git a/go.mod b/go.mod index dcff0cc..2765697 100644 --- a/go.mod +++ b/go.mod @@ -8,47 +8,48 @@ require ( github.com/alibaba/pouch v0.0.0-20230911120100-8680cc4c3a81 github.com/fsnotify/fsnotify v1.6.0 github.com/fsouza/go-dockerclient v1.11.0 - github.com/hooto/hauth v0.1.0 + github.com/hooto/hauth v0.1.2 github.com/hooto/hflag4g v0.10.1 - github.com/hooto/hini4g v0.1.1 + github.com/hooto/hini4g v0.1.2 github.com/hooto/hlang4g v0.1.1 github.com/hooto/hlog4g v0.9.4 github.com/hooto/hmsg v0.1.0 github.com/hooto/htoml4g v0.9.5 - github.com/hooto/httpsrv v0.12.2 - github.com/hooto/iam v0.9.4 + github.com/hooto/httpsrv v0.12.3 + github.com/hooto/iam v1.0.0 github.com/lessos/lessgo v1.0.1 github.com/lynkdb/iomix v0.0.0-20210408130459-cc48edfc442f - github.com/lynkdb/kvgo v1.1.9 - github.com/lynkdb/kvspec/v2 v2.0.4 - github.com/shirou/gopsutil/v3 v3.24.1 + github.com/lynkdb/kvgo/v2 v2.0.3 + github.com/shirou/gopsutil/v3 v3.24.2 github.com/spf13/cobra v1.8.0 github.com/sysinner/injob v0.1.0 github.com/sysinner/innerstack v0.0.0-20230709093411-b23cc5fbac90 - github.com/sysinner/inpack v0.0.2 + github.com/sysinner/inpack v0.0.3 github.com/sysinner/inpanel v0.0.0-20220827140619-233310e777c7 github.com/sysinner/viper v1.7.2-0.20210407011308-00fddcdabb8a github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.862 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.862 github.com/vishvananda/netlink v1.2.1-beta.2 github.com/yhat/wsutil v0.0.0-20170731153501-1d66fa95c997 - golang.org/x/net v0.22.0 - google.golang.org/grpc v1.62.0 - google.golang.org/protobuf v1.32.0 + golang.org/x/net v0.24.0 + google.golang.org/grpc v1.62.1 + google.golang.org/protobuf v1.33.0 ) require ( github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect - github.com/DataDog/zstd v1.5.2 // indirect + github.com/DataDog/zstd v1.5.5 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/ServiceWeaver/weaver v0.15.0 // indirect github.com/andybalholm/brotli v1.1.0 // indirect github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/cockroachdb/errors v1.9.1 // indirect + github.com/cockroachdb/errors v1.11.1 // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect - github.com/cockroachdb/pebble v0.0.0-20230412222916-60cfeb46143b // indirect - github.com/cockroachdb/redact v1.1.3 // indirect + github.com/cockroachdb/pebble v1.1.0 // indirect + github.com/cockroachdb/redact v1.1.5 // indirect + github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect github.com/containerd/containerd v1.7.14 // indirect github.com/containerd/log v0.1.0 // indirect github.com/contiv/executor v0.0.0-20180626233236-d263f4daa3ad // indirect @@ -56,7 +57,7 @@ require ( github.com/docker/docker v25.0.4+incompatible // indirect github.com/docker/go-connections v0.5.0 // indirect github.com/docker/go-units v0.5.0 // indirect - github.com/getsentry/sentry-go v0.20.0 // indirect + github.com/getsentry/sentry-go v0.26.0 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-openapi/analysis v0.22.2 // indirect github.com/go-openapi/errors v0.21.0 // indirect @@ -68,10 +69,11 @@ require ( github.com/go-openapi/swag v0.22.9 // indirect github.com/go-openapi/validate v0.23.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/protobuf v1.5.3 // indirect + github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect + github.com/hooto/hmetrics v0.0.1 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/klauspost/compress v1.17.7 // indirect @@ -81,7 +83,6 @@ require ( github.com/lynkdb/kvspec v1.0.3 // indirect github.com/magiconair/properties v1.8.1 // indirect github.com/mailru/easyjson v0.7.7 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/moby/patternmatcher v0.6.0 // indirect github.com/moby/sys/sequential v0.5.0 // indirect @@ -94,12 +95,12 @@ require ( github.com/pelletier/go-toml v1.9.5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect - github.com/prometheus/client_golang v1.15.0 // indirect - github.com/prometheus/client_model v0.3.0 // indirect - github.com/prometheus/common v0.42.0 // indirect - github.com/prometheus/procfs v0.9.0 // indirect + github.com/prometheus/client_golang v1.18.0 // indirect + github.com/prometheus/client_model v0.5.0 // indirect + github.com/prometheus/common v0.46.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect github.com/rakyll/statik v0.1.7 // indirect - github.com/rogpeppe/go-internal v1.11.0 // indirect + github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/spf13/afero v1.9.2 // indirect @@ -107,20 +108,18 @@ require ( github.com/spf13/jwalterweatherman v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.2.0 // indirect - github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect - github.com/valuedig/apis v0.1.2 // indirect github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect - github.com/yusufpapurcu/wmi v1.2.3 // indirect + github.com/yusufpapurcu/wmi v1.2.4 // indirect go.mongodb.org/mongo-driver v1.13.1 // indirect - golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect - golang.org/x/image v0.5.0 // indirect + golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect + golang.org/x/image v0.16.0 // indirect golang.org/x/mod v0.16.0 // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/sys v0.19.0 // indirect + golang.org/x/text v0.15.0 // indirect golang.org/x/tools v0.19.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240325203815-454cdb8f5daa // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/hostlet/box/docker/job.go b/hostlet/box/docker/job.go index ae03474..6d282d2 100644 --- a/hostlet/box/docker/job.go +++ b/hostlet/box/docker/job.go @@ -63,6 +63,11 @@ func (it *BoxImageUpdate) Spec() *injob.JobSpec { path: "misc/boximages/docker/g2", tag: "sysinner/innerstack-g2:el7", }, + { + name: "b1", + path: "misc/boximages/docker/b1", + tag: "sysinner/innerstack-b1:v1.0", + }, /** { name: "bg1", diff --git a/hostlet/box/pouch/doc.go b/hostlet/box/pouch/doc.go new file mode 100644 index 0000000..1da36b0 --- /dev/null +++ b/hostlet/box/pouch/doc.go @@ -0,0 +1 @@ +package pouch diff --git a/hostlet/box/pouch/pouch.go b/hostlet/box/pouch/pouch.go index 9e4de3a..62c48db 100644 --- a/hostlet/box/pouch/pouch.go +++ b/hostlet/box/pouch/pouch.go @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build enable_pouch + package pouch import ( diff --git a/hostlet/init.go b/hostlet/init.go index d627a70..4d1bd63 100644 --- a/hostlet/init.go +++ b/hostlet/init.go @@ -48,7 +48,7 @@ func InitData(items map[string]interface{}) error { for k, v := range items { - if rs := data.DataLocal.NewWriter([]byte(k), v).Commit(); !rs.OK() { + if rs := data.DataLocal.NewWriter([]byte(k), v).Exec(); !rs.OK() { return fmt.Errorf("hostlet.initdata error on put key : %s", k) } diff --git a/inagent/daemon/daemon.go b/inagent/daemon/daemon.go index 11408cc..b69e416 100644 --- a/inagent/daemon/daemon.go +++ b/inagent/daemon/daemon.go @@ -113,17 +113,17 @@ func (it *agentDaemonCommand) run(cmd *inapi.BaseCommand, args []string) error { hlog.Printf("info", "inagent/daemon started") // - httpsrv.GlobalService.Config.HttpAddr = addr_sock + httpsrv.DefaultService.Config.HttpAddr = addr_sock /** - httpsrv.GlobalService.HandlerRegister( + httpsrv.DefaultService.HandlerRegister( "/in/v1/pb/termws", websocket.Handler(v1.TerminalWsOpenAction)) */ - httpsrv.GlobalService.ModuleRegister("/in/v1/", v1.NewModule()) + httpsrv.DefaultService.HandleModule("/in/v1/", v1.NewModule()) - go httpsrv.GlobalService.Start() + go httpsrv.DefaultService.Start() // go sshRun() worker() diff --git a/inagent/v1/fs.go b/inagent/v1/fs.go index f491b2e..9f913a9 100644 --- a/inagent/v1/fs.go +++ b/inagent/v1/fs.go @@ -288,7 +288,7 @@ func (c *Fs) ListAction() { // // path := filepath.Clean(req.Path) - path := filepath.Clean(c.Params.Get("path")) + path := filepath.Clean(c.Params.Value("path")) if !strings.HasPrefix(path, "/home/action") { rsp.Error = &types.ErrorMeta{"403", "Forbidden"} return @@ -383,7 +383,7 @@ func (c Fs) GetAction() { defer c.RenderJson(&rsp) - path := filepath.Clean(c.Params.Get("path")) + path := filepath.Clean(c.Params.Value("path")) if !strings.HasPrefix(path, "/home/action") { rsp.Error = &types.ErrorMeta{"403", "Forbidden"} return diff --git a/inagent/v1/health.go b/inagent/v1/health.go index d8c600a..f453bf0 100644 --- a/inagent/v1/health.go +++ b/inagent/v1/health.go @@ -31,7 +31,7 @@ type Health struct { func (c Health) SyncAction() { var ( - action = strings.ToLower(c.Params.Get("action")) + action = strings.ToLower(c.Params.Value("action")) ) switch action { diff --git a/inagent/v1/httpsrv.go b/inagent/v1/httpsrv.go index 1151181..5d5148a 100644 --- a/inagent/v1/httpsrv.go +++ b/inagent/v1/httpsrv.go @@ -20,7 +20,7 @@ import ( func NewModule() *httpsrv.Module { - mod := httpsrv.NewModule("lp-boxlet") + mod := httpsrv.NewModule() mod.SetRoute("/podbound/:podid/:controller/:action", map[string]string{}) diff --git a/inapi/app.go b/inapi/app.go index 406dd29..914a774 100644 --- a/inapi/app.go +++ b/inapi/app.go @@ -165,7 +165,6 @@ func (it *AppSpecDepend) Valid() error { return nil } -// type AppSpec struct { types.TypeMeta `json:",inline" toml:",inline"` Meta types.InnerObjectMeta `json:"meta" toml:"meta"` @@ -216,6 +215,7 @@ func (it *AppSpec) Fix() *AppSpec { it.RuntimeImages = []string{ "sysinner/innerstack-g3:el8", "sysinner/innerstack-g2:el7", + "sysinner/innerstack-b1:v1.0", } } return it @@ -374,7 +374,6 @@ func (ls *AppPackages) Remove(name string) { } } -// type AppVolumeMount struct { Name string `json:"name" toml:"name"` Path string `json:"path" toml:"path"` @@ -383,7 +382,6 @@ type AppVolumeMount struct { type AppVolumeMounts []AppVolumeMount -// type AppConfigurator struct { Name types.NameIdentifier `json:"name" toml:"name"` Fields AppConfigFields `json:"fields,omitempty" toml:"fields,omitempty"` @@ -503,7 +501,6 @@ func (it *AppConfigFieldTypeCA) Valid(field *AppConfigField) error { return nil } -// type AppOperate struct { Action uint32 `json:"action,omitempty" toml:"action,omitempty"` Zone string `json:"zone,omitempty" toml:"zone,omitempty"` diff --git a/inapi/app.pb.go b/inapi/app.pb.go index ace465d..ae7bed5 100644 --- a/inapi/app.pb.go +++ b/inapi/app.pb.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.32.0 -// protoc v4.25.1 +// protoc v4.25.3 // source: app.proto package inapi diff --git a/inapi/cluster.pb.go b/inapi/cluster.pb.go index 01bac56..10a6cd7 100644 --- a/inapi/cluster.pb.go +++ b/inapi/cluster.pb.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.32.0 -// protoc v4.25.1 +// protoc v4.25.3 // source: cluster.proto package inapi diff --git a/inapi/cluster_grpc.pb.go b/inapi/cluster_grpc.pb.go index b9ccbc9..ebff759 100644 --- a/inapi/cluster_grpc.pb.go +++ b/inapi/cluster_grpc.pb.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v4.25.1 +// - protoc v4.25.3 // source: cluster.proto package inapi diff --git a/inapi/config.pb.go b/inapi/config.pb.go index 551fe09..1116aec 100644 --- a/inapi/config.pb.go +++ b/inapi/config.pb.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.32.0 -// protoc v4.25.1 +// protoc v4.25.3 // source: config.proto package inapi diff --git a/inapi/inapi.pb.go b/inapi/inapi.pb.go index a70f4cf..d22e591 100644 --- a/inapi/inapi.pb.go +++ b/inapi/inapi.pb.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.32.0 -// protoc v4.25.1 +// protoc v4.25.3 // source: inapi.proto package inapi diff --git a/inapi/mail.pb.go b/inapi/mail.pb.go index 90cd2f5..1cca911 100644 --- a/inapi/mail.pb.go +++ b/inapi/mail.pb.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.32.0 -// protoc v4.25.1 +// protoc v4.25.3 // source: mail.proto package inapi diff --git a/inapi/operator.pb.go b/inapi/operator.pb.go index f25d454..bd528be 100644 --- a/inapi/operator.pb.go +++ b/inapi/operator.pb.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.32.0 -// protoc v4.25.1 +// protoc v4.25.3 // source: operator.proto package inapi diff --git a/inapi/pod.pb.go b/inapi/pod.pb.go index 8fb7ca1..883df75 100644 --- a/inapi/pod.pb.go +++ b/inapi/pod.pb.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.32.0 -// protoc v4.25.1 +// protoc v4.25.3 // source: pod.proto package inapi diff --git a/inapi/stats.pb.go b/inapi/stats.pb.go index e9b7a71..17ed0bd 100644 --- a/inapi/stats.pb.go +++ b/inapi/stats.pb.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.32.0 -// protoc v4.25.1 +// protoc v4.25.3 // source: stats.proto package inapi diff --git a/module/mail_queue/entry.go b/module/mail_queue/entry.go index c596df7..5d5e3db 100644 --- a/module/mail_queue/entry.go +++ b/module/mail_queue/entry.go @@ -60,15 +60,14 @@ func (it *MailQueue) Run(ctx *injob.Context) error { zkey = inapi.NsZoneMailQueue("") ) - rs := data.DataZone.NewReader(nil). - KeyRangeSet(zkey, zkey). - LimitNumSet(100). - Query() + rs := data.DataZone.NewRanger(zkey, zkey). + SetLimit(100). + Exec() for _, v := range rs.Items { var item hmsg.MsgItem - if err := v.Decode(&item); err != nil { + if err := v.JsonDecode(&item); err != nil { continue } @@ -76,9 +75,8 @@ func (it *MailQueue) Run(ctx *injob.Context) error { it.done += 1 - if rs2 := data.DataZone.NewWriter(v.Meta.Key, nil). - ModeDeleteSet(true).Commit(); !rs2.OK() { - hlog.Printf("info", "zm/v1 msg post clean err %s", rs2.Message) + if rs2 := data.DataZone.NewDeleter(v.Key).Exec(); !rs2.OK() { + hlog.Printf("info", "zm/v1 msg post clean err %s", rs2.ErrorMessage()) } hlog.Printf("info", "zm/v1 msg post %s to %s ok", item.Id, item.ToUser) diff --git a/module/pod_status_mail/entry.go b/module/pod_status_mail/entry.go index 4d0aea9..82bfadc 100644 --- a/module/pod_status_mail/entry.go +++ b/module/pod_status_mail/entry.go @@ -76,15 +76,14 @@ func (it *PodStatusMail) Run(c *injob.Context) error { zkey = inapi.NsZonePodInstance(ctx.Zone.Meta.Id, "") ) - rs := data.DataZone.NewReader(nil). - KeyRangeSet(zkey, zkey). - LimitNumSet(10000). - Query() + rs := data.DataZone.NewRanger(zkey, zkey). + SetLimit(10000). + Exec() for _, v := range rs.Items { var pod inapi.Pod - if err := v.Decode(&pod); err != nil { + if err := v.JsonDecode(&pod); err != nil { continue } @@ -160,7 +159,7 @@ func (it *PodStatusMail) Run(c *injob.Context) error { msg.Created = tn if rs := data.DataZone.NewWriter( - inapi.NsZoneMailQueue(msg.SentId()), msg).Commit(); !rs.OK() { + inapi.NsZoneMailQueue(msg.SentId()), msg).Exec(); !rs.OK() { return rs.Error() } } diff --git a/websrv/ops/host-cell.go b/websrv/ops/host-cell.go index 840cf6b..ff7b814 100644 --- a/websrv/ops/host-cell.go +++ b/websrv/ops/host-cell.go @@ -59,12 +59,12 @@ func (c Host) CellEntryAction() { ) if rs := data.DataGlobal.NewReader( - inapi.NsGlobalSysCell(zoneId, cellId)).Query(); rs.OK() { - rs.Decode(&set.ResCell) + inapi.NsGlobalSysCell(zoneId, cellId)).Exec(); rs.OK() { + rs.Item().JsonDecode(&set.ResCell) } else if rs.NotFound() { if rs = data.DataGlobal.NewReader( - inapi.NsKvGlobalSysCellDestroyed(zoneId, cellId)).Query(); rs.OK() { - rs.Decode(&set.ResCell) + inapi.NsKvGlobalSysCellDestroyed(zoneId, cellId)).Exec(); rs.OK() { + rs.Item().JsonDecode(&set.ResCell) } } @@ -134,8 +134,8 @@ func (c Host) CellSetAction() { } else { - if rs := data.DataGlobal.NewReader(inapi.NsGlobalSysZone(cell.ZoneId)).Query(); rs.OK() { - rs.Decode(&zone) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalSysZone(cell.ZoneId)).Exec(); rs.OK() { + rs.Item().JsonDecode(&zone) } if zone.Meta.Id == "" { @@ -144,13 +144,13 @@ func (c Host) CellSetAction() { } // global - if rs := data.DataGlobal.NewReader(inapi.NsGlobalSysCell(cell.ZoneId, cell.Meta.Id)).Query(); rs.NotFound() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalSysCell(cell.ZoneId, cell.Meta.Id)).Exec(); rs.NotFound() { cell.Meta.Created = uint64(types.MetaTimeNow()) } else if rs.OK() { var prev inapi.ResCell - if err := rs.Decode(&prev); err != nil { + if err := rs.Item().JsonDecode(&prev); err != nil { cell.Error = &types.ErrorMeta{"500", err.Error()} return } @@ -166,15 +166,15 @@ func (c Host) CellSetAction() { cell.Meta.Updated = uint64(types.MetaTimeNow()) if rs := data.DataGlobal.NewWriter( - inapi.NsGlobalSysCell(cell.ZoneId, cell.Meta.Id), cell.ResCell).Commit(); !rs.OK() { - cell.Error = &types.ErrorMeta{"500", rs.Message} + inapi.NsGlobalSysCell(cell.ZoneId, cell.Meta.Id), cell.ResCell).Exec(); !rs.OK() { + cell.Error = &types.ErrorMeta{"500", rs.ErrorMessage()} return } if cell.ZoneId == status.ZoneId { if rs := data.DataZone.NewWriter( - inapi.NsZoneSysCell(cell.ZoneId, cell.Meta.Id), cell.ResCell).Commit(); !rs.OK() { - cell.Error = &types.ErrorMeta{"500", rs.Message} + inapi.NsZoneSysCell(cell.ZoneId, cell.Meta.Id), cell.ResCell).Exec(); !rs.OK() { + cell.Error = &types.ErrorMeta{"500", rs.ErrorMessage()} return } } diff --git a/websrv/ops/host-node-stats.go b/websrv/ops/host-node-stats.go index d11b9a5..482b09a 100644 --- a/websrv/ops/host-node-stats.go +++ b/websrv/ops/host-node-stats.go @@ -62,15 +62,15 @@ func (c Host) NodeStatsFeedAction() { feed := inapi.NewPbStatsSampleFeed(fq.TimeCycle) - if rs := data.DataZone.NewReader(nil).KeyRangeSet( + if rs := data.DataZone.NewRanger( inapi.NsKvZoneSysHostStats(status.ZoneId, host_id, fq.TimeStart), inapi.NsKvZoneSysHostStats(status.ZoneId, host_id, fq.TimeCutset+600)). - LimitNumSet(10000).Query(); rs.OK() { + SetLimit(10000).Exec(); rs.OK() { for _, v := range rs.Items { var ifeed inapi.PbStatsIndexFeed - if err := v.Decode(&ifeed); err != nil { + if err := v.JsonDecode(&ifeed); err != nil { continue } diff --git a/websrv/ops/host-node.go b/websrv/ops/host-node.go index 160bb6d..b4f92dd 100644 --- a/websrv/ops/host-node.go +++ b/websrv/ops/host-node.go @@ -21,7 +21,7 @@ import ( "github.com/hooto/hlog4g/hlog" "github.com/lessos/lessgo/crypto/idhash" "github.com/lessos/lessgo/types" - kv2 "github.com/lynkdb/kvspec/v2/go/kvspec" + "github.com/lynkdb/kvgo/v2/pkg/kvapi" "golang.org/x/net/context" "github.com/sysinner/incore/config" @@ -38,25 +38,25 @@ func (c Host) NodeListAction() { zoneid = c.Params.Value("zoneid") cellid = c.Params.Value("cellid") sets inapi.GeneralObjectList - rs *kv2.ObjectResult + rs *kvapi.ResultSet ) defer c.RenderJson(&sets) if zoneid == status.ZoneId { - rs = data.DataZone.NewReader(nil).KeyRangeSet( + rs = data.DataZone.NewRanger( inapi.NsZoneSysHost(zoneid, ""), inapi.NsZoneSysHost(zoneid, "")). - LimitNumSet(1000).Query() + SetLimit(1000).Exec() } else { - rs = data.DataGlobal.NewReader(nil).KeyRangeSet( + rs = data.DataGlobal.NewRanger( inapi.NsGlobalSysHost(zoneid, ""), inapi.NsGlobalSysHost(zoneid, "")). - LimitNumSet(1000).Query() + SetLimit(1000).Exec() } for _, v := range rs.Items { var node inapi.ResHost - if err := v.Decode(&node); err == nil { + if err := v.JsonDecode(&node); err == nil { // TOPO if cellid != "" && (node.Operate == nil || node.Operate.CellId != cellid) { @@ -79,17 +79,17 @@ func (c Host) NodeEntryAction() { inapi.GeneralObject inapi.ResHost } - rs *kv2.ObjectResult + rs *kvapi.ResultSet ) defer c.RenderJson(&node) if zoneid == status.ZoneId { - rs = data.DataZone.NewReader(inapi.NsZoneSysHost(zoneid, nodeid)).Query() + rs = data.DataZone.NewReader(inapi.NsZoneSysHost(zoneid, nodeid)).Exec() } else { - rs = data.DataGlobal.NewReader(inapi.NsGlobalSysHost(zoneid, nodeid)).Query() + rs = data.DataGlobal.NewReader(inapi.NsGlobalSysHost(zoneid, nodeid)).Exec() } if rs.OK() { - if err := rs.Decode(&node.ResHost); err != nil { + if err := rs.Item().JsonDecode(&node.ResHost); err != nil { node.Error = &types.ErrorMeta{Code: "400", Message: err.Error()} return } @@ -202,15 +202,15 @@ func (c Host) NodeNewAction() { } data.DataZone.NewWriter( - inapi.NsZoneSysHostSecretKey(set.ZoneId, node.Meta.Id), set.SecretKey).Commit() + inapi.NsZoneSysHostSecretKey(set.ZoneId, node.Meta.Id), set.SecretKey).Exec() status.ZoneHostSecretKeys.Set(node.Meta.Id, set.SecretKey) // cell.NodeNum++ /** - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalSysCell(set.ZoneId, cell.Meta.Id), cell).Commit(); rs.OK() { - data.DataZone.NewWriter(inapi.NsZoneSysCell(set.ZoneId, cell.Meta.Id), cell).Commit() + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalSysCell(set.ZoneId, cell.Meta.Id), cell).Exec(); rs.OK() { + data.DataZone.NewWriter(inapi.NsZoneSysCell(set.ZoneId, cell.Meta.Id), cell).Exec() } else { set.Error = types.NewErrorMeta("500", "Server Error") return @@ -258,8 +258,8 @@ func (c Host) NodeSetAction() { var host inapi.ResHost if rs := data.DataGlobal.NewReader( - inapi.NsGlobalSysHost(set.Operate.ZoneId, set.Meta.Id)).Query(); rs.OK() { - rs.Decode(&host) + inapi.NsGlobalSysHost(set.Operate.ZoneId, set.Meta.Id)).Exec(); rs.OK() { + rs.Item().JsonDecode(&host) } if host.Meta.Id != set.Meta.Id { @@ -356,7 +356,7 @@ func (c Host) NodeSecretKeySetAction() { } data.DataZone.NewWriter( - inapi.NsZoneSysHostSecretKey(prev.Operate.ZoneId, set.NodeId), set.SecretKey).Commit() + inapi.NsZoneSysHostSecretKey(prev.Operate.ZoneId, set.NodeId), set.SecretKey).Exec() status.ZoneHostSecretKeys.Set(set.NodeId, set.SecretKey) @@ -590,7 +590,7 @@ func (c Host) NodeSyncPullSetAction() { nodeEntry.Operate.SecretKey = idhash.RandBase64String(40) data.DataZone.NewWriter( inapi.NsZoneSysHostSecretKey(entry.ZoneId, nodeEntry.Meta.Id), - nodeEntry.Operate.SecretKey).Commit() + nodeEntry.Operate.SecretKey).Exec() } } diff --git a/websrv/ops/host-zone.go b/websrv/ops/host-zone.go index 6ad8400..f4369de 100644 --- a/websrv/ops/host-zone.go +++ b/websrv/ops/host-zone.go @@ -99,14 +99,14 @@ func (c Host) ZoneEntryAction() { ) rs := data.DataGlobal.NewReader( - inapi.NsGlobalSysZone(zoneId)).Query() + inapi.NsGlobalSysZone(zoneId)).Exec() if rs.OK() { - rs.Decode(&set.ResZone) + rs.Item().JsonDecode(&set.ResZone) } else if rs.NotFound() { rs = data.DataGlobal.NewReader( - inapi.NsGlobalSysZone(zoneId)).Query() + inapi.NsGlobalSysZone(zoneId)).Exec() if rs.OK() { - rs.Decode(&set.ResZone) + rs.Item().JsonDecode(&set.ResZone) } } @@ -114,13 +114,13 @@ func (c Host) ZoneEntryAction() { var ( offset = inapi.NsGlobalSysCell(set.Meta.Id, "") - rs2 = data.DataGlobal.NewReader(nil).KeyRangeSet(offset, offset). - LimitNumSet(100).Query() + rs2 = data.DataGlobal.NewRanger(offset, offset). + SetLimit(100).Exec() ) for _, v2 := range rs2.Items { var cell inapi.ResCell - if err := v2.Decode(&cell); err == nil { + if err := v2.JsonDecode(&cell); err == nil { set.Cells = append(set.Cells, &cell) } } @@ -295,9 +295,9 @@ func (c Host) ZoneSetAction() { } set.Groups = groups - if rs := data.DataGlobal.NewReader(inapi.NsGlobalSysZone(set.Meta.Id)).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalSysZone(set.Meta.Id)).Exec(); rs.OK() { var prev inapi.ResZone - if err := rs.Decode(&prev); err == nil { + if err := rs.Item().JsonDecode(&prev); err == nil { if prev.Meta.Created > 0 { set.Meta.Created = prev.Meta.Created } @@ -318,7 +318,7 @@ func (c Host) ZoneSetAction() { set.Meta.Updated = uint64(types.MetaTimeNow()) - data.DataGlobal.NewWriter(inapi.NsGlobalSysZone(set.Meta.Id), set.ResZone).Commit() + data.DataGlobal.NewWriter(inapi.NsGlobalSysZone(set.Meta.Id), set.ResZone).Exec() if inapi.OpActionAllow(set.Phase, inapi.OpActionDestroy) && inapi.OpActionAllow(set.Phase, inapi.OpActionForce) { @@ -349,8 +349,8 @@ func (c Host) ZoneAccChargeKeyRefreshAction() { return } - if rs := data.DataGlobal.NewReader(inapi.NsGlobalSysZone(zone_id)).Query(); rs.OK() { - rs.Decode(&zone) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalSysZone(zone_id)).Exec(); rs.OK() { + rs.Item().JsonDecode(&zone) } if zone.Meta.Id != zone_id { @@ -379,14 +379,14 @@ func (c Host) ZoneAccChargeKeyRefreshAction() { zone.OptionSet("iam/acc_charge/access_key", init_akacc.Id) zone.OptionSet("iam/acc_charge/secret_key", init_akacc.Secret) - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalSysZone(zone_id), zone).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta("500", "database/global error "+rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalSysZone(zone_id), zone).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta("500", "database/global error "+rs.ErrorMessage()) return } if zone_id == status.ZoneId { - if rs := data.DataZone.NewWriter(inapi.NsZoneSysZone(zone_id), zone).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta("500", "database/zone error "+rs.Message) + if rs := data.DataZone.NewWriter(inapi.NsZoneSysZone(zone_id), zone).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta("500", "database/zone error "+rs.ErrorMessage()) return } } diff --git a/websrv/ops/pod-spec.go b/websrv/ops/pod-spec.go index fc850b1..2d72dfa 100644 --- a/websrv/ops/pod-spec.go +++ b/websrv/ops/pod-spec.go @@ -69,19 +69,18 @@ func (c PodSpec) ResComputeListAction() { } // TODO - rs := data.DataGlobal.NewReader(nil).KeyRangeSet( + rs := data.DataGlobal.NewRanger( inapi.NsGlobalPodSpec("res/compute", ""), inapi.NsGlobalPodSpec("res/compute", "")). - LimitNumSet(100).Query() + SetLimit(100).Exec() if rs.OK() { for _, v := range rs.Items { var item inapi.PodSpecResCompute - if err := v.Decode(&item); err == nil { + if err := v.JsonDecode(&item); err == nil { // datafix if item.Meta.ID != fmt.Sprintf("c%dm%d", item.CpuLimit, item.MemLimit) { - data.DataGlobal.NewWriter(inapi.NsGlobalPodSpec("res/compute", item.Meta.ID), nil). - ModeDeleteSet(true).Commit() + data.DataGlobal.NewDeleter(inapi.NsGlobalPodSpec("res/compute", item.Meta.ID)).Exec() continue } @@ -141,17 +140,17 @@ func (c PodSpec) ResComputeNewAction() { } set.Status = inapi.SpecStatusActive - rs := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("res/compute", set.Meta.ID)).Query() + rs := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("res/compute", set.Meta.ID)).Exec() if rs.OK() { set.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, "Spec Already Exists") return } - rs = data.DataGlobal.NewWriter(inapi.NsGlobalPodSpec("res/compute", set.Meta.ID), set).Commit() + rs = data.DataGlobal.NewWriter(inapi.NsGlobalPodSpec("res/compute", set.Meta.ID), set).Exec() if rs.OK() { set.Kind = "PodSpecResCompute" } else { - set.Error = types.NewErrorMeta("500", rs.Message) + set.Error = types.NewErrorMeta("500", rs.ErrorMessage()) } } @@ -174,12 +173,12 @@ func (c PodSpec) ResComputeSetAction() { } var prev inapi.PodSpecResCompute - rs := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("res/compute", set.Meta.ID)).Query() + rs := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("res/compute", set.Meta.ID)).Exec() if !rs.OK() { set.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, "Spec Not Found") return } else { - rs.Decode(&prev) + rs.Item().JsonDecode(&prev) } if prev.Meta.ID == "" || prev.Meta.ID != set.Meta.ID { set.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, "Spec Not Found") @@ -189,11 +188,11 @@ func (c PodSpec) ResComputeSetAction() { prev.Status = set.Status prev.Meta.Updated = types.MetaTimeNow() - rs = data.DataGlobal.NewWriter(inapi.NsGlobalPodSpec("res/compute", prev.Meta.ID), set).Commit() + rs = data.DataGlobal.NewWriter(inapi.NsGlobalPodSpec("res/compute", prev.Meta.ID), set).Exec() if !rs.OK() { set.Kind = "PodSpecResCompute" } else { - set.Error = types.NewErrorMeta("500", rs.Message) + set.Error = types.NewErrorMeta("500", rs.ErrorMessage()) } } @@ -208,13 +207,13 @@ func (c PodSpec) PlanListAction() { } // TODO - rs := data.DataGlobal.NewReader(nil).KeyRangeSet( + rs := data.DataGlobal.NewRanger( inapi.NsGlobalPodSpec("plan", ""), inapi.NsGlobalPodSpec("plan", "")). - LimitNumSet(100).Query() + SetLimit(100).Exec() for _, v := range rs.Items { var item inapi.PodSpecPlan - if err := v.Decode(&item); err == nil { + if err := v.JsonDecode(&item); err == nil { item.ChargeFix() upgrade := false @@ -231,7 +230,7 @@ func (c PodSpec) PlanListAction() { } if upgrade { - data.DataGlobal.NewWriter(inapi.NsGlobalPodSpec("plan", item.Meta.ID), item).Commit() + data.DataGlobal.NewWriter(inapi.NsGlobalPodSpec("plan", item.Meta.ID), item).Exec() hlog.Printf("warn", "v1 pod/spec/image upgrade %s", item.Meta.ID) } @@ -259,9 +258,9 @@ func (c PodSpec) PlanEntryAction() { } // TODO - rs := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("plan", c.Params.Value("id"))).Query() + rs := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("plan", c.Params.Value("id"))).Exec() if rs.OK() { - rs.Decode(&set) + rs.Item().JsonDecode(&set) } if set.Meta.ID == "" || set.Meta.ID != c.Params.Value("id") { set.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, "SpecPlan Not Found") @@ -293,8 +292,8 @@ func (c PodSpec) PlanSetAction() { // TODO var prev inapi.PodSpecPlan - if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("plan", set.Meta.ID)).Query(); rs.OK() { - rs.Decode(&prev) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("plan", set.Meta.ID)).Exec(); rs.OK() { + rs.Item().JsonDecode(&prev) } if prev.Meta.ID == "" || prev.Meta.ID != set.Meta.ID { prev.Meta.ID = set.Meta.ID @@ -343,12 +342,12 @@ func (c PodSpec) PlanSetAction() { offset = inapi.NsGlobalBoxImage("", "") cutset = inapi.NsGlobalBoxImage("", "") ) - rss := data.DataGlobal.NewReader(nil).KeyRangeSet(offset, cutset). - LimitNumSet(100).Query() + rss := data.DataGlobal.NewRanger(offset, cutset). + SetLimit(100).Exec() for _, v := range rss.Items { var item inapi.PodSpecBoxImage - if err := v.Decode(&item); err != nil { + if err := v.JsonDecode(&item); err != nil { continue } @@ -379,13 +378,13 @@ func (c PodSpec) PlanSetAction() { // prev.ResComputes = inapi.PodSpecPlanResComputeBounds{} - rss = data.DataGlobal.NewReader(nil).KeyRangeSet( + rss = data.DataGlobal.NewRanger( inapi.NsGlobalPodSpec("res/compute", ""), inapi.NsGlobalPodSpec("res/compute", "")). - LimitNumSet(100).Query() + SetLimit(100).Exec() for _, v := range rss.Items { var item inapi.PodSpecResCompute - if err := v.Decode(&item); err != nil { + if err := v.JsonDecode(&item); err != nil { continue } @@ -411,13 +410,13 @@ func (c PodSpec) PlanSetAction() { // prev.ResVolumeDefault = "" prev.ResVolumes = []*inapi.PodSpecPlanResVolumeBound{} - rss = data.DataGlobal.NewReader(nil).KeyRangeSet( + rss = data.DataGlobal.NewRanger( inapi.NsGlobalPodSpec("res/volume", ""), inapi.NsGlobalPodSpec("res/volume", "")). - LimitNumSet(100).Query() + SetLimit(100).Exec() for _, v := range rss.Items { var item inapi.PodSpecResVolume - if err := v.Decode(&item); err != nil { + if err := v.JsonDecode(&item); err != nil { continue } @@ -460,10 +459,10 @@ func (c PodSpec) PlanSetAction() { prev.Meta.Updated = types.MetaTimeNow() - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalPodSpec("plan", prev.Meta.ID), prev).Commit(); rs.OK() { + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalPodSpec("plan", prev.Meta.ID), prev).Exec(); rs.OK() { set.Kind = "PodSpecPlan" } else { - set.Error = types.NewErrorMeta("500", rs.Message) + set.Error = types.NewErrorMeta("500", rs.ErrorMessage()) } } @@ -485,11 +484,11 @@ func (c PodSpec) BoxImageListAction() { ) // TODO - rss := data.DataGlobal.NewReader(nil).KeyRangeSet(offset, cutset). - LimitNumSet(100).Query() + rss := data.DataGlobal.NewRanger(offset, cutset). + SetLimit(100).Exec() for _, v := range rss.Items { var item inapi.PodSpecBoxImage - if err := v.Decode(&item); err != nil { + if err := v.JsonDecode(&item); err != nil { continue } if action > 0 && action != item.Action { @@ -563,15 +562,15 @@ func (c PodSpec) BoxImageSetAction() { return } - if rs := data.DataGlobal.NewReader(inapi.NsGlobalBoxImage(setItem.Name, setItem.Tag)).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalBoxImage(setItem.Name, setItem.Tag)).Exec(); rs.OK() { var prev inapi.PodSpecBoxImage - if err := rs.Decode(&prev); err == nil { + if err := rs.Item().JsonDecode(&prev); err == nil { setItem.Meta.Created = prev.Meta.Created } } - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalBoxImage(setItem.Name, setItem.Tag), setItem).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalBoxImage(setItem.Name, setItem.Tag), setItem).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return } @@ -589,13 +588,13 @@ func (c PodSpec) ResVolumeListAction() { } // TODO - rs := data.DataGlobal.NewReader(nil).KeyRangeSet( + rs := data.DataGlobal.NewRanger( inapi.NsGlobalPodSpec("res/volume", ""), inapi.NsGlobalPodSpec("res/volume", "")). - LimitNumSet(100).Query() + SetLimit(100).Exec() for _, v := range rs.Items { var item inapi.PodSpecResVolume - if err := v.Decode(&item); err == nil { + if err := v.JsonDecode(&item); err == nil { ls.Items = append(ls.Items, item) } else { hlog.Printf("info", "%s, %s", err.Error(), v.String()) diff --git a/websrv/ops/sys.go b/websrv/ops/sys.go index eae4d0d..447dfa7 100644 --- a/websrv/ops/sys.go +++ b/websrv/ops/sys.go @@ -94,9 +94,9 @@ func (c Sys) ConfigWizardAction() { } // - if rs := in_db.DataGlobal.NewReader(inapi.NsGlobalSysConfig(name)).Query(); rs.OK() { + if rs := in_db.DataGlobal.NewReader(inapi.NsGlobalSysConfig(name)).Exec(); rs.OK() { var item inapi.AppOption - if err := rs.Decode(&item); err == nil { + if err := rs.Item().JsonDecode(&item); err == nil { set.Option = item } } @@ -141,8 +141,8 @@ func (c Sys) ConfigSetAction() { } var prev inapi.SysConfigGroup - if rs := in_db.DataGlobal.NewReader(inapi.NsGlobalSysConfig(set.Name)).Query(); rs.OK() { - rs.Decode(&prev) + if rs := in_db.DataGlobal.NewReader(inapi.NsGlobalSysConfig(set.Name)).Exec(); rs.OK() { + rs.Item().JsonDecode(&prev) } if prev.Name != set.Name { @@ -213,8 +213,8 @@ func (c Sys) ConfigSetAction() { hlog.Printf("info", "SysConfig refresh %s", set.Name) set.Updated = uint32(time.Now().Unix()) - if rs := in_db.DataGlobal.NewWriter(inapi.NsGlobalSysConfig(set.Name), set).Commit(); !rs.OK() { - rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.Message) + if rs := in_db.DataGlobal.NewWriter(inapi.NsGlobalSysConfig(set.Name), set).Exec(); !rs.OK() { + rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.ErrorMessage()) return } diff --git a/websrv/p1/app-spec.go b/websrv/p1/app-spec.go index c21a413..ab1f465 100644 --- a/websrv/p1/app-spec.go +++ b/websrv/p1/app-spec.go @@ -58,16 +58,15 @@ func appSpecRefresh() { defer appSpecMu.Unlock() var ( - rs = data.DataGlobal.NewReader(nil). - KeyRangeSet(inapi.NsGlobalAppSpec(""), inapi.NsGlobalAppSpec("zzzz")). - LimitNumSet(1000).Query() + rs = data.DataGlobal.NewRanger(inapi.NsGlobalAppSpec(""), inapi.NsGlobalAppSpec("zzzz")). + SetLimit(1000).Exec() items = []*inapi.AppSpec{} ) for _, v := range rs.Items { var item inapi.AppSpec - if err := v.Decode(&item); err != nil { + if err := v.JsonDecode(&item); err != nil { continue } diff --git a/websrv/v1/app-spec.go b/websrv/v1/app-spec.go index 28f4c61..6f08b64 100644 --- a/websrv/v1/app-spec.go +++ b/websrv/v1/app-spec.go @@ -78,10 +78,10 @@ func (c AppSpec) ListAction() { ls := inapi.AppSpecList{} defer c.RenderJson(&ls) - rs := data.DataGlobal.NewReader(nil).KeyRangeSet( + rs := data.DataGlobal.NewRanger( inapi.NsGlobalAppSpec("zzzzzzzz"), inapi.NsGlobalAppSpec("")). - ModeRevRangeSet(true). - LimitNumSet(200).Query() + SetRevert(true). + SetLimit(200).Exec() var fields types.ArrayPathTree if fns := c.Params.Value("fields"); fns != "" { @@ -92,15 +92,15 @@ func (c AppSpec) ListAction() { for _, v := range rs.Items { var spec inapi.AppSpec - if err := v.Decode(&spec); err != nil { + if err := v.JsonDecode(&spec); err != nil { continue } // if _, ok := appSpecVersionCaches.Load(spec.Meta.ID + ":" + spec.Meta.Version); !ok { if rs := data.DataGlobal.NewReader( - inapi.NsKvGlobalAppSpecVersion(spec.Meta.ID, spec.Meta.Version)).Query(); !rs.NotFound() { - data.DataGlobal.NewWriter(inapi.NsKvGlobalAppSpecVersion(spec.Meta.ID, spec.Meta.Version), spec).Commit() + inapi.NsKvGlobalAppSpecVersion(spec.Meta.ID, spec.Meta.Version)).Exec(); !rs.NotFound() { + data.DataGlobal.NewWriter(inapi.NsKvGlobalAppSpecVersion(spec.Meta.ID, spec.Meta.Version), spec).Exec() } appSpecVersionCaches.Store(spec.Meta.ID+":"+spec.Meta.Version, true) } @@ -252,8 +252,8 @@ func (c AppSpec) VersionListAction() { ) var spec inapi.AppSpec - if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(c.Params.Value("id"))).Query(); rs.OK() { - rs.Decode(&spec) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(c.Params.Value("id"))).Exec(); rs.OK() { + rs.Item().JsonDecode(&spec) } if spec.Meta.User != c.us.UserName && @@ -263,10 +263,10 @@ func (c AppSpec) VersionListAction() { } // TODO - rs := data.DataGlobal.NewReader(nil).ModeRevRangeSet(true).KeyRangeSet( + rs := data.DataGlobal.NewRanger( inapi.NsKvGlobalAppSpecVersion(spec.Meta.ID, "99999999.0.0"), inapi.NsKvGlobalAppSpecVersion(spec.Meta.ID, "0")). - LimitNumSet(1000).Query() + SetRevert(true).SetLimit(1000).Exec() var ( prevVersion = "" lastCount = 0 @@ -275,7 +275,7 @@ func (c AppSpec) VersionListAction() { for _, v := range rs.Items { var spec inapi.AppSpec - if err := v.Decode(&spec); err != nil { + if err := v.JsonDecode(&spec); err != nil { continue } @@ -317,8 +317,8 @@ func (c AppSpec) ItemDelAction() { } var spec inapi.AppSpec - if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(c.Params.Value("id"))).Query(); rs.OK() { - rs.Decode(&spec) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(c.Params.Value("id"))).Exec(); rs.OK() { + rs.Item().JsonDecode(&spec) } if spec.Meta.ID != c.Params.Value("id") { @@ -332,17 +332,16 @@ func (c AppSpec) ItemDelAction() { return } - if rs := data.DataGlobal.NewReader(nil).KeyRangeSet( + if rs := data.DataGlobal.NewRanger( inapi.NsKvGlobalAppSpecVersion(spec.Meta.ID, ""), inapi.NsKvGlobalAppSpecVersion(spec.Meta.ID, "99999999.0.0")). - LimitNumSet(10000).Query(); rs.OK() { + SetLimit(10000).Exec(); rs.OK() { for _, v := range rs.Items { var item inapi.AppSpec - if err := v.Decode(&item); err == nil { - if rs := data.DataGlobal.NewWriter( - inapi.NsKvGlobalAppSpecVersion(spec.Meta.ID, item.Meta.Version), nil). - ModeDeleteSet(true).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, "Server Error "+rs.Message) + if err := v.JsonDecode(&item); err == nil { + if rs := data.DataGlobal.NewDeleter( + inapi.NsKvGlobalAppSpecVersion(spec.Meta.ID, item.Meta.Version)).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, "Server Error "+rs.ErrorMessage()) return } } @@ -353,9 +352,8 @@ func (c AppSpec) ItemDelAction() { return } - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppSpec(spec.Meta.ID), nil). - ModeDeleteSet(true).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, "Server Error "+rs.Message) + if rs := data.DataGlobal.NewDeleter(inapi.NsGlobalAppSpec(spec.Meta.ID)).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, "Server Error "+rs.ErrorMessage()) return } @@ -391,15 +389,15 @@ func (c AppSpec) EntryAction() { version := c.Params.Value("version") if version != "" { if rs := data.DataGlobal.NewReader( - inapi.NsKvGlobalAppSpecVersion(c.Params.Value("id"), version)).Query(); rs.OK() { - rs.Decode(&set) + inapi.NsKvGlobalAppSpecVersion(c.Params.Value("id"), version)).Exec(); rs.OK() { + rs.Item().JsonDecode(&set) } } if set.Meta.ID != c.Params.Value("id") { if rs := data.DataGlobal.NewReader( - inapi.NsGlobalAppSpec(c.Params.Value("id"))).Query(); rs.OK() { - rs.Decode(&set) + inapi.NsGlobalAppSpec(c.Params.Value("id"))).Exec(); rs.OK() { + rs.Item().JsonDecode(&set) } } @@ -410,9 +408,9 @@ func (c AppSpec) EntryAction() { if inapi.AppIdRe2.MatchString(appId) { if rs := data.DataGlobal.NewReader( - inapi.NsGlobalAppInstance(appId)).Query(); rs.OK() { + inapi.NsGlobalAppInstance(appId)).Exec(); rs.OK() { var app inapi.AppInstance - rs.Decode(&app) + rs.Item().JsonDecode(&app) if app.Meta.ID == appId && app.Spec.Meta.ID == c.Params.Value("id") { set = app.Spec } @@ -440,9 +438,9 @@ func (c AppSpec) EntryAction() { if version != "" && c.Params.Value("last_version") == "true" { if rs := data.DataGlobal.NewReader( - inapi.NsGlobalAppSpec(set.Meta.ID)).Query(); rs.OK() { + inapi.NsGlobalAppSpec(set.Meta.ID)).Exec(); rs.OK() { var last_spec inapi.AppSpec - rs.Decode(&last_spec) + rs.Item().JsonDecode(&last_spec) if inapi.NewAppSpecVersion(last_spec.Meta.Version).Compare(inapi.NewAppSpecVersion(set.Meta.Version)) == 1 { set.LastVersion = last_spec.Meta.Version } @@ -508,14 +506,14 @@ func (c AppSpec) SetAction() { } var prev inapi.AppSpec - rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(req.Meta.ID)).Query() + rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(req.Meta.ID)).Exec() if !rs.OK() { if !rs.NotFound() { set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, "ServerError") return } } else { - rs.Decode(&prev) + rs.Item().JsonDecode(&prev) if prev.Meta.User != c.us.UserName { set.Error = types.NewErrorMeta(inapi.ErrCodeAccessDenied, "AccessDenied") return @@ -815,10 +813,10 @@ func (c AppSpec) SetAction() { v.Version = vs.PrefixString() vs.Patch = 99999999 - if rs := data.DataGlobal.NewReader().KeyRangeSet( + if rs := data.DataGlobal.NewRanger( inapi.NsKvGlobalAppSpecVersion(v.Id, vs.MajorMinorVersion()), inapi.NsKvGlobalAppSpecVersion(v.Id, vs.FullVersion())). - LimitNumSet(1).Query(); !rs.OK() || len(rs.Items) == 0 { + SetLimit(1).Exec(); !rs.OK() || len(rs.Items) == 0 { set.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, "Internally dependent AppSpec ("+v.Id+") Not Found") return @@ -840,10 +838,10 @@ func (c AppSpec) SetAction() { v.Version = vs.PrefixString() vs.Patch = 99999999 - if rs := data.DataGlobal.NewReader().KeyRangeSet( + if rs := data.DataGlobal.NewRanger( inapi.NsKvGlobalAppSpecVersion(v.Id, vs.MajorMinorVersion()), inapi.NsKvGlobalAppSpecVersion(v.Id, vs.FullVersion())). - LimitNumSet(1).Query(); !rs.OK() || len(rs.Items) == 0 { + SetLimit(1).Exec(); !rs.OK() || len(rs.Items) == 0 { set.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, "Remotely dependent AppSpec ("+v.Id+") Not Found") return @@ -862,10 +860,20 @@ func (c AppSpec) SetAction() { return } - if rs := data.DataInpack.NewReader().KeyRangeSet( + // if rs := data.DataInpack.NewRanger( + // ipapi.DataPackKey(fmt.Sprintf("%s-%s", v.Name, v.Version)), + // ipapi.DataPackKey(fmt.Sprintf("%s-%sz", v.Name, v.Version)), + // ).SetLimit(1).Exec(); !rs.OK() { + + // set.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, + // fmt.Sprintf("Package %s/%s Not Found", v.Name, v.Version)) + // return + // } + + if rs := data.DataPack.NewRanger( ipapi.DataPackKey(fmt.Sprintf("%s-%s", v.Name, v.Version)), ipapi.DataPackKey(fmt.Sprintf("%s-%sz", v.Name, v.Version)), - ).LimitNumSet(1).Query(); !rs.OK() { + ).SetLimit(1).Exec(); !rs.OK() { set.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, fmt.Sprintf("Package %s/%s Not Found", v.Name, v.Version)) @@ -896,20 +904,20 @@ func (c AppSpec) SetAction() { // if setNew { rs = data.DataGlobal.NewWriter(inapi.NsGlobalAppSpec(prev.Meta.ID), prev). - ModeCreateSet(true).Commit() + SetCreateOnly(true).Exec() } else { - rs = data.DataGlobal.NewWriter(inapi.NsGlobalAppSpec(prev.Meta.ID), prev).Commit() + rs = data.DataGlobal.NewWriter(inapi.NsGlobalAppSpec(prev.Meta.ID), prev).Exec() } if !rs.OK() { - set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.Message) + set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.ErrorMessage()) return } rs = data.DataGlobal.NewWriter( - inapi.NsKvGlobalAppSpecVersion(prev.Meta.ID, prev.Meta.Version), prev).Commit() + inapi.NsKvGlobalAppSpecVersion(prev.Meta.ID, prev.Meta.Version), prev).Exec() if !rs.OK() { - set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.Message) + set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.ErrorMessage()) } else { set.Kind = "AppSpec" } @@ -949,8 +957,8 @@ func (c AppSpec) CfgSetAction() { } var prev inapi.AppSpec - if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(req.Meta.ID)).Query(); rs.OK() { - rs.Decode(&prev) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(req.Meta.ID)).Exec(); rs.OK() { + rs.Item().JsonDecode(&prev) } if prev.Meta.ID == "" { @@ -1008,14 +1016,14 @@ func (c AppSpec) CfgSetAction() { resVersion.Add(false, false, true) prev.Meta.Version = resVersion.FullVersion() - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppSpec(prev.Meta.ID), prev).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppSpec(prev.Meta.ID), prev).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.ErrorMessage()) return } if rs := data.DataGlobal.NewWriter( - inapi.NsKvGlobalAppSpecVersion(prev.Meta.ID, prev.Meta.Version), prev).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.Message) + inapi.NsKvGlobalAppSpecVersion(prev.Meta.ID, prev.Meta.Version), prev).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.ErrorMessage()) return } @@ -1057,8 +1065,8 @@ func (c AppSpec) CfgFieldDelAction() { } var prev inapi.AppSpec - if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(req.Meta.ID)).Query(); rs.OK() { - rs.Decode(&prev) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(req.Meta.ID)).Exec(); rs.OK() { + rs.Item().JsonDecode(&prev) } if prev.Meta.ID == "" { @@ -1088,14 +1096,14 @@ func (c AppSpec) CfgFieldDelAction() { resVersion.Add(false, false, true) prev.Meta.Version = resVersion.FullVersion() - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppSpec(prev.Meta.ID), prev).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppSpec(prev.Meta.ID), prev).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.ErrorMessage()) return } if rs := data.DataGlobal.NewWriter( - inapi.NsKvGlobalAppSpecVersion(prev.Meta.ID, prev.Meta.Version), prev).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.Message) + inapi.NsKvGlobalAppSpecVersion(prev.Meta.ID, prev.Meta.Version), prev).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.ErrorMessage()) return } @@ -1111,19 +1119,19 @@ func appSpecVersionLastPatch(specId, version string) *inapi.AppSpec { v.Patch = 99999999 - if rs := data.DataGlobal.NewReader().KeyRangeSet( + if rs := data.DataGlobal.NewRanger( inapi.NsKvGlobalAppSpecVersion(specId, v.FullVersion()), inapi.NsKvGlobalAppSpecVersion(specId, v.MajorMinorVersion())). - ModeRevRangeSet(true).Query(); rs.OK() && len(rs.Items) > 0 { - rs.Items[0].Decode(&spec) + SetRevert(true).Exec(); rs.OK() && len(rs.Items) > 0 { + rs.Items[0].JsonDecode(&spec) if spec.Meta.ID == specId { return &spec } } if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(specId)). - Query(); rs.OK() { - rs.Decode(&spec) + Exec(); rs.OK() { + rs.Item().JsonDecode(&spec) if spec.Meta.ID == specId { return &spec } diff --git a/websrv/v1/app.go b/websrv/v1/app.go index bb5d09f..ac52497 100644 --- a/websrv/v1/app.go +++ b/websrv/v1/app.go @@ -31,7 +31,7 @@ import ( "github.com/lessos/lessgo/crypto/idhash" "github.com/lessos/lessgo/types" iox_utils "github.com/lynkdb/iomix/utils" - kv2 "github.com/lynkdb/kvspec/v2/go/kvspec" + "github.com/lynkdb/kvgo/v2/pkg/kvapi" "github.com/sysinner/incore/config" "github.com/sysinner/incore/data" @@ -71,9 +71,8 @@ func (c App) ListAction() { defer c.RenderJson(&ls) // TODO pager - rs := data.DataGlobal.NewReader(nil).ModeRevRangeSet(true). - KeyRangeSet(inapi.NsGlobalAppInstance("zzzzzzzz"), inapi.NsGlobalAppInstance("")). - LimitNumSet(10000).Query() + rs := data.DataGlobal.NewRanger(inapi.NsGlobalAppInstance("zzzzzzzz"), inapi.NsGlobalAppInstance("")). + SetRevert(true).SetLimit(10000).Exec() var fields types.ArrayPathTree if fns := c.Params.Value("fields"); fns != "" { @@ -85,7 +84,7 @@ func (c App) ListAction() { var inst inapi.AppInstance - if err := v.Decode(&inst); err != nil { + if err := v.JsonDecode(&inst); err != nil { continue } @@ -100,9 +99,9 @@ func (c App) ListAction() { // auto fix if inapi.OpActionAllow(inst.Operate.Action, inapi.OpActionDestroy) { if v.Meta == nil || v.Meta.Expired == 0 { - if rs := data.DataGlobal.NewWriter(inapi.NsKvGlobalAppInstanceDestroyed(inst.Meta.ID), inst).Commit(); rs.OK() { + if rs := data.DataGlobal.NewWriter(inapi.NsKvGlobalAppInstanceDestroyed(inst.Meta.ID), inst).Exec(); rs.OK() { data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(inst.Meta.ID), inst). - ExpireSet(inapi.PodDestroyTTL * 1000).Commit() + SetTTL(inapi.PodDestroyTTL * 1000).Exec() } } continue @@ -191,8 +190,8 @@ func (c App) ListAction() { func (c App) EntryAction() { var app inapi.AppInstance - if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(c.Params.Value("id"))).Query(); rs.OK() { - rs.Decode(&app) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(c.Params.Value("id"))).Exec(); rs.OK() { + rs.Item().JsonDecode(&app) } appOpOptRender(&app, true) @@ -238,8 +237,8 @@ func (c App) SetAction() { } else { - if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(set.Meta.ID)).Query(); rs.OK() { - rs.Decode(&prev) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(set.Meta.ID)).Exec(); rs.OK() { + rs.Item().JsonDecode(&prev) } if prev.Meta.ID != set.Meta.ID || !c.owner_or_sysadmin_allow(prev.Meta.User, "sysinner.admin") { @@ -285,7 +284,7 @@ func (c App) SetAction() { prev.Operate.Action = prev.Operate.Action | inapi.OpActionStop } - var rs *kv2.ObjectResult + var rs *kvapi.ResultSet if set_new { @@ -295,11 +294,11 @@ func (c App) SetAction() { } var pod inapi.Pod - if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(prev.Operate.PodId)).Query(); !rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(prev.Operate.PodId)).Exec(); !rs.OK() { rsp.Error = types.NewErrorMeta("500", "Server Error") return } else { - rs.Decode(&pod) + rs.Item().JsonDecode(&pod) } if pod.Meta.ID != prev.Operate.PodId { @@ -317,14 +316,14 @@ func (c App) SetAction() { return } - rs = data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(prev.Meta.ID), prev).ModeCreateSet(true).Commit() + rs = data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(prev.Meta.ID), prev).SetCreateOnly(true).Exec() } else { - rs = data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(prev.Meta.ID), prev).Commit() + rs = data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(prev.Meta.ID), prev).Exec() } if !rs.OK() { - rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.Message) + rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.ErrorMessage()) return } @@ -335,9 +334,9 @@ func (c App) SetAction() { } if inapi.OpActionAllow(prev.Operate.Action, inapi.OpActionDestroy) { - if rs := data.DataGlobal.NewWriter(inapi.NsKvGlobalAppInstanceDestroyed(prev.Meta.ID), prev).Commit(); rs.OK() { + if rs := data.DataGlobal.NewWriter(inapi.NsKvGlobalAppInstanceDestroyed(prev.Meta.ID), prev).Exec(); rs.OK() { rs = data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(prev.Meta.ID), prev). - ExpireSet(inapi.PodDestroyTTL * 1000).Commit() + SetTTL(inapi.PodDestroyTTL * 1000).Exec() } } rsp.Meta.ID = prev.Meta.ID @@ -456,14 +455,14 @@ func (c App) ListOpResAction() { } // TODO pager - rs := data.DataGlobal.NewReader(nil).KeyRangeSet( + rs := data.DataGlobal.NewRanger( inapi.NsGlobalAppInstance(""), inapi.NsGlobalAppInstance("")). - LimitNumSet(1000).Query() + SetLimit(1000).Exec() for _, v := range rs.Items { var inst inapi.AppInstance - if err := v.Decode(&inst); err != nil { + if err := v.JsonDecode(&inst); err != nil { continue } @@ -534,8 +533,8 @@ func (c App) OpActionSetAction() { // var app inapi.AppInstance - if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(app_id)).Query(); rs.OK() { - rs.Decode(&app) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(app_id)).Exec(); rs.OK() { + rs.Item().JsonDecode(&app) } if app.Meta.ID != app_id || !c.owner_or_sysadmin_allow(app.Meta.User, "sysinner.admin") { @@ -562,8 +561,8 @@ func (c App) OpActionSetAction() { app.Operate.Action = op_action app.Meta.Updated = types.MetaTimeNow() - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(app.Meta.ID), app).Commit(); !rs.OK() { - rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(app.Meta.ID), app).Exec(); !rs.OK() { + rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.ErrorMessage()) return } } @@ -573,9 +572,9 @@ func (c App) OpActionSetAction() { } if inapi.OpActionAllow(app.Operate.Action, inapi.OpActionDestroy) { - if rs := data.DataGlobal.NewWriter(inapi.NsKvGlobalAppInstanceDestroyed(app.Meta.ID), app).Commit(); rs.OK() { + if rs := data.DataGlobal.NewWriter(inapi.NsKvGlobalAppInstanceDestroyed(app.Meta.ID), app).Exec(); rs.OK() { data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(app.Meta.ID), app). - ExpireSet(inapi.PodDestroyTTL * 1000).Commit() + SetTTL(inapi.PodDestroyTTL * 1000).Exec() } } @@ -589,10 +588,10 @@ func appInstDeploy(app inapi.AppInstance) *types.ErrorMeta { } var pod inapi.Pod - if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(app.Operate.PodId)).Query(); !rs.OK() { - return types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(app.Operate.PodId)).Exec(); !rs.OK() { + return types.NewErrorMeta("500", rs.ErrorMessage()) } else { - rs.Decode(&pod) + rs.Item().JsonDecode(&pod) } if pod.Meta.ID != app.Operate.PodId { @@ -613,14 +612,14 @@ func appInstDeploy(app inapi.AppInstance) *types.ErrorMeta { pod.Operate.Version++ pod.Meta.Updated = types.MetaTimeNow() - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(pod.Meta.ID), pod).Commit(); !rs.OK() { - return types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(pod.Meta.ID), pod).Exec(); !rs.OK() { + return types.NewErrorMeta("500", rs.ErrorMessage()) } // Pod Map to Cell Queue sqkey := inapi.NsKvGlobalSetQueuePod(pod.Spec.Zone, pod.Spec.Cell, pod.Meta.ID) - if rs := data.DataGlobal.NewWriter(sqkey, pod).Commit(); !rs.OK() { - return types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewWriter(sqkey, pod).Exec(); !rs.OK() { + return types.NewErrorMeta("500", rs.ErrorMessage()) } hlog.Printf("info", "deploy app/%s to pod/%s", app.Meta.ID, pod.Meta.ID) @@ -642,10 +641,10 @@ func (c App) OpResSetAction() { // var res inapi.Resource - if rs := data.DataGlobal.NewReader(inapi.NsGlobalResInstance(set.Meta.Name)).Query(); !rs.OK() { - rsp.Error = types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalResInstance(set.Meta.Name)).Exec(); !rs.OK() { + rsp.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return - } else if err := rs.Decode(&res); err != nil { + } else if err := rs.Item().JsonDecode(&res); err != nil { rsp.Error = types.NewErrorMeta("400", err.Error()) return } @@ -662,8 +661,8 @@ func (c App) OpResSetAction() { // var app inapi.AppInstance - if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(set.Operate.AppId)).Query(); rs.OK() { - rs.Decode(&app) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(set.Operate.AppId)).Exec(); rs.OK() { + rs.Item().JsonDecode(&app) } if app.Meta.ID == "" || (!app.Operate.ResBoundRoles.MatchAny(c.us.Roles) && @@ -749,14 +748,14 @@ func (c App) OpResSetAction() { res.Meta.Updated = types.MetaTime(opt.Updated) // - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalResInstance(res.Meta.Name), res).Commit(); !rs.OK() { - rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalResInstance(res.Meta.Name), res).Exec(); !rs.OK() { + rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.ErrorMessage()) return } // } - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(app.Meta.ID), app).Commit(); !rs.OK() { - rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(app.Meta.ID), app).Exec(); !rs.OK() { + rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.ErrorMessage()) return } @@ -797,8 +796,8 @@ func (c App) ConfigAction() { } var app inapi.AppInstance - if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(set.Id)).Query(); rs.OK() { - rs.Decode(&app) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(set.Id)).Exec(); rs.OK() { + rs.Item().JsonDecode(&app) } if app.Meta.ID != set.Id || @@ -925,8 +924,8 @@ func (c App) ConfigAction() { app.Operate.Options.Sync(set_opt) app.Meta.Updated = types.MetaTimeNow() - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(app.Meta.ID), app).Commit(); !rs.OK() { - rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(app.Meta.ID), app).Exec(); !rs.OK() { + rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.ErrorMessage()) return } @@ -951,8 +950,8 @@ func (c App) ConfigRepRemotesAction() { } var app inapi.AppInstance - if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(set.Id)).Query(); rs.OK() { - rs.Decode(&app) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(set.Id)).Exec(); rs.OK() { + rs.Item().JsonDecode(&app) } if len(set.DepRemotes) == 0 || len(app.Spec.DepRemotes) == 0 { @@ -978,8 +977,8 @@ func (c App) ConfigRepRemotesAction() { // var refApp inapi.AppInstance - if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(v.AppId)).Query(); rs.OK() { - rs.Decode(&refApp) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(v.AppId)).Exec(); rs.OK() { + rs.Item().JsonDecode(&refApp) } if refApp.Meta.ID != v.AppId { rsp.Error = types.NewErrorMeta("400", @@ -1016,10 +1015,10 @@ func (c App) ConfigRepRemotesAction() { // clean prev settings if optRefCfg != nil && optRefCfg.Ref != nil && (optRefCfg.Ref.AppId != v.AppId || v.Delete) { - if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(optRefCfg.Ref.AppId)).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(optRefCfg.Ref.AppId)).Exec(); rs.OK() { var refAppPrev inapi.AppInstance - rs.Decode(&refAppPrev) + rs.Item().JsonDecode(&refAppPrev) if refAppPrev.Meta.ID == optRefCfg.Ref.AppId { @@ -1028,8 +1027,8 @@ func (c App) ConfigRepRemotesAction() { refAppPrevOpt.Subs.Del(app.Meta.ID) refAppPrev.Operate.Options.Sync(*refAppPrevOpt) - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(refAppPrev.Meta.ID), refAppPrev).Commit(); !rs.OK() { - rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(refAppPrev.Meta.ID), refAppPrev).Exec(); !rs.OK() { + rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.ErrorMessage()) return } } @@ -1054,8 +1053,8 @@ func (c App) ConfigRepRemotesAction() { // refAppOpt.Subs.Set(app.Meta.ID) refApp.Operate.Options.Sync(*refAppOpt) - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(refApp.Meta.ID), refApp).Commit(); !rs.OK() { - rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(refApp.Meta.ID), refApp).Exec(); !rs.OK() { + rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.ErrorMessage()) return } @@ -1099,8 +1098,8 @@ func (c App) ConfigRepRemotesAction() { app.Meta.Updated = types.MetaTimeNow() - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(app.Meta.ID), app).Commit(); !rs.OK() { - rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(app.Meta.ID), app).Exec(); !rs.OK() { + rsp.Error = types.NewErrorMeta(inapi.ErrCodeServerError, rs.ErrorMessage()) return } diff --git a/websrv/v1/charge.go b/websrv/v1/charge.go index fa015a1..6e935d4 100644 --- a/websrv/v1/charge.go +++ b/websrv/v1/charge.go @@ -91,8 +91,8 @@ func (c Charge) PodEstimateAction() { } // - if rs := in_db.DataGlobal.NewReader(inapi.NsGlobalPodSpec("plan", set.Plan)).Query(); rs.OK() { - rs.Decode(&spec_plan) + if rs := in_db.DataGlobal.NewReader(inapi.NsGlobalPodSpec("plan", set.Plan)).Exec(); rs.OK() { + rs.Item().JsonDecode(&spec_plan) } if spec_plan.Meta.ID == "" || spec_plan.Meta.ID != set.Plan { rsp.Error = types.NewErrorMeta("400", "Spec Not Found") @@ -108,8 +108,8 @@ func (c Charge) PodEstimateAction() { // var zone inapi.ResZone - if rs := in_db.DataGlobal.NewReader(inapi.NsGlobalSysZone(set.Zone)).Query(); rs.OK() { - rs.Decode(&zone) + if rs := in_db.DataGlobal.NewReader(inapi.NsGlobalSysZone(set.Zone)).Exec(); rs.OK() { + rs.Item().JsonDecode(&zone) } if zone.Meta.Id == "" { rsp.Error = types.NewErrorMeta("400", "Zone Not Found") @@ -118,8 +118,8 @@ func (c Charge) PodEstimateAction() { // var cell inapi.ResCell - if rs := in_db.DataGlobal.NewReader(inapi.NsGlobalSysCell(set.Zone, set.Cell)).Query(); rs.OK() { - rs.Decode(&cell) + if rs := in_db.DataGlobal.NewReader(inapi.NsGlobalSysCell(set.Zone, set.Cell)).Exec(); rs.OK() { + rs.Item().JsonDecode(&cell) } if cell.Meta.Id == "" { rsp.Error = types.NewErrorMeta("400", "Cell Not Found") diff --git a/websrv/v1/pod-app.go b/websrv/v1/pod-app.go index f0650f3..2ba164d 100644 --- a/websrv/v1/pod-app.go +++ b/websrv/v1/pod-app.go @@ -42,9 +42,9 @@ func (c Pod) AppSyncAction() { app inapi.AppInstance app_sync = false ) - rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(app_id)).Query() + rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(app_id)).Exec() if rs.OK() { - rs.Decode(&app) + rs.Item().JsonDecode(&app) } if app.Meta.ID != app_id { set.Error = types.NewErrorMeta("400", "Bad Request") @@ -85,8 +85,8 @@ func (c Pod) AppSyncAction() { if app_sync { app.Meta.Updated = types.MetaTimeNow() - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(app_id), app).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(app_id), app).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return } } @@ -161,8 +161,8 @@ func (c Pod) AppSyncAction() { // var pod inapi.Pod - if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(app.Operate.PodId)).Query(); rs.OK() { - rs.Decode(&pod) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(app.Operate.PodId)).Exec(); rs.OK() { + rs.Item().JsonDecode(&pod) } if pod.Meta.ID == "" || pod.Meta.ID != app.Operate.PodId || @@ -180,16 +180,16 @@ func (c Pod) AppSyncAction() { pod.Operate.Version++ pod.Meta.Updated = types.MetaTimeNow() - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(pod.Meta.ID), pod).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(pod.Meta.ID), pod).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return } // Pod Map to Cell Queue // pod.OpLogNew("app/"+app.Meta.ID, "info", "deploy sync") sqkey := inapi.NsKvGlobalSetQueuePod(pod.Spec.Zone, pod.Spec.Cell, pod.Meta.ID) - if rs := data.DataGlobal.NewWriter(sqkey, pod).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewWriter(sqkey, pod).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return } @@ -214,9 +214,9 @@ func (c Pod) AppSetAction() { // var pod inapi.Pod - obj := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(app.Operate.PodId)).Query() + obj := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(app.Operate.PodId)).Exec() if obj.OK() { - obj.Decode(&pod) + obj.JsonDecode(&pod) } if pod.Meta.ID == "" || pod.Meta.ID != app.Operate.PodId || !c.owner_or_sysadmin_allow(pod.Meta.User, "sysinner.admin") { @@ -251,15 +251,15 @@ func (c Pod) AppSetAction() { pod.Operate.Version++ pod.Meta.Updated = types.MetaTimeNow() - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(pod.Meta.ID), pod).Commit(); !rs.OK() { - rsp.Error = types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(pod.Meta.ID), pod).Exec(); !rs.OK() { + rsp.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return } // Pod Map to Cell Queue sqkey := inapi.NsKvGlobalSetQueuePod(pod.Spec.Zone, pod.Spec.Cell, pod.Meta.ID) - if rs := data.DataGlobal.NewWriter(sqkey, pod).Commit(); !rs.OK() { - rsp.Error = types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewWriter(sqkey, pod).Exec(); !rs.OK() { + rsp.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return } @@ -294,12 +294,12 @@ func (c Pod) AppExecutorSetAction() { var ( pod inapi.Pod ) - if obj := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(set.PodId)).Query(); !obj.OK() { + if obj := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(set.PodId)).Exec(); !obj.OK() { set.Error = types.NewErrorMeta("400", "Pod Not Found") return } else { - obj.Decode(&pod) + obj.JsonDecode(&pod) } if pod.Meta.ID != set.PodId { @@ -326,11 +326,11 @@ func (c Pod) AppExecutorSetAction() { var spec inapi.SpecExecutor - if obj := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("executor", spec_id)).Query(); !obj.OK() { + if obj := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("executor", spec_id)).Exec(); !obj.OK() { set.Error = types.NewErrorMeta("400", "Spec Not Found") return } else { - obj.Decode(&spec) + obj.JsonDecode(&spec) } if spec.Meta.ID != spec_id { @@ -354,14 +354,14 @@ func (c Pod) AppExecutorSetAction() { pod.Operate.Version++ pod.Meta.Updated = types.MetaTimeNow() - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(set.PodId), pod).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(set.PodId), pod).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return } sqkey := inapi.NsKvGlobalSetQueuePod(pod.Spec.Zone, pod.Spec.Cell, pod.Meta.ID) - if rs := data.DataGlobal.NewWriter(sqkey, pod).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewWriter(sqkey, pod).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return } diff --git a/websrv/v1/pod-bound.go b/websrv/v1/pod-bound.go index fbda8a0..c754cee 100644 --- a/websrv/v1/pod-bound.go +++ b/websrv/v1/pod-bound.go @@ -89,15 +89,15 @@ func (c Podbound) IndexAction() { var pod inapi.Pod - rs := data.DataLocal.NewReader(inapi.NsKvLocalCacheBoundPod(pod_id, rep_id)).Query() + rs := data.DataLocal.NewReader(inapi.NsKvLocalCacheBoundPod(pod_id, rep_id)).Exec() if rs.OK() { - rs.Decode(&pod) + rs.Item().JsonDecode(&pod) } else if rs.NotFound() { json.DecodeFile(fmt.Sprintf(inagent_pod_json, config.Config.Zone.PodHomeDir, pod_id, inutils.Uint16ToHexString(uint16(rep_id))), &pod) if pod.Meta.ID == pod_id { - data.DataLocal.NewWriter(inapi.NsKvLocalCacheBoundPod(pod_id, rep_id), pod).ExpireSet(3600000).Commit() + data.DataLocal.NewWriter(inapi.NsKvLocalCacheBoundPod(pod_id, rep_id), pod).SetTTL(3600000).Exec() } } @@ -182,15 +182,15 @@ func pbPodInstanceSpec(pod_id string, rep_id uint32) *inapi.Pod { var pod inapi.Pod - rs := data.DataLocal.NewReader(inapi.NsKvLocalCacheBoundPod(pod_id, rep_id)).Query() + rs := data.DataLocal.NewReader(inapi.NsKvLocalCacheBoundPod(pod_id, rep_id)).Exec() if rs.OK() { - rs.Decode(&pod) + rs.Item().JsonDecode(&pod) } else if rs.NotFound() { json.DecodeFile(fmt.Sprintf(inagent_pod_json, config.Config.Zone.PodHomeDir, pod_id, inutils.Uint16ToHexString(uint16(rep_id))), &pod) if pod.Meta.ID == pod_id { - data.DataLocal.NewWriter(inapi.NsKvLocalCacheBoundPod(pod_id, rep_id), pod).ExpireSet(3600000).Commit() + data.DataLocal.NewWriter(inapi.NsKvLocalCacheBoundPod(pod_id, rep_id), pod).SetTTL(3600000).Exec() } } diff --git a/websrv/v1/pod-rep.go b/websrv/v1/pod-rep.go index 5a42d71..0c76bd1 100644 --- a/websrv/v1/pod-rep.go +++ b/websrv/v1/pod-rep.go @@ -92,11 +92,11 @@ func (c PodRep) SetAction() { podGlobalKey = inapi.NsGlobalPodInstance(item.Meta.ID) prev inapi.Pod ) - if rs := data.DataGlobal.NewReader(podGlobalKey).Query(); !rs.OK() { + if rs := data.DataGlobal.NewReader(podGlobalKey).Exec(); !rs.OK() { set.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, "Pod Not Found") return } else { - rs.Decode(&prev) + rs.Item().JsonDecode(&prev) } if prev.Meta.ID != item.Meta.ID || @@ -127,7 +127,7 @@ func (c PodRep) SetAction() { // Pod Map to Cell Queue podQueueKey := inapi.NsKvGlobalSetQueuePod(prev.Spec.Zone, prev.Spec.Cell, prev.Meta.ID) - if rs := data.DataGlobal.NewReader(podQueueKey).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(podQueueKey).Exec(); rs.OK() { if tn-prev.Operate.Operated < podActionQueueTimeMin { set.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, "the previous operation is in processing, please try again later") @@ -138,7 +138,7 @@ func (c PodRep) SetAction() { prev.Operate.Version++ prev.Operate.Operated = tn - if rs := data.DataGlobal.NewWriter(podGlobalKey, prev).Commit(); !rs.OK() { + if rs := data.DataGlobal.NewWriter(podGlobalKey, prev).Exec(); !rs.OK() { set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, "server error, please try again later") return @@ -159,7 +159,7 @@ func (c PodRep) SetAction() { } } - if rs := data.DataGlobal.NewWriter(podQueueKey, prev).Commit(); !rs.OK() { + if rs := data.DataGlobal.NewWriter(podQueueKey, prev).Exec(); !rs.OK() { set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, "server error, please try again later") return diff --git a/websrv/v1/pod-spec.go b/websrv/v1/pod-spec.go index 41bd3f8..fb1acd0 100644 --- a/websrv/v1/pod-spec.go +++ b/websrv/v1/pod-spec.go @@ -52,14 +52,14 @@ func (c PodSpec) PlanEntryAction() { set := inapi.PodSpecPlan{} defer c.RenderJson(&set) - rs := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("plan", c.Params.Value("id"))).Query() + rs := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("plan", c.Params.Value("id"))).Exec() if !rs.OK() { set.Error = types.NewErrorMeta("404", "No Spec Found") return } var item inapi.PodSpecPlan - rs.Decode(&item) + rs.Item().JsonDecode(&item) if item.Meta.ID != c.Params.Value("id") { set.Error = types.NewErrorMeta("404", "No Spec Found") return @@ -78,12 +78,12 @@ func (c PodSpec) PlanListAction() { defer c.RenderJson(&ls) // TODO - rs := data.DataGlobal.NewReader(nil).KeyRangeSet( + rs := data.DataGlobal.NewRanger( inapi.NsGlobalPodSpec("plan", ""), inapi.NsGlobalPodSpec("plan", "")). - LimitNumSet(100).Query() + SetLimit(100).Exec() for _, v := range rs.Items { var item inapi.PodSpecPlan - if err := v.Decode(&item); err == nil { + if err := v.JsonDecode(&item); err == nil { if item.Status != inapi.SpecStatusActive { continue @@ -104,7 +104,7 @@ func (c PodSpec) PlanListAction() { } if upgrade { - data.DataGlobal.NewWriter(inapi.NsGlobalPodSpec("plan", item.Meta.ID), item).Commit() + data.DataGlobal.NewWriter(inapi.NsGlobalPodSpec("plan", item.Meta.ID), item).Exec() hlog.Printf("warn", "v1 pod/spec/image upgrade %s", item.Meta.ID) } @@ -126,13 +126,13 @@ func (c PodSpec) ResVolumeListAction() { ls := inapi.PodSpecResVolumeList{} defer c.RenderJson(&ls) - rs := data.DataGlobal.NewReader(nil).KeyRangeSet( + rs := data.DataGlobal.NewRanger( inapi.NsGlobalPodSpec("res/volume", ""), inapi.NsGlobalPodSpec("res/volume", "")). - LimitNumSet(1000).Query() + SetLimit(1000).Exec() for _, v := range rs.Items { var item inapi.PodSpecResVolume - if err := v.Decode(&item); err == nil { + if err := v.JsonDecode(&item); err == nil { ls.Items = append(ls.Items, item) } } diff --git a/websrv/v1/pod-stats.go b/websrv/v1/pod-stats.go index 6b9acff..6ca6ce5 100644 --- a/websrv/v1/pod-stats.go +++ b/websrv/v1/pod-stats.go @@ -106,8 +106,8 @@ func (c PodStats) FeedAction() { return } - if obj := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(podId)).Query(); obj.OK() { - obj.Decode(&pod) + if obj := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(podId)).Exec(); obj.OK() { + obj.JsonDecode(&pod) if pod.Meta.ID == "" || !c.owner_or_sysadmin_allow(pod.Meta.User, "sysinner.admin") { c.RenderJson(types.NewTypeErrorMeta("400", "Pod Not Found")) return @@ -137,10 +137,10 @@ func (c PodStats) FeedAction() { for _, repId := range reps { - if rs := data.DataZone.NewReader(nil).KeyRangeSet( + if rs := data.DataZone.NewRanger( inapi.NsKvZonePodRepStats(pod.Spec.Zone, pod.Meta.ID, repId, "sys", fq.TimeStart-fq.TimeCycle-600), inapi.NsKvZonePodRepStats(pod.Spec.Zone, pod.Meta.ID, repId, "sys", fq.TimeCutset+600)). - LimitNumSet(50000).Query(); rs.OK() { + SetLimit(50000).Exec(); rs.OK() { var ( ifeed inapi.PbStatsIndexFeed @@ -148,7 +148,7 @@ func (c PodStats) FeedAction() { ) for _, v := range rs.Items { - if err := v.Decode(&ifeed); err != nil { + if err := v.JsonDecode(&ifeed); err != nil { continue } diff --git a/websrv/v1/pod-transfer.go b/websrv/v1/pod-transfer.go index ce3f899..0e5c596 100644 --- a/websrv/v1/pod-transfer.go +++ b/websrv/v1/pod-transfer.go @@ -95,11 +95,11 @@ func (c Pod) UserTransferAction() { return } - if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(set.Id)).Query(); !rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(set.Id)).Exec(); !rs.OK() { rsp.Error = types.NewErrorMeta("400", "Prev Pod Not Found") return } else { - rs.Decode(&prev) + rs.Item().JsonDecode(&prev) } if prev.Meta.ID != set.Id { @@ -126,9 +126,9 @@ func (c Pod) UserTransferAction() { } // - if rs := data.DataGlobal.NewReader(inapi.NsKvGlobalPodUserTransfer(prev.Meta.ID)).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsKvGlobalPodUserTransfer(prev.Meta.ID)).Exec(); rs.OK() { var prevTransfer inapi.PodUserTransfer - rs.Decode(&prevTransfer) + rs.Item().JsonDecode(&prevTransfer) if prevTransfer.UserTo == set.UserTo { rsp.Kind = "PodInstance" return @@ -141,8 +141,8 @@ func (c Pod) UserTransferAction() { // if rs := data.DataGlobal.NewWriter(inapi.NsKvGlobalPodUserTransfer(set.Id), set). - ExpireSet(3600 * 1000).Commit(); !rs.OK() { - rsp.Error = types.NewErrorMeta("500", rs.Message) + SetTTL(3600 * 1000).Exec(); !rs.OK() { + rsp.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return } @@ -168,8 +168,8 @@ func (c Pod) UserTransferAction() { msg.Type = mail.BodyType if rs := data.DataZone.NewWriter( - inapi.NsZoneMailQueue(msg.SentId()), msg).Commit(); !rs.OK() { - rsp.Error = types.NewErrorMeta("500", rs.Message) + inapi.NsZoneMailQueue(msg.SentId()), msg).Exec(); !rs.OK() { + rsp.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return } @@ -198,9 +198,9 @@ func (c Pod) UserTransferPerformAction() { it inapi.PodUserTransfer ) - if rs := data.DataGlobal.NewReader(utp).Query(); !rs.OK() { + if rs := data.DataGlobal.NewReader(utp).Exec(); !rs.OK() { continue - } else if err := rs.Decode(&it); err != nil { + } else if err := rs.Item().JsonDecode(&it); err != nil { hlog.Printf("warn", "decode err %s", err.Error()) continue } @@ -212,15 +212,15 @@ func (c Pod) UserTransferPerformAction() { // var pod inapi.Pod - if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(podId)).Query(); rs.OK() { - rs.Decode(&pod) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(podId)).Exec(); rs.OK() { + rs.Item().JsonDecode(&pod) } else { rsp.Error = types.NewErrorMeta(iamapi.ErrCodeAccessDenied, "Access Denied") return } if pod.Meta.User == it.UserTo { - data.DataGlobal.NewWriter(utp, nil).ModeDeleteSet(true).Commit() + data.DataGlobal.NewDeleter(utp).Exec() continue } @@ -236,7 +236,7 @@ func (c Pod) UserTransferPerformAction() { } sqkey := inapi.NsKvGlobalSetQueuePod(pod.Spec.Zone, pod.Spec.Cell, pod.Meta.ID) - if rs := data.DataGlobal.NewReader(sqkey).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(sqkey).Exec(); rs.OK() { if (pod.Operate.Operated + podActionQueueTimeMin) > tn { rsp.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, "the previous operation is in processing, please try again later (1)") @@ -247,8 +247,8 @@ func (c Pod) UserTransferPerformAction() { // var spec_plan inapi.PodSpecPlan if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("plan", - pod.Spec.Ref.Id)).Query(); rs.OK() { - rs.Decode(&spec_plan) + pod.Spec.Ref.Id)).Exec(); rs.OK() { + rs.Item().JsonDecode(&spec_plan) } if spec_plan.Meta.ID == "" || spec_plan.Meta.ID != pod.Spec.Ref.Id { rsp.Error = types.NewErrorMeta("400", "Spec Not Found") @@ -270,15 +270,15 @@ func (c Pod) UserTransferPerformAction() { pod.Operate.Operated = tn // - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(pod.Meta.ID), pod).Commit(); !rs.OK() { - rsp.Error = types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(pod.Meta.ID), pod).Exec(); !rs.OK() { + rsp.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return } // // Pod Map to Cell Queue - data.DataGlobal.NewWriter(sqkey, pod).Commit() - data.DataGlobal.NewWriter(utp, nil).ModeDeleteSet(true).Commit() + data.DataGlobal.NewWriter(sqkey, pod).Exec() + data.DataGlobal.NewDeleter(utp).Exec() } rsp.Kind = "PodInstance" @@ -292,7 +292,7 @@ func (c Pod) userTransferPerformApp(set *inapi.Pod) error { continue } - rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(v.Meta.ID)).Query() + rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(v.Meta.ID)).Exec() if rs.NotFound() { continue } else if !rs.OK() { @@ -300,7 +300,7 @@ func (c Pod) userTransferPerformApp(set *inapi.Pod) error { } // var app inapi.AppInstance - if err := rs.Decode(&app); err != nil { + if err := rs.Item().JsonDecode(&app); err != nil { return err } if app.Meta.ID != v.Meta.ID { @@ -313,7 +313,7 @@ func (c Pod) userTransferPerformApp(set *inapi.Pod) error { continue } - rs2 := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(v2.AppId)).Query() + rs2 := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(v2.AppId)).Exec() if rs2.NotFound() { continue } else if !rs2.OK() { @@ -321,7 +321,7 @@ func (c Pod) userTransferPerformApp(set *inapi.Pod) error { } var app2 inapi.AppInstance - if err := rs2.Decode(&app2); err != nil { + if err := rs2.JsonDecode(&app2); err != nil { return err } if app2.Meta.ID != v2.AppId || @@ -334,7 +334,7 @@ func (c Pod) userTransferPerformApp(set *inapi.Pod) error { app2.Meta.User = set.Meta.User if rs2 = data.DataGlobal.NewWriter( - inapi.NsGlobalAppInstance(v2.AppId), app2).Commit(); !rs2.OK() { + inapi.NsGlobalAppInstance(v2.AppId), app2).Exec(); !rs2.OK() { return rs2.Error() } } @@ -347,7 +347,7 @@ func (c Pod) userTransferPerformApp(set *inapi.Pod) error { v.Meta.ID, app.Meta.User, set.Meta.User) app.Meta.User = set.Meta.User - rs2 := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(v.Meta.ID), app).Commit() + rs2 := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(v.Meta.ID), app).Exec() if !rs2.OK() { return rs2.Error() } diff --git a/websrv/v1/pod.go b/websrv/v1/pod.go index b6fa0b8..4755c71 100644 --- a/websrv/v1/pod.go +++ b/websrv/v1/pod.go @@ -26,7 +26,7 @@ import ( "github.com/lessos/lessgo/crypto/idhash" "github.com/lessos/lessgo/types" iox_utils "github.com/lynkdb/iomix/utils" - kv2 "github.com/lynkdb/kvspec/v2/go/kvspec" + "github.com/lynkdb/kvgo/v2/pkg/kvapi" "github.com/sysinner/incore/config" "github.com/sysinner/incore/data" @@ -75,23 +75,23 @@ func (c Pod) ListAction() { defer c.RenderJson(&ls) // TODO pager - var rs *kv2.ObjectResult + var rs *kvapi.ResultSet if zone_id := c.Params.Value("zone_id"); zone_id != "" { - rs = data.DataZone.NewReader(nil).ModeRevRangeSet(true).KeyRangeSet( + rs = data.DataZone.NewRanger( inapi.NsZonePodInstance(zone_id, "zzzz"), inapi.NsZonePodInstance(zone_id, "")). - LimitNumSet(10000).Query() + SetRevert(true).SetLimit(10000).Exec() if v := c.Params.Value("recover_zone_to_global"); v == "true" { gids := map[string]bool{} - if grs := data.DataGlobal.NewReader(nil).ModeRevRangeSet(true).KeyRangeSet( + if grs := data.DataGlobal.NewRanger( inapi.NsGlobalPodInstance("zzzz"), inapi.NsGlobalPodInstance("")). - LimitNumSet(10000).Query(); grs.OK() { + SetRevert(true).SetLimit(10000).Exec(); grs.OK() { for _, v := range grs.Items { var pod inapi.Pod - if err := v.Decode(&pod); err != nil { + if err := v.JsonDecode(&pod); err != nil { continue } gids[pod.Meta.ID] = true @@ -101,7 +101,7 @@ func (c Pod) ListAction() { for _, v := range rs.Items { var pod inapi.Pod - if err := v.Decode(&pod); err != nil { + if err := v.JsonDecode(&pod); err != nil { continue } @@ -109,14 +109,14 @@ func (c Pod) ListAction() { continue } - data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(pod.Meta.ID), pod).ModeCreateSet(true).Commit() + data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(pod.Meta.ID), pod).SetCreateOnly(true).Exec() hlog.Printf("info", "recover pod %s", pod.Meta.ID) } } } else { - rs = data.DataGlobal.NewReader(nil).ModeRevRangeSet(true).KeyRangeSet( + rs = data.DataGlobal.NewRanger( inapi.NsGlobalPodInstance("zzzz"), inapi.NsGlobalPodInstance("")). - LimitNumSet(10000).Query() + SetRevert(true).SetLimit(10000).Exec() } var fields types.ArrayPathTree @@ -132,9 +132,9 @@ func (c Pod) ListAction() { exp_filter_app_spec_res := &inapi.AppSpecResRequirements{} if v := c.Params.Value("exp_filter_app_spec_id"); v != "" { - if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(v)).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(v)).Exec(); rs.OK() { var spec inapi.AppSpec - rs.Decode(&spec) + rs.Item().JsonDecode(&spec) if spec.Meta.ID == v { if spec.ExpRes != nil { exp_filter_app_spec_res = spec.ExpRes @@ -154,7 +154,7 @@ func (c Pod) ListAction() { var pod inapi.Pod - if err := v.Decode(&pod); err != nil { + if err := v.JsonDecode(&pod); err != nil { continue } @@ -299,13 +299,13 @@ func (c Pod) ListAction() { } } - if rs := data.DataGlobal.NewReader(nil).KeyRangeSet( + if rs := data.DataGlobal.NewRanger( inapi.NsKvGlobalPodUserTransfer(""), inapi.NsKvGlobalPodUserTransfer("")). - LimitNumSet(1000).Query(); rs.OK() { + SetLimit(1000).Exec(); rs.OK() { for _, v := range rs.Items { var it inapi.PodUserTransfer - if err := v.Decode(&it); err == nil { + if err := v.JsonDecode(&it); err == nil { if c.us.AccessAllow(it.UserTo) { ls.UserTransfers = append(ls.UserTransfers, &it) } @@ -328,8 +328,8 @@ func (c Pod) EntryAction() { defer c.RenderJson(&set) if zone_id == "" { - if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(id)).Query(); rs.OK() { - if err := rs.Decode(&set); err != nil { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(id)).Exec(); rs.OK() { + if err := rs.Item().JsonDecode(&set); err != nil { set.Error = types.NewErrorMeta("404", "Pod Not Found "+err.Error()) return } @@ -346,8 +346,8 @@ func (c Pod) EntryAction() { if zone_id != "" { - if rs := data.DataZone.NewReader(inapi.NsZonePodInstance(zone_id, id)).Query(); rs.OK() { - if err := rs.Decode(&set); err != nil { + if rs := data.DataZone.NewReader(inapi.NsZonePodInstance(zone_id, id)).Exec(); rs.OK() { + if err := rs.Item().JsonDecode(&set); err != nil { set.Error = types.NewErrorMeta("404", "Pod Not Found "+err.Error()) return } @@ -418,8 +418,8 @@ func (c Pod) NewAction() { } // - if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("plan", set.Plan)).Query(); rs.OK() { - rs.Decode(&spec_plan) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("plan", set.Plan)).Exec(); rs.OK() { + rs.Item().JsonDecode(&spec_plan) } if spec_plan.Meta.ID == "" || spec_plan.Meta.ID != set.Plan { set.Error = types.NewErrorMeta("400", "Spec Not Found") @@ -529,9 +529,9 @@ func (c Pod) NewAction() { var appSpec *inapi.AppSpec if v := c.Params.Value("exp_filter_app_spec_id"); v != "" { - if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(v)).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(v)).Exec(); rs.OK() { var item inapi.AppSpec - rs.Decode(&item) + rs.Item().JsonDecode(&item) if item.Meta.ID == v && item.ExpRes != nil && item.ExpRes.CpuMin > 0 { // inapi.ObjPrint("app-spec", item) @@ -613,14 +613,14 @@ func (c Pod) NewAction() { // if rs := data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(pod.Meta.ID), pod). - ModeCreateSet(true).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta("500", rs.Message) + SetCreateOnly(true).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return } // Pod Map to Cell Queue sqkey := inapi.NsKvGlobalSetQueuePod(pod.Spec.Zone, pod.Spec.Cell, pod.Meta.ID) - rs := data.DataGlobal.NewWriter(sqkey, pod).Commit() + rs := data.DataGlobal.NewWriter(sqkey, pod).Exec() hlog.Printf("info", "pod map to cell queue %v, msg %v", rs.OK(), pod) set.Pod = pod.Meta.ID @@ -648,11 +648,11 @@ func (c Pod) OpActionSetAction() { } var prev inapi.Pod - if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(pod_id)).Query(); !rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(pod_id)).Exec(); !rs.OK() { set.Error = types.NewErrorMeta("400", "Pod Not Found") return } else { - rs.Decode(&prev) + rs.Item().JsonDecode(&prev) } if prev.Meta.ID != pod_id || @@ -695,7 +695,7 @@ func (c Pod) OpActionSetAction() { // Pod Map to Cell Queue sqkey := inapi.NsKvGlobalSetQueuePod(prev.Spec.Zone, prev.Spec.Cell, prev.Meta.ID) - if rs := data.DataGlobal.NewReader(sqkey).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(sqkey).Exec(); rs.OK() { if (prev.Operate.Operated + podActionQueueTimeMin) > tn { set.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, "the previous operation is in processing, please try again later") } @@ -707,18 +707,18 @@ func (c Pod) OpActionSetAction() { } prev.Operate.Operated = tn - if rs := data.DataGlobal.NewWriter(sqkey, prev).Commit(); !rs.OK() { + if rs := data.DataGlobal.NewWriter(sqkey, prev).Exec(); !rs.OK() { set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, "server error, please try again later") return } if inapi.OpActionAllow(prev.Operate.Action, inapi.OpActionDestroy) { data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(prev.Meta.ID), prev). - ExpireSet(inapi.PodDestroyTTL * 1000).Commit() + SetTTL(inapi.PodDestroyTTL * 1000).Exec() data.DataGlobal.NewWriter(inapi.NsKvGlobalPodInstanceDestroyed(prev.Meta.ID), prev). - Commit() + Exec() } else { - data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(prev.Meta.ID), prev).Commit() + data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(prev.Meta.ID), prev).Exec() } set.Kind = "PodInstance" @@ -743,11 +743,11 @@ func (c Pod) SetInfoAction() { return } - if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(set.Meta.ID)).Query(); !rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(set.Meta.ID)).Exec(); !rs.OK() { set.Error = types.NewErrorMeta("400", "Prev Pod Not Found") return } else { - rs.Decode(&prev) + rs.Item().JsonDecode(&prev) } if prev.Meta.ID != set.Meta.ID { @@ -867,7 +867,7 @@ func (c Pod) SetInfoAction() { // Pod Map to Cell Queue sqkey := inapi.NsKvGlobalSetQueuePod(prev.Spec.Zone, prev.Spec.Cell, prev.Meta.ID) - if rs := data.DataGlobal.NewReader(sqkey).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(sqkey).Exec(); rs.OK() { if (prev.Operate.Operated + podActionQueueTimeMin) > tn { set.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, "the previous operation is in processing, please try again later") return @@ -875,17 +875,17 @@ func (c Pod) SetInfoAction() { } prev.Operate.Operated = tn - if rs := data.DataGlobal.NewWriter(sqkey, prev).Commit(); !rs.OK() { + if rs := data.DataGlobal.NewWriter(sqkey, prev).Exec(); !rs.OK() { set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, "server error, please try again later") return } if inapi.OpActionAllow(prev.Operate.Action, inapi.OpActionDestroy) { data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(prev.Meta.ID), prev). - ExpireSet(inapi.PodDestroyTTL * 1000).Commit() - data.DataGlobal.NewWriter(inapi.NsKvGlobalPodInstanceDestroyed(prev.Meta.ID), prev).Commit() + SetTTL(inapi.PodDestroyTTL * 1000).Exec() + data.DataGlobal.NewWriter(inapi.NsKvGlobalPodInstanceDestroyed(prev.Meta.ID), prev).Exec() } else { - data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(prev.Meta.ID), prev).Commit() + data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(prev.Meta.ID), prev).Exec() } set.Kind = "PodInstance" @@ -901,11 +901,11 @@ func (c Pod) DeleteAction() { defer c.RenderJson(&set) - if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(pod_id)).Query(); !rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(pod_id)).Exec(); !rs.OK() { set.Error = types.NewErrorMeta("400", "Prev Pod Not Found") return } else { - rs.Decode(&prev) + rs.Item().JsonDecode(&prev) } if prev.Meta.ID != pod_id { @@ -927,16 +927,16 @@ func (c Pod) DeleteAction() { var app inapi.AppInstance - rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(v.Meta.ID)).Query() + rs := data.DataGlobal.NewReader(inapi.NsGlobalAppInstance(v.Meta.ID)).Exec() if rs.NotFound() { continue } if !rs.OK() { - set.Error = types.NewErrorMeta("500", "server error "+rs.Message) + set.Error = types.NewErrorMeta("500", "server error "+rs.ErrorMessage()) return } else { - rs.Decode(&app) + rs.Item().JsonDecode(&app) } if app.Meta.ID != v.Meta.ID { @@ -951,8 +951,8 @@ func (c Pod) DeleteAction() { app.Operate.Action = inapi.OpActionDestroy app.Meta.Updated = types.MetaTimeNow() - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(v.Meta.ID), app).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalAppInstance(v.Meta.ID), app).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return } @@ -969,7 +969,7 @@ func (c Pod) DeleteAction() { // Pod Map to Cell Queue sqkey := inapi.NsKvGlobalSetQueuePod(prev.Spec.Zone, prev.Spec.Cell, prev.Meta.ID) - if rs := data.DataGlobal.NewReader(sqkey).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(sqkey).Exec(); rs.OK() { if tn-prev.Operate.Operated < podActionSetTimeMin { set.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, "the previous operation is in processing, please try again later") return @@ -977,17 +977,17 @@ func (c Pod) DeleteAction() { } prev.Operate.Operated = tn - if rs := data.DataGlobal.NewWriter(sqkey, prev).Commit(); !rs.OK() { + if rs := data.DataGlobal.NewWriter(sqkey, prev).Exec(); !rs.OK() { set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, "server error, please try again later") return } if inapi.OpActionAllow(prev.Operate.Action, inapi.OpActionDestroy) { data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(prev.Meta.ID), prev). - ExpireSet(inapi.PodDestroyTTL * 1000).Commit() - data.DataGlobal.NewWriter(inapi.NsKvGlobalPodInstanceDestroyed(prev.Meta.ID), prev).Commit() + SetTTL(inapi.PodDestroyTTL * 1000).Exec() + data.DataGlobal.NewWriter(inapi.NsKvGlobalPodInstanceDestroyed(prev.Meta.ID), prev).Exec() } else { - data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(prev.Meta.ID), prev).Commit() + data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(prev.Meta.ID), prev).Exec() } set.Kind = "PodInstance" @@ -1007,8 +1007,8 @@ func (c *Pod) status(pod inapi.Pod, pod_id string) inapi.PodStatus { if pod.Meta.ID == "" { // - if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(pod_id)).Query(); rs.OK() { - rs.Decode(&pod) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(pod_id)).Exec(); rs.OK() { + rs.Item().JsonDecode(&pod) } if pod.Meta.ID == "" || !c.owner_or_sysadmin_allow(pod.Meta.User, "sysinner.admin") { @@ -1024,8 +1024,8 @@ func (c *Pod) status(pod inapi.Pod, pod_id string) inapi.PodStatus { } } else { - if rs := data.DataGlobal.NewReader(inapi.NsKvGlobalPodStatus(pod.Spec.Zone, pod.Meta.ID)).Query(); rs.OK() { - rs.Decode(&podStatus) + if rs := data.DataGlobal.NewReader(inapi.NsKvGlobalPodStatus(pod.Spec.Zone, pod.Meta.ID)).Exec(); rs.OK() { + rs.Item().JsonDecode(&podStatus) } } @@ -1097,11 +1097,11 @@ func (c Pod) AccessSetAction() { } } - if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(set.Meta.ID)).Query(); !rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(set.Meta.ID)).Exec(); !rs.OK() { set.Error = types.NewErrorMeta("400", "Prev Pod Not Found") return } else { - rs.Decode(&prev) + rs.Item().JsonDecode(&prev) } if prev.Meta.ID != set.Meta.ID { @@ -1156,7 +1156,7 @@ func (c Pod) AccessSetAction() { // Pod Map to Cell Queue sqkey := inapi.NsKvGlobalSetQueuePod(prev.Spec.Zone, prev.Spec.Cell, prev.Meta.ID) - if rs := data.DataGlobal.NewReader(sqkey).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(sqkey).Exec(); rs.OK() { if (prev.Operate.Operated + podActionQueueTimeMin) > tn { set.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, "the previous operation is in processing, please try again later") } @@ -1164,11 +1164,11 @@ func (c Pod) AccessSetAction() { } prev.Operate.Operated = tn - if rs := data.DataGlobal.NewWriter(sqkey, prev).Commit(); !rs.OK() { + if rs := data.DataGlobal.NewWriter(sqkey, prev).Exec(); !rs.OK() { set.Error = types.NewErrorMeta(inapi.ErrCodeServerError, "server error, please try again later") return } - data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(prev.Meta.ID), prev).Commit() + data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(prev.Meta.ID), prev).Exec() set.Kind = "PodInstance" } @@ -1193,8 +1193,8 @@ func (c Pod) SpecSetAction() { } // - if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(set.Pod)).Query(); rs.OK() { - rs.Decode(&prev) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodInstance(set.Pod)).Exec(); rs.OK() { + rs.Item().JsonDecode(&prev) } if prev.Meta.ID != set.Pod { set.Error = types.NewErrorMeta("400", "Pod Not Found") @@ -1243,8 +1243,8 @@ func (c Pod) SpecSetAction() { } // - if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("plan", set.Plan)).Query(); rs.OK() { - rs.Decode(&spec_plan) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalPodSpec("plan", set.Plan)).Exec(); rs.OK() { + rs.Item().JsonDecode(&spec_plan) } if spec_plan.Meta.ID == "" || spec_plan.Meta.ID != set.Plan { set.Error = types.NewErrorMeta("400", "Spec Not Found") @@ -1373,9 +1373,9 @@ func (c Pod) SpecSetAction() { for _, app := range prev.Apps { - if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(app.Spec.Meta.ID)).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalAppSpec(app.Spec.Meta.ID)).Exec(); rs.OK() { var app_spec inapi.AppSpec - rs.Decode(&app_spec) + rs.Item().JsonDecode(&app_spec) if app_spec.Meta.ID == app.Spec.Meta.ID && app_spec.ExpRes != nil && app_spec.ExpRes.CpuMin > 0 { if err := appPodResCheck(&prev, app_spec.ExpRes); err != nil { @@ -1395,7 +1395,7 @@ func (c Pod) SpecSetAction() { prev.Meta.Updated = types.MetaTimeNow() sqkey := inapi.NsKvGlobalSetQueuePod(prev.Spec.Zone, prev.Spec.Cell, prev.Meta.ID) - if rs := data.DataGlobal.NewReader(sqkey).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(sqkey).Exec(); rs.OK() { if (prev.Operate.Operated + podActionQueueTimeMin) > tn { set.Error = types.NewErrorMeta(inapi.ErrCodeBadArgument, "the previous operation is in processing, please try again later") return @@ -1405,13 +1405,13 @@ func (c Pod) SpecSetAction() { prev.Operate.Operated = tn // - if rs := data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(prev.Meta.ID), prev).Commit(); !rs.OK() { - set.Error = types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewWriter(inapi.NsGlobalPodInstance(prev.Meta.ID), prev).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return } // Pod Map to Cell Queue - rs := data.DataGlobal.NewWriter(sqkey, prev).ModeCreateSet(true).Commit() + rs := data.DataGlobal.NewWriter(sqkey, prev).SetCreateOnly(true).Exec() hlog.Printf("info", "pod map to cell queue %v, msg %v", rs.OK(), prev) set.Pod = prev.Meta.ID diff --git a/websrv/v1/res-domain.go b/websrv/v1/res-domain.go index b79d383..1941353 100644 --- a/websrv/v1/res-domain.go +++ b/websrv/v1/res-domain.go @@ -86,10 +86,10 @@ func (c Resource) DomainAction() { obj_name := fmt.Sprintf("%s/%s", inapi.ResourceTypeDomain, name) var prev inapi.Resource - if rs := data.DataGlobal.NewReader(inapi.NsGlobalResInstance(obj_name)).Query(); !rs.OK() { - set.Error = types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalResInstance(obj_name)).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return - } else if err := rs.Decode(&prev); err != nil { + } else if err := rs.Item().JsonDecode(&prev); err != nil { set.Error = types.NewErrorMeta("400", err.Error()) return } @@ -143,9 +143,9 @@ func (c Resource) DomainNewAction() { obj_name_main := fmt.Sprintf("%s/%s", inapi.ResourceTypeDomain, strings.Join(ar[len(ar)-2:], ".")) - if rs := data.DataGlobal.NewReader(inapi.NsGlobalResInstance(obj_name_main)).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalResInstance(obj_name_main)).Exec(); rs.OK() { var res inapi.Resource - if err := rs.Decode(&res); err != nil { + if err := rs.Item().JsonDecode(&res); err != nil { set.Error = types.NewErrorMeta(inapi.ErrCodeObjectExists, "Domain Exists") return } @@ -170,13 +170,13 @@ func (c Resource) DomainNewAction() { Action: inapi.ResourceActionOK, } - if rs := data.DataGlobal.NewReader(inapi.NsGlobalResInstance(obj_name)).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalResInstance(obj_name)).Exec(); rs.OK() { set.Error = types.NewErrorMeta(inapi.ErrCodeObjectExists, "Domain Exists") return } // - data.DataGlobal.NewWriter(inapi.NsGlobalResInstance(obj_name), inst).Commit() + data.DataGlobal.NewWriter(inapi.NsGlobalResInstance(obj_name), inst).Exec() set.Kind = "Resource" } @@ -213,10 +213,10 @@ func (c Resource) DomainSetAction() { sync = false ) - if rs := data.DataGlobal.NewReader(inapi.NsGlobalResInstance(obj_name)).Query(); !rs.OK() { - set.Error = types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalResInstance(obj_name)).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return - } else if err := rs.Decode(&prev); err != nil { + } else if err := rs.Item().JsonDecode(&prev); err != nil { set.Error = types.NewErrorMeta("400", err.Error()) return } @@ -255,7 +255,7 @@ func (c Resource) DomainSetAction() { if sync { prev.Meta.Updated = types.MetaTimeNow() - data.DataGlobal.NewWriter(inapi.NsGlobalResInstance(obj_name), prev).Commit() + data.DataGlobal.NewWriter(inapi.NsGlobalResInstance(obj_name), prev).Exec() } set.Kind = "Resource" @@ -288,10 +288,10 @@ func (c Resource) DomainBoundAction() { var prev inapi.Resource - if rs := data.DataGlobal.NewReader(inapi.NsGlobalResInstance(obj_name)).Query(); !rs.OK() { - set.Error = types.NewErrorMeta("500", rs.Message) + if rs := data.DataGlobal.NewReader(inapi.NsGlobalResInstance(obj_name)).Exec(); !rs.OK() { + set.Error = types.NewErrorMeta("500", rs.ErrorMessage()) return - } else if err := rs.Decode(&prev); err != nil { + } else if err := rs.Item().JsonDecode(&prev); err != nil { set.Error = types.NewErrorMeta("400", err.Error()) return } @@ -383,7 +383,7 @@ func (c Resource) DomainBoundAction() { prev.Meta.Updated = types.MetaTimeNow() // - data.DataGlobal.NewWriter(inapi.NsGlobalResInstance(obj_name), prev).Commit() + data.DataGlobal.NewWriter(inapi.NsGlobalResInstance(obj_name), prev).Exec() } set.Kind = "Resource" diff --git a/websrv/v1/res.go b/websrv/v1/res.go index 9614d24..3672b2d 100644 --- a/websrv/v1/res.go +++ b/websrv/v1/res.go @@ -67,8 +67,8 @@ func (c Resource) ListAction() { var ( offset = inapi.NsGlobalResInstance(c.Params.Value("type") + "/") - rs = data.DataGlobal.NewReader(nil).KeyRangeSet(offset, offset). - LimitNumSet(1000).Query() + rs = data.DataGlobal.NewRanger(offset, offset). + SetLimit(1000).Exec() fields types.ArrayPathTree ) @@ -81,7 +81,7 @@ func (c Resource) ListAction() { var inst inapi.Resource - if err := v.Decode(&inst); err != nil { + if err := v.JsonDecode(&inst); err != nil { continue } diff --git a/websrv/v1/sys.go b/websrv/v1/sys.go index 15367bd..512594d 100644 --- a/websrv/v1/sys.go +++ b/websrv/v1/sys.go @@ -81,9 +81,9 @@ func (c *Sys) CfgAction() { } // - if rs := in_db.DataGlobal.NewReader(inapi.NsGlobalSysConfig(v.Name)).Query(); rs.OK() { + if rs := in_db.DataGlobal.NewReader(inapi.NsGlobalSysConfig(v.Name)).Exec(); rs.OK() { var item inapi.SysConfigGroup - if err := rs.Decode(&item); err == nil { + if err := rs.Item().JsonDecode(&item); err == nil { sysCfg.SysConfigs = append(sysCfg.SysConfigs, &item) } } diff --git a/zonemaster/init.go b/zonemaster/init.go index 742d93e..b581282 100644 --- a/zonemaster/init.go +++ b/zonemaster/init.go @@ -19,12 +19,11 @@ import ( "strings" "github.com/hooto/hlog4g/hlog" - kv2 "github.com/lynkdb/kvspec/v2/go/kvspec" "github.com/sysinner/incore/data" ) -func InitData(items []*kv2.ClientObjectItem) error { +func InitData(items map[string]interface{}) error { if data.DataGlobal == nil { return fmt.Errorf("data.DataGlobal Not Init") @@ -34,31 +33,35 @@ func InitData(items []*kv2.ClientObjectItem) error { return fmt.Errorf("data.DataZone Not Init") } - for _, v := range items { + if len(items) == 0 { + return nil + } + + for key, value := range items { - if strings.HasPrefix(string(v.Key), "ing:") || - strings.Contains(string(v.Key), "/ing/") { + if strings.HasPrefix(key, "ing:") || + strings.Contains(key, "/ing/") { - if rs := data.DataGlobal.NewWriter(v.Key, v.Value). - ModeCreateSet(true).Commit(); !rs.OK() { - return fmt.Errorf("gm.initdata error on key : %s", string(v.Key)) - } else if rs.Meta.Created > 0 { + if rs := data.DataGlobal.NewWriter([]byte(key), value). + SetCreateOnly(true).Exec(); !rs.OK() { + return fmt.Errorf("gm.initdata error on key : %s", key) + } else if rs.Item().Meta.Updated > 0 { continue } } - if strings.HasPrefix(string(v.Key), "inz:") || - strings.Contains(string(v.Key), "/inz/") { + if strings.HasPrefix(key, "inz:") || + strings.Contains(key, "/inz/") { - if rs := data.DataZone.NewWriter(v.Key, v.Value). - ModeCreateSet(true).Commit(); !rs.OK() { - return fmt.Errorf("zm.initdata error on key : %s", string(v.Key)) - } else if rs.Meta.Created > 0 { + if rs := data.DataZone.NewWriter([]byte(key), value). + SetCreateOnly(true).Exec(); !rs.OK() { + return fmt.Errorf("zm.initdata error on key : %s", key) + } else if rs.Item().Meta.Updated > 0 { continue } } - hlog.Printf("info", "init.data skip key %s", string(v.Key)) + hlog.Printf("info", "init.data skip key %s", key) } return nil diff --git a/zonemaster/job.go b/zonemaster/job.go index 5347874..ff898f0 100644 --- a/zonemaster/job.go +++ b/zonemaster/job.go @@ -89,6 +89,7 @@ func (it *ZoneMainJob) Run(ctx *injob.Context) error { if !it.inited { if err := it.init(); err != nil { + hlog.Printf("error", "zm/job init err:%s", err.Error()) return err } it.inited = true @@ -167,6 +168,9 @@ func (it *ZoneMainJob) init() error { (iam_cfg.Config.InstanceID + iam_cfg.Version)), 16) // init database + if ic_db.DataGlobal == nil { + return fmt.Errorf("iam.Store.Init error: config not setup") + } iam_db.Data = ic_db.DataGlobal if err := iam_db.Setup(); err != nil { hlog.Printf("warn", "zone job init %v", err.Error()) @@ -236,11 +240,10 @@ func (it *ZoneMainJob) init() error { } // init inpack database - ip_db.Data = ic_db.DataInpack + ip_db.Data = ic_db.DataPack if err = ip_db.Setup(); err != nil { return fmt.Errorf("ip_db setup failed:%s", err.Error()) } - // ic_db.DataInpack = ip_db.Data // TODEL ip_cfg.Config.Sync() diff --git a/zonemaster/leader.go b/zonemaster/leader.go index 1ee5b9f..1b1b497 100644 --- a/zonemaster/leader.go +++ b/zonemaster/leader.go @@ -39,44 +39,44 @@ func zmWorkerMasterLeaderRefresh() { if rs := data.DataZone.NewWriter( zmLeaderKey, status.Host.Meta.Id). - PrevDataCheckSet(status.Host.Meta.Id, nil). - ExpireSet(12000).Commit(); rs.OK() { + SetPrevChecksum(status.Host.Meta.Id). + SetTTL(12000).Exec(); rs.OK() { - status.ZoneMasterList.Version = rs.Meta.Version - status.ZoneMasterList.Updated = rs.Meta.Updated + status.ZoneMasterList.Version = rs.Item().Meta.Version + status.ZoneMasterList.Updated = uint64(rs.Item().Meta.Updated) - hlog.Printf("debug", "zm/zone-master/leader refresh %d", rs.Meta.Version) + hlog.Printf("debug", "zm/zone-master/leader refresh %d", rs.Item().Meta.Version) } else { - hlog.Printf("warn", "zm/zone-master/leader refresh failed %s", rs.Message) + hlog.Printf("warn", "zm/zone-master/leader refresh failed %s", rs.ErrorMessage()) } return } - if rs := data.DataZone.NewReader(zmLeaderKey).Query(); rs.NotFound() { + if rs := data.DataZone.NewReader(zmLeaderKey).Exec(); rs.NotFound() { if rs2 := data.DataZone.NewWriter( zmLeaderKey, status.Host.Meta.Id). - PrevDataCheckSet(status.Host.Meta.Id, nil). - ExpireSet(12000).Commit(); rs2.OK() { + SetPrevChecksum(status.Host.Meta.Id). + SetTTL(12000).Exec(); rs2.OK() { status.ZoneMasterList.Leader = status.Host.Meta.Id - status.ZoneMasterList.Version = rs2.Meta.Version - status.ZoneMasterList.Updated = rs2.Meta.Updated + status.ZoneMasterList.Version = rs2.Item().Meta.Version + status.ZoneMasterList.Updated = uint64(rs2.Item().Meta.Updated) status.ZoneLeaded = time.Now().Unix() hlog.Printf("warn", "zm/zone-master/leader new node %s, version %d", - status.Host.Meta.Id, rs2.Meta.Version) + status.Host.Meta.Id, rs2.Item().Meta.Version) } else { - hlog.Printf("warn", "zm/zone-master/leader refresh failed %s", rs2.Message) + hlog.Printf("warn", "zm/zone-master/leader refresh failed %s", rs2.ErrorMessage()) } } else if rs.OK() && len(rs.Items) > 0 { - hostId := rs.DataValue().String() + hostId := rs.Item().StringValue() if inapi.ResSysHostIdReg.MatchString(hostId) && (hostId != status.ZoneMasterList.Leader || rs.Items[0].Meta.Version > status.ZoneMasterList.Version) { @@ -88,10 +88,10 @@ func zmWorkerMasterLeaderRefresh() { hostId, status.ZoneMasterList.Version, rs.Items[0].Meta.Expired) } - status.ZoneMasterList.Updated = rs.Items[0].Meta.Updated + status.ZoneMasterList.Updated = uint64(rs.Items[0].Meta.Updated) } else { - hlog.Printf("warn", "zm/zone-master/leader active refresh failed %s", rs.Message) + hlog.Printf("warn", "zm/zone-master/leader active refresh failed %s", rs.ErrorMessage()) } } diff --git a/zonemaster/mail.go b/zonemaster/mail.go index 8acf815..45a0171 100644 --- a/zonemaster/mail.go +++ b/zonemaster/mail.go @@ -90,7 +90,7 @@ func haEmailAction(pod *inapi.Pod, repId uint32) error { msg.Type = mail.BodyType if rs := data.DataZone.NewWriter( - inapi.NsZoneMailQueue(msg.SentId()), msg).Commit(); !rs.OK() { + inapi.NsZoneMailQueue(msg.SentId()), msg).Exec(); !rs.OK() { return rs.Error() } diff --git a/zonemaster/pod-charge.go b/zonemaster/pod-charge.go index a54172c..af3ca97 100644 --- a/zonemaster/pod-charge.go +++ b/zonemaster/pod-charge.go @@ -49,12 +49,12 @@ func podChargeRefresh() error { // TODO pod_specPlans = []*inapi.PodSpecPlan{} - if rs := data.DataGlobal.NewReader(nil).KeyRangeSet( + if rs := data.DataGlobal.NewRanger( inapi.NsGlobalPodSpec("plan", ""), inapi.NsGlobalPodSpec("plan", "")). - LimitNumSet(100).Query(); rs.OK() { + SetLimit(100).Exec(); rs.OK() { for _, v := range rs.Items { var item inapi.PodSpecPlan - if err := v.Decode(&item); err == nil { + if err := v.JsonDecode(&item); err == nil { item.ChargeFix() pod_specPlans = append(pod_specPlans, &item) } @@ -156,7 +156,7 @@ func podItemCharge(pod *inapi.Pod) bool { if inapi.OpActionAllow(pod.Operate.Action, inapi.OpActionDestroy) { pod.Payment.TimeClose = tn data.DataZone.NewWriter( - inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID), pod).Commit() + inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID), pod).Exec() } return false } @@ -230,7 +230,7 @@ func podItemCharge(pod *inapi.Pod) bool { pod.Payment.User = payUser data.DataZone.NewWriter( - inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID), pod).Commit() + inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID), pod).Exec() hlog.Printf("info", "Pod %s AccountChargePrepay %f, time start %d, in %d sec", pod.Meta.ID, payAmount, @@ -245,7 +245,7 @@ func podItemCharge(pod *inapi.Pod) bool { inapi.NewPbOpLogEntry(inapi.OpLogNsZoneMasterPodScheduleCharge, inapi.PbOpLogWarn, rsp.Error.Message)) data.DataZone.NewWriter( - inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID), pod).Commit() + inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID), pod).Exec() } hlog.Printf("error", "Pod %s AccountChargePrepay %f %s", pod.Meta.ID, pod.Payment.Prepay, rsp.Error.Code+" : "+rsp.Error.Message) @@ -272,7 +272,7 @@ func podItemCharge(pod *inapi.Pod) bool { pod.Payment.User = "" data.DataZone.NewWriter( - inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID), pod).Commit() + inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID), pod).Exec() hlog.Printf("info", "Pod %s AccountChargePayout %f DONE", pod.Meta.ID, pod.Payment.Payout) @@ -309,11 +309,11 @@ func podEntryChargeOut(pod_id string) { prev.Operate.Version++ prev.Meta.Updated = types.MetaTimeNow() - data.DataZone.NewWriter(inapi.NsZonePodInstance(status.ZoneId, prev.Meta.ID), prev).Commit() + data.DataZone.NewWriter(inapi.NsZonePodInstance(status.ZoneId, prev.Meta.ID), prev).Exec() // Pod Map to Cell Queue sqkey := inapi.NsKvGlobalSetQueuePod(prev.Spec.Zone, prev.Spec.Cell, prev.Meta.ID) - data.DataGlobal.NewWriter(sqkey, prev).Commit() + data.DataGlobal.NewWriter(sqkey, prev).Exec() hlog.Printf("info", "Pod %s AccountChargeOut", prev.Meta.ID) } diff --git a/zonemaster/rpc-server.go b/zonemaster/rpc-server.go index 28116bd..8241cb9 100644 --- a/zonemaster/rpc-server.go +++ b/zonemaster/rpc-server.go @@ -71,7 +71,7 @@ func (s *ApiZoneMaster) HostConfig( } dbkey := inapi.NsZoneSysHost(status.ZoneId, req.Id) - rs := data.DataZone.NewReader(dbkey).Query() + rs := data.DataZone.NewReader(dbkey).Exec() if !rs.OK() { if !rs.NotFound() { return nil, errors.New("Server Error, Try again later") @@ -99,7 +99,7 @@ func (s *ApiZoneMaster) HostConfig( } if rs := data.DataZone.NewWriter( - inapi.NsZoneSysHostSecretKey(node.Operate.ZoneId, node.Meta.Id), req.SecretKey).Commit(); !rs.OK() { + inapi.NsZoneSysHostSecretKey(node.Operate.ZoneId, node.Meta.Id), req.SecretKey).Exec(); !rs.OK() { return nil, errors.New("Server Error") } } @@ -157,8 +157,8 @@ func (s *ApiZoneMaster) HostStatusSync( pk := inapi.NsKvZoneSysHostStats(status.ZoneId, req.Meta.Id, v.Time) var statsIndex inapi.PbStatsIndexFeed - if rs := data.DataZone.NewReader(pk).Query(); rs.OK() { - rs.Decode(&statsIndex) + if rs := data.DataZone.NewReader(pk).Exec(); rs.OK() { + rs.Item().JsonDecode(&statsIndex) if statsIndex.Time < 1 { continue } @@ -172,7 +172,7 @@ func (s *ApiZoneMaster) HostStatusSync( } if len(statsIndex.Items) > 0 { - data.DataZone.NewWriter(pk, statsIndex).ExpireSet(30 * 86400 * 1000).Commit() + data.DataZone.NewWriter(pk, statsIndex).SetTTL(30 * 86400 * 1000).Exec() } } req.Status.Stats = nil @@ -229,8 +229,8 @@ func (s *ApiZoneMaster) HostStatusSync( status.ZoneId, repStatus.PodId, repStatus.RepId, "sys", iv.Time) var statsIndex inapi.PbStatsIndexFeed - if rs := data.DataZone.NewReader(repStatsKey).Query(); rs.OK() { - rs.Decode(&statsIndex) + if rs := data.DataZone.NewReader(repStatsKey).Exec(); rs.OK() { + rs.Item().JsonDecode(&statsIndex) if statsIndex.Time < 1 { continue } @@ -244,7 +244,7 @@ func (s *ApiZoneMaster) HostStatusSync( } if len(statsIndex.Items) > 0 { - data.DataZone.NewWriter(repStatsKey, statsIndex).ExpireSet(30 * 86400 * 1000).Commit() + data.DataZone.NewWriter(repStatsKey, statsIndex).SetTTL(30 * 86400 * 1000).Exec() } } } @@ -528,9 +528,9 @@ func zmHostAddrChange(host *inapi.ResHost, addr_prev string) { // TOPO if rs := data.DataGlobal.NewWriter( - inapi.NsGlobalSysZone(status.ZoneId), status.Zone).Commit(); rs.OK() { + inapi.NsGlobalSysZone(status.ZoneId), status.Zone).Exec(); rs.OK() { data.DataZone.NewWriter( - inapi.NsZoneSysZone(status.ZoneId), status.Zone).Commit() + inapi.NsZoneSysZone(status.ZoneId), status.Zone).Exec() } break @@ -539,10 +539,10 @@ func zmHostAddrChange(host *inapi.ResHost, addr_prev string) { } if rs := data.DataZone.NewReader( - inapi.NsZoneSysMasterNode(status.ZoneId, host.Meta.Id)).Query(); rs.OK() { + inapi.NsZoneSysMasterNode(status.ZoneId, host.Meta.Id)).Exec(); rs.OK() { var obj inapi.ResZoneMasterNode - if err := rs.Decode(&obj); err == nil { + if err := rs.Item().JsonDecode(&obj); err == nil { if obj.Addr == addr_prev { @@ -550,7 +550,7 @@ func zmHostAddrChange(host *inapi.ResHost, addr_prev string) { Id: host.Meta.Id, Addr: host.Spec.PeerLanAddr, Action: 1, - }).Commit() + }).Exec() hlog.Printf("warn", "zm NsZoneSysMasterNode %s->%s", addr_prev, host.Spec.PeerLanAddr) diff --git a/zonemaster/scheduler.go b/zonemaster/scheduler.go index 52bfe2c..2fcbe2b 100644 --- a/zonemaster/scheduler.go +++ b/zonemaster/scheduler.go @@ -141,9 +141,9 @@ func scheduleAction() error { func schedulePodSpecPlanListRefresh() error { - rs := data.DataGlobal.NewReader(nil).KeyRangeSet( + rs := data.DataGlobal.NewRanger( inapi.NsGlobalPodSpec("plan", ""), inapi.NsGlobalPodSpec("plan", "")). - LimitNumSet(1000).Query() + SetLimit(1000).Exec() if !rs.OK() { return errors.New("gm/db error") } @@ -151,7 +151,7 @@ func schedulePodSpecPlanListRefresh() error { zonePodSpecPlans = inapi.PodSpecPlans{} for _, v := range rs.Items { var specPlan inapi.PodSpecPlan - if err := v.Decode(&specPlan); err == nil { + if err := v.JsonDecode(&specPlan); err == nil { specPlan.ChargeFix() zonePodSpecPlans = append(zonePodSpecPlans, &specPlan) } @@ -174,9 +174,9 @@ func schedulePodListRefresh() error { ) // local zone scheduled pods - rs := data.DataZone.NewReader(nil).KeyRangeSet( + rs := data.DataZone.NewRanger( inapi.NsZonePodInstance(status.ZoneId, ""), inapi.NsZonePodInstance(status.ZoneId, "")). - LimitNumSet(10000).Query() + SetLimit(10000).Exec() if !rs.OK() { return errors.New("zm/db err") } @@ -184,7 +184,7 @@ func schedulePodListRefresh() error { for _, v := range rs.Items { var srcPod inapi.Pod - if err := v.Decode(&srcPod); err != nil { + if err := v.JsonDecode(&srcPod); err != nil { hlog.Printf("warn", "zm/pod data/struct err %s", err.Error()) continue } @@ -225,9 +225,8 @@ func schedulePodListRefresh() error { // if (pod.Operate.Operated + uint32(inapi.PodDestroyTTL)) < tn { - if rs := data.DataZone.NewWriter(inapi.NsKvZonePodInstanceDestroy(status.ZoneId, pod.Meta.ID), pod).Commit(); rs.OK() { - rs = data.DataZone.NewWriter(inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID), nil). - ModeDeleteSet(true).Commit() + if rs := data.DataZone.NewWriter(inapi.NsKvZonePodInstanceDestroy(status.ZoneId, pod.Meta.ID), pod).Exec(); rs.OK() { + rs = data.DataZone.NewDeleter(inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID)).Exec() // status.ZonePodList.Items.Del(pod.Meta.ID) hlog.Printf("warn", "zm/scheduler pod %s, remove", pod.Meta.ID) @@ -244,8 +243,8 @@ func schedulePodListRefresh() error { pod.Operate.Action = pod.Operate.Action | inapi.OpActionResFree // - if rs := data.DataZone.NewWriter(inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID), pod).Commit(); !rs.OK() { - hlog.Printf("info", "zm/scheduler pod %s, db err %s", pod.Meta.ID, rs.Message) + if rs := data.DataZone.NewWriter(inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID), pod).Exec(); !rs.OK() { + hlog.Printf("info", "zm/scheduler pod %s, db err %s", pod.Meta.ID, rs.ErrorMessage()) continue } @@ -595,9 +594,9 @@ func scheduleHostListRefresh() error { cell.Meta.Updated = uint64(types.MetaTimeNow()) if rs := data.DataGlobal.NewWriter( - inapi.NsGlobalSysCell(status.ZoneId, id), cell).Commit(); rs.OK() { + inapi.NsGlobalSysCell(status.ZoneId, id), cell).Exec(); rs.OK() { data.DataZone.NewWriter( - inapi.NsZoneSysCell(status.ZoneId, id), cell).Commit() + inapi.NsZoneSysCell(status.ZoneId, id), cell).Exec() // hlog.Printf("info", "cell %s : %s", id, cell.Meta.Name) } } @@ -613,8 +612,8 @@ func schedulePodListQueue(cellId string) { cutset = inapi.NsKvGlobalSetQueuePod(status.ZoneId, cellId, "") ) - rss := data.DataGlobal.NewReader(nil).KeyRangeSet(offset, cutset). - LimitNumSet(10000).Query() + rss := data.DataGlobal.NewRanger(offset, cutset). + SetLimit(10000).Exec() if len(rss.Items) == 0 { return } @@ -623,7 +622,7 @@ func schedulePodListQueue(cellId string) { var podq inapi.Pod - if err := v.Decode(&podq); err != nil { + if err := v.JsonDecode(&podq); err != nil { hlog.Printf("error", "invalid data struct: %s", err.Error()) continue } @@ -638,10 +637,10 @@ func schedulePodListQueue(cellId string) { ) if rs := data.DataZone.NewReader( - inapi.NsZonePodInstance(status.ZoneId, podq.Meta.ID)).Query(); rs.OK() { + inapi.NsZonePodInstance(status.ZoneId, podq.Meta.ID)).Exec(); rs.OK() { var prev inapi.Pod - if err := rs.Decode(&prev); err != nil { + if err := rs.Item().JsonDecode(&prev); err != nil { hlog.Printf("error", "bad prev podq %s instance, err %s", podq.Meta.ID, err.Error()) continue } @@ -752,14 +751,13 @@ func schedulePodListQueue(cellId string) { hlog.Printf("warn", "Scheduler Pod %s, ER %s", pod.Meta.ID, err.Error()) } - if rs := data.DataZone.NewWriter(inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID), pod).Commit(); !rs.OK() { - hlog.Printf("error", "zone/podq saved %s, err (%s)", pod.Meta.ID, rs.Message) + if rs := data.DataZone.NewWriter(inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID), pod).Exec(); !rs.OK() { + hlog.Printf("error", "zone/podq saved %s, err (%s)", pod.Meta.ID, rs.ErrorMessage()) continue } if err == nil { - data.DataGlobal.NewWriter(inapi.NsKvGlobalSetQueuePod(status.ZoneId, pod.Spec.Cell, pod.Meta.ID), nil). - ModeDeleteSet(true).Commit() + data.DataGlobal.NewDeleter(inapi.NsKvGlobalSetQueuePod(status.ZoneId, pod.Spec.Cell, pod.Meta.ID)).Exec() hlog.Printf("info", "zone/podq queue/clean %s", pod.Meta.ID) podInQueue.Set(pod.Meta.ID) } @@ -813,8 +811,8 @@ func schedulePodListBound() { } } - if rs := data.DataZone.NewWriter(inapi.NsZonePodInstance(status.ZoneId, podq.Meta.ID), podq).Commit(); !rs.OK() { - hlog.Printf("error", "zone/podq saved %s, err (%s)", podq.Meta.ID, rs.Message) + if rs := data.DataZone.NewWriter(inapi.NsZonePodInstance(status.ZoneId, podq.Meta.ID), podq).Exec(); !rs.OK() { + hlog.Printf("error", "zone/podq saved %s, err (%s)", podq.Meta.ID, rs.ErrorMessage()) continue } } @@ -1207,8 +1205,8 @@ func schedulePodRepItem(podq *inapi.Pod, opAction uint32, changed = true // TOTK - if rs := data.DataZone.NewWriter(inapi.NsZonePodInstance(status.ZoneId, podq.Meta.ID), podq).Commit(); !rs.OK() { - hlog.Printf("error", "zone/podq saved %s, err (%s)", podq.Meta.ID, rs.Message) + if rs := data.DataZone.NewWriter(inapi.NsZonePodInstance(status.ZoneId, podq.Meta.ID), podq).Exec(); !rs.OK() { + hlog.Printf("error", "zone/podq saved %s, err (%s)", podq.Meta.ID, rs.ErrorMessage()) return inapi.NewPbOpLogEntry("", inapi.PbOpLogWarn, "Data IO error") } @@ -1393,7 +1391,7 @@ func schedulePodMigrate(podq *inapi.Pod) error { repStatus.Action = 0 // TODO - data.DataZone.NewWriter(inapi.NsZonePodInstance(status.ZoneId, podq.Meta.ID), podq).Commit() + data.DataZone.NewWriter(inapi.NsZonePodInstance(status.ZoneId, podq.Meta.ID), podq).Exec() hlog.Printf("warn", "scheduler rep %s:%d, host %s, set opAction to %s, Migrate DONE", podq.Meta.ID, repId, ctrRep.Node, @@ -1563,8 +1561,8 @@ func schedulePodMigrate(podq *inapi.Pod) error { podq.Meta.ID, rep.RepId, prevHostId, hit.HostId) if rs := data.DataZone.NewWriter( - inapi.NsZonePodInstance(status.ZoneId, podq.Meta.ID), podq).Commit(); !rs.OK() { - hlog.Printf("error", "zone/podq saved %s, err (%s)", podq.Meta.ID, rs.Message) + inapi.NsZonePodInstance(status.ZoneId, podq.Meta.ID), podq).Exec(); !rs.OK() { + hlog.Printf("error", "zone/podq saved %s, err (%s)", podq.Meta.ID, rs.ErrorMessage()) } repStatus.OpLog.LogSet( @@ -1996,8 +1994,8 @@ func schedulePodFailover(podq *inapi.Pod) error { foRep.ManualChecked = 0 if rs := data.DataZone.NewWriter( - inapi.NsZonePodInstance(status.ZoneId, podq.Meta.ID), podq).Commit(); !rs.OK() { - hlog.Printf("error", "zone/podq saved %s, err (%s)", podq.Meta.ID, rs.Message) + inapi.NsZonePodInstance(status.ZoneId, podq.Meta.ID), podq).Exec(); !rs.OK() { + hlog.Printf("error", "zone/podq saved %s, err (%s)", podq.Meta.ID, rs.ErrorMessage()) } repStatus.OpLog.LogSet( @@ -2032,24 +2030,22 @@ func scheduleClean() error { hlog.Printf("warn", "destroy node #%s ...", host.Meta.Id) if rs := data.DataGlobal.NewWriter( - inapi.NsKvGlobalSysHostDestroyed(host.Operate.ZoneId, host.Meta.Id), host).Commit(); !rs.OK() { + inapi.NsKvGlobalSysHostDestroyed(host.Operate.ZoneId, host.Meta.Id), host).Exec(); !rs.OK() { continue } if rs := data.DataZone.NewWriter( - inapi.NsKvZoneSysHostDestroyed(host.Operate.ZoneId, host.Meta.Id), host).Commit(); !rs.OK() { + inapi.NsKvZoneSysHostDestroyed(host.Operate.ZoneId, host.Meta.Id), host).Exec(); !rs.OK() { continue } - if rs := data.DataGlobal.NewWriter( - inapi.NsGlobalSysHost(host.Operate.ZoneId, host.Meta.Id), nil). - ModeDeleteSet(true).Commit(); !rs.OK() { + if rs := data.DataGlobal.NewDeleter( + inapi.NsGlobalSysHost(host.Operate.ZoneId, host.Meta.Id)).Exec(); !rs.OK() { continue } - if rs := data.DataZone.NewWriter( - inapi.NsZoneSysHost(host.Operate.ZoneId, host.Meta.Id), nil). - ModeDeleteSet(true).Commit(); !rs.OK() { + if rs := data.DataZone.NewDeleter( + inapi.NsZoneSysHost(host.Operate.ZoneId, host.Meta.Id)).Exec(); !rs.OK() { continue } diff --git a/zonemaster/tracker.go b/zonemaster/tracker.go index df5678a..d6f7542 100644 --- a/zonemaster/tracker.go +++ b/zonemaster/tracker.go @@ -50,12 +50,12 @@ func zoneTracker() { if len(status.ZoneHostSecretKeys) == 0 { offset := inapi.NsZoneSysHostSecretKey(status.ZoneId, "") - if rs := data.DataZone.NewReader(nil).KeyRangeSet(offset, offset). - LimitNumSet(1000).Query(); rs.OK() { + if rs := data.DataZone.NewRanger(offset, offset). + SetLimit(1000).Exec(); rs.OK() { for _, v := range rs.Items { status.ZoneHostSecretKeys.Set( - inapi.NsKeyPathLastName(v.Meta.Key), v.DataValue().String()) + inapi.NsKeyPathLastName(v.Key), v.StringValue()) } } else { @@ -67,8 +67,8 @@ func zoneTracker() { // refresh zone-master leader ttl if rs := data.DataZone.NewWriter( inapi.NsKvZoneSysMasterLeader(status.ZoneId), status.Host.Meta.Id). - ExpireSet(12000).Commit(); !rs.OK() { - hlog.Printf("warn", "zm/zone-master/leader ttl refresh failed "+rs.Message) + SetTTL(12000).Exec(); !rs.OK() { + hlog.Printf("warn", "zm/zone-master/leader ttl refresh failed "+rs.ErrorMessage()) return } */ @@ -169,8 +169,8 @@ func zmWorkerZoneAccessKeySetup() error { func zmWorkerGlobalZoneListRefresh() error { offset := inapi.NsGlobalSysZone("") - rs := data.DataGlobal.NewReader(nil).KeyRangeSet(offset, offset). - LimitNumSet(50).Query() + rs := data.DataGlobal.NewRanger(offset, offset). + SetLimit(50).Exec() if !rs.OK() { return errors.New("db/scan error") } @@ -178,7 +178,7 @@ func zmWorkerGlobalZoneListRefresh() error { for _, v := range rs.Items { var zone inapi.ResZone - if err := v.Decode(&zone); err != nil { + if err := v.JsonDecode(&zone); err != nil { continue } @@ -193,12 +193,12 @@ func zmWorkerGlobalZoneListRefresh() error { // offset := inapi.NsGlobalSysCell(zone.Meta.Id, "") - if rs := data.DataGlobal.NewReader(nil).KeyRangeSet(offset, offset). - LimitNumSet(100).Query(); rs.OK() { + if rs := data.DataGlobal.NewRanger(offset, offset). + SetLimit(100).Exec(); rs.OK() { for _, v2 := range rs.Items { var cell inapi.ResCell - if err := v2.Decode(&cell); err == nil { + if err := v2.JsonDecode(&cell); err == nil { if _, chg2 := pZone.CellSync(&cell); chg2 { chg = true } @@ -213,7 +213,7 @@ func zmWorkerGlobalZoneListRefresh() error { if chg || status.Zone == nil { status.Zone = pZone - data.DataZone.NewWriter(inapi.NsZoneSysZone(status.ZoneId), pZone).Commit() + data.DataZone.NewWriter(inapi.NsZoneSysZone(status.ZoneId), pZone).Exec() hlog.Printf("info", "zonemaster status/zone refreshed %s", status.ZoneId) } } @@ -229,10 +229,10 @@ func zmWorkerZoneHostListRefresh() error { return err } - rs := data.DataZone.NewReader(nil).KeyRangeSet( + rs := data.DataZone.NewRanger( inapi.NsZoneSysHost(status.ZoneId, ""), inapi.NsZoneSysHost(status.ZoneId, "")). - LimitNumSet(1000).Query() + SetLimit(1000).Exec() if !rs.OK() { hlog.Printf("warn", "refresh host list failed") return errors.New("db/scan error") @@ -243,7 +243,7 @@ func zmWorkerZoneHostListRefresh() error { for _, v := range rs.Items { var o inapi.ResHost - if err := v.Decode(&o); err != nil { + if err := v.JsonDecode(&o); err != nil { hlog.Printf("error", "refresh host list %s", err.Error()) continue } @@ -264,8 +264,8 @@ func zmWorkerZoneHostListRefresh() error { // if gn := status.GlobalHostList.Item(o.Meta.Id); gn == nil { - if rs := data.DataGlobal.NewReader(inapi.NsGlobalSysHost(o.Operate.ZoneId, o.Meta.Id)).Query(); rs.NotFound() { - data.DataGlobal.NewWriter(inapi.NsGlobalSysHost(o.Operate.ZoneId, o.Meta.Id), o).Commit() + if rs := data.DataGlobal.NewReader(inapi.NsGlobalSysHost(o.Operate.ZoneId, o.Meta.Id)).Exec(); rs.NotFound() { + data.DataGlobal.NewWriter(inapi.NsGlobalSysHost(o.Operate.ZoneId, o.Meta.Id), o).Exec() } } status.GlobalHostList.Sync(o) @@ -285,9 +285,9 @@ func zmWorkerZoneHostListRefresh() error { pCell.NodeNum = num if rs := data.DataGlobal.NewWriter( - inapi.NsGlobalSysCell(status.ZoneId, cellId), pCell).Commit(); rs.OK() { + inapi.NsGlobalSysCell(status.ZoneId, cellId), pCell).Exec(); rs.OK() { data.DataZone.NewWriter( - inapi.NsZoneSysCell(status.ZoneId, cellId), pCell).Commit() + inapi.NsZoneSysCell(status.ZoneId, cellId), pCell).Exec() // hlog.Printf("info", "cell %s : %s", cellId, pCell.Meta.Name) } @@ -298,18 +298,18 @@ func zmWorkerZoneHostListRefresh() error { offset := inapi.NsZonePodInstance(status.ZoneId, "") for { - rs := data.DataZone.NewReader(nil).KeyRangeSet(offset, offset). - LimitNumSet(1000).Query() + rs := data.DataZone.NewRanger(offset, offset). + SetLimit(1000).Exec() if !rs.OK() { break } for _, v := range rs.Items { - offset = v.Meta.Key + offset = v.Key var pod inapi.Pod - if err := v.Decode(&pod); err != nil { + if err := v.JsonDecode(&pod); err != nil { continue } @@ -343,7 +343,7 @@ func zmWorkerZoneHostListRefresh() error { } } - if !rs.Next { + if !rs.NextResultSet { break } } @@ -382,15 +382,15 @@ func zmWorkerZoneHostListRefresh() error { func zmWorkerZoneHostKeyListRefresh() error { offset := inapi.NsZoneSysHostSecretKey(status.ZoneId, "") - rs := data.DataZone.NewReader(nil).KeyRangeSet(offset, offset). - LimitNumSet(1000).Query() + rs := data.DataZone.NewRanger(offset, offset). + SetLimit(1000).Exec() if !rs.OK() { return errors.New("db/scan error") } for _, v := range rs.Items { status.ZoneHostSecretKeys.Set( - inapi.NsKeyPathLastName(v.Meta.Key), v.DataValue().String()) + inapi.NsKeyPathLastName(v.Key), v.StringValue()) } return nil @@ -399,7 +399,7 @@ func zmWorkerZoneHostKeyListRefresh() error { func zmWorkerZoneMasterListRefresh() error { offset := inapi.NsZoneSysMasterNode(status.ZoneId, "") - rs := data.DataZone.NewReader(nil).KeyRangeSet(offset, offset).LimitNumSet(100).Query() + rs := data.DataZone.NewRanger(offset, offset).SetLimit(100).Exec() if !rs.OK() { return errors.New("db/scan error") } @@ -411,7 +411,7 @@ func zmWorkerZoneMasterListRefresh() error { for _, v := range rs.Items { var o inapi.ResZoneMasterNode - if err := v.Decode(&o); err == nil { + if err := v.JsonDecode(&o); err == nil { zms.Sync(o) } } @@ -437,9 +437,9 @@ func zmWorkerSysConfigRefresh() { for _, v := range config.SysConfigurators { // - if rs := data.DataGlobal.NewReader(inapi.NsGlobalSysConfig(v.Name)).Query(); rs.OK() { + if rs := data.DataGlobal.NewReader(inapi.NsGlobalSysConfig(v.Name)).Exec(); rs.OK() { var item inapi.SysConfigGroup - if err := rs.Decode(&item); err == nil { + if err := rs.Item().JsonDecode(&item); err == nil { status.ZoneSysConfigGroupList.Sync(&item) } } @@ -472,9 +472,9 @@ func zmWorkerPodListStatusRefresh() { ) if podStatus == nil { - if rs := data.DataZone.NewReader(podStatusKey).Query(); rs.OK() { + if rs := data.DataZone.NewReader(podStatusKey).Exec(); rs.OK() { var item inapi.PodStatus - if err := rs.Decode(&item); err == nil { + if err := rs.Item().JsonDecode(&item); err == nil { podStatus = &item } @@ -604,16 +604,16 @@ func zmWorkerPodListStatusRefresh() { hlog.Printf("info", "zm/rep %s:%d, status out", pod.Meta.ID, repId) } - if rs := data.DataZone.NewWriter(podStatusKey, podStatus).Commit(); !rs.OK() { + if rs := data.DataZone.NewWriter(podStatusKey, podStatus).Exec(); !rs.OK() { continue } - if rs := data.DataGlobal.NewWriter(podStatusKeyG, podStatus).Commit(); !rs.OK() { + if rs := data.DataGlobal.NewWriter(podStatusKeyG, podStatus).Exec(); !rs.OK() { continue } if podSync { - data.DataZone.NewWriter(inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID), pod).Commit() + data.DataZone.NewWriter(inapi.NsZonePodInstance(status.ZoneId, pod.Meta.ID), pod).Exec() // hlog.Printf("info", "pod %s operate db-sync", pod.Meta.ID) }