http

package
v0.15.10 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: Apache-2.0 Imports: 19 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

func (api *API) Options() Options

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

func (*API) Server

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 ApplySchema

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

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

func CancelSchemaMigration

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

CancelSchemaMigration implements the http wrapper for /migration/{cluster_id}/{keyspace}/cancel[?uuid].

func CleanupSchemaMigration

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

CleanupSchemaMigration implements the http wrapper for /migration/{cluster_id}/{keyspace}/cleanup[?uuid].

func CompleteSchemaMigration

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

CompleteSchemaMigration implements the http wrapper for /migration/{cluster_id}/{keyspace}/complete[?uuid].

func CreateKeyspace

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

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

func CreateShard

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

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

func DeleteKeyspace

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

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

func DeleteShards

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

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

func EmergencyFailoverShard

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

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

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

func GetBackups

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

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

func GetCellInfos

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

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

func GetCellsAliases

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

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

func GetClusters

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

GetClusters implements the http wrapper for /clusters

func GetFullStatus

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_id=[&cluster_id=]].

func GetKeyspace

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

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

func GetKeyspaces

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

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

func GetSchema

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

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

func GetSchemaMigrations

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

GetSchemaMigrations implements the http wrapper for /migrations/.

func GetSchemas

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

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

func GetShardReplicationPositions

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

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

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

func GetSrvKeyspace

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

GetSrvKeyspace implements the http wrapper for the /api/srvkeyspaces/{cluster_id}/{name} route.

func GetSrvKeyspaces

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

GetSrvKeyspaces implements the http wrapper for the /api/srvkeyspaces route.

func GetSrvVSchema

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

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

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

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

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

func GetVSchemas

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

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

func GetVtctlds

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

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

func GetWorkflow

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

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_id: repeated, cluster IDs - active_only - keyspace: repeated - ignore_keyspace: repeated

func LaunchSchemaMigration

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

LaunchSchemaMigration implements the http wrapper for /migration/{cluster_id}/{keyspace}/launch[?uuid].

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

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

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

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

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

RefreshState reloads the tablet record on the specified tablet.

func RefreshTabletReplicationSource

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_id: 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

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

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

ReloadSchemas implements the http wrapper for /schemas/reload

func ReloadTabletSchema

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_id`, are ignored.

func RemoveKeyspaceCell

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

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

func RetrySchemaMigration

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

RetrySchemaMigration implements the http wrapper for /migration/{cluster_id}/{keyspace}/retry[?uuid].

func RunHealthCheck

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

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

func SetReadOnly

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

SetReadOnly sets the tablet to read only mode

func SetReadWrite

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

SetReadWrite sets the tablet to read write mode

func StartReplication

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

StartReplication starts replication on the specified tablet.

func StopReplication

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

StopReplication stops replication on the specified tablet.

func TabletExternallyPromoted

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_id`: repeated list of clusterIDs to limit the request to.

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

func VTExplain

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

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

func Validate

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

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

func ValidateKeyspace

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

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

func ValidateSchemaKeyspace

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

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

func ValidateShard

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

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

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

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) ParseQueryParamAsInt32

func (r Request) ParseQueryParamAsInt32(name string, defaultVal int32) (int32, error)

ParseQueryParamAsInt32 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) ParseQueryParamAsUint32

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

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

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