E2SAR 0.2.0
All Data Structures Namespaces Functions Typedefs Enumerations
e2sar::LBManager Class Reference

Public Member Functions

 LBManager (const EjfatURI &cpuri, bool validateServer=true, bool useHostAddress=false, grpc::SslCredentialsOptions opts=grpc::SslCredentialsOptions())
 
result< u_int32_t > reserveLB (const std::string &lb_name, const TimeUntil &until, const std::vector< std::string > &senders) noexcept
 
result< u_int32_t > reserveLB (const std::string &lb_name, const boost::posix_time::time_duration &duration, const std::vector< std::string > &senders) noexcept
 
result< u_int32_t > reserveLB (const std::string &lb_name, const double &durationSeconds, const std::vector< std::string > &senders) noexcept
 
result< int > getLB (const std::string &lbid) noexcept
 
result< int > getLB () noexcept
 
result< std::unique_ptr< LoadBalancerStatusReply > > getLBStatus (const std::string &lbid) noexcept
 
result< std::unique_ptr< LoadBalancerStatusReply > > getLBStatus () noexcept
 
result< std::unique_ptr< OverviewReply > > overview () noexcept
 
result< int > addSenders (const std::vector< std::string > &senders) noexcept
 
result< int > removeSenders (const std::vector< std::string > &senders) noexcept
 
result< int > addSenderSelf (bool v6=false) noexcept
 
result< int > removeSenderSelf (bool v6=false) noexcept
 
result< int > freeLB (const std::string &lbid) noexcept
 
result< int > freeLB () noexcept
 
result< int > registerWorker (const std::string &node_name, std::pair< ip::address, u_int16_t > node_ip_port, float weight, u_int16_t source_count, float min_factor, float max_factor) noexcept
 
result< int > registerWorkerSelf (const std::string &node_name, u_int16_t node_port, float weight, u_int16_t source_count, float min_factor, float max_factor, bool v6=false) noexcept
 
result< int > deregisterWorker () noexcept
 
result< int > sendState (float fill_percent, float control_signal, bool is_ready) noexcept
 
result< int > sendState (float fill_percent, float control_signal, bool is_ready, const Timestamp &ts) noexcept
 
result< boost::tuple< std::string, std::string, std::string > > version () noexcept
 
const EjfatURIget_URI () const noexcept
 
std::string get_AddrString ()
 

Static Public Member Functions

static std::vector< WorkerStatus > get_WorkerStatusVector (std::unique_ptr< LoadBalancerStatusReply > &rep) noexcept
 
static std::vector< WorkerStatus > get_WorkerStatusVector (const LoadBalancerStatusReply &rep) noexcept
 
static std::vector< std::string > get_SenderAddressVector (std::unique_ptr< LoadBalancerStatusReply > &rep) noexcept
 
static std::vector< std::string > get_SenderAddressVector (const LoadBalancerStatusReply &rep) noexcept
 
static const std::unique_ptr< LBStatusasLBStatus (std::unique_ptr< LoadBalancerStatusReply > &rep) noexcept
 
static const LBStatus asLBStatus (const LoadBalancerStatusReply &rep) noexcept
 
static const OverviewMessage asOverviewMessage (std::unique_ptr< OverviewReply > &rep) noexcept
 
static const OverviewMessage asOverviewMessage (const OverviewReply &rep) noexcept
 
static result< grpc::SslCredentialsOptions > makeSslOptions (const std::string &pem_root_certs, const std::string &pem_private_key, const std::string &pem_cert_chain) noexcept
 
static result< grpc::SslCredentialsOptions > makeSslOptionsFromFiles (std::string_view pem_root_certs, std::string_view pem_private_key, std::string_view pem_cert_chain) noexcept
 
static result< grpc::SslCredentialsOptions > makeSslOptionsFromFiles (std::string_view pem_root_certs) noexcept
 

Constructor & Destructor Documentation

◆ LBManager()

e2sar::LBManager::LBManager ( const EjfatURI & cpuri,
bool validateServer = true,
bool useHostAddress = false,
grpc::SslCredentialsOptions opts = grpc::SslCredentialsOptions() )
inline

Initialize manager. Default is with TLS/SSL and default client options. To enable custom SSL configuration with custom root certs, private key (for authN) and cert use makeSslOptions[FromFiles]() methods and pass the output to this constructor.

Parameters
cpurian EjfatURI object parsed from configuration data
validateServerif false, skip server certificate validation (useful for self-signed testing)
useHostAddresseven if hostname is provided, use host address as resolved by URI object (with preference for IPv4 by default or for IPv6 if explicitly requested)
optsgrpc::SslCredentialsOptions containing some combination of server root certs, client key and client cert use of SSL/TLS is governed by the URI scheme ('ejfat' vs 'ejfats')

Member Function Documentation

◆ addSenders()

result< int > e2sar::LBManager::addSenders ( const std::vector< std::string > & senders)
noexcept

Add 'safe' sender addresses to CP to allow these sender to send data to the LB

Parameters
sender_list- list of sender addresses

◆ addSenderSelf()

result< int > e2sar::LBManager::addSenderSelf ( bool v6 = false)
noexcept

Determine the caller's outgoing interface towards LB dataplane and register it as a sender

Parameters
-use IPv6 dataplane (default false)

◆ asLBStatus() [1/2]

static const LBStatus e2sar::LBManager::asLBStatus ( const LoadBalancerStatusReply & rep)
inlinestaticnoexcept

Helper function copies LoadBalancerStatusReply protobuf into a simpler struct

◆ asLBStatus() [2/2]

static const std::unique_ptr< LBStatus > e2sar::LBManager::asLBStatus ( std::unique_ptr< LoadBalancerStatusReply > & rep)
inlinestaticnoexcept

Helper function copies LoadBalancerStatusReply protobuf into a simpler struct

◆ asOverviewMessage() [1/2]

static const OverviewMessage e2sar::LBManager::asOverviewMessage ( const OverviewReply & rep)
inlinestaticnoexcept

Helper function copies OverviewReply protobuf into a simpler struct

◆ asOverviewMessage() [2/2]

static const OverviewMessage e2sar::LBManager::asOverviewMessage ( std::unique_ptr< OverviewReply > & rep)
inlinestaticnoexcept

Helper function copies OverviewReply protobuf into a simpler struct

◆ deregisterWorker()

result< int > e2sar::LBManager::deregisterWorker ( )
noexcept

Deregister worker using session ID and session token from the register call

Returns
- 0 on success or an error condition

◆ freeLB() [1/2]

result< int > e2sar::LBManager::freeLB ( )
noexcept

Free previously reserved load balancer. Uses admin token and uses LB ID obtained from reserve call on the same LBManager object.

Returns
- 0 on success or error code with message on failure

◆ freeLB() [2/2]

result< int > e2sar::LBManager::freeLB ( const std::string & lbid)
noexcept

Free previously reserved load balancer. Uses admin token.

Parameters
-externally provided lbid, in this case the URI only needs to contain cp address and admin token
Returns
- 0 on success or error code with message on failure

◆ get_AddrString()

std::string e2sar::LBManager::get_AddrString ( )
inline

Return the address string used by gRPC to connect to control plane. Can be in the format of hostname:port or ipv4:///W.X.Y.Z:port or ipv6:///[XXXX::XX:XXXX]:port

Returns
the string containing the address

◆ get_SenderAddressVector() [1/2]

static std::vector< std::string > e2sar::LBManager::get_SenderAddressVector ( const LoadBalancerStatusReply & rep)
inlinestaticnoexcept

Helper function copies sender addresses into a vector. Relies on move semantics.

Parameters
rep- the referenced return of getLBStatus() call
Returns
- a vector of strings with known sender addresses communicated in the reserve call

◆ get_SenderAddressVector() [2/2]

static std::vector< std::string > e2sar::LBManager::get_SenderAddressVector ( std::unique_ptr< LoadBalancerStatusReply > & rep)
inlinestaticnoexcept

Helper function copies sender addresses into a vector. Relies on move semantics.

Parameters
rep- the referenced return of getLBStatus() call
Returns
- a vector of strings with known sender addresses communicated in the reserve call

◆ get_URI()

const EjfatURI & e2sar::LBManager::get_URI ( ) const
inlinenoexcept

Get the internal URI object.

◆ get_WorkerStatusVector() [1/2]

static std::vector< WorkerStatus > e2sar::LBManager::get_WorkerStatusVector ( const LoadBalancerStatusReply & rep)
inlinestaticnoexcept

Helper function copies worker records into a vector It takes a unique_ptr from getLBStatus() call and helps parse it. Relies on move semantics.

Parameters
rep- the return of the getLBStatus() call
Returns
- a vector of WorkerStatus objects with fields like name, fillpercent, controlsignal, slotsassigned and a lastupdated timestamp

◆ get_WorkerStatusVector() [2/2]

static std::vector< WorkerStatus > e2sar::LBManager::get_WorkerStatusVector ( std::unique_ptr< LoadBalancerStatusReply > & rep)
inlinestaticnoexcept

Helper function copies worker records into a vector It takes a unique_ptr from getLBStatus() call and helps parse it. Relies on move semantics.

Parameters
rep- the return of the getLBStatus() call
Returns
- a vector of WorkerStatus objects with fields like name, fillpercent, controlsignal, slotsassigned and a lastupdated timestamp

◆ getLB() [1/2]

result< int > e2sar::LBManager::getLB ( )
noexcept

Get load balancer info using lb id in the URI object

Returns
- 0 on success or error code with message on failure

◆ getLB() [2/2]

result< int > e2sar::LBManager::getLB ( const std::string & lbid)
noexcept

Get load balancer info - it updates the info inside the EjfatURI object just like reserveLB. Uses admin token of the internal URI object. Note that unlike reserve it does NOT set the instance token - it is not available.

Parameters
lbid- externally provided lb id, in this case the URI only needs to contain the cp address and admin token and it will be updated to contain dataplane and sync addresses.
Returns
- 0 on success or error code with message on failure

protobuf definition uses u_int32

◆ getLBStatus() [1/2]

result< std::unique_ptr< LoadBalancerStatusReply > > e2sar::LBManager::getLBStatus ( )
noexcept

Get load balancer status including list of workers, sender IP addresses etc using lb id in the URI object

Returns
- loadbalancer::LoadBalancerStatusReply protobuf object with getters for fields like timestamp, currentepoch, currentpredictedeventnumber and iterators over senders and workers. For each worker you get name, fill percent, controlsignal, slotsassigned and timestamp last updated.

◆ getLBStatus() [2/2]

result< std::unique_ptr< LoadBalancerStatusReply > > e2sar::LBManager::getLBStatus ( const std::string & lbid)
noexcept

Get load balancer status including list of workers, sender IP addresses.

Parameters
lbid- externally provided lbid, in this case the URI only needs to contain cp address and admin token
Returns
- loadbalancer::LoadBalancerStatusReply protobuf object with getters for fields like timestamp, currentepoch, currentpredictedeventnumber and iterators over senders and workers. For each worker you get name, fill percent, controlsignal, slotsassigned and timestamp last updated.

◆ makeSslOptions()

static result< grpc::SslCredentialsOptions > e2sar::LBManager::makeSslOptions ( const std::string & pem_root_certs,
const std::string & pem_private_key,
const std::string & pem_cert_chain )
inlinestaticnoexcept

Generate gRPC-compliant custom SSL Options object with the following parameters, where any parameter can be empty. Uses std::move to avoid copies.

Parameters
pem_root_certsThe buffer containing the PEM encoding of the server root certificates.
pem_private_keyThe buffer containing the PEM encoding of the client's private key.
pem_cert_chainThe buffer containing the PEM encoding of the client's certificate chain.
Returns
outcome for grpc::SslCredentialsOptions object with parameters filled in

◆ makeSslOptionsFromFiles() [1/2]

result< grpc::SslCredentialsOptions > e2sar::LBManager::makeSslOptionsFromFiles ( std::string_view pem_root_certs)
staticnoexcept

Generate gRPC-compliant custom SSL Options object with just the server root cert

Parameters
pem_root_certs- The file name containing the PEM encoding of the server root certificate.

◆ makeSslOptionsFromFiles() [2/2]

result< grpc::SslCredentialsOptions > e2sar::LBManager::makeSslOptionsFromFiles ( std::string_view pem_root_certs,
std::string_view pem_private_key,
std::string_view pem_cert_chain )
staticnoexcept

Generate gRPC-compliant custom SSL Options object with the following parameters, where any parameter can be empty

Parameters
pem_root_certs- The file name containing the PEM encoding of the server root certificate.
pem_private_key- The file name containing the PEM encoding of the client's private key.
pem_cert_chain- The file name containing the PEM encoding of the client's certificate chain.
Returns
outcome for grpc::SslCredentialsOptions object with parameters filled in

◆ overview()

result< std::unique_ptr< OverviewReply > > e2sar::LBManager::overview ( )
noexcept

Get an 'overview' of reserved load balancer instances

Returns
- loadbalancer::OverviewReply protobuf object which itself is an array of ReserveLoadBalancerReply and LoadBalancerStatusReply for each instance as well as the name given to each instance in reserveLB.

◆ registerWorker()

result< int > e2sar::LBManager::registerWorker ( const std::string & node_name,
std::pair< ip::address, u_int16_t > node_ip_port,
float weight,
u_int16_t source_count,
float min_factor,
float max_factor )
noexcept

Register a workernode/backend with an allocated loadbalancer. Note that this call uses instance token. It sets session token and session id on the internal URI object. Note that a new worker must send state immediately (within 10s) or be automatically deregistered.

Parameters
node_name- name of the node (can be FQDN)
node_ip_port- a pair of ip::address and u_int16_t starting UDP port on which it listens
weight- weight given to this node in terms of processing power
source_count- how many sources we can listen to (gets converted to port range [0,14])
min_factor- multiplied with the number of slots that would be assigned evenly to determine min number of slots for example, 4 nodes with a minFactor of 0.5 = (512 slots / 4) * 0.5 = min 64 slots
max_factor- multiplied with the number of slots that would be assigned evenly to determine max number of slots for example, 4 nodes with a maxFactor of 2 = (512 slots / 4) * 2 = max 256 slots set to 0 to specify no maximum
Returns
- 0 on success or an error condition

◆ registerWorkerSelf()

result< int > e2sar::LBManager::registerWorkerSelf ( const std::string & node_name,
u_int16_t node_port,
float weight,
u_int16_t source_count,
float min_factor,
float max_factor,
bool v6 = false )
noexcept

Register the calling worker workernode/backend with an allocated loadbalancer. The node tries to determine its outgoing IP address towards LB dataplane. Note that this call uses instance token. It sets session token and session id on the internal URI object. Note that a new worker must send state immediately (within 10s) or be automatically deregistered.

Parameters
node_name- name of the node (can be FQDN)
node_port- a u_int16_t starting UDP port on which it listens
weight- weight given to this node in terms of processing power
source_count- how many sources we can listen to (gets converted to port range [0,14])
min_factor- multiplied with the number of slots that would be assigned evenly to determine min number of slots for example, 4 nodes with a minFactor of 0.5 = (512 slots / 4) * 0.5 = min 64 slots
max_factor- multiplied with the number of slots that would be assigned evenly to determine max number of slots for example, 4 nodes with a maxFactor of 2 = (512 slots / 4) * 2 = max 256 slots set to 0 to specify no maximum
v6- use IPv6 dataplane (defaults to false)
Returns
- 0 on success or an error condition

◆ removeSenders()

result< int > e2sar::LBManager::removeSenders ( const std::vector< std::string > & senders)
noexcept

Remove 'safe' sender addresses from CP to disallow these senders to send data to the LB

◆ removeSenderSelf()

result< int > e2sar::LBManager::removeSenderSelf ( bool v6 = false)
noexcept

Determine the caller's outgoing interface towards LB dataplane and unregister as a sender

Parameters
-use IPv6 dataplane (default false)

◆ reserveLB() [1/3]

result< u_int32_t > e2sar::LBManager::reserveLB ( const std::string & lb_name,
const boost::posix_time::time_duration & duration,
const std::vector< std::string > & senders )
noexcept

Reserve a new load balancer with this name until specified time. It sets the intstance token on the internal URI object.

Parameters
lb_nameLB name internal to you
durationfor how long it is needed as boost::posix_time::time_duration. You can use boost::posix_time::duration_from_string from string like "23:59:59.000"s
senderslist of sender IP addresses
Returns
- FPGA LB ID, for use in correlating logs/metrics

◆ reserveLB() [2/3]

result< u_int32_t > e2sar::LBManager::reserveLB ( const std::string & lb_name,
const double & durationSeconds,
const std::vector< std::string > & senders )
noexcept

Reserve a new load balancer with this name of duration in seconds

Parameters
lb_nameLB name internal to you
durationSecondsfor how long it is needed in seconds
senderslist of sender IP addresses
Returns
- 0 on success or error code with message on failure

NOTE: this static casting may lose time accuracy, but should be accepted

◆ reserveLB() [3/3]

result< u_int32_t > e2sar::LBManager::reserveLB ( const std::string & lb_name,
const TimeUntil & until,
const std::vector< std::string > & senders )
noexcept

Reserve a new load balancer with this name until specified time

Parameters
lb_nameLB name internal to you
untiltime until it's needed as google protobuf timestamp pointer.
senderslist of sender IP addresses
Returns
- FPGA LB ID, for use in correlating logs/metrics

protobuf definition uses u_int32

◆ sendState() [1/2]

result< int > e2sar::LBManager::sendState ( float fill_percent,
float control_signal,
bool is_ready )
noexcept

Send worker state update using session ID and session token from register call. Automatically uses localtime to set the timestamp. Workers are expected to send state every 100ms or so.

Parameters
fill_percent- [0:1] percentage filled of the queue
control_signal- change to data rate
is_ready- if true, worker ready to accept more data, else not ready

◆ sendState() [2/2]

result< int > e2sar::LBManager::sendState ( float fill_percent,
float control_signal,
bool is_ready,
const Timestamp & ts )
noexcept

Send worker state update using session ID and session token from register call. Allows to explicitly set the timestamp.

Parameters
fill_percent- [0:1] percentage filled of the queue
control_signal- change to data rate
is_ready- if true, worker ready to accept more data, else not ready
ts- google::protobuf::Timestamp timestamp for this message (if you want to explicitly not use localtime)

◆ version()

result< boost::tuple< std::string, std::string, std::string > > e2sar::LBManager::version ( )
noexcept

Get the version of the load balancer (the commit string)

Returns
the result with commit string, build tag and compatTag in

The documentation for this class was generated from the following files: