Skip to content

Commit

Permalink
stack rollback fixe issue (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
freignat91 authored and chrisccoy committed Sep 21, 2016
1 parent 65e75ae commit 9878093
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions api/rpc/stack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *Server) Up(ctx context.Context, in *UpRequest) (*UpReply, error) {
_, errStart := s.Start(ctx, &startRequest)
if errStart != nil {
fmt.Printf("Error found during service creation: %v \n", err)
s.rollbackETCDStack(ctx, stack.Id)
s.rollbackETCDStack(ctx, stack)
return nil, errStart
}
fmt.Printf("Stack is up: %s\n", stack.Id)
Expand Down Expand Up @@ -97,10 +97,11 @@ func (s *Server) rollbackServiceStack(ctx context.Context, stackID string, servi
}

// clean up if error happended during stack creation, delete all created services and all etcd data
func (s *Server) rollbackETCDStack(ctx context.Context, stackID string) {
fmt.Printf("Cleanning up ETCD storage %s\n", stackID)
s.Store.Delete(ctx, path.Join(stackRootKey, stackID), true, nil)
fmt.Printf("ETCD cleaned %s\n", stackID)
func (s *Server) rollbackETCDStack(ctx context.Context, stack *Stack) {
fmt.Printf("Cleanning up ETCD storage %s\n", stack.Id)
s.Store.Delete(ctx, path.Join(stackRootKey, stack.Id), true, nil)
s.Store.Delete(ctx, path.Join(stackRootNameKey, stack.Name), true, nil)
fmt.Printf("ETCD cleaned %s\n", stack.Id)
}

// start one service and if ok store it in ETCD:
Expand Down
4 changes: 2 additions & 2 deletions api/rpc/stack/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestShouldManageStackLifeCycleSuccessfully(t *testing.T) {
}
assert.NotEmpty(t, rUp1.StackId, "Stack essai1 StackId should not be empty")
assert.NotEmpty(t, rUp2.StackId, "Stack essai2 StackId should not be empty")
time.Sleep(5 * time.Second)
time.Sleep(3 * time.Second)
//verifyusing ls
t.Log("perform stack ls")
listRequest := stack.ListRequest{}
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestShouldManageStackLifeCycleSuccessfully(t *testing.T) {
t.Fatal(errRestart1)
}
assert.NotEmpty(t, rRestart1.StackId, "Stack essai1 StackId should not be empty")
time.Sleep(3 * time.Second)
time.Sleep(1 * time.Second)
//Stop again stack essai1
t.Log("stop again stack essai1")
rStop12, errStop12 := client.Stop(ctx, &stackRequest1)
Expand Down

0 comments on commit 9878093

Please sign in to comment.