-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
healthcheck: distinguish between agent/server/client
This is the first step towards formalizing the concept of "agent", "server", and "client" nodes.
- Loading branch information
Showing
5 changed files
with
130 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type StatusService struct { | ||
client *Client | ||
} | ||
|
||
type Status struct { | ||
Status string `json:"status"` | ||
} | ||
|
||
func (s *StatusService) Get(ctx context.Context) (*Status, error) { | ||
var status *Status | ||
_, err := s.client.doGET(ctx, "/api/v2/status", &status) | ||
return status, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package healthcheck | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/LINBIT/linstor-gateway/client" | ||
"github.com/fatih/color" | ||
"strings" | ||
"time" | ||
) | ||
|
||
type checkGatewayServerConnection struct { | ||
cli *client.Client | ||
} | ||
|
||
func (c *checkGatewayServerConnection) check(bool) error { | ||
ctx, done := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer done() | ||
status, err := c.cli.Status.Get(ctx) | ||
if err != nil { | ||
return fmt.Errorf("failed to connect to server: %w", err) | ||
} | ||
if status == nil { | ||
return fmt.Errorf("received nil status from server") | ||
} | ||
if status.Status != "ok" { | ||
return fmt.Errorf("received invalid status from server: %q", status.Status) | ||
} | ||
return nil | ||
} | ||
|
||
func (c *checkGatewayServerConnection) format(err error) string { | ||
var b strings.Builder | ||
fmt.Fprintf(&b, " %s The LINSTOR Gateway server cannot be reached from this node\n", color.RedString("✗")) | ||
fmt.Fprintf(&b, " %s\n\n", err.Error()) | ||
fmt.Fprintf(&b, " Make sure the %s command line option points to a running LINSTOR Gateway server.\n", bold("--connect")) | ||
return b.String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters