Skip to content

Commit

Permalink
refactor favor to scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Nov 1, 2017
1 parent 24d7217 commit 2ca8d1f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
9 changes: 5 additions & 4 deletions cluster/calcium/create_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
enginenetwork "github.com/docker/docker/api/types/network"
engineslice "github.com/docker/docker/api/types/strslice"
"github.com/docker/go-units"
"github.com/projecteru2/core/scheduler"
"github.com/projecteru2/core/stats"
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
Expand All @@ -32,7 +33,7 @@ func (c *calcium) CreateContainer(opts *types.DeployOptions) (chan *types.Create
log.Errorf("[CreateContainer] Error during GetPod for %s: %v", opts.Podname, err)
return nil, err
}
if pod.Favor == types.CPU_PRIOR {
if pod.Favor == scheduler.CPU_PRIOR {
return c.createContainerWithCPUPrior(opts)
}
log.Infof("[CreateContainer] Creating container with options: %v", opts)
Expand Down Expand Up @@ -97,7 +98,7 @@ func (c *calcium) doCreateContainerWithMemoryPrior(nodeInfo types.NodeInfo, opts

for i := 0; i < nodeInfo.Deploy; i++ {
// createAndStartContainer will auto cleanup
ms[i] = c.createAndStartContainer(i+index, node, opts, nil, types.MEMORY_PRIOR)
ms[i] = c.createAndStartContainer(i+index, node, opts, nil, scheduler.MEMORY_PRIOR)
if !ms[i].Success {
log.Errorf("[doCreateContainerWithMemoryPrior] Error when create and start a container, %v", ms[i].Error)
continue
Expand Down Expand Up @@ -162,7 +163,7 @@ func (c *calcium) doCreateContainerWithCPUPrior(nodeName string, cpuMap []types.

for i, quota := range cpuMap {
// createAndStartContainer will auto cleanup
ms[i] = c.createAndStartContainer(i+index, node, opts, quota, types.CPU_PRIOR)
ms[i] = c.createAndStartContainer(i+index, node, opts, quota, scheduler.CPU_PRIOR)
if !ms[i].Success {
log.Errorf("[doCreateContainerWithCPUPrior] Error when create and start a container, %v", ms[i].Error)
continue
Expand Down Expand Up @@ -291,7 +292,7 @@ func (c *calcium) makeContainerOptions(index int, quota types.CPUMap, opts *type
}

var resource enginecontainer.Resources
if favor == types.CPU_PRIOR {
if favor == scheduler.CPU_PRIOR {
resource = c.makeCPUPriorSetting(quota)
} else {
resource = c.makeMemoryPriorSetting(opts.Memory, opts.CPUQuota)
Expand Down
5 changes: 3 additions & 2 deletions cluster/calcium/realloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

log "github.com/Sirupsen/logrus"
enginecontainer "github.com/docker/docker/api/types/container"
"github.com/projecteru2/core/scheduler"
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
)
Expand Down Expand Up @@ -52,7 +53,7 @@ func (c *calcium) ReallocResource(ids []string, cpu float64, mem int64) (chan *t
}
containersInfo[pod][node] = append(containersInfo[pod][node], container)

if pod.Favor == types.CPU_PRIOR {
if pod.Favor == scheduler.CPU_PRIOR {
if _, ok := cpuContainersInfo[pod]; !ok {
cpuContainersInfo[pod] = CPUNodeContainers{}
}
Expand All @@ -75,7 +76,7 @@ func (c *calcium) ReallocResource(ids []string, cpu float64, mem int64) (chan *t
wg := sync.WaitGroup{}
wg.Add(len(containersInfo))
for pod, nodeContainers := range containersInfo {
if pod.Favor == types.CPU_PRIOR {
if pod.Favor == scheduler.CPU_PRIOR {
nodeCPUContainersInfo := cpuContainersInfo[pod]
go func(pod *types.Pod, nodeCPUContainersInfo CPUNodeContainers) {
defer wg.Done()
Expand Down
7 changes: 7 additions & 0 deletions scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ package scheduler

import "github.com/projecteru2/core/types"

const (
//CPU_PRIOR define cpu select
CPU_PRIOR = "CPU"
//MEMORY_PRIOR define mem select
MEMORY_PRIOR = "MEM"
)

// A scheduler is used to determine which nodes are we gonna use.
// `types.CPUMap` represents the CPU label and remaining quota.
// `nodes` represents node name and the corresponding CPUMap.
Expand Down
5 changes: 3 additions & 2 deletions store/etcd/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/coreos/etcd/client"
"github.com/projecteru2/core/scheduler"
"github.com/projecteru2/core/types"
"github.com/projecteru2/core/utils"
)
Expand Down Expand Up @@ -38,8 +39,8 @@ func (k *krypton) AddPod(name, favor, desc string) (*types.Pod, error) {
key := fmt.Sprintf(podInfoKey, name)
favor = strings.ToUpper(favor)
if favor == "" {
favor = types.MEMORY_PRIOR
} else if favor != types.MEMORY_PRIOR && favor != types.CPU_PRIOR {
favor = scheduler.MEMORY_PRIOR
} else if favor != scheduler.MEMORY_PRIOR && favor != scheduler.CPU_PRIOR {
return nil, fmt.Errorf("favor should be either CPU or MEM, got %s", favor)
}
pod := &types.Pod{Name: name, Desc: desc, Favor: favor}
Expand Down
5 changes: 0 additions & 5 deletions types/pod.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package types

const (
CPU_PRIOR = "CPU"
MEMORY_PRIOR = "MEM"
)

type Pod struct {
Name string `json:"name"`
Desc string `json:"desc"`
Expand Down

0 comments on commit 2ca8d1f

Please sign in to comment.