habapi

package
v0.0.0-...-be2ef80 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 12 Imported by: 5

Documentation

Overview

Package habapi provides access to the Habitat supervisor's HTTP API

The Habitat supervisor's API contains information about the running services.

This package is currently incomplete and contains only those API functions used in other parts of automate-deployment.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrServiceNotFound = errors.New("service not found")
)

Functions

func AllConsumingServices

func AllConsumingServices(c *Client, pkg habpkg.VersionedPackage) ([]habpkg.HabPkg, error)

AllConsumingServices returns a list of Identifiables for all of the loaded services that are bound to the given service. This assumes that the service group is always default.

func PortForService

func PortForService(svcs []ServiceInfo, svcName string) (int32, bool)

PortForService retrieves the GRPC port for the named service from the []ServiceInfo.

func Timeout

func Timeout(timeout time.Duration) func(*Client)

Timeout returns an "option func" suitable for passing to New which will set to Client's timeout to the specified duration.

func WaitForDown

func WaitForDown(c *Client, services []habpkg.VersionedPackage, timeout time.Duration) error

WaitForStopped waits the given duration for all passed services to have a process state of down. Unloaded services will also be counted as down.

func WaitForUnload

func WaitForUnload(c *Client, services []habpkg.VersionedPackage, timeout time.Duration) error

WaitForUnload waits for all services to be unloaded. We consider a service unloaded if the habitat supervisor doesn't know about it.

func WaitForUp

func WaitForUp(c *Client, services []habpkg.VersionedPackage, timeout time.Duration) error

WaitForUp waits the given duration for all passed services to be up.

Types

type Client

type Client struct {
	// BaseURI is the Habitat API endpoint that this client should
	// talk to.  For example: "http://127.0.0.1:9631"
	BaseURI *url.URL
	// HTTPClient is the underlying http.Client used to
	// communicate with the Habitat API.
	//
	// NOTE(ssd) 2018-01-24: We use a concrete type here since
	// there is no standard http client interface. The standard
	// advice is that if you need to swap something out, you can
	// swap out the Transport field in the http.Client. We don't
	// currently use this for testing since we start a test http
	// server instead.
	HTTPClient http.Client
}

A Client is a Habitat API client.

func New

func New(baseURI string, options ...func(*Client)) *Client

New returns a Client with all passed options applied to it.

func (*Client) ListServices

func (c *Client) ListServices(ctx context.Context) ([]ServiceInfo, error)

ListServices returns a list of services currently running under the Habitat supervisor

func (*Client) ServiceHealth

func (c *Client) ServiceHealth(ctx context.Context, serviceName string, serviceGroup string) (ServiceStatus, error)

ServiceHealth returns the health of a service according to the Habitat supervisor.

Uses the /service/SERVICE_NAME/SERVICE_GROUP/health endpoint.

func (*Client) ServiceInfo

func (c *Client) ServiceInfo(ctx context.Context, serviceName string, serviceGroup string) (ServiceInfo, error)

ServiceInfo returns information about a service running under the Habitat supervisor.

Uses the /service/SERVICE_NAME/SERVICE_GROUP endpoint

type HabServiceInfoAPIClient

type HabServiceInfoAPIClient interface {
	ServiceInfo(ctx context.Context, serviceName string, serviceGroup string) (ServiceInfo, error)
}

HabServiceInfoAPIClient interface describes things that can get the ServiceInfo

type ServiceInfo

type ServiceInfo struct {
	Binds          []string               `json:"binds"`
	Pkg            ServicePkg             `json:"pkg"`
	StartStyle     string                 `json:"start_style"`
	UpdateStrategy string                 `json:"update_strategy"`
	Process        ServiceProcess         `json:"process"`
	Sys            SysInfo                `json:"sys"`
	DesiredState   string                 `json:"desired_state"`
	Cfg            map[string]interface{} `json:"cfg"`
}

ServiceInfo contains information about a service according to the Habitat supervisor. Note that this structure currently only contains a small portion of the data Habitat actually knows about.

func ServiceInfoByName

func ServiceInfoByName(svcs []ServiceInfo, svcName string) (*ServiceInfo, bool)

ServiceInfoByName searches the passed slice of ServiceInfo structs and returns a pointer to the ServiceInfo for the named service.

type ServicePkg

type ServicePkg struct {
	Origin  string `json:"origin"`
	Name    string `json:"name"`
	Version string `json:"version"`
	Release string `json:"release"`
	Channel string `json:"channel"`
}

ServicePkg represents package information for a service. Note that this structure is currently incomplete when compared to the API return.

type ServiceProcess

type ServiceProcess struct {
	PID              uint64 `json:"pid"`
	State            string `json:"state"`
	TimeStateEntered uint64 `json:"state_entered"`
}

type ServiceStatus

type ServiceStatus int

ServiceStatus represents the current health of a service according to the Habitat supervisor. This is returned by ServiceHealth.

const (
	// StatusOk indicates that the health endpoint has
	// returned 200 OK.
	StatusOk ServiceStatus = iota
	// StatusWarning is included for completeness but is not
	// currently returned because the health API does not
	// distinguish between OK and WARNING (both return 200 OK) and
	// the other API that may provide insight appears to have a
	// bug:
	//
	//     https://github.com/habitat-sh/core-plans/issues/1474
	StatusWarning
	// StatusCritical indicates that the health endpoint returned
	// 503
	StatusCritical
	// StatusUnknown indicates that the health endpoint returned
	// 500 or another unrecognized status code.
	StatusUnknown
	// StatusDown indicates that the habitat supervisor doesn't
	// know about this service and it is likely not started.
	StatusDown
)

type SysInfo

type SysInfo struct {
	GossipIP        string `json:"gossip_ip"`
	GossipPort      uint32 `json:"gossip_port"`
	Hostname        string `json:"hostname"`
	HTTPGatewayIP   string `json:"http_gateway_ip"`
	HTTPGatewayPort uint32 `json:"http_gateway_port"`
	IP              string `json:"ip"`
	MemberID        string `json:"member_id"`
	Permanent       bool   `json:"permanent"`
	Version         string `json:"version"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL