Skip to content

Commit

Permalink
minor revise for cpumem client stage3
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed May 26, 2023
1 parent 8b80aec commit bf2f194
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions resource/cobalt/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (m Manager) AddNode(ctx context.Context, nodename string, opts resourcetype
resps, err := call(ctx, m.plugins, func(plugin plugins.Plugin) (*plugintypes.AddNodeResponse, error) {
r := opts[plugin.Name()]
if r == nil {
logger.WithField("plugin", plugin.Name()).Warn(ctx, "empty plugin config")
return &plugintypes.AddNodeResponse{}, nil
}
logger.WithField("plugin", plugin.Name()).WithField("node", nodename).Infof(ctx, "%v", litter.Sdump(r))
Expand Down
35 changes: 35 additions & 0 deletions resource/plugins/cpumem/client/cpu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package client

import (
"fmt"
"strings"

"github.com/projecteru2/core/resource/plugins/cpumem/types"
"github.com/projecteru2/core/utils"
)

// NewNUMAFromStr .
func NewNUMAFromStr(numa []string) (types.NUMA, error) {
r := types.NUMA{}
for index, numaCPUList := range numa {
nodeID := fmt.Sprintf("%d", index)
for _, cpuID := range strings.Split(numaCPUList, ",") {
r[cpuID] = nodeID
}
}
return r, nil
}

// NewNUMAMemoryFromStr .
func NewNUMAMemoryFromStr(numaMemory []string) (types.NUMAMemory, error) {
r := types.NUMAMemory{}
for index, nodeMemory := range numaMemory {
nodeID := fmt.Sprintf("%d", index)
mem, err := utils.ParseRAMInHuman(nodeMemory)
if err != nil {
return r, err
}
r[nodeID] = mem
}
return r, nil
}
1 change: 1 addition & 0 deletions resource/plugins/cpumem/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func (n *NodeResourceRequest) Parse(config coretypes.Config, rawParams resourcet
}

for nodeID, nodeMemory := range rawParams.RawParams("numa-memory") {
// stupid golang covert int64 to float64 when using json.unmarshal
n.NUMAMemory[nodeID] = int64(nodeMemory.(float64))
}
return nil
Expand Down
6 changes: 0 additions & 6 deletions rpc/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
pb "github.com/projecteru2/core/rpc/gen"
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
"github.com/sanity-io/litter"

"golang.org/x/net/context"
)
Expand Down Expand Up @@ -540,17 +539,12 @@ func toCoreRemoveImageOptions(opts *pb.RemoveImageOptions) *types.ImageOptions {
func toCoreResources(resources map[string][]byte) resourcetypes.Resources {
r := resourcetypes.Resources{}
for k, v := range resources {
fmt.Println("==============")
fmt.Println(k, string(v))
fmt.Println("==============")
rp := resourcetypes.RawParams{}
if err := json.Unmarshal(v, &rp); err != nil {
log.WithFunc("toCoreResources").Errorf(nil, err, "%v", string(v)) // nolint
continue
}
r[k] = rp
litter.Dump(rp)
fmt.Println("==============")
}
return r
}
Expand Down

0 comments on commit bf2f194

Please sign in to comment.