Skip to content

Commit

Permalink
Merge branch 'bug/error-message' into 'master'
Browse files Browse the repository at this point in the history
display core error message in citadel

core的err msg一直以来都被掩盖了,请core的维护者参考这个pr中的方法,把core抛出的异常传给citadel(并且在citadel做相应的修改展示到前端),否则citadel操作出问题开发者无感知,平台自己则难debug

@platform

See merge request !23
  • Loading branch information
timfeirg committed Nov 2, 2016
2 parents fc5f16d + fe8356e commit 747db24
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.6
0.7.7
10 changes: 6 additions & 4 deletions cluster/calcium/create_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c *calcium) CreateContainer(specs types.Specs, opts *types.DeployOptions)

// when shits go wrong before doCreateContainerWithCPUPeriod, don't just return
// the channel and return an error, because citadel don't know what's going on
func (c *calcium) createErrorMessage(err error) *types.CreateContainerMessage {
func (c *calcium) sendErrorMessage(err error, ch chan<- *types.CreateContainerMessage) {
log.Errorf("Got error %s", err.Error())
m := &types.CreateContainerMessage{
Podname: "",
Expand All @@ -44,21 +44,22 @@ func (c *calcium) createErrorMessage(err error) *types.CreateContainerMessage {
CPU: nil,
Memory: 0,
}
return m
ch <- m
close(ch)
}

func (c *calcium) createContainerWithCPUPeriod(specs types.Specs, opts *types.DeployOptions) (chan *types.CreateContainerMessage, error) {
ch := make(chan *types.CreateContainerMessage)

if opts.Memory < 4194304 { // 4194304 Byte = 4 MB, docker 创建容器的内存最低标准
err := fmt.Errorf("Minimum memory limit allowed is 4MB")
ch <- c.createErrorMessage(err)
go c.sendErrorMessage(err, ch)
return ch, err
}

cpuandmem, _, err := c.getCPUAndMem(opts.Podname, opts.Nodename, 1.0)
if err != nil {
ch <- c.createErrorMessage(err)
go c.sendErrorMessage(err, ch)
return ch, err
}
nodesInfo := utils.GetNodesInfo(cpuandmem)
Expand All @@ -67,6 +68,7 @@ func (c *calcium) createContainerWithCPUPeriod(specs types.Specs, opts *types.De
plan, err := utils.AllocContainerPlan(nodesInfo, cpuQuota, opts.Memory, opts.Count) // 还是以 Bytes 作单位, 不转换了

if err != nil {
go c.sendErrorMessage(err, ch)
return ch, err
}

Expand Down
7 changes: 3 additions & 4 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,9 @@ func (v *virbranium) CreateContainer(opts *pb.DeployOptions, stream pb.CoreRPC_C
return err
}

ch, err := v.cluster.CreateContainer(specs, toCoreDeployOptions(opts))
if err != nil {
return err
}
// ignore err because the error message will be sent to ch, and citadel
// will receive them
ch, _ := v.cluster.CreateContainer(specs, toCoreDeployOptions(opts))

for m := range ch {
if err := stream.Send(toRPCCreateContainerMessage(m)); err != nil {
Expand Down

0 comments on commit 747db24

Please sign in to comment.