Skip to content

Commit

Permalink
add ttl to deploy status
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Jul 4, 2019
1 parent 3f891d7 commit 72a2520
Show file tree
Hide file tree
Showing 14 changed files with 469 additions and 414 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
19.07.09
19.07.10
3 changes: 2 additions & 1 deletion cluster/calcium/control.go
Expand Up @@ -36,7 +36,8 @@ func (c *Calcium) ControlContainer(ctx context.Context, IDs []string, t string,
defer func() {
if err == nil {
log.Infof("[ControlContainer] Control container %s %s", container.ID, t)
log.Infof("[ControlContainer] Output:\n %s", string(types.HookOutput(message)))
log.Info("[ControlContainer] Output:")
log.Info(string(types.HookOutput(message)))
}
ch <- &types.ControlContainerMessage{
ContainerID: container.ID,
Expand Down
7 changes: 4 additions & 3 deletions cluster/calcium/meta.go
Expand Up @@ -108,7 +108,8 @@ func (c *Calcium) SetNodeAvailable(ctx context.Context, podname, nodename string
log.Errorf("[SetNodeAvailable] Get container %s on node %s failed %v", container.ID, nodename, err)
continue
}
if err := c.store.ContainerDeployed(ctx, container.ID, appname, entrypoint, container.Nodename, ""); err != nil {
// mark container which belongs to this node as unhealthy
if err := c.ContainerDeployed(ctx, container.ID, appname, entrypoint, container.Nodename, []byte{}, 0); err != nil {
log.Errorf("[SetNodeAvailable] Set container %s on node %s inactive failed %v", container.ID, nodename, err)
}
}
Expand All @@ -123,6 +124,6 @@ func (c *Calcium) GetNodeByName(ctx context.Context, nodename string) (*types.No
}

// ContainerDeployed set container deploy status
func (c *Calcium) ContainerDeployed(ctx context.Context, ID, appname, entrypoint, nodename, data string) error {
return c.store.ContainerDeployed(ctx, ID, appname, entrypoint, nodename, data)
func (c *Calcium) ContainerDeployed(ctx context.Context, ID, appname, entrypoint, nodename string, data []byte, ttl int64) error {
return c.store.ContainerDeployed(ctx, ID, appname, entrypoint, nodename, data, ttl)
}
23 changes: 22 additions & 1 deletion cluster/calcium/meta_test.go
Expand Up @@ -232,17 +232,37 @@ func TestSetNodeAvailable(t *testing.T) {

store := &storemocks.Store{}
c.store = store
lock := &lockmocks.DistributedLock{}
store.On("CreateLock", mock.Anything, mock.Anything).Return(lock, nil)
lock.On("Lock", mock.Anything).Return(nil)
lock.On("Unlock", mock.Anything).Return(nil)
// failed by get node
store.On("GetNode", mock.Anything, mock.Anything, mock.Anything).Return(nil, types.ErrCannotGetEngine).Once()
_, err := c.SetNodeAvailable(ctx, "", "", true)
assert.Error(t, err)
store.On("GetNode", mock.Anything, mock.Anything, mock.Anything).Return(node, nil)
// failed by updatenode
store.On("UpdateNode", mock.Anything, mock.Anything).Return(types.ErrCannotGetEngine).Once()
_, err = c.SetNodeAvailable(ctx, "", "", true)
assert.Error(t, err)
store.On("UpdateNode", mock.Anything, mock.Anything).Return(nil)
// succ when node available
n, err := c.SetNodeAvailable(ctx, "", "", true)
assert.NoError(t, err)
assert.Equal(t, n.Name, name)
// not available
// failed by list node containers
store.On("ListNodeContainers", mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
_, err = c.SetNodeAvailable(ctx, "", "", false)
assert.Error(t, err)
containers := []*types.Container{&types.Container{Name: "wrong_name"}, &types.Container{Name: "a_b_c"}}
store.On("ListNodeContainers", mock.Anything, mock.Anything).Return(containers, nil)
store.On("ContainerDeployed",
mock.Anything, mock.Anything, mock.Anything,
mock.Anything, mock.Anything, mock.Anything, mock.Anything,
).Return(types.ErrNoETCD)
n, err = c.SetNodeAvailable(ctx, "", "", false)
assert.NoError(t, err)
}

func TestContainerDeployed(t *testing.T) {
Expand All @@ -256,8 +276,9 @@ func TestContainerDeployed(t *testing.T) {
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything).Return(nil)
c.store = store

assert.NoError(t, c.ContainerDeployed(ctx, "", "", "", "", ""))
assert.NoError(t, c.ContainerDeployed(ctx, "", "", "", "", []byte{}, 0))
}
2 changes: 1 addition & 1 deletion cluster/cluster.go
Expand Up @@ -64,7 +64,7 @@ type Cluster interface {
SetNodeAvailable(ctx context.Context, podname, nodename string, available bool) (*types.Node, error)
// used by agent
GetNodeByName(ctx context.Context, nodename string) (*types.Node, error)
ContainerDeployed(ctx context.Context, ID, appname, entrypoint, nodename, data string) error
ContainerDeployed(ctx context.Context, ID, appname, entrypoint, nodename string, data []byte, ttl int64) error
// cluster methods
PodResource(ctx context.Context, podname string) (*types.PodResource, error)
NodeResource(ctx context.Context, podname, nodename string) (*types.NodeResource, error)
Expand Down
10 changes: 5 additions & 5 deletions cluster/mocks/Cluster.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 72a2520

Please sign in to comment.