bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
TheBESKeys Class Reference

mapping of key/value pairs defining different behaviors of an application. More...

#include <TheBESKeys.h>

Inheritance diagram for TheBESKeys:
Inheritance graph
Collaboration diagram for TheBESKeys:
Collaboration graph

Public Member Functions

void delete_key (const std::string &key)
 Delete the key Added primarily for testing purposes.
 
virtual std::string dump () const
 dumps information about this object
 
void dump (std::ostream &strm) const override
 dumps information about this object
 
std::string get_as_config () const
 
void get_value (const std::string &s, std::string &val, bool &found)
 Retrieve the value of a given key, if set.
 
void get_values (const std::string &, std::unordered_map< std::string, std::string > &map_values, bool case_insensitive_map_keys, bool &found)
 
void get_values (const std::string &, std::unordered_map< std::string, std::unordered_map< std::string, std::vector< std::string > > > &map, bool case_insensitive_map_keys, bool &found)
 
void get_values (const std::string &s, std::vector< std::string > &vals, bool &found)
 Retrieve the values of a given key, if set.
 
std::unordered_map< std::string, std::vector< std::string > >::const_iterator keys_begin ()
 
std::unordered_map< std::string, std::vector< std::string > >::const_iterator keys_end ()
 
std::string keys_file_name () const
 
void load_dynamic_config (const std::string &name)
 Loads the the applicable dynamic configuration or nothing if no configuration is applicable.
 
TheBESKeysoperator= (const TheBESKeys &)=delete
 
TheBESKeysoperator= (TheBESKeys &&)=delete
 
void reload_keys ()
 Reload the keys. Erase the existing keys and reload them from the file. This uses the name of the keys file previously set in the constructor.
 
void reload_keys (const std::string &keys_file_name)
 Reload the keys. Erase the existing keys and reload them from the file. This version provides a way to change the name of the file to load the keys from.
 
void set_key (const std::string &key, const std::string &val, bool addto=false)
 allows the user to set key/value pairs from within the application.
 
void set_key (const std::string &pair)
 allows the user to set key/value pairs from within the application.
 
void set_keys (const std::string &key, const std::unordered_map< std::string, std::string > &values, bool case_insensitive_map_keys, bool addto)
 allows the user to encode a map in the Keys from within the application.
 
void set_keys (const std::string &key, const std::vector< std::string > &values, bool addto)
 allows the user to set key/value pairs from within the application.
 
 TheBESKeys (const TheBESKeys &)=delete
 
 TheBESKeys (TheBESKeys &&)=delete
 
bool using_dynamic_config () const
 

Static Public Member Functions

static bool read_bool_key (const std::string &key, bool default_value)
 Read a boolean-valued key from the bes.conf file.
 
static int read_int_key (const std::string &key, int default_value)
 Read an integer-valued key from the bes.conf file.
 
static std::string read_string_key (const std::string &key, const std::string &default_value)
 Read a string-valued key from the bes.conf file.
 
static uint64_t read_uint64_key (const std::string &key, uint64_t default_value)
 Read an integer-valued key from the bes.conf file.
 
static unsigned long read_ulong_key (const std::string &key, unsigned long default_value)
 Read an integer-valued key from the bes.conf file.
 
static TheBESKeysTheKeys ()
 Access to the singleton.
 

Static Public Attributes

static std::string ConfigFile
 

Friends

class http::HttpCacheTest
 
class keysT
 

Detailed Description

mapping of key/value pairs defining different behaviors of an application.

TheBESKeys provides a mechanism to define the behavior of an application given key/value pairs. For example, how authentication will work, database access information, level of debugging and where log files are to be located.

Key/value pairs can be loaded from an external initialization file or set within the application itself, for example from the command line.

If from a file the key/value pair is set one per line and cannot span multiple lines. Comments are allowed using the pound (#) character. For example:

#
# Who is responsible for this server
#
BES.ServerAdministrator=email:support@opendap.org

#
# Default server port and unix socket information and whether the server
# is secure or not.
#
BES.ServerPort=10022
BES.ServerUnixSocket=/tmp/bes.socket
BES.ServerSecure=no
* 

Key/value pairs can also be set by passing in a key=value string, or by passing in a key and value string to the object.

BES provides a single object for access to a single BESKeys object, TheBESKeys.

Definition at line 91 of file TheBESKeys.h.

Member Function Documentation

◆ delete_key()

void TheBESKeys::delete_key ( const std::string & key)
inline

Delete the key Added primarily for testing purposes.

Parameters
key

Definition at line 141 of file TheBESKeys.h.

◆ dump() [1/2]

string TheBESKeys::dump ( ) const
virtual

dumps information about this object

Returns
A string containing the dump from this instance of TheBESKeys object.

Definition at line 747 of file TheBESKeys.cc.

◆ dump() [2/2]

void TheBESKeys::dump ( std::ostream & strm) const
overridevirtual

dumps information about this object

Displays the pointer value of this instance along with all of the keys.

Parameters
strmC++ i/o stream to dump the information to

Implements BESObj.

Definition at line 737 of file TheBESKeys.cc.

◆ get_as_config()

string TheBESKeys::get_as_config ( ) const
Returns
The BES configuration keys, sorted by the std::map default rule for std:string, formatted for ingest by the BES.

This returns the BES keys state as a string. The content is formatted for inclusion in a bes.conf file. The keys sorted alphabetically by the std::map default rule for std:string. Why? The order is not important for key ingest later, but sorting them allows for simple comparisons of the configuration state in TheBESKeys. This is particularly important for provenance. Since TheBESKeys uses an unordered_map internally (for performance reasons) we need to sort the keys in this method before we assemble the string.

Returns
The BES keys, sorted by the std::map default rule for std:string.

Definition at line 488 of file TheBESKeys.cc.

◆ get_value()

void TheBESKeys::get_value ( const std::string & s,
std::string & val,
bool & found )

Retrieve the value of a given key, if set.

This method allows the user of BESKeys to retrieve the value of the specified key. If multiple values are set then an exception is thrown.

Parameters
sThe key the user is looking for
valThe value of the key the user is looking for
foundSet to true of the key is set or false if the key is not set. The value of a key can be set to the empty string, which is why this boolean is provided.
Exceptions
BESSyntaxUserErrorif multiple values are available for the specified key

Definition at line 288 of file TheBESKeys.cc.

◆ get_values() [1/3]

void TheBESKeys::get_values ( const std::string & key,
std::unordered_map< std::string, std::string > & map_values,
bool case_insensitive_map_keys,
bool & found )
Parameters
key
map_values
case_insensitive_map_keys
found

Definition at line 537 of file TheBESKeys.cc.

◆ get_values() [2/3]

void TheBESKeys::get_values ( const std::string & key,
std::unordered_map< std::string, std::unordered_map< std::string, std::vector< std::string > > > & primary_map,
bool case_insensitive_map_keys,
bool & found )
Parameters
key
map_values
case_insensitive_map_keys
found

Definition at line 569 of file TheBESKeys.cc.

◆ get_values() [3/3]

void TheBESKeys::get_values ( const std::string & s,
std::vector< std::string > & vals,
bool & found )

Retrieve the values of a given key, if set.

This method allows the user of BESKeys to retrieve the value of the specified key.

Parameters
sThe key the user is looking for
valsThe value set for the specified key. A value-result parameter.
foundSet to true of the key is set or false if the key is not set. The value of a key can be set to the empty string, which is why this boolean is provided.

Definition at line 318 of file TheBESKeys.cc.

◆ keys_begin()

std::unordered_map< std::string, std::vector< std::string > >::const_iterator TheBESKeys::keys_begin ( )
inline

Definition at line 177 of file TheBESKeys.h.

◆ keys_end()

std::unordered_map< std::string, std::vector< std::string > >::const_iterator TheBESKeys::keys_end ( )
inline

Definition at line 181 of file TheBESKeys.h.

◆ keys_file_name()

std::string TheBESKeys::keys_file_name ( ) const
inline

Definition at line 129 of file TheBESKeys.h.

◆ load_dynamic_config()

void TheBESKeys::load_dynamic_config ( const std::string & name)

Loads the the applicable dynamic configuration or nothing if no configuration is applicable.

Parameters
name

Definition at line 633 of file TheBESKeys.cc.

◆ read_bool_key()

bool TheBESKeys::read_bool_key ( const std::string & key,
bool default_value )
static

Read a boolean-valued key from the bes.conf file.

Look-up the bes key

  • key and return its value if set. If the key is not set, return the default value.
Parameters
keyThe key to loop up
default_valueReturn this value if
  • key is not found.
Returns
The boolean value of
  • key. The value of the key is true if the key is set to "true", "yes", or "on", otherwise the key value is interpreted as false. If
  • key is not set, return
  • default_value.

Definition at line 342 of file TheBESKeys.cc.

◆ read_int_key()

int TheBESKeys::read_int_key ( const std::string & key,
int default_value )
static

Read an integer-valued key from the bes.conf file.

Look-up the bes key

  • key and return its value if set. If the key is not set, return the default value.
Parameters
keyThe key to loop up
default_valueReturn this value if
  • key is not found.
Returns
The integer value of
  • key.

Definition at line 394 of file TheBESKeys.cc.

◆ read_string_key()

string TheBESKeys::read_string_key ( const std::string & key,
const std::string & default_value )
static

Read a string-valued key from the bes.conf file.

Look-up the bes key

  • key and return its value if set. If the key is not set, return the default value.
Parameters
keyThe key to loop up
default_valueReturn this value if
  • key is not found.
Returns
The string value of
  • key.

Definition at line 367 of file TheBESKeys.cc.

◆ read_uint64_key()

uint64_t TheBESKeys::read_uint64_key ( const std::string & key,
uint64_t default_value )
static

Read an integer-valued key from the bes.conf file.

Look-up the bes key

  • key and return its value if set. If the key is not set, return the default value.
Parameters
keyThe key to loop up
default_valueReturn this value if
  • key is not found.
Returns
The integer value of
  • key.

Definition at line 456 of file TheBESKeys.cc.

◆ read_ulong_key()

unsigned long TheBESKeys::read_ulong_key ( const std::string & key,
unsigned long default_value )
static

Read an integer-valued key from the bes.conf file.

Look-up the bes key

  • key and return its value if set. If the key is not set, return the default value.
Parameters
keyThe key to loop up
default_valueReturn this value if
  • key is not found.
Returns
The integer value of
  • key.

Definition at line 424 of file TheBESKeys.cc.

◆ reload_keys() [1/2]

void TheBESKeys::reload_keys ( )

Reload the keys. Erase the existing keys and reload them from the file. This uses the name of the keys file previously set in the constructor.

Definition at line 137 of file TheBESKeys.cc.

◆ reload_keys() [2/2]

void TheBESKeys::reload_keys ( const std::string & keys_file_name)

Reload the keys. Erase the existing keys and reload them from the file. This version provides a way to change the name of the file to load the keys from.

Parameters
keys_file_nameThe name of the file to load the keys from.

Definition at line 127 of file TheBESKeys.cc.

◆ set_key() [1/2]

void TheBESKeys::set_key ( const std::string & key,
const std::string & val,
bool addto = false )

allows the user to set key/value pairs from within the application.

This method allows users of BESKeys to set key/value pairs from within the application, such as for testing purposes, key/value pairs from the command line, etc...

If addto is set to true then the value is added to the list of values for key

If addto is false, and the key is already set then this value replaces all values for the key

Parameters
keyname of the key/value pair to be set
valvalue of the key to be set; value is not set if empty.
addtoSpecifies whether to add the value to the key or set the value. Default is to set, not add to

Definition at line 160 of file TheBESKeys.cc.

◆ set_key() [2/2]

void TheBESKeys::set_key ( const std::string & pair)

allows the user to set key/value pairs from within the application.

This method allows users of BESKeys to set key/value pairs from within the application, such as for testing purposes, key/value pairs from the command line, etc...

If the key is already set then this value replaces the value currently held in the keys map.

Parameters
pairthe key/value pair passed as key=value

Definition at line 265 of file TheBESKeys.cc.

◆ set_keys() [1/2]

void TheBESKeys::set_keys ( const std::string & key,
const std::unordered_map< std::string, std::string > & values,
bool case_insensitive_map_keys,
bool addto )

allows the user to encode a map in the Keys from within the application.

This method allows users of BESKeys to set the value of a kep to be a map of key value pairs from within the application, such as for testing purposes, key/value pairs from the command line, etc...

If addto is set to true then the value is added to the list of values for key

If addto is false, and the key is already set then this value replaces all values for the key

Parameters
keyname of the key/value pair to be set
valuesA map of key value pairs to associate with the key
addtoSpecifies whether to append the values to the key or set the value. Default is to set, not append to

Definition at line 223 of file TheBESKeys.cc.

◆ set_keys() [2/2]

void TheBESKeys::set_keys ( const std::string & key,
const std::vector< std::string > & values,
bool addto )

allows the user to set key/value pairs from within the application.

This method allows users of BESKeys to set key/value pairs from within the application, such as for testing purposes, key/value pairs from the command line, etc...

If addto is set to true then the value is added to the list of values for key

If addto is false, and the key is already set then this value replaces all values for the key

Parameters
keyname of the key/value pair to be set
valuesA collection of values to to associate with the key; empty values are not set.
addtoSpecifies whether to append the values to the key or set the value. Default is to set, not append to

Definition at line 190 of file TheBESKeys.cc.

◆ TheKeys()

TheBESKeys * TheBESKeys::TheKeys ( )
static

Access to the singleton.

Definition at line 85 of file TheBESKeys.cc.

◆ using_dynamic_config()

bool TheBESKeys::using_dynamic_config ( ) const
inline

Definition at line 189 of file TheBESKeys.h.

Friends And Related Symbol Documentation

◆ http::HttpCacheTest

friend class http::HttpCacheTest
friend

Definition at line 94 of file TheBESKeys.h.

◆ keysT

friend class keysT
friend

Definition at line 93 of file TheBESKeys.h.

Member Data Documentation

◆ ConfigFile

string TheBESKeys::ConfigFile
static

TheBESKeys::ConfigFile provides a way for the daemon and test code to set the location of a particular configuration file.

This is the name of the file that holds the key/value pairs. However, it will only be used once, when the singleton is created. To load different sets of keys (e.g., during testing), use the reload_keys(string) method which clears the current data and loads the name key file.

Definition at line 117 of file TheBESKeys.h.


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