http

package
v0.16.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API is used to power HTTP endpoint wrappers to the VTAdminServer interface.

func NewAPI

func NewAPI(server vtadminpb.VTAdminServer, opts Options) *API

NewAPI returns an HTTP API backed by the given VTAdminServer implementation.

func (*API) Adapt

func (api *API) Adapt(handler VTAdminHandler) http.HandlerFunc

Adapt converts a VTAdminHandler into an http.HandlerFunc. It deals with wrapping the request in a wrapper for some convenience functions and starts a new context, after extracting any potential spans that were set by an upstream middleware in the request context.

func (*API) Options added in v0.11.0

func (api *API) Options() Options

Options returns a copy of the Options this API was configured with.

func (*API) Server added in v0.11.0

func (api *API) Server() vtadminpb.VTAdminServer

Server returns the VTAdminServer wrapped by this API.

type JSONResponse

type JSONResponse struct {
	Result any        `json:"result,omitempty"`
	Error  *errorBody `json:"error,omitempty"`
	Ok     bool       `json:"ok"`
	// contains filtered or unexported fields
}

JSONResponse represents a generic response object.

func CreateKeyspace added in v0.12.0

func CreateKeyspace(ctx context.Context, r Request, api *API) *JSONResponse

CreateKeyspace implements the http wrapper for POST /keyspace/{cluster_id}.

func CreateShard added in v0.13.0

func CreateShard(ctx context.Context, r Request, api *API) *JSONResponse

CreateShard implements the http wrapper for POST /shards/{cluster_id}.

func DeleteKeyspace added in v0.12.0

func DeleteKeyspace(ctx context.Context, r Request, api *API) *JSONResponse

DeleteKeyspace implements the http wrapper for DELETE /keyspace/{cluster_id}/{name}[?recursive=].

func DeleteShards added in v0.13.0

func DeleteShards(ctx context.Context, r Request, api *API) *JSONResponse

DeleteShards implements the http wrapper for DELETE /shards/{cluster_id}. Query params: - keyspace_shard: required, repeated list of keyspace/shards to delete. - recursive: bool - even_if_serving: bool

func DeleteTablet added in v0.13.0

func DeleteTablet(ctx context.Context, r Request, api *API) *JSONResponse

func EmergencyFailoverShard added in v0.14.0

func EmergencyFailoverShard(ctx context.Context, r Request, api *API) *JSONResponse

EmergencyFailoverShard implements the http wrapper for POST /shard/{cluster_id}/{keyspace}/{shard}/emergency_failover.

Query params: none

POST body is unmarshalled as vtctldatapb.EmergencyReparentShardRequest, but the Keyspace and Shard fields are ignored (coming instead from the route).

func FindSchema added in v0.10.0

func FindSchema(ctx context.Context, r Request, api *API) *JSONResponse

FindSchema implements the http wrapper for the /schema/{table}[?cluster=[&cluster=]] route.

func GetBackups added in v0.11.0

func GetBackups(ctx context.Context, r Request, api *API) *JSONResponse

GetBackups implements the http wrapper for /backups[?cluster=[&cluster=]].

func GetCellInfos added in v0.14.0

func GetCellInfos(ctx context.Context, r Request, api *API) *JSONResponse

GetCellInfos implements the http wrapper for the /cells[?cluster=[&cluster=...]?cell=[&cell=...]&names_only=(true|false)] route.

func GetCellsAliases added in v0.14.0

func GetCellsAliases(ctx context.Context, r Request, api *API) *JSONResponse

GetCellsAliases implements the http wrapper for the /cells_aliases[?cluster=[&cluster=]] route.

func GetClusters added in v0.10.0

func GetClusters(ctx context.Context, r Request, api *API) *JSONResponse

GetClusters implements the http wrapper for /clusters

func GetFullStatus added in v0.15.0

func GetFullStatus(ctx context.Context, r Request, api *API) *JSONResponse

GetFullStatus implements the http wrapper for /tablets/{tablet}/full_status

func GetGates

func GetGates(ctx context.Context, r Request, api *API) *JSONResponse

GetGates implements the http wrapper for /gates[?cluster=[&cluster=]].

func GetKeyspace added in v0.11.0

func GetKeyspace(ctx context.Context, r Request, api *API) *JSONResponse

GetKeyspace implements the http wrapper for /keyspace/{cluster_id}/{name}.

func GetKeyspaces added in v0.10.0

func GetKeyspaces(ctx context.Context, r Request, api *API) *JSONResponse

GetKeyspaces implements the http wrapper for /keyspaces[?cluster=[&cluster=]].

func GetSchema added in v0.10.0

func GetSchema(ctx context.Context, r Request, api *API) *JSONResponse

GetSchema implements the http wrapper for the /schema/{cluster_id}/{keyspace}/{table} route.

func GetSchemas added in v0.10.0

func GetSchemas(ctx context.Context, r Request, api *API) *JSONResponse

GetSchemas implements the http wrapper for the /schemas[?cluster=[&cluster=] route.

func GetShardReplicationPositions added in v0.12.0

func GetShardReplicationPositions(ctx context.Context, r Request, api *API) *JSONResponse

GetShardReplicationPositions implements the http wrapper for /shard_replication_positions. Query params:

  • cluster: repeated, cluster ID
  • keyspace: repeated, keyspace names
  • keyspace_shard: repeated, keyspace shard names

func GetSrvVSchema added in v0.11.0

func GetSrvVSchema(ctx context.Context, r Request, api *API) *JSONResponse

GetSrvVSchema implements the http wrapper for the /api/srvvschema/{cluster_id}/{cell} route.

func GetSrvVSchemas added in v0.11.0

func GetSrvVSchemas(ctx context.Context, r Request, api *API) *JSONResponse

GetSrvVSchemas implements the http wrapper for the /api/srvvschemas route.

func GetTablet

func GetTablet(ctx context.Context, r Request, api *API) *JSONResponse

GetTablet implements the http wrapper for /tablet/{tablet}[?cluster=[&cluster=]].

func GetTablets

func GetTablets(ctx context.Context, r Request, api *API) *JSONResponse

GetTablets implements the http wrapper for /tablets[?cluster=[&cluster=]].

func GetTopologyPath added in v0.15.0

func GetTopologyPath(ctx context.Context, r Request, api *API) *JSONResponse

GetTopologyPath implements the http wrapper for /cluster/{cluster_id}/topology

Query params: - path: string

func GetVSchema added in v0.10.0

func GetVSchema(ctx context.Context, r Request, api *API) *JSONResponse

GetVSchema implements the http wrapper for the /vschema/{cluster_id}/{keyspace} route.

func GetVSchemas added in v0.10.0

func GetVSchemas(ctx context.Context, r Request, api *API) *JSONResponse

GetVSchemas implements the http wrapper for the /vschemas[?cluster=[&cluster=]] route.

func GetVtctlds added in v0.12.0

func GetVtctlds(ctx context.Context, r Request, api *API) *JSONResponse

GetVtctlds implements the http wrapper for /vtctlds[?cluster=[&cluster=]].

func GetWorkflow added in v0.10.0

func GetWorkflow(ctx context.Context, r Request, api *API) *JSONResponse

GetWorkflow implements the http wrapper for the VTAdminServer.GetWorkflow method.

Its route is /workflow/{cluster_id}/{keyspace}/{name}[?active_only=].

func GetWorkflows added in v0.10.0

func GetWorkflows(ctx context.Context, r Request, api *API) *JSONResponse

GetWorkflows implements the http wrapper for the VTAdminServer.GetWorkflows method.

Its route is /workflows, with query params: - cluster: repeated, cluster IDs - active_only - keyspace: repeated - ignore_keyspace: repeated

func NewJSONResponse

func NewJSONResponse(value any, err error) *JSONResponse

NewJSONResponse returns a JSONResponse for the given result and error. If err is non-nil, and implements errors.TypedError, the HTTP status code and message are provided by the error. If not, the code and message fallback to 500 unknown.

func PingTablet added in v0.13.0

func PingTablet(ctx context.Context, r Request, api *API) *JSONResponse

PingTablet checks that the specified tablet is awake and responding to RPCs. This command can be blocked by other in-flight operations.

func PlannedFailoverShard added in v0.14.0

func PlannedFailoverShard(ctx context.Context, r Request, api *API) *JSONResponse

PlannedFailoverShard implements the http wrapper for POST /shard/{cluster_id}/{keyspace}/{shard}/planned_failover.

Query params: none

POST body is unmarshalled as vtctldatapb.PlannedReparentShardRequest, but the Keyspace and Shard fields are ignored (coming instead from the route).

func RebuildKeyspaceGraph added in v0.15.0

func RebuildKeyspaceGraph(ctx context.Context, r Request, api *API) *JSONResponse

RebuildKeyspaceGraph implements the http wrapper for /keyspaces/{cluster_id}/{name}/rebuild_keyspace_graph

func RefreshState added in v0.13.0

func RefreshState(ctx context.Context, r Request, api *API) *JSONResponse

RefreshState reloads the tablet record on the specified tablet.

func RefreshTabletReplicationSource added in v0.14.0

func RefreshTabletReplicationSource(ctx context.Context, r Request, api *API) *JSONResponse

RefreshTabletReplicationSource implements the http wrapper for PUT /tablet/{tablet}/refresh_replication_source.

Query params:

  • cluster: repeatable, list of cluster IDs to restrict to when searching fo a tablet with that alias.

PUT body is unused; this endpoint takes no additional options.

func ReloadSchemaShard added in v0.15.0

func ReloadSchemaShard(ctx context.Context, r Request, api *API) *JSONResponse

ReloadSchemaShard implements the http wrapper for PUT /shard/{cluster_id}/{keyspace}/{shard}/reload_schema_shard

Query params: none

Body params: - wait_position: string - include_primary: bool - concurrency: uint32

func ReloadSchemas added in v0.14.0

func ReloadSchemas(ctx context.Context, r Request, api *API) *JSONResponse

ReloadSchemas implements the http wrapper for /schemas/reload

func ReloadTabletSchema added in v0.14.0

func ReloadTabletSchema(ctx context.Context, r Request, api *API) *JSONResponse

ReloadTabletSchema implements the http wrapper for /tablets/{tablet}/reload_schema.

Note that all query parameters that apply to ReloadSchemas, except for `cluster`, are ignored.

func RemoveKeyspaceCell added in v0.15.0

func RemoveKeyspaceCell(ctx context.Context, r Request, api *API) *JSONResponse

RemoveKeyspaceCell implements the http wrapper for /keyspaces/{cluster_id}/{name}/remove_keyspace_cell

func RunHealthCheck added in v0.13.0

func RunHealthCheck(ctx context.Context, r Request, api *API) *JSONResponse

RunHealthCheck runs a healthcheck on the tablet and returns the result.

func SetReadOnly added in v0.14.0

func SetReadOnly(ctx context.Context, r Request, api *API) *JSONResponse

SetReadOnly sets the tablet to read only mode

func SetReadWrite added in v0.14.0

func SetReadWrite(ctx context.Context, r Request, api *API) *JSONResponse

SetReadWrite sets the tablet to read write mode

func StartReplication added in v0.13.0

func StartReplication(ctx context.Context, r Request, api *API) *JSONResponse

StartReplication starts replication on the specified tablet.

func StopReplication added in v0.13.0

func StopReplication(ctx context.Context, r Request, api *API) *JSONResponse

StartReplication stops replication on the specified tablet.

func TabletExternallyPromoted added in v0.14.0

func TabletExternallyPromoted(ctx context.Context, r Request, api *API) *JSONResponse

TabletExternallyPromoted implements the http wrapper for POST /tablet/{tablet}/tablet_externally_promoted.

Query params: - `cluster`: repeated list of clusterIDs to limit the request to.

POST body is unused; this endpoint takes no additional options.

func VTExplain added in v0.10.0

func VTExplain(ctx context.Context, r Request, api *API) *JSONResponse

VTExplain implements the http wrapper for /vtexplain?cluster=&keyspace=&sql=

func Validate added in v0.15.0

func Validate(ctx context.Context, r Request, api *API) *JSONResponse

Validate implements the http wrapper for /cluster/{cluster_id}/validate

func ValidateKeyspace added in v0.14.0

func ValidateKeyspace(ctx context.Context, r Request, api *API) *JSONResponse

ValidateKeyspace validates that all nodes reachable from the specified keyspace are consistent.

func ValidateSchemaKeyspace added in v0.14.0

func ValidateSchemaKeyspace(ctx context.Context, r Request, api *API) *JSONResponse

ValidateKeyspace validates that all nodes reachable from the specified keyspace are consistent.

func ValidateShard added in v0.15.0

func ValidateShard(ctx context.Context, r Request, api *API) *JSONResponse

ValidateShard implements the http wrapper for PUT /shard/{cluster_id}/{keyspace}/{shard}/validate

Query params: none

Body params: - ping_tablets: bool

func ValidateVersionKeyspace added in v0.14.0

func ValidateVersionKeyspace(ctx context.Context, r Request, api *API) *JSONResponse

ValidateVersionKeyspace validates that the version on the primary of shard 0 matches all of the other tablets in the keyspace.

func ValidateVersionShard added in v0.15.0

func ValidateVersionShard(ctx context.Context, r Request, api *API) *JSONResponse

ValidateVersionShard implements the http wrapper for PUT /shard/{cluster_id}/{keyspace}/{shard}/validate_version

Query params: none

Body params: none

func (*JSONResponse) WithHTTPStatus

func (r *JSONResponse) WithHTTPStatus(code int) *JSONResponse

WithHTTPStatus forces a response to be used for the JSONResponse.

func (*JSONResponse) Write

func (r *JSONResponse) Write(w http.ResponseWriter)

Write marshals a JSONResponse into the http response.

type Options

type Options struct {
	// CORSOrigins is the list of origins to allow via CORS. An empty or nil
	// slice disables CORS entirely.
	CORSOrigins []string
	// EnableTracing specifies whether to install a tracing middleware on the
	// API subrouter.
	EnableTracing bool
	// DisableCompression specifies whether to turn off gzip compression for API
	// endpoints. It is named as the negative (as opposed to EnableTracing) so
	// the zero value has compression enabled.
	DisableCompression bool
	// DisableDebug specifies whether to omit the /debug/pprof/* and /debug/env
	// routes.
	DisableDebug        bool
	ExperimentalOptions struct {
		TabletURLTmpl string
	}
}

Options defines the set of configurations for an HTTP API server.

type Request

type Request struct{ *http.Request }

Request wraps an *http.Request to provide some convenience functions for accessing request data.

func (Request) ParseQueryParamAsBool added in v0.10.0

func (r Request) ParseQueryParamAsBool(name string, defaultVal bool) (bool, error)

ParseQueryParamAsBool attempts to parse the query parameter of the given name into a boolean value. If the parameter is not set, the provided default value is returned.

func (Request) ParseQueryParamAsUint32 added in v0.11.0

func (r Request) ParseQueryParamAsUint32(name string, defaultVal uint32) (uint32, error)

ParseQueryParamAsUint32 attempts to parse the query parameter of the given name into a uint32 value. If the parameter is not set, the provided default value is returned.

func (Request) Vars

func (r Request) Vars() Vars

Vars returns the route variables in a request, if any, as defined by gorilla/mux.

type VTAdminHandler

type VTAdminHandler func(ctx context.Context, r Request, api *API) *JSONResponse

VTAdminHandler is an HTTP endpoint handler that takes, via injection, everything needed to implement a JSON API response.

type Vars added in v0.14.0

type Vars map[string]string

Vars is a mapping of the route variable values in a given request.

See (gorilla/mux).Vars for details. We define a type here to add some additional behavior for extracting non-string values.

func (Vars) GetTabletAlias added in v0.14.0

func (v Vars) GetTabletAlias(key string) (*topodatapb.TabletAlias, error)

GetTabletAlias returns the route named `key` as a TabletAlias.

It returns an error if the route has no variable with that name, or if it cannot be parsed as a TabletAlias.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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