1
#pragma once
2

            
3
#include "envoy/event/deferred_deletable.h"
4
#include "envoy/network/connection.h"
5
#include "envoy/upstream/upstream.h"
6

            
7
#include "source/extensions/filters/network/thrift_proxy/thrift.h"
8

            
9
namespace Envoy {
10
namespace Extensions {
11
namespace HealthCheckers {
12
namespace ThriftHealthChecker {
13

            
14
/**
15
 * Outbound request callbacks.
16
 */
17
class ClientCallback : public Network::ConnectionCallbacks {
18
public:
19
  /**
20
   * Called when the client needs a connection
21
   */
22
  virtual Upstream::Host::CreateConnectionData createConnection() PURE;
23

            
24
  /**
25
   * Called when a response is received.
26
   * @param is_success indicate if the response is a success response
27
   */
28
  virtual void onResponseResult(bool is_success) PURE;
29
};
30

            
31
/**
32
 * A single thrift client connection.
33
 */
34
class Client : public Event::DeferredDeletable {
35
public:
36
  /**
37
   * Initialize the connection.
38
   */
39
  virtual void start() PURE;
40

            
41
  /**
42
   * Send the health check request.
43
   */
44
  virtual bool sendRequest() PURE;
45

            
46
  /**
47
   * Close the underlying network connection.
48
   */
49
  virtual void close() PURE;
50
};
51

            
52
using ClientPtr = std::unique_ptr<Client>;
53

            
54
/**
55
 * A factory for individual thrift client connections.
56
 */
57
class ClientFactory {
58
public:
59
7
  virtual ~ClientFactory() = default;
60

            
61
  /**
62
   * Create a thrift client.
63
   * @param callbacks supplies the connection data creation, network connection callbacks
64
   *                  to the underlying network connection, and thrift response handling.
65
   * @param transport supplies the type of transport.
66
   * @param protocol supplies the type of protocol.
67
   * @param method_name supplies the method name.
68
   * @param data supplies the connection data.
69
   * @param seq_id supplies the initial sequence id.
70
   * @param fixed_seq_id supplies whether we have sequence id fixed or not.
71
   */
72
  virtual ClientPtr create(ClientCallback& callbacks,
73
                           NetworkFilters::ThriftProxy::TransportType transport,
74
                           NetworkFilters::ThriftProxy::ProtocolType protocol,
75
                           const std::string& method_name, Upstream::HostSharedPtr host,
76
                           int32_t seq_id, bool fixed_seq_id) PURE;
77
};
78

            
79
} // namespace ThriftHealthChecker
80
} // namespace HealthCheckers
81
} // namespace Extensions
82
} // namespace Envoy