Skip to content

Commit

Permalink
SetNodeResourceCapacity tested
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Feb 3, 2023
1 parent f2dda62 commit 0d6bd9a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 32 deletions.
9 changes: 4 additions & 5 deletions resource3/plugins/cpumem/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ func (p Plugin) SetNodeResourceCapacity(ctx context.Context, nodename string, re

// add new cpu
for cpu := range nodeResourceInfo.Capacity.CPUMap {
_, ok := nodeResourceInfo.Usage.CPUMap[cpu]
if !ok {
if _, ok := nodeResourceInfo.Usage.CPUMap[cpu]; !ok {
nodeResourceInfo.Usage.CPUMap[cpu] = 0
}
}
Expand Down Expand Up @@ -345,13 +344,13 @@ func (p Plugin) getNodeResourceInfo(ctx context.Context, nodename string, worklo
diffs = append(diffs, fmt.Sprintf("node.CPUUsed != sum(workload.CPURequest): %.2f != %.2f", totalCPUUsage, actuallyWorkloadsUsage.CPURequest))
}

for cpu := range nodeResourceInfo.Capacity.CPUMap {
for cpu := range nodeResourceInfo.Usage.CPUMap {
if actuallyWorkloadsUsage.CPUMap[cpu] != nodeResourceInfo.Usage.CPUMap[cpu] {
diffs = append(diffs, fmt.Sprintf("node.CPUMap[%+v] != sum(workload.CPUMap[%+v]): %+v != %+v", cpu, cpu, nodeResourceInfo.Usage.CPUMap[cpu], actuallyWorkloadsUsage.CPUMap[cpu]))
}
}

for numaNodeID := range nodeResourceInfo.Capacity.NUMAMemory {
for numaNodeID := range nodeResourceInfo.Usage.NUMAMemory {
if actuallyWorkloadsUsage.NUMAMemory[numaNodeID] != nodeResourceInfo.Usage.NUMAMemory[numaNodeID] {
diffs = append(diffs, fmt.Sprintf("node.NUMAMemory[%+v] != sum(workload.NUMAMemory[%+v]: %+v != %+v)", numaNodeID, numaNodeID, nodeResourceInfo.Usage.NUMAMemory[numaNodeID], actuallyWorkloadsUsage.NUMAMemory[numaNodeID]))
}
Expand Down Expand Up @@ -425,7 +424,7 @@ func (p Plugin) doGetNodeDeployCapacity(nodeResourceInfo *cpumemtypes.NodeResour
func (p Plugin) calculateNodeResource(req *cpumemtypes.NodeResourceRequest, nodeResource *cpumemtypes.NodeResource, origin *cpumemtypes.NodeResource, workloadsResource []*cpumemtypes.WorkloadResource, delta bool, incr bool) *cpumemtypes.NodeResource {
var resp *cpumemtypes.NodeResource
if origin == nil || !delta { // no delta means node resource rewrite with whole new data
resp = &cpumemtypes.NodeResource{}
resp = (&cpumemtypes.NodeResource{}).DeepCopy() // init nil pointer!
} else {
resp = origin.DeepCopy()
}
Expand Down
20 changes: 7 additions & 13 deletions resource3/plugins/cpumem/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (

// NodeResource indicate node cpumem resource
type NodeResource struct {
CPU float64 `json:"cpu"`
CPUMap CPUMap `json:"cpu_map"`
Memory int64 `json:"memory"`
NUMAMemory NUMAMemory `json:"numa_memory"`
NUMA NUMA `json:"numa"`
CPU float64 `json:"cpu" mapstructure:"cpu"`
CPUMap CPUMap `json:"cpu_map" mapstructure:"cpu_map"`
Memory int64 `json:"memory" mapstructure:"memory"`
NUMAMemory NUMAMemory `json:"numa_memory" mapstructure:"numa_memory"`
NUMA NUMA `json:"numa" mapstructure:"numa"`
}

// Parse .
Expand Down Expand Up @@ -88,23 +88,17 @@ func (n *NodeResourceInfo) DeepCopy() *NodeResourceInfo {

// RemoveEmptyCores .
func (n *NodeResourceInfo) RemoveEmptyCores() {
keysToDelete := []string{}
for cpu := range n.Capacity.CPUMap {
if n.Capacity.CPUMap[cpu] == 0 && n.Usage.CPUMap[cpu] == 0 {
keysToDelete = append(keysToDelete, cpu)
delete(n.Capacity.CPUMap, cpu)
}
}
for cpu := range n.Usage.CPUMap {
if n.Capacity.CPUMap[cpu] == 0 && n.Usage.CPUMap[cpu] == 0 {
keysToDelete = append(keysToDelete, cpu)
delete(n.Usage.CPUMap, cpu)
}
}

for _, cpu := range keysToDelete {
delete(n.Capacity.CPUMap, cpu)
delete(n.Usage.CPUMap, cpu)
}

n.Capacity.CPU = float64(len(n.Capacity.CPUMap))
}

Expand Down
14 changes: 0 additions & 14 deletions resource3/plugins/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import (
"context"

enginetypes "github.com/projecteru2/core/engine/types"
"github.com/projecteru2/core/resource3/plugins/binary"
"github.com/projecteru2/core/resource3/plugins/cpumem"
"github.com/projecteru2/core/resource3/plugins/storage"
plugintypes "github.com/projecteru2/core/resource3/plugins/types"
"github.com/projecteru2/core/types"
)

const (
Expand Down Expand Up @@ -75,13 +71,3 @@ type Plugin interface {
// Name returns the name of plugin
Name() string
}

func _() {
ctx := context.TODO()
b, _ := binary.NewPlugin(ctx, "", types.Config{})
c, _ := cpumem.NewPlugin(ctx, types.Config{})
s, _ := storage.NewPlugin(ctx, types.Config{})
_ = Plugin(b)
_ = Plugin(c)
_ = Plugin(s)
}

0 comments on commit 0d6bd9a

Please sign in to comment.