ELB support. Client servers can remove themselves from an ELB pool if loaded

or otherwise broken. Clients won't join an ELB pool until they're stable.
This commit is contained in:
JoelKatz
2013-05-29 15:20:26 -07:00
parent 130459dcca
commit a0b6584c9a
5 changed files with 53 additions and 5 deletions

View File

@@ -507,4 +507,36 @@ bool Application::loadOldLedger(const std::string& l)
return true;
}
bool serverOkay(std::string& reason)
{
if (!theConfig.ELB_SUPPORT)
return true;
if (!theApp)
{
reason = "Server has not started";
return false;
}
if (theApp->getOPs().isNeedNetworkLedger())
{
reason = "Not synchronized with network yet";
return false;
}
if (theApp->getOPs().getOperatingMode() < NetworkOPs::omSYNCING)
{
reason = "Not synchronized with network";
return false;
}
if (theApp->getFeeTrack().isLoaded())
{
reason = "Too much load";
return false;
}
return true;
}
// vim:ts=4

View File

@@ -16,6 +16,7 @@
#define SECTION_CLUSTER_NODES "cluster_nodes"
#define SECTION_DATABASE_PATH "database_path"
#define SECTION_DEBUG_LOGFILE "debug_logfile"
#define SECTION_ELB_SUPPORT "elb_support"
#define SECTION_FEE_DEFAULT "fee_default"
#define SECTION_FEE_NICKNAME_CREATE "fee_nickname_create"
#define SECTION_FEE_OFFER "fee_offer"
@@ -253,6 +254,7 @@ Config::Config()
NODE_DB = "sqlite";
LDB_IMPORT = false;
ELB_SUPPORT = false;
RUN_STANDALONE = false;
START_UP = NORMAL;
}
@@ -389,6 +391,9 @@ void Config::load()
}
}
if (sectionSingleB(secConfig, SECTION_ELB_SUPPORT, strTemp))
ELB_SUPPORT = boost::lexical_cast<bool>(strTemp);
(void) sectionSingleB(secConfig, SECTION_WEBSOCKET_IP, WEBSOCKET_IP);
if (sectionSingleB(secConfig, SECTION_WEBSOCKET_PORT, strTemp))

View File

@@ -85,6 +85,7 @@ public:
boost::filesystem::path VALIDATORS_FILE; // As specifed in rippled.cfg.
std::string NODE_DB; // Database to use for nodes
bool LDB_IMPORT; // Import into LevelDB
bool ELB_SUPPORT; // Support Amazon ELB
std::string VALIDATORS_SITE; // Where to find validators.txt on the Internet.
std::string VALIDATORS_URI; // URI of validators.txt.

View File

@@ -7,6 +7,8 @@
extern void initSSLContext(boost::asio::ssl::context& context,
std::string key_file, std::string cert_file, std::string chain_file);
extern bool serverOkay(std::string& reason);
template <typename endpoint_type>
class WSConnection;
@@ -274,11 +276,18 @@ public:
}
// Respond to http requests.
void http(connection_ptr cpClient)
bool http(connection_ptr cpClient)
{
std::string reason;
if (!serverOkay(reason))
{
cpClient->set_body(std::string("<HTML><BODY>Server cannot accept clients: ") + reason + "</BODY></HTML>");
return false;
}
cpClient->set_body(
"<!DOCTYPE html><html><head><title>" SYSTEM_NAME " Test</title></head>"
"<body><h1>" SYSTEM_NAME " Test</h1><p>This page shows http(s) connectivity is working.</p></body></html>");
return true;
}
};

View File

@@ -227,7 +227,7 @@ public:
virtual bool on_ping(connection_ptr con,std::string) {return true;}
virtual void on_pong(connection_ptr con,std::string) {}
virtual void on_pong_timeout(connection_ptr con,std::string) {}
virtual void http(connection_ptr con) {}
virtual bool http(connection_ptr con) { return true; }
virtual void on_send_empty(connection_ptr con) {}
};
@@ -744,9 +744,10 @@ void server<endpoint>::connection<connection_type>::handle_read_request(
}
// continue as HTTP?
m_endpoint.get_handler()->http(m_connection.shared_from_this());
m_response.set_status(http::status_code::OK);
if (m_endpoint.get_handler()->http(m_connection.shared_from_this()))
m_response.set_status(http::status_code::OK);
else
m_response.set_status(http::status_code::INTERNAL_SERVER_ERROR);
}
} catch (const http::exception& e) {
m_endpoint.m_elog->at(log::elevel::RERROR) << e.what() << log::endl;