kronoshttp

package
v0.0.0-...-d504ea7 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 20 Imported by: 4

README

Cluster HTTP handler

Add Node

Add a new node to the raft cluster of kronos.

POST: https://address:raft_port/cluster/add

Input: AddNodeRequest with NodeID, Address in JSON format, e.g.,

{"node_id":"5085e631629d4560","address":"127.0.0.1:6766"}

Output: None

Remove Node

POST: https://address:raft_port/cluster/remove

Remove a node from the raft cluster of kronos.

Input: RemoveNodeRequest with NodeID in JSON format, e.g.,

{"node_id":"5085e631629d4560"}

Output: None

Get Nodes

GET: https://address:raft_port/cluster/nodes

Get all the nodes currently part of the cluster according to the server.

Output: A list of nodes. The list can be incomplete when the cluster is bootstrapping and multiple nodes are being added simultaneously.

[
  {
    "node_id": "1",
     // JSON representation of kronospb.Node.
  },
  {
    "node_id": "2",
    // ...
  }
]

Documentation

Index

Constants

View Source
const ClusterPath = "cluster"

ClusterPath is the endpoint of HTTP server which handles cluster requests.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddNodeRequest

type AddNodeRequest struct {
	// NodeID should be in hex format. uin64 can be converted to nodeID using:
	// nodeID uint64 -> types.Id(nodeID).String().
	NodeID string `json:"node_id"`
	// Address should be in ip_address:raft_port format.
	Address string `json:"address"`
}

AddNodeRequest is used by a new node to send the data required to add itself to an existing cluster. The server adds the node with given raft address with raft id NodeID.

type ClusterClient

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

ClusterClient issues HTTP requests on the URL for performing cluster operations like removal or addition of nodes. This contains a http client that is thread-safe and should be reused to avoid leaking TCP connections. Close should be called after completing all the requests to avoid connection leaks.

func NewClusterClient

func NewClusterClient(host *kronospb.NodeAddr, tlsInfo transport.TLSInfo) (*ClusterClient, error)

NewClusterClient creates a new ClusterClient which can be used to perform cluster operations like addition or removal of nodes on the raft HTTP server listening on the given host. All the requests of this client have a default timeout of 10 minutes. Requests can be passed with contexts with smaller timeouts as per use case. Close should be called after completing all the requests to avoid connection leaks.

func (*ClusterClient) AddNode

func (c *ClusterClient) AddNode(ctx context.Context, request *AddNodeRequest) error

AddNode sends a request to add a new node to the raft HTTP server of ClusterClient.

func (*ClusterClient) Close

func (c *ClusterClient) Close()

Close closes all the idle connections that cluster client has made.

func (*ClusterClient) GRPCAddr

func (c *ClusterClient) GRPCAddr(ctx context.Context) (*kronospb.NodeAddr, error)

GRPCAddr sends a request to get grpc address of the raft HTTP server of ClusterClient.

func (*ClusterClient) Nodes

func (c *ClusterClient) Nodes(ctx context.Context) ([]Node, error)

Nodes sends a request to get current nodes of the cluster to the raft HTTP server of ClusterClient.

func (*ClusterClient) RemoveNode

func (c *ClusterClient) RemoveNode(ctx context.Context, request *RemoveNodeRequest) error

RemoveNode sends a request to remove a node to the raft HTTP server of ClusterClient.

type ClusterHandler

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

ClusterHandler handles cluster operations via to http requests.

func NewClusterHandler

func NewClusterHandler(
	confChangeC chan<- sdraftpb.ConfChange, dataDir string, grpcAddr *kronospb.NodeAddr,
) *ClusterHandler

NewClusterHandler returns a cluster handler which handles cluster requests and sends the corresponding confChanges to confChangeC.

func (*ClusterHandler) ServeHTTP

func (h *ClusterHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves HTTP requests using ClusterHandler

type Node

type Node struct {
	*kronospb.Node
	NodeID string `json:"node_id"`
}

Node is used to store the metadata for every node that we send in response to /cluster/nodes requests.

type RemoveNodeRequest

type RemoveNodeRequest struct {
	NodeID string `json:"node_id"`
}

RemoveNodeRequest is used to remove node with raft id NodeID.

type StatusHandler

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

StatusHandler is used to check whether the raft HTTP server is up. It returns the raft id of the node on GET calls.

func NewStatusHandler

func NewStatusHandler(nodeID string) *StatusHandler

NewStatusHandler creates a statusHandler, that responds with nodeID on GET requests.

func (*StatusHandler) ServeHTTP

func (h *StatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP returns whether the raft HTTP server is up

Jump to

Keyboard shortcuts

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