Skip to content
This repository has been archived by the owner on Dec 19, 2017. It is now read-only.

Add ConfigureHealthCheck call #71

Merged
merged 2 commits into from
Jul 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions elb/elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,48 @@ func (elb *ELB) DeregisterInstancesFromLoadBalancer(options *DeregisterInstances
return
}

// ----------------------------------------------------------------------------
// Health Checks

type HealthCheck struct {
HealthyThreshold int64
UnhealthyThreshold int64
Interval int64
Target string
Timeout int64
}

type ConfigureHealthCheck struct {
LoadBalancerName string
Check HealthCheck
}

type ConfigureHealthCheckResp struct {
Check HealthCheck `xml:"ConfigureHealthCheckResult>HealthCheck"`
RequestId string `xml:"ResponseMetadata>RequestId"`
}

func (elb *ELB) ConfigureHealthCheck(options *ConfigureHealthCheck) (resp *ConfigureHealthCheckResp, err error) {
params := makeParams("ConfigureHealthCheck")

params["LoadBalancerName"] = options.LoadBalancerName
params["HealthCheck.HealthyThreshold"] = strconv.Itoa(int(options.Check.HealthyThreshold))
params["HealthCheck.UnhealthyThreshold"] = strconv.Itoa(int(options.Check.UnhealthyThreshold))
params["HealthCheck.Interval"] = strconv.Itoa(int(options.Check.Interval))
params["HealthCheck.Target"] = options.Check.Target
params["HealthCheck.Timeout"] = strconv.Itoa(int(options.Check.Timeout))

resp = &ConfigureHealthCheckResp{}

err = elb.query(params, resp)

if err != nil {
resp = nil
}

return
}

// ----------------------------------------------------------------------------
// Instance Health

Expand Down
29 changes: 29 additions & 0 deletions elb/elb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,35 @@ func (s *S) TestDeregisterInstancesFromLoadBalancer(c *C) {
c.Assert(resp.RequestId, Equals, "83c88b9d-12b7-11e3-8b82-87b12EXAMPLE")
}

func (s *S) TestConfigureHealthCheck(c *C) {
testServer.Response(200, nil, ConfigureHealthCheckExample)

options := elb.ConfigureHealthCheck{
LoadBalancerName: "foobar",
Check: elb.HealthCheck{
HealthyThreshold: 2,
UnhealthyThreshold: 2,
Interval: 30,
Target: "HTTP:80/ping",
Timeout: 3,
},
}

resp, err := s.elb.ConfigureHealthCheck(&options)
req := testServer.WaitRequest()

c.Assert(req.Form["Action"], DeepEquals, []string{"ConfigureHealthCheck"})
c.Assert(req.Form["LoadBalancerName"], DeepEquals, []string{"foobar"})
c.Assert(err, IsNil)

c.Assert(resp.Check.HealthyThreshold, Equals, 2)
c.Assert(resp.Check.UnhealthyThreshold, Equals, 2)
c.Assert(resp.Check.Interval, Equals, 30)
c.Assert(resp.Check.Target, Equals, "HTTP:80/ping")
c.Assert(resp.Check.Timeout, Equals, 3)
c.Assert(resp.RequestId, Equals, "83c88b9d-12b7-11e3-8b82-87b12EXAMPLE")
}

func (s *S) TestDescribeInstanceHealth(c *C) {
testServer.Response(200, nil, DescribeInstanceHealthExample)

Expand Down
17 changes: 17 additions & 0 deletions elb/responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ var DeregisterInstancesFromLoadBalancerExample = `
</DeregisterInstancesFromLoadBalancerResponse>
`

// http://docs.aws.amazon.com/ElasticLoadBalancing/latest/APIReference/API_ConfigureHealthCheck.html
var ConfigureHealthCheckExample = `
<ConfigureHealthCheckResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
<ConfigureHealthCheckResult>
<HealthCheck>
<Interval>30</Interval>
<Target>HTTP:80/ping</Target>
<HealthyThreshold>2</HealthyThreshold>
<Timeout>3</Timeout>
<UnhealthyThreshold>2</UnhealthyThreshold>
</HealthCheck>
</ConfigureHealthCheckResult>
<ResponseMetadata>
<RequestId>83c88b9d-12b7-11e3-8b82-87b12EXAMPLE</RequestId>
</ResponseMetadata>
</ConfigureHealthCheckResponse>`

// http://goo.gl/cGNxfj
var DescribeInstanceHealthExample = `
<DescribeInstanceHealthResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
Expand Down