Skip to content

Commit

Permalink
Merge pull request #19 from storageos/health_broken_during_init
Browse files Browse the repository at this point in the history
Health broken during init
  • Loading branch information
croomes authored Sep 12, 2017
2 parents 0f104d4 + 1c1b62e commit 28749f1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
14 changes: 6 additions & 8 deletions health.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package storageos
import (
"context"
"encoding/json"
//"errors"
//"fmt"
"github.com/storageos/go-api/types"
"net/http"
//"net/url"

"github.com/storageos/go-api/types"
)

var (
Expand All @@ -16,7 +14,7 @@ var (
)

// CPHealth returns the health of the control plane server at a given url.
func (c *Client) CPHealth(hostname string) (*types.CPHealthStatus, error) {
func (c *Client) CPHealth(ctx context.Context, hostname string) (*types.CPHealthStatus, error) {

req, err := http.NewRequest("GET", "http://"+hostname+":5705/v1/"+HealthAPIPrefix, nil)
if err != nil {
Expand All @@ -28,7 +26,7 @@ func (c *Client) CPHealth(hostname string) (*types.CPHealthStatus, error) {
req.SetBasicAuth(c.username, c.secret)
}

resp, err := c.HTTPClient.Do(req.WithContext(context.Background()))
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
if err != nil {
return nil, err
}
Expand All @@ -43,7 +41,7 @@ func (c *Client) CPHealth(hostname string) (*types.CPHealthStatus, error) {
}

// DPHealth returns the health of the data plane server at a given url.
func (c *Client) DPHealth(hostname string) (*types.DPHealthStatus, error) {
func (c *Client) DPHealth(ctx context.Context, hostname string) (*types.DPHealthStatus, error) {

req, err := http.NewRequest("GET", "http://"+hostname+":8001/v1/"+HealthAPIPrefix, nil)
if err != nil {
Expand All @@ -55,7 +53,7 @@ func (c *Client) DPHealth(hostname string) (*types.DPHealthStatus, error) {
req.SetBasicAuth(c.username, c.secret)
}

resp, err := c.HTTPClient.Do(req.WithContext(context.Background()))
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions health_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package storageos

import (
"context"
"encoding/json"
"net/http"
"reflect"
Expand Down Expand Up @@ -45,7 +46,7 @@ func TestCPHealth(t *testing.T) {
}

client := newTestClient(&FakeRoundTripper{message: data, status: http.StatusOK})
cpHealth, err := client.CPHealth("someHostname")
cpHealth, err := client.CPHealth(context.Background(), "someHostname")
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -96,7 +97,7 @@ func TestDPHealth(t *testing.T) {
}

client := newTestClient(&FakeRoundTripper{message: data, status: http.StatusOK})
dpHealth, err := client.DPHealth("someHostname")
dpHealth, err := client.DPHealth(context.Background(), "someHostname")
if err != nil {
t.Error(err)
}
Expand Down
18 changes: 9 additions & 9 deletions types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ type CPHealthStatus struct {

func (c *CPHealthStatus) ToNamedSubmodules() []NamedSubModuleStatus {
return []NamedSubModuleStatus{
{Name: "NATS", SubModuleStatus: c.NATS},
{Name: "KV", SubModuleStatus: c.KV},
{Name: "KV_WRITE", SubModuleStatus: c.KVWrite},
{Name: "SCHEDULER", SubModuleStatus: c.Scheduler},
{Name: "nats", SubModuleStatus: c.NATS},
{Name: "kv", SubModuleStatus: c.KV},
{Name: "kv_write", SubModuleStatus: c.KVWrite},
{Name: "scheduler", SubModuleStatus: c.Scheduler},
}
}

Expand Down Expand Up @@ -64,11 +64,11 @@ type DPHealthStatus struct {

func (d *DPHealthStatus) ToNamedSubmodules() []NamedSubModuleStatus {
return []NamedSubModuleStatus{
{Name: "DFS_CLIENT", SubModuleStatus: d.DirectFSClient},
{Name: "DFS_SERVER", SubModuleStatus: d.DirectFSServer},
{Name: "DIRECTOR", SubModuleStatus: d.Director},
{Name: "FS_DRIVER", SubModuleStatus: d.FSDriver},
{Name: "FS", SubModuleStatus: d.FS},
{Name: "dfs_client", SubModuleStatus: d.DirectFSClient},
{Name: "dfs_server", SubModuleStatus: d.DirectFSServer},
{Name: "director", SubModuleStatus: d.Director},
{Name: "fs_driver", SubModuleStatus: d.FSDriver},
{Name: "fs", SubModuleStatus: d.FS},
}
}

Expand Down

0 comments on commit 28749f1

Please sign in to comment.