Skip to content

Commit

Permalink
add a bunch of error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
timfeirg committed Aug 25, 2017
1 parent 1a626c9 commit 944d5c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 3 additions & 2 deletions cluster/calcium/build_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ type richSpecs struct {
func getRandomNode(c *calcium, podname string) (*types.Node, error) {
nodes, err := c.ListPodNodes(podname, false)
if err != nil {
log.Errorf("Error during ListPodNodes for %s: %v", podname, err)
return nil, err
}
if len(nodes) == 0 {
err = fmt.Errorf("No nodes available in pod %s", podname)
log.Debugf("Error during getRandomNode from %s: %v", podname, err)
log.Errorf("Error during getRandomNode from %s: %v", podname, err)
return nil, err
}

Expand All @@ -64,7 +65,7 @@ func getRandomNode(c *calcium, podname string) (*types.Node, error) {
}
nodename, err := c.scheduler.RandomNode(nodemap)
if err != nil {
log.Debugf("Error during getRandomNode from %s: %v", podname, err)
log.Errorf("Error during getRandomNode from %s: %v", podname, err)
return nil, err
}
if nodename == "" {
Expand Down
16 changes: 13 additions & 3 deletions cluster/calcium/create_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
func (c *calcium) CreateContainer(specs types.Specs, opts *types.DeployOptions) (chan *types.CreateContainerMessage, error) {
pod, err := c.store.GetPod(opts.Podname)
if err != nil {
log.Errorf("Error during GetPod for %s: %v", opts.Podname, err)
return nil, err
}
if pod.Favor == types.CPU_PRIOR {
Expand All @@ -43,16 +44,17 @@ func (c *calcium) CreateContainer(specs types.Specs, opts *types.DeployOptions)
func (c *calcium) createContainerWithMemoryPrior(specs types.Specs, opts *types.DeployOptions) (chan *types.CreateContainerMessage, error) {
ch := make(chan *types.CreateContainerMessage)
if opts.Memory < MEMORY_LOW_LIMIT { // 4194304 Byte = 4 MB, docker 创建容器的内存最低标准
return ch, fmt.Errorf("Minimum memory limit allowed is 4MB")
return ch, fmt.Errorf("Minimum memory limit allowed is 4MB, got %d", opts.Memory)
}
if opts.Count <= 0 { // Count 要大于0
return ch, fmt.Errorf("Count must be positive")
return ch, fmt.Errorf("Count must be positive, got %d", opts.Count)
}

// TODO RFC 计算当前 app 部署情况的时候需要保证同一时间只有这个 app 的这个 entrypoint 在跑
// 因此需要在这里加个全局锁,直到部署完毕才释放
nodesInfo, err := c.allocMemoryPodResource(opts)
if err != nil {
log.Errorf("Error during allocMemoryPodResource with opts %v: %v", opts, err)
return ch, err
}

Expand Down Expand Up @@ -98,12 +100,16 @@ func (c *calcium) doCreateContainerWithMemoryPrior(nodeInfo types.NodeInfo, spec

node, err := c.GetNode(opts.Podname, nodeInfo.Name)
if err != nil {
log.Errorf("Error during GetNode for %s, %s: %v", opts.Podname, nodeInfo.Name, err)
return ms
}

if err := pullImage(node, opts.Image, c.config.Timeout.CreateContainer); err != nil {
for i := 0; i < nodeInfo.Deploy; i++ {
ms[i].Error = err.Error()
if err != nil {
log.Errorf("Error during pullImage %s for %s: %v", opts.Image, nodeInfo.Name, err)
ms[i].Error = err.Error()
}
}
return ms
}
Expand All @@ -115,6 +121,7 @@ func (c *calcium) doCreateContainerWithMemoryPrior(nodeInfo types.NodeInfo, spec
ms[i].Nodename = node.Name
ms[i].Memory = opts.Memory
if err != nil {
log.Errorf("Error during makeContainerOptions: %v", err)
ms[i].Error = err.Error()
c.store.UpdateNodeMem(opts.Podname, nodeInfo.Name, opts.Memory, "+") // 创建容器失败就要把资源还回去对不对?
continue
Expand Down Expand Up @@ -216,6 +223,7 @@ func (c *calcium) createContainerWithCPUPrior(specs types.Specs, opts *types.Dep
ch := make(chan *types.CreateContainerMessage)
result, err := c.allocCPUPodResource(opts)
if err != nil {
log.Errorf("Error during allocCPUPodResource with opts %v: %v", opts, err)
return ch, err
}

Expand Down Expand Up @@ -272,6 +280,7 @@ func (c *calcium) doCreateContainerWithCPUPrior(nodeName string, cpuMap []types.
}

if err := pullImage(node, opts.Image, c.config.Timeout.CreateContainer); err != nil {
log.Errorf("Error during pullImage: %v", err)
for i := 0; i < len(ms); i++ {
ms[i].Error = err.Error()
}
Expand All @@ -286,6 +295,7 @@ func (c *calcium) doCreateContainerWithCPUPrior(nodeName string, cpuMap []types.
ms[i].Nodename = node.Name
ms[i].Memory = opts.Memory
if err != nil {
log.Errorf("Error during makeContainerOptions: %v", err)
ms[i].Error = err.Error()
c.releaseQuota(node, quota)
continue
Expand Down

0 comments on commit 944d5c4

Please sign in to comment.