From 9bea9b529be4b3ec3ed7332132245fa245a34038 Mon Sep 17 00:00:00 2001 From: Luke Chadwick Date: Wed, 30 Jul 2014 15:28:33 +1000 Subject: [PATCH 1/2] Add ConfigureHealthCheck call --- elb/elb.go | 42 ++++++++++++++++++++++++++++++++++++++++++ elb/elb_test.go | 29 +++++++++++++++++++++++++++++ elb/responses_test.go | 17 +++++++++++++++++ 3 files changed, 88 insertions(+) diff --git a/elb/elb.go b/elb/elb.go index 61a515d9..7cc48ff8 100644 --- a/elb/elb.go +++ b/elb/elb.go @@ -302,6 +302,48 @@ func (elb *ELB) DeregisterInstancesFromLoadBalancer(options *DeregisterInstances return } +// ---------------------------------------------------------------------------- +// Health Checks + +type HealthCheck struct { + HealthyThreshold int + UnhealthyThreshold int + Interval int + Target string + Timeout int +} + +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(options.Check.HealthyThreshold) + params["HealthCheck.UnhealthyThreshold"] = strconv.Itoa(options.Check.UnhealthyThreshold) + params["HealthCheck.Interval"] = strconv.Itoa(options.Check.Interval) + params["HealthCheck.Target"] = options.Check.Target + params["HealthCheck.Timeout"] = strconv.Itoa(options.Check.Timeout) + + resp = &ConfigureHealthCheckResp{} + + err = elb.query(params, resp) + + if err != nil { + resp = nil + } + + return +} + // ---------------------------------------------------------------------------- // Instance Health diff --git a/elb/elb_test.go b/elb/elb_test.go index 3043e720..eeae4bf0 100644 --- a/elb/elb_test.go +++ b/elb/elb_test.go @@ -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) diff --git a/elb/responses_test.go b/elb/responses_test.go index 6b8578dc..c9f8f15f 100644 --- a/elb/responses_test.go +++ b/elb/responses_test.go @@ -119,6 +119,23 @@ var DeregisterInstancesFromLoadBalancerExample = ` ` +// http://docs.aws.amazon.com/ElasticLoadBalancing/latest/APIReference/API_ConfigureHealthCheck.html +var ConfigureHealthCheckExample = ` + + + + 30 + HTTP:80/ping + 2 + 3 + 2 + + + + 83c88b9d-12b7-11e3-8b82-87b12EXAMPLE + +` + // http://goo.gl/cGNxfj var DescribeInstanceHealthExample = ` From b59a4a9354d44abf2e9fac48ec4ad175fca06e74 Mon Sep 17 00:00:00 2001 From: Luke Chadwick Date: Wed, 30 Jul 2014 21:44:51 +1000 Subject: [PATCH 2/2] Use int64 in struct instead of int --- elb/elb.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/elb/elb.go b/elb/elb.go index 7cc48ff8..75761447 100644 --- a/elb/elb.go +++ b/elb/elb.go @@ -306,11 +306,11 @@ func (elb *ELB) DeregisterInstancesFromLoadBalancer(options *DeregisterInstances // Health Checks type HealthCheck struct { - HealthyThreshold int - UnhealthyThreshold int - Interval int + HealthyThreshold int64 + UnhealthyThreshold int64 + Interval int64 Target string - Timeout int + Timeout int64 } type ConfigureHealthCheck struct { @@ -327,11 +327,11 @@ func (elb *ELB) ConfigureHealthCheck(options *ConfigureHealthCheck) (resp *Confi params := makeParams("ConfigureHealthCheck") params["LoadBalancerName"] = options.LoadBalancerName - params["HealthCheck.HealthyThreshold"] = strconv.Itoa(options.Check.HealthyThreshold) - params["HealthCheck.UnhealthyThreshold"] = strconv.Itoa(options.Check.UnhealthyThreshold) - params["HealthCheck.Interval"] = strconv.Itoa(options.Check.Interval) + 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(options.Check.Timeout) + params["HealthCheck.Timeout"] = strconv.Itoa(int(options.Check.Timeout)) resp = &ConfigureHealthCheckResp{}