Skip to content

Commit

Permalink
Report stabilize error.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejholmes committed Jun 15, 2016
1 parent d5a7fbd commit ba094d8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions server/cloudformation/cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Provisioner interface {
//
// 1. The physical id that was created, if any.
// 2. The data to return.
Provision(Request) (string, interface{}, error)
Provision(context.Context, Request) (string, interface{}, error)
}

// Possible request types.
Expand Down Expand Up @@ -273,7 +273,7 @@ func (c *CustomResourceProvisioner) Handle(ctx context.Context, message *sqs.Mes
}

resp := NewResponseFromRequest(req)
resp.PhysicalResourceId, resp.Data, err = p.Provision(req)
resp.PhysicalResourceId, resp.Data, err = p.Provision(ctx, req)
switch err {
case nil:
resp.Status = StatusSuccess
Expand Down
4 changes: 3 additions & 1 deletion server/cloudformation/cloudformation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/stretchr/testify/mock"
)

var ctx = context.Background()

func TestCustomResourceProvisioner_Handle(t *testing.T) {
p := new(mockProvisioner)
h := new(mockHTTPClient)
Expand Down Expand Up @@ -96,7 +98,7 @@ type mockProvisioner struct {
mock.Mock
}

func (m *mockProvisioner) Provision(req Request) (string, interface{}, error) {
func (m *mockProvisioner) Provision(_ context.Context, req Request) (string, interface{}, error) {
args := m.Called(req)
return args.String(0), args.Get(1), args.Error(2)
}
Expand Down
16 changes: 10 additions & 6 deletions server/cloudformation/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import (
"reflect"
"strings"

"golang.org/x/net/context"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/remind101/pkg/reporter"
)

type ecsClient interface {
Expand Down Expand Up @@ -48,17 +51,17 @@ func (p *ECSServiceResource) Properties() interface{} {
return &ECSServiceProperties{}
}

func (p *ECSServiceResource) Provision(req Request) (string, interface{}, error) {
func (p *ECSServiceResource) Provision(ctx context.Context, req Request) (string, interface{}, error) {
properties := req.ResourceProperties.(*ECSServiceProperties)
oldProperties := req.OldResourceProperties.(*ECSServiceProperties)

switch req.RequestType {
case Create:
id, err := p.create(properties)
id, err := p.create(ctx, properties)
return id, nil, err
case Delete:
id := req.PhysicalResourceId
err := p.delete(aws.String(id), properties.Cluster)
err := p.delete(ctx, aws.String(id), properties.Cluster)
return id, nil, err
case Update:
id := req.PhysicalResourceId
Expand All @@ -67,7 +70,7 @@ func (p *ECSServiceResource) Provision(req Request) (string, interface{}, error)
// If we can't update the service, we'll need to create a new
// one, and destroy the old one.
oldId := id
id, err := p.create(properties)
id, err := p.create(ctx, properties)
if err != nil {
return oldId, nil, err
}
Expand All @@ -91,7 +94,7 @@ func (p *ECSServiceResource) Provision(req Request) (string, interface{}, error)
}
}

func (p *ECSServiceResource) create(properties *ECSServiceProperties) (string, error) {
func (p *ECSServiceResource) create(ctx context.Context, properties *ECSServiceProperties) (string, error) {
var loadBalancers []*ecs.LoadBalancer
for _, v := range properties.LoadBalancers {
loadBalancers = append(loadBalancers, &ecs.LoadBalancer{
Expand Down Expand Up @@ -126,12 +129,13 @@ func (p *ECSServiceResource) create(properties *ECSServiceProperties) (string, e
// We're ignoring this error, because the service was created,
// and if the service doesn't stabilize, it's better to just let
// the stack finish creating than rolling back.
reporter.Report(ctx, err)
}

return *arn, nil
}

func (p *ECSServiceResource) delete(service, cluster *string) error {
func (p *ECSServiceResource) delete(ctx context.Context, service, cluster *string) error {
// We have to scale the service down to 0, before we're able to
// destroy it.
if _, err := p.ecs.UpdateService(&ecs.UpdateServiceInput{
Expand Down
10 changes: 5 additions & 5 deletions server/cloudformation/ecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestECSServiceResource_Create(t *testing.T) {
Services: []*string{aws.String("arn:aws:ecs:us-east-1:012345678901:service/acme-inc-web-A")},
}).Return(nil)

id, data, err := p.Provision(Request{
id, data, err := p.Provision(ctx, Request{
RequestType: Create,
ResourceProperties: &ECSServiceProperties{
Cluster: aws.String("cluster"),
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestECSServiceResource_Update(t *testing.T) {
TaskDefinition: aws.String("arn:aws:ecs:us-east-1:012345678910:task-definition/acme-inc:2"),
}).Return(&ecs.UpdateServiceOutput{}, nil)

id, data, err := p.Provision(Request{
id, data, err := p.Provision(ctx, Request{
RequestType: Update,
PhysicalResourceId: "arn:aws:ecs:us-east-1:012345678901:service/acme-inc-web",
ResourceProperties: &ECSServiceProperties{
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestECSServiceResource_Update_RequiresReplacement(t *testing.T) {
Services: []*string{aws.String("arn:aws:ecs:us-east-1:012345678901:service/acme-inc-web-B")},
}).Return(nil)

id, data, err := p.Provision(Request{
id, data, err := p.Provision(ctx, Request{
RequestType: Update,
PhysicalResourceId: "arn:aws:ecs:us-east-1:012345678901:service/acme-inc-web-A",
ResourceProperties: &ECSServiceProperties{
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestECSServiceResource_Delete(t *testing.T) {
Cluster: aws.String("cluster"),
}).Return(&ecs.DeleteServiceOutput{}, nil)

id, data, err := p.Provision(Request{
id, data, err := p.Provision(ctx, Request{
RequestType: Delete,
PhysicalResourceId: "arn:aws:ecs:us-east-1:012345678901:service/acme-inc-web",
ResourceProperties: &ECSServiceProperties{
Expand Down Expand Up @@ -181,7 +181,7 @@ func TestECSServiceResource_Delete_NotActive(t *testing.T) {
DesiredCount: aws.Int64(0),
}).Return(&ecs.UpdateServiceOutput{}, awserr.New("ServiceNotActiveException", "Service was not ACTIVE", errors.New("")))

id, data, err := p.Provision(Request{
id, data, err := p.Provision(ctx, Request{
RequestType: Delete,
PhysicalResourceId: "arn:aws:ecs:us-east-1:012345678901:service/acme-inc-web",
ResourceProperties: &ECSServiceProperties{
Expand Down
4 changes: 3 additions & 1 deletion server/cloudformation/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cloudformation
import (
"fmt"
"strconv"

"golang.org/x/net/context"
)

type portAllocator interface {
Expand All @@ -15,7 +17,7 @@ type InstancePortsProvisioner struct {
ports portAllocator
}

func (p *InstancePortsProvisioner) Provision(req Request) (id string, data interface{}, err error) {
func (p *InstancePortsProvisioner) Provision(_ context.Context, req Request) (id string, data interface{}, err error) {
switch req.RequestType {
case Create:
var port int64
Expand Down

0 comments on commit ba094d8

Please sign in to comment.