github.com/projecteru2/core@v0.0.0-20240321043226-06bcc1c23f58/resource/plugins/cpumem/cpumem.go (about) 1 package cpumem 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/projecteru2/core/log" 8 "github.com/projecteru2/core/store/etcdv3/meta" 9 coretypes "github.com/projecteru2/core/types" 10 ) 11 12 const ( 13 name = "cpumem" 14 rate = 8 15 nodeResourceInfoKey = "/resource/cpumem/%s" 16 priority = 100 17 ) 18 19 // Plugin 20 type Plugin struct { 21 name string 22 config coretypes.Config 23 store meta.KV 24 } 25 26 // NewPlugin . 27 func NewPlugin(ctx context.Context, config coretypes.Config, t *testing.T) (*Plugin, error) { 28 if t == nil && len(config.Etcd.Machines) < 1 { 29 return nil, coretypes.ErrConfigInvaild 30 } 31 var err error 32 plugin := &Plugin{name: name, config: config} 33 if plugin.store, err = meta.NewETCD(config.Etcd, t); err != nil { 34 log.WithFunc("resource.cpumem.NewPlugin").Error(ctx, err) 35 return nil, err 36 } 37 return plugin, nil 38 } 39 40 // Name . 41 func (p Plugin) Name() string { 42 return p.name 43 }