1// Package adminport provides admin-port client/server library that can be
2// used by system components to talk with each other. It is based on
3// request/response protocol, by default used http for transport and protobuf,
4// JSON for payload. Admin port can typically be used for collecting
5// statistics, administering and managing cluster.
6package adminport
7
8import "errors"
9import c "github.com/couchbase/indexing/secondary/common"
10
11// errors codes
12
13// ErrorRegisteringRequest
14var ErrorRegisteringRequest = errors.New("adminport.registeringRequest")
15
16// ErrorMessageUnknown
17var ErrorMessageUnknown = errors.New("adminport.unknownMessage")
18
19// ErrorPathNotFound
20var ErrorPathNotFound = errors.New("adminport.pathNotFound")
21
22// ErrorRequest
23var ErrorRequest = errors.New("adminport.request")
24
25// ErrorServerStarted
26var ErrorServerStarted = errors.New("adminport.serverStarted")
27
28// ErrorDecodeRequest
29var ErrorDecodeRequest = errors.New("adminport.decodeRequest")
30
31// ErrorEncodeResponse
32var ErrorEncodeResponse = errors.New("adminport.encodeResponse")
33
34// ErrorDecodeResponse
35var ErrorDecodeResponse = errors.New("adminport.decodeResponse")
36
37// ErrorInternal
38var ErrorInternal = errors.New("adminport.internal")
39
40// MessageMarshaller APIs message format.
41type MessageMarshaller interface {
42	// Name of the message
43	Name() string
44
45	// Content type to be used by the transport layer.
46	ContentType() string
47
48	// Encode function shall marshal message to byte array.
49	Encode() (data []byte, err error)
50
51	// Decode function shall unmarshal byte array back to message.
52	Decode(data []byte) (err error)
53}
54
55// Request API for server application to handle incoming request.
56type Request interface {
57	// Get message from request packet.
58	GetMessage() MessageMarshaller
59
60	// Send a response message back to the client.
61	Send(MessageMarshaller) error
62
63	// Send error back to the client.
64	SendError(error) error
65}
66
67// Server API for adminport
68type Server interface {
69	// Register a request message that shall be supported by adminport-server
70	Register(msg MessageMarshaller) error
71
72	// RegisterHandler a request message that shall be supported by
73	// adminport-server
74	RegisterHTTPHandler(pattern string, handler interface{}) error
75
76	// Unregister a previously registered request message
77	Unregister(msg MessageMarshaller) error
78
79	// Start server routine and wait for incoming request, Register() and
80	// Unregister() APIs cannot be called after starting the server.
81	Start() error
82
83	// GetStatistics returns server statistics.
84	GetStatistics() c.Statistics
85
86	// Stop server routine.
87	Stop()
88}
89
90// Client API for a remote adminport
91type Client interface {
92	// Request shall post a `request` message to server, wait for response and
93	// decode response into `response` argument. `response` argument must be a
94	// pointer to an object implementing `MessageMarshaller` interface.
95	Request(request, response MessageMarshaller) (err error)
96}
97