1 /** @file
2 
3   Network message marshalling.
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 #pragma once
25 
26 #include "MgmtMarshall.h"
27 
28 #define REMOTE_DELIM ':'
29 #define REMOTE_DELIM_STR ":"
30 
31 #define MAX_CONN_TRIES 10 // maximum number of attempts to reconnect to TM
32 
33 // the possible operations or msg types sent from remote client to TM
34 enum class OpType : MgmtMarshallInt {
35   RECORD_SET,
36   RECORD_GET,
37   PROXY_STATE_GET,
38   PROXY_STATE_SET,
39   RECONFIGURE,
40   RESTART,
41   BOUNCE,
42   STOP,
43   DRAIN,
44   EVENT_RESOLVE,
45   EVENT_GET_MLT,
46   EVENT_ACTIVE,
47   EVENT_REG_CALLBACK,
48   EVENT_UNREG_CALLBACK,
49   EVENT_NOTIFY, /* only msg sent from TM to client */
50   STATS_RESET_NODE,
51   STORAGE_DEVICE_CMD_OFFLINE,
52   RECORD_MATCH_GET,
53   API_PING,
54   SERVER_BACKTRACE,
55   RECORD_DESCRIBE_CONFIG,
56   LIFECYCLE_MESSAGE,
57   HOST_STATUS_UP,
58   HOST_STATUS_DOWN,
59   UNDEFINED_OP /* This must be last */
60 };
61 
62 enum {
63   RECORD_DESCRIBE_FLAGS_MATCH = 0x0001,
64 };
65 
66 struct mgmt_message_sender {
67   virtual TSMgmtError send(void *msg, size_t msglen) const = 0;
~mgmt_message_sendermgmt_message_sender68   virtual ~mgmt_message_sender(){};
69 
70   // Check if the sender is connected.
71   virtual bool is_connected() const = 0;
72 };
73 
74 // Marshall and send a request, prefixing the message length as a MGMT_MARSHALL_INT.
75 TSMgmtError send_mgmt_request(const mgmt_message_sender &snd, OpType optype, ...);
76 TSMgmtError send_mgmt_request(int fd, OpType optype, ...);
77 
78 // Marshall and send an error response for this operation type.
79 TSMgmtError send_mgmt_error(int fd, OpType op, TSMgmtError error);
80 
81 // Parse a request message from a buffer.
82 TSMgmtError recv_mgmt_request(void *buf, size_t buflen, OpType optype, ...);
83 
84 // Marshall and send a response, prefixing the message length as a MGMT_MARSHALL_INT.
85 TSMgmtError send_mgmt_response(int fd, OpType optype, ...);
86 
87 // Parse a response message from a buffer.
88 TSMgmtError recv_mgmt_response(void *buf, size_t buflen, OpType optype, ...);
89 
90 // Pull a management message (either request or response) off the wire.
91 TSMgmtError recv_mgmt_message(int fd, MgmtMarshallData &msg);
92 
93 // Extract the first MGMT_MARSHALL_INT from the buffered message. This is the OpType.
94 OpType extract_mgmt_request_optype(void *msg, size_t msglen);
95