httphelper

package
v1.21.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: Apache-2.0 Imports: 22 Imported by: 6

Documentation

Index

Constants

View Source
const (
	NodeDrainEndpoint        = "/api/v0/ops/node/drain"
	MgmtApiTargetHostAndPort = "localhost:8080"
	LivenessEndpoint         = "/api/v0/probes/liveness"
	ReadinessEndpoint        = "/api/v0/probes/readiness"
	DefaultTimeout           = 10
)

Variables

This section is empty.

Functions

func AddManagementApiServerSecurity

func AddManagementApiServerSecurity(dc *api.CassandraDatacenter, pod *corev1.PodTemplateSpec) error

func BuildPodHostFromPod

func BuildPodHostFromPod(pod *corev1.Pod) (string, int, error)

func FakeExecutorServerWithDetails added in v1.10.0

func FakeExecutorServerWithDetails(callDetails *CallDetails) (*httptest.Server, error)

func FakeExecutorServerWithDetailsFails added in v1.10.0

func FakeExecutorServerWithDetailsFails(callDetails *CallDetails) (*httptest.Server, error)

func FakeMgmtApiServer added in v1.10.0

func FakeMgmtApiServer(callDetails *CallDetails, handlerFunc http.HandlerFunc) (*httptest.Server, error)

func FakeServerWithoutFeaturesEndpoint added in v1.10.0

func FakeServerWithoutFeaturesEndpoint(callDetails *CallDetails) (*httptest.Server, error)

func GetManagementApiProtocol

func GetManagementApiProtocol(dc *api.CassandraDatacenter) (string, error)

API for Node Management mAuth Config

func GetMgmtApiPostAction added in v1.17.0

func GetMgmtApiPostAction(dc *api.CassandraDatacenter, endpoint string, timeout int) (*corev1.ExecAction, error)

func GetPodHost

func GetPodHost(podName, clusterName, dcName, namespace string) string

func ValidateManagementApiConfig

func ValidateManagementApiConfig(dc *api.CassandraDatacenter, client client.Client, ctx context.Context) []error

Types

type CallDetails added in v1.10.0

type CallDetails struct {
	URLCounts map[string]int
	Payloads  [][]byte
}

func NewCallDetails added in v1.10.0

func NewCallDetails() *CallDetails

type CassMetadataEndpoints

type CassMetadataEndpoints struct {
	Entity []EndpointState `json:"entity"`
}

type ClusteringOrder added in v1.9.0

type ClusteringOrder string
const (
	ClusteringOrderAsc  ClusteringOrder = "ASC"
	ClusteringOrderDesc ClusteringOrder = "DESC"
)

type ColumnDefinition added in v1.9.0

type ColumnDefinition struct {
	Name     string          `json:"name"`
	Type     string          `json:"type"`
	Kind     ColumnKind      `json:"kind"`
	Position int             `json:"position"`
	Order    ClusteringOrder `json:"order,omitempty"`
}

func NewClusteringColumn added in v1.9.0

func NewClusteringColumn(name string, dataType string, position int, order ClusteringOrder) *ColumnDefinition

func NewPartitionKeyColumn added in v1.9.0

func NewPartitionKeyColumn(name string, dataType string, position int) *ColumnDefinition

func NewRegularColumn added in v1.9.0

func NewRegularColumn(name string, dataType string) *ColumnDefinition

func NewStaticColumn added in v1.9.0

func NewStaticColumn(name string, dataType string) *ColumnDefinition

type ColumnKind added in v1.9.0

type ColumnKind string
const (
	ColumnKindPartitionKey     ColumnKind = "PARTITION_KEY"
	ColumnKindClusteringColumn ColumnKind = "CLUSTERING_COLUMN"
	ColumnKindRegular          ColumnKind = "REGULAR"
	ColumnKindStatic           ColumnKind = "STATIC"
)

type CompactRequest added in v1.13.0

type CompactRequest struct {
	SplitOutput      bool     `json:"split_output,omitempty"`
	UserDefined      bool     `json:"user_defined,omitempty"`
	StartToken       string   `json:"start_token,omitempty"`
	EndToken         string   `json:"end_token,omitempty"`
	KeyspaceName     string   `json:"keyspace_name"`
	UserDefinedFiles []string `json:"user_defined_files,omitempty"`
	Tables           []string `json:"tables"`
}

type EndpointState

type EndpointState struct {
	Datacenter             string `json:"DC,omitempty"`
	Rack                   string `json:"RACK,omitempty"`
	ReleaseVersion         string `json:"RELEASE_VERSION,omitempty"`
	SchemaVersion          string `json:"SCHEMA,omitempty"`
	SSTableVersion         string `json:"SSTABLE_VERSIONS,omitempty"`
	HostID                 string `json:"HOST_ID,omitempty"`
	IsAlive                string `json:"IS_ALIVE,omitempty"`
	EndpointIP             string `json:"ENDPOINT_IP,omitempty"`
	NativeAddressAndPort   string `json:"NATIVE_ADDRESS_AND_PORT,omitempty"`
	NativeTransportAddress string `json:"NATIVE_TRANSPORT_ADDRESS,omitempty"`
	RpcAddress             string `json:"RPC_ADDRESS,omitempty"`
	Status                 string `json:"STATUS,omitempty"`
	StatusWithPort         string `json:"STATUS_WITH_PORT,omitempty"`
	Load                   string `json:"LOAD,omitempty"`
}

func (*EndpointState) GetRpcAddress

func (x *EndpointState) GetRpcAddress() string

func (*EndpointState) HasStatus added in v1.10.0

func (e *EndpointState) HasStatus(status EndpointStateStatus) bool

type EndpointStateStatus added in v1.10.0

type EndpointStateStatus string
const (
	StatusNormal  EndpointStateStatus = "NORMAL"
	StatusLeaving EndpointStateStatus = "LEAVING"
	StatusLeft    EndpointStateStatus = "LEFT"
	StatusMoving  EndpointStateStatus = "MOVING"
	StatusRemoved EndpointStateStatus = "removed"
)

type Feature added in v1.9.0

type Feature string
const (
	// AsyncSSTableTasks includes "cleanup" and "decommission"
	AsyncSSTableTasks       Feature = "async_sstable_tasks"
	AsyncUpgradeSSTableTask Feature = "async_upgrade_sstable_task"
	AsyncCompactionTask     Feature = "async_compaction_task"
	AsyncScrubTask          Feature = "async_scrub_task"
	FullQuerySupport        Feature = "full_query_logging"
	Rebuild                 Feature = "rebuild"
	Move                    Feature = "async_move_task"
	AsyncGarbageCollect     Feature = "async_gc_task"
	AsyncFlush              Feature = "async_flush_task"
)

Features are generational (mgmt-api version bound) and can include multiple endpoints under a single Feature name.

type FeatureSet added in v1.9.0

type FeatureSet struct {
	CassandraVersion string
	Features         map[string]struct{}
}

func (*FeatureSet) Supports added in v1.9.0

func (f *FeatureSet) Supports(feature Feature) bool

Supports returns true if the target pod's management-api supports certain feature

func (*FeatureSet) UnmarshalJSON added in v1.9.0

func (f *FeatureSet) UnmarshalJSON(b []byte) error

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (*http.Response, error)
}

func BuildManagementApiHttpClient

func BuildManagementApiHttpClient(dc *api.CassandraDatacenter, client client.Client, ctx context.Context) (HttpClient, error)

type InsecureManagementApiSecurityProvider

type InsecureManagementApiSecurityProvider struct {
}

func (*InsecureManagementApiSecurityProvider) AddServerSecurity

func (provider *InsecureManagementApiSecurityProvider) AddServerSecurity(pod *corev1.PodTemplateSpec) error

func (*InsecureManagementApiSecurityProvider) BuildHttpClient

func (provider *InsecureManagementApiSecurityProvider) BuildHttpClient(client client.Client, ctx context.Context) (HttpClient, error)

func (*InsecureManagementApiSecurityProvider) BuildMgmtApiGetAction added in v1.17.0

func (provider *InsecureManagementApiSecurityProvider) BuildMgmtApiGetAction(endpoint string, timeout int) *corev1.ExecAction

func (*InsecureManagementApiSecurityProvider) BuildMgmtApiPostAction added in v1.17.0

func (provider *InsecureManagementApiSecurityProvider) BuildMgmtApiPostAction(endpoint string, timeout int) *corev1.ExecAction

func (*InsecureManagementApiSecurityProvider) GetProtocol

func (provider *InsecureManagementApiSecurityProvider) GetProtocol() string

func (*InsecureManagementApiSecurityProvider) ValidateConfig

func (provider *InsecureManagementApiSecurityProvider) ValidateConfig(client client.Client, ctx context.Context) []error

type JobDetails added in v1.9.0

type JobDetails struct {
	Id         string `json:"id"`
	Type       string `json:"type"`
	Status     string `json:"status"`
	SubmitTime string `json:"submit_time,omitempty"`
	EndTime    string `json:"end_time,omitempty"`
	Error      string `json:"error,omitempty"`
}

type ManagementApiSecurityProvider

type ManagementApiSecurityProvider interface {
	BuildHttpClient(client client.Client, ctx context.Context) (HttpClient, error)
	BuildMgmtApiGetAction(endpoint string, timeout int) *corev1.ExecAction
	BuildMgmtApiPostAction(endpoint string, timeout int) *corev1.ExecAction
	AddServerSecurity(pod *corev1.PodTemplateSpec) error
	GetProtocol() string
	ValidateConfig(client client.Client, ctx context.Context) []error
}

SPI for adding new mechanisms for securing the management API

func BuildManagementApiSecurityProvider added in v1.10.5

func BuildManagementApiSecurityProvider(dc *api.CassandraDatacenter) (ManagementApiSecurityProvider, error)

type ManualManagementApiSecurityProvider

type ManualManagementApiSecurityProvider struct {
	Namespace string
	Config    *api.ManagementApiAuthManualConfig
}

func (*ManualManagementApiSecurityProvider) AddServerSecurity

func (provider *ManualManagementApiSecurityProvider) AddServerSecurity(pod *corev1.PodTemplateSpec) error

func (*ManualManagementApiSecurityProvider) BuildHttpClient

func (provider *ManualManagementApiSecurityProvider) BuildHttpClient(client client.Client, ctx context.Context) (HttpClient, error)

func (*ManualManagementApiSecurityProvider) BuildMgmtApiGetAction added in v1.17.0

func (provider *ManualManagementApiSecurityProvider) BuildMgmtApiGetAction(endpoint string, timeout int) *corev1.ExecAction

func (*ManualManagementApiSecurityProvider) BuildMgmtApiPostAction added in v1.17.0

func (provider *ManualManagementApiSecurityProvider) BuildMgmtApiPostAction(endpoint string, timeout int) *corev1.ExecAction

func (*ManualManagementApiSecurityProvider) GetProtocol

func (provider *ManualManagementApiSecurityProvider) GetProtocol() string

func (*ManualManagementApiSecurityProvider) ValidateConfig

func (provider *ManualManagementApiSecurityProvider) ValidateConfig(client client.Client, ctx context.Context) []error

type NoPodIPError

type NoPodIPError error

type NodeMgmtClient

type NodeMgmtClient struct {
	Client   HttpClient
	Log      logr.Logger
	Protocol string
}

func NewMgmtClient added in v1.10.0

func NewMgmtClient(ctx context.Context, client client.Client, dc *cassdcapi.CassandraDatacenter) (NodeMgmtClient, error)

func (*NodeMgmtClient) AlterKeyspace

func (client *NodeMgmtClient) AlterKeyspace(pod *corev1.Pod, keyspaceName string, replicationSettings []map[string]string) error

AlterKeyspace modifies the keyspace by calling management API

func (*NodeMgmtClient) CallCompaction added in v1.13.0

func (client *NodeMgmtClient) CallCompaction(pod *corev1.Pod, compactRequest *CompactRequest) (string, error)

CallCompaction calls the v1 version of compaction to force a (major) compaction on one or more tables or user-defined compaction on given SSTables, returning the jobId

func (*NodeMgmtClient) CallCompactionEndpoint added in v1.13.0

func (client *NodeMgmtClient) CallCompactionEndpoint(pod *corev1.Pod, compactRequest *CompactRequest) error

CallCompactionEndpoint calls the blocking version (v0) of compactionto force a (major) compaction on one or more tables or user-defined compaction on given SSTables

func (*NodeMgmtClient) CallCreateRoleEndpoint

func (client *NodeMgmtClient) CallCreateRoleEndpoint(pod *corev1.Pod, username string, password string, superuser bool) error

Create a new superuser with the given username and password

func (*NodeMgmtClient) CallDatacenterRebuild added in v1.10.0

func (client *NodeMgmtClient) CallDatacenterRebuild(pod *corev1.Pod, sourceDatacenter string) (string, error)

CallDatacenterRebuild returns the job id of the rebuild job.

func (*NodeMgmtClient) CallDecommissionNode added in v1.10.0

func (client *NodeMgmtClient) CallDecommissionNode(pod *corev1.Pod, force bool) (string, error)

CallDecommissionNode returns the job id of the decommission job.

func (*NodeMgmtClient) CallDecommissionNodeEndpoint

func (client *NodeMgmtClient) CallDecommissionNodeEndpoint(pod *corev1.Pod) error

CallDecommissionNodeEndpoint is for the old /api/v0 decommission. Use the CallDecommissionNode for async behavior if available

func (*NodeMgmtClient) CallDrainEndpoint

func (client *NodeMgmtClient) CallDrainEndpoint(pod *corev1.Pod) error

func (*NodeMgmtClient) CallFlush added in v1.18.0

func (client *NodeMgmtClient) CallFlush(pod *corev1.Pod, keyspaceName string, tables []string) (string, error)

func (*NodeMgmtClient) CallFlushEndpoint added in v1.18.0

func (client *NodeMgmtClient) CallFlushEndpoint(pod *corev1.Pod, keyspaceName string, tables []string) error

func (*NodeMgmtClient) CallGarbageCollect added in v1.18.0

func (client *NodeMgmtClient) CallGarbageCollect(pod *corev1.Pod, keyspaceName string, tables []string) (string, error)

func (*NodeMgmtClient) CallGarbageCollectEndpoint added in v1.18.0

func (client *NodeMgmtClient) CallGarbageCollectEndpoint(pod *corev1.Pod, keyspaceName string, tables []string) error

func (*NodeMgmtClient) CallIsFullQueryLogEnabledEndpoint added in v1.9.0

func (client *NodeMgmtClient) CallIsFullQueryLogEnabledEndpoint(pod *corev1.Pod) (bool, error)

func (*NodeMgmtClient) CallKeyspaceCleanup added in v1.9.0

func (client *NodeMgmtClient) CallKeyspaceCleanup(pod *corev1.Pod, jobs int, keyspaceName string, tables []string) (string, error)

CallKeyspaceCleanup returns the job id of the cleanup job

func (*NodeMgmtClient) CallKeyspaceCleanupEndpoint

func (client *NodeMgmtClient) CallKeyspaceCleanupEndpoint(pod *corev1.Pod, jobs int, keyspaceName string, tables []string) error

CallKeyspaceCleanupEndpoint is deprecated. Use it only when accessing old management-api versions. Otherwise, use CallKeyspaceCleanup

func (*NodeMgmtClient) CallLifecycleStartEndpoint

func (client *NodeMgmtClient) CallLifecycleStartEndpoint(pod *corev1.Pod) error

func (*NodeMgmtClient) CallLifecycleStartEndpointWithReplaceIp

func (client *NodeMgmtClient) CallLifecycleStartEndpointWithReplaceIp(pod *corev1.Pod, replaceIp string) error

func (*NodeMgmtClient) CallMetadataEndpointsEndpoint

func (client *NodeMgmtClient) CallMetadataEndpointsEndpoint(pod *corev1.Pod) (CassMetadataEndpoints, error)

func (*NodeMgmtClient) CallMove added in v1.14.0

func (client *NodeMgmtClient) CallMove(pod *corev1.Pod, newToken string) (string, error)

CallMove invokes the node move endpoint and returns the job id of the move job.

func (*NodeMgmtClient) CallProbeClusterEndpoint

func (client *NodeMgmtClient) CallProbeClusterEndpoint(pod *corev1.Pod, consistencyLevel string, rfPerDc int) error

func (*NodeMgmtClient) CallReloadSeedsEndpoint

func (client *NodeMgmtClient) CallReloadSeedsEndpoint(pod *corev1.Pod) error

func (*NodeMgmtClient) CallSchemaVersionsEndpoint added in v1.10.0

func (client *NodeMgmtClient) CallSchemaVersionsEndpoint(pod *corev1.Pod) (map[string][]string, error)

CallSchemaVersionsEndpoint returns a map of all schema versions. Map keys are the schema UUIDs and the values are lists of nodes' IPs that are at that version. The JSON response looks like this:

{"2207c2a9-f598-3971-986b-2926e09e239d": ["10.244.1.4", "10.244.2.3, 10.244.3.3"]}

A map length of 1 indicates schema agreement.

func (*NodeMgmtClient) CallScrub added in v1.13.0

func (client *NodeMgmtClient) CallScrub(pod *corev1.Pod, scrubRequest *ScrubRequest) (string, error)

CallScrub calls the v1 version of scrub, rebuilding sstables for one or more tables, returning the jobId.

func (*NodeMgmtClient) CallScrubEndpoint added in v1.13.0

func (client *NodeMgmtClient) CallScrubEndpoint(pod *corev1.Pod, scrubRequest *ScrubRequest) error

CallScrubEndpoint calls the blocking version of scrub (v0 version) rebuilding sstables for one or more tables

func (*NodeMgmtClient) CallSetFullQueryLog added in v1.9.0

func (client *NodeMgmtClient) CallSetFullQueryLog(pod *corev1.Pod, enableFullQueryLogging bool) error

func (*NodeMgmtClient) CallUpgradeSSTables added in v1.13.0

func (client *NodeMgmtClient) CallUpgradeSSTables(pod *corev1.Pod, jobs int, keyspaceName string, tables []string) (string, error)

CallUpgradeSSTables calls the v1 version of upgradeSSTables, returning the jobId

func (*NodeMgmtClient) CallUpgradeSSTablesEndpoint added in v1.13.0

func (client *NodeMgmtClient) CallUpgradeSSTablesEndpoint(pod *corev1.Pod, jobs int, keyspaceName string, tables []string) error

CallUpgradeSSTablesEndpoint calls the v0 version of upgradeSSTables endpoint (blocking operation)

func (*NodeMgmtClient) CreateKeyspace

func (client *NodeMgmtClient) CreateKeyspace(pod *corev1.Pod, keyspaceName string, replicationSettings []map[string]string) error

CreateKeyspace calls management API to create a new Keyspace.

func (*NodeMgmtClient) CreateTable added in v1.9.0

func (client *NodeMgmtClient) CreateTable(pod *corev1.Pod, table *TableDefinition) error

CreateTable calls the management API to create a new table.

func (*NodeMgmtClient) FeatureSet added in v1.9.0

func (client *NodeMgmtClient) FeatureSet(pod *corev1.Pod) (*FeatureSet, error)

FeatureSet returns supported features on the target pod. If the target pod is too old, empty FeatureSet is returned. One can check the supported feature by using FeatureSet.Supports(feature) and that will work regardless if this endpoint returns a result or 404 (other errors are passed as error)

func (*NodeMgmtClient) GetKeyspace

func (client *NodeMgmtClient) GetKeyspace(pod *corev1.Pod, keyspaceName string) ([]string, error)

GetKeyspace calls the management API to check if a specific keyspace exists

func (*NodeMgmtClient) GetKeyspaceReplication added in v1.9.0

func (client *NodeMgmtClient) GetKeyspaceReplication(pod *corev1.Pod, keyspaceName string) (map[string]string, error)

GetKeyspaceReplication calls the management API to retrieve the replication settings of the given keyspace.

func (*NodeMgmtClient) JobDetails added in v1.9.0

func (client *NodeMgmtClient) JobDetails(pod *corev1.Pod, jobId string) (*JobDetails, error)

func (*NodeMgmtClient) ListKeyspaces

func (client *NodeMgmtClient) ListKeyspaces(pod *corev1.Pod) ([]string, error)

ListKeyspaces calls the management API to list existing keyspaces

func (*NodeMgmtClient) ListTables added in v1.9.0

func (client *NodeMgmtClient) ListTables(pod *corev1.Pod, keyspaceName string) ([]string, error)

ListTables calls the management API and returns the table names in the given keyspace

type RequestError added in v1.9.0

type RequestError struct {
	StatusCode int
	Err        error
}

func (*RequestError) Error added in v1.9.0

func (r *RequestError) Error() string

func (*RequestError) NotFound added in v1.9.0

func (r *RequestError) NotFound() bool

type ScrubRequest added in v1.13.0

type ScrubRequest struct {
	DisableSnapshot       bool     `json:"disable_snapshot"`
	SkipCorrupted         bool     `json:"skip_corrupted"`
	CheckData             bool     `json:"check_data"`
	ReinsertOverflowedTTL bool     `json:"reinsert_overflowed_ttl"`
	Jobs                  int      `json:"jobs"`
	KeyspaceName          string   `json:"keyspace_name"`
	Tables                []string `json:"tables"`
}

type TableDefinition added in v1.9.0

type TableDefinition struct {
	KeyspaceName string                 `json:"keyspace_name"`
	TableName    string                 `json:"table_name"`
	Columns      []*ColumnDefinition    `json:"columns"`
	Options      map[string]interface{} `json:"options,omitempty"`
}

func NewTableDefinition added in v1.9.0

func NewTableDefinition(keyspaceName string, tableName string, columns ...*ColumnDefinition) *TableDefinition

Jump to

Keyboard shortcuts

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