diff --git a/cmd/lbagent/main.go b/cmd/lbagent/main.go index 9215a1ece1..1dce0f27f6 100644 --- a/cmd/lbagent/main.go +++ b/cmd/lbagent/main.go @@ -17,7 +17,7 @@ func main() { consts.SetServiceType("lbagent") opts := &lbagent.Options{} - commonOpts := &opts.CommonOpts + commonOpts := &opts.CommonOptions { cloudcommon.ParseOptions(opts, commonOpts, os.Args, "lbagent.conf") cloudcommon.InitAuth(commonOpts, func() { diff --git a/pkg/lbagent/api.go b/pkg/lbagent/api.go index 38866f24a2..d55468c429 100644 --- a/pkg/lbagent/api.go +++ b/pkg/lbagent/api.go @@ -63,7 +63,7 @@ func (h *ApiHelper) Run(ctx context.Context) { } func (h *ApiHelper) adminClientSession(ctx context.Context) *mcclient.ClientSession { - region := h.opts.CommonOpts.Region + region := h.opts.CommonOptions.Region apiVersion := "v2" s := auth.GetAdminSession(ctx, region, apiVersion) return s diff --git a/pkg/lbagent/models/corpus.go b/pkg/lbagent/models/corpus.go index b0c51f30e7..04f539ab03 100644 --- a/pkg/lbagent/models/corpus.go +++ b/pkg/lbagent/models/corpus.go @@ -1,6 +1,7 @@ package models import ( + "encoding/json" "fmt" "io/ioutil" "path/filepath" @@ -11,7 +12,12 @@ import ( "yunion.io/x/onecloud/pkg/mcclient" ) +const ( + CORPUS_VERSION = "v1" +) + type LoadbalancerCorpus struct { + CorpusVersion string *ModelSets ModelSetsMaxUpdatedAt *ModelSetsMaxUpdatedAt } @@ -50,10 +56,12 @@ func (b *LoadbalancerCorpus) MaxSeenUpdatedAtParams() *jsonutils.JSONDict { } func (b *LoadbalancerCorpus) SaveDir(dir string) error { - j := jsonutils.Marshal(b) - d := j.String() + d, err := json.Marshal(b) + if err != nil { + return err + } p := filepath.Join(dir, "corpus") - err := ioutil.WriteFile(p, []byte(d), agentutils.FileModeFileSensitive) + err = ioutil.WriteFile(p, d, agentutils.FileModeFileSensitive) return err } @@ -63,13 +71,14 @@ func (b *LoadbalancerCorpus) LoadDir(dir string) error { if err != nil { return err } - jd, err := jsonutils.Parse(d) + err = json.Unmarshal(d, b) if err != nil { - return fmt.Errorf("%s: json parse failed: %s", p, err) + return err } - err = jd.Unmarshal(b) - if err != nil { - return fmt.Errorf("%s: json unmarshal failed: %s", p, err) + // version for updating + if ver := b.CorpusVersion; ver != CORPUS_VERSION { + b.Reset() + return fmt.Errorf("%s: corpus version %s != %s", p, ver, CORPUS_VERSION) } correct := b.join() if !correct { @@ -77,3 +86,8 @@ func (b *LoadbalancerCorpus) LoadDir(dir string) error { } return nil } + +func (b *LoadbalancerCorpus) Reset() { + bb := NewEmptyLoadbalancerCorpus() + *b = *bb +} diff --git a/pkg/lbagent/models/modelset.go b/pkg/lbagent/models/modelset.go index 5d86435713..0c94eb49a6 100644 --- a/pkg/lbagent/models/modelset.go +++ b/pkg/lbagent/models/modelset.go @@ -136,7 +136,7 @@ func (ms LoadbalancerListeners) JoinCertificates(subEntries LoadbalancerCertific if m.CertificateId != "" { subEntry, ok := subEntries[m.CertificateId] if !ok { - log.Warningf("loadbalancer m id %s: cannot find certificate id %s", + log.Warningf("loadbalancerlistener id %s: cannot find certificate id %s", m.Id, m.CertificateId) correct = false continue diff --git a/pkg/lbagent/models/reflect.go b/pkg/lbagent/models/reflect.go index 34af04a0f9..0d129638ea 100644 --- a/pkg/lbagent/models/reflect.go +++ b/pkg/lbagent/models/reflect.go @@ -90,7 +90,7 @@ func GetModels(opts *GetModelsOptions) error { Details: options.Bool(true), Filter: []string{ minUpdatedAtFilter(minUpdatedAt), // order matters, filter.0 - "isempty(manager_id)", // len(manager_id) > 0 is for pubcloud objects + "manager_id.isnull()", // len(manager_id) > 0 is for pubcloud objects }, OrderBy: []string{"updated_at", "id"}, Order: "asc", diff --git a/pkg/lbagent/options.go b/pkg/lbagent/options.go index 11dae1370c..8ac80d5f8e 100644 --- a/pkg/lbagent/options.go +++ b/pkg/lbagent/options.go @@ -31,7 +31,7 @@ type LbagentOptions struct { } type Options struct { - CommonOpts cloudcommon.CommonOptions + cloudcommon.CommonOptions LbagentOptions }