core

package
v0.0.0-...-457da86 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PerConnection not supported yet
	PerConnection RoutingModeType = "PerConnection"

	// PerStream not supported yet
	PerStream RoutingModeType = "PerStream"

	// PerPacket the most common type, like http
	PerPacket RoutingModeType = "PerPacket"

	// Accept ready to receive requests
	Accept Verdict = 1

	// Reject can not receive requests
	Reject Verdict = 2

	// Wait too busy to receive requests, have to wait
	Wait Verdict = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientRequest

type ClientRequest struct {
	ServerRequest     *ServerRequest
	SrcServiceName    string
	SrcServiceCluster string
	DstServiceName    string
}

ClientRequest ServerRequest => ClientRequest: by parsing the request, we know what is the target service

type ConnForwardingDecision

type ConnForwardingDecision struct {
	RoutingMode    RoutingModeType
	ServerProtocol coretype.Protocol
}

ConnForwardingDecision ServerConn => ConnForwardingDecision: when a tcp connection is established, how to forward the connection (routing mode/protocol) is determined

func HowToForward

func HowToForward(serverConn *ServerConn) *ConnForwardingDecision

HowToForward determines how to forward the connection (routing mode/protocol) when a tcp connection is established,

type RoutingDecision

type RoutingDecision struct {
	ServiceInstance *ServiceInstance
	Verdict         Verdict
	RejectResponse  interface{}
	WaitDuration    time.Duration
}

RoutingDecision ServiceInstance => RoutingDecision: given the service status, should we accept/reject/wait the request. If accept, handle the request by chosen service instance.

func HowToRoute

func HowToRoute(serverRequest *ServerRequest, rs RoutingStrategy) (*RoutingDecision, error)

HowToRoute according to the request, decide:

which is the service we want
which cluster of the service do we choose, which version of the service-cluster do we choose (ServiceKind)
which instance in the service-cluster do we choose
what is the corresponding ip:port for the chosen instance
how to handle the request? shall we accept, reject or wait?

The whole process: ServerRequest => ClientRequest => ServiceKind => ServiceInstance => RoutingDecision

type RoutingModeType

type RoutingModeType string

RoutingModeType is the methods of forwarding the connection

type RoutingStrategy

type RoutingStrategy interface {
	LocateClientService(sr *ServerRequest) (*ClientRequest, error)
	GetServiceKind(cr *ClientRequest) *ServiceKind
	SelectOneInst(sk *ServiceKind) (*ServiceInstance, error)
	GetRoutingDecision(inst *ServiceInstance) *RoutingDecision
	Close() error
}

RoutingStrategy defines the process between the core models

type ServerConn

type ServerConn struct {
	LocalAddr  *net.TCPAddr
	RemoteAddr *net.TCPAddr
}

ServerConn accept connection from inbound

type ServerRequest

type ServerRequest struct {
	ServerConn             *ServerConn
	ConnForwardingDecision *ConnForwardingDecision
	Packet                 codec.Packet
}

ServerRequest ConnForwardingDecision => ServerRequest: parse request arrived server Packet might be nil if routing mode is per connection

type ServiceInstance

type ServiceInstance struct {
	Kind       *ServiceKind
	RemoteAddr *net.TCPAddr
}

ServiceInstance ServiceKinds => ServiceInstance: choose one most optimal service cluster from many clusters, choose one most optimal service instance from that cluster. there might be many instances for one ServiceKind, as long as the four values are the same the instances are interchangeable (no big performance difference, same config, same geo-location)

type ServiceKind

type ServiceKind struct {
	// what service actually is, determined by its source code
	Name string
	// traffic segregation by src/type/dst etc,
	// data center is the most often used clustering strategy
	// clusters are defined for management reasons
	Cluster string
	// multiple versions of the source code might be running concurrently
	// to support service version roll-out and roll-back without re-deployment
	Version string
	// one running service os process might speak more than one protocol on different tcp ports
	Protocol coretype.Protocol
	// tag of this service
	Tag string
	// packet of request
	Packet codec.Packet
}

ServiceKind ClientRequest => ServiceKinds: one service have many clusters, filter out feasible clusters by cluster routing table. one ServerRequest might have many ServiceKinds as viable options

func (ServiceKind) Qualifier

func (sk ServiceKind) Qualifier() string

Qualifier to qualifier string

type Verdict

type Verdict int

Verdict accept/reject/wait

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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