consul: Adding RPCInfo to get common info

This commit is contained in:
Armon Dadgar 2014-04-18 17:14:00 -07:00
parent 6ea9ec310c
commit 85fd3158c3
1 changed files with 62 additions and 0 deletions

View File

@ -28,6 +28,13 @@ const (
HealthCritical = "critical"
)
// RPCInfo is used to describe common information about query
type RPCInfo interface {
RequestDatacenter() string
IsRead() bool
AllowStaleRead() bool
}
// BlockingQuery is used to block on a query and wait for a change.
// Either both fields, or neither must be provided.
type BlockingQuery struct {
@ -49,6 +56,26 @@ type QueryOptions struct {
RequireConsistent bool
}
// QueryOption only applies to reads, so always true
func (q QueryOptions) IsRead() bool {
return true
}
func (q QueryOptions) AllowStaleRead() bool {
return q.AllowStale
}
type WriteRequest struct{}
// WriteRequest only applies to writes, always false
func (w WriteRequest) IsRead() bool {
return false
}
func (w WriteRequest) AllowStaleRead() bool {
return false
}
// QueryMeta allows a query response to include potentially
// useful metadata about a query
type QueryMeta struct {
@ -70,6 +97,11 @@ type RegisterRequest struct {
Address string
Service *NodeService
Check *HealthCheck
WriteRequest
}
func (r *RegisterRequest) RequestDatacenter() string {
return r.Datacenter
}
// DeregisterRequest is used for the Catalog.Deregister endpoint
@ -80,6 +112,11 @@ type DeregisterRequest struct {
Node string
ServiceID string
CheckID string
WriteRequest
}
func (r *DeregisterRequest) RequestDatacenter() string {
return r.Datacenter
}
// DCSpecificRequest is used to query about a specific DC
@ -89,6 +126,10 @@ type DCSpecificRequest struct {
QueryOptions
}
func (r *DCSpecificRequest) RequestDatacenter() string {
return r.Datacenter
}
// ServiceSpecificRequest is used to query about a specific node
type ServiceSpecificRequest struct {
Datacenter string
@ -99,6 +140,10 @@ type ServiceSpecificRequest struct {
QueryOptions
}
func (r *ServiceSpecificRequest) RequestDatacenter() string {
return r.Datacenter
}
// NodeSpecificRequest is used to request the information about a single node
type NodeSpecificRequest struct {
Datacenter string
@ -107,6 +152,10 @@ type NodeSpecificRequest struct {
QueryOptions
}
func (r *NodeSpecificRequest) RequestDatacenter() string {
return r.Datacenter
}
// ChecksInStateRequest is used to query for nodes in a state
type ChecksInStateRequest struct {
Datacenter string
@ -115,6 +164,10 @@ type ChecksInStateRequest struct {
QueryOptions
}
func (r *ChecksInStateRequest) RequestDatacenter() string {
return r.Datacenter
}
// Used to return information about a node
type Node struct {
Node string
@ -231,6 +284,11 @@ type KVSRequest struct {
Datacenter string
Op KVSOp // Which operation are we performing
DirEnt DirEntry // Which directory entry
WriteRequest
}
func (r *KVSRequest) RequestDatacenter() string {
return r.Datacenter
}
// KeyRequest is used to request a key, or key prefix
@ -241,6 +299,10 @@ type KeyRequest struct {
QueryOptions
}
func (r *KeyRequest) RequestDatacenter() string {
return r.Datacenter
}
type IndexedDirEntries struct {
Index uint64
Entries DirEntries