Skip to content

Commit

Permalink
Merge pull request mitchellh#71 from vertis/add_configure_health_chec…
Browse files Browse the repository at this point in the history
…k_to_elb

Add ConfigureHealthCheck call
  • Loading branch information
pearkes committed Jul 30, 2014
2 parents c8d5edd + 0d31f08 commit 52323c8
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
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

0 comments on commit 52323c8

Please sign in to comment.