65 string const& keyspace,
string const& domain,
66 shared_ptr<CCassConnection> connection,
67 optional<chrono::milliseconds> timeout
69 vector<SSatInfoEntry>
result;
72 auto query = connection->NewQuery();
74 query->UsePerRequestTimeout(
true);
75 query->SetTimeout(timeout.value().count());
78 "SELECT sat, keyspace_name, schema_type, service, flags FROM "
79 + keyspace +
".sat2keyspace WHERE domain = ?", 1);
80 query->BindStr(0, domain);
84 row.sat =
query->FieldGetInt32Value(0);
85 row.keyspace =
query->FieldGetStrValue(1);
87 row.service =
query->FieldGetStrValueDef(3,
"");
88 row.flags =
query->FieldGetInt64Value(4, 0);
108 return a.sat <
b.sat;
115 shared_ptr<CPSGMessages>
117 string const& keyspace,
string const& domain,
118 shared_ptr<CCassConnection> connection,
119 optional<chrono::milliseconds> timeout
121 auto result = make_shared<CPSGMessages>();
125 auto query = connection->NewQuery();
127 query->UsePerRequestTimeout(
true);
128 query->SetTimeout(timeout.value().count());
130 query->SetSQL(
"SELECT name, value FROM " + keyspace +
".messages WHERE domain = ?", 1);
131 query->BindStr(0, domain);
135 query->FieldGetStrValue(0),
136 query->FieldGetStrValueDef(1,
"")
151 string const& keyspace,
int32_t sat,
152 shared_ptr<CCassConnection> connection,
153 optional<chrono::milliseconds> timeout
159 auto query = connection->NewQuery();
161 query->UsePerRequestTimeout(
true);
162 query->SetTimeout(timeout.value().count());
164 query->SetSQL(
"SELECT username FROM " + keyspace +
".web_user WHERE sat = ?", 1);
165 query->BindInt32(0, sat);
168 auto username =
query->FieldGetStrValueDef(0,
"");
169 if (!username.empty()) {
204 vector<SSatInfoEntry>
const& rows,
205 string const& secure_registry_section,
211 for (
auto const&
row : rows) {
217 if (
row.IsSecureSat()) {
218 for (
auto user: secure_users[
row.sat]) {
227 shared_ptr<CCassConnection>
229 shared_ptr<IRegistry const>
const&
registry,
230 string const& section,
231 string const& service,
236 factory->LoadConfig(
registry.get(), section);
237 if (!service.empty()) {
238 factory->SetServiceName(service);
240 if (reset_namespace) {
241 factory->SetDataNamespace(
"");
243 auto connection = factory->CreateInstance();
244 connection->Connect();
248 inline string GetServiceKey(
string const& service,
string const& registry_section)
250 return registry_section +
"|" + service;
255 return registry_section +
"|" + peer +
":" + to_string(port);
262 auto itr = m_BlobKeyspaces.find(sat);
264 itr != cend(m_BlobKeyspaces)
309 shared_ptr<CCassConnection>
const& connection,
310 string const& registry_section,
311 string const& service,
316 for (
auto peer : connection->GetLocalPeersAddressList(
"", timeout)) {
330 string const& service,
string const& registry_section, vector<string>& connection_points)
332 connection_points.clear();
338 bool is_hostlist = (service.find(
':') != string::npos)
339 || (service.find(
' ') != string::npos)
340 || (service.find(
',') != string::npos);
344 ERR_POST(
Info <<
"CSatInfoSchema::x_AddClusterByServiceName uses service name: '" << service <<
"'");
347 ERR_POST(
Info <<
"CSatInfoSchema::x_AddClusterByServiceName failed to resolve LBSM service name: '" << service <<
"'");
350 ERR_POST(
Info <<
"CSatInfoSchema::x_AddClusterByServiceName resolved service name: '" << service <<
"' => '" << hosts <<
"'");
353 ERR_POST(
Info <<
"CSatInfoSchema::x_AddClusterByServiceName uses host list: '" << service <<
"'");
357 vector<string> items;
359 for (
auto item : items) {
361 string item_port_token;
366 if (item_host.empty()) {
376 connection_points.push_back(
386 shared_ptr<CSatInfoSchema>
const& old_schema,
387 shared_ptr<IRegistry const>
const&
registry,
388 string const& registry_section,
389 shared_ptr<CCassConnection>& connection
393 if (service.empty()) {
399 service =
registry->
Get(registry_section,
"service");
410 vector<string> connection_points;
415 for (
auto const& connection_point : connection_points) {
425 connection = old_schema->x_GetConnectionByService(service, registry_section);
430 for (
auto const& connection_point : connection_points) {
431 connection = old_schema->x_GetConnectionByConnectionPoint(connection_point);
450 shared_ptr<CSatInfoSchema>
const& old_schema,
451 shared_ptr<IRegistry const>
const&
registry,
452 string const& registry_section,
456 shared_ptr<CCassConnection> connection;
461 if (!secure_users.
empty()) {
513 s <<
"\n" << prefix <<
" - '" << user <<
"'";
516 string secure_users = s.str();
517 secure_users = secure_users.empty() ?
"{}" : secure_users;
518 return prefix +
"sat: " + to_string(
sat)
519 +
", schema: "+ to_string(
static_cast<int>(
schema_type))
521 +
", service: '" +
service +
"'"
522 +
", flags: " + to_string(
flags)
525 +
", secure_users: " + secure_users;
537 bool user_allowed_to_read = user_entry != cend(
m_SecureUsers);
538 if (user_allowed_to_read) {
557 s <<
"Blob keyspaces: \n";
559 s << sat.second.ToString(
" ") <<
"\n";
561 s <<
"BioseqNA keyspaces: \n";
563 s << sat.ToString(
" ") <<
"\n";
565 s <<
"Resolver keyspace: \n";
567 s <<
"IPG keyspace: \n";
569 s <<
"Secure sat users: \n";
571 s <<
" " << sat_users.first <<
"\n";
572 for (
auto user : sat_users.second) {
573 s <<
" - '" << user <<
"'\n";
578 s <<
"m_Point2Cluster: \n";
580 s <<
" " << item.first <<
" : &" << to_string(
reinterpret_cast<intptr_t>(item.second.get())) <<
"\n";
582 s <<
"m_Service2Cluster: \n";
584 s <<
" " << item.first <<
" : &" << to_string(
reinterpret_cast<intptr_t>(item.second.get())) <<
"\n";
590 string const& sat_info_keyspace,
591 string const& domain,
592 shared_ptr<CCassConnection> sat_info_connection,
593 shared_ptr<IRegistry const>
registry,
594 string const& registry_section
596 : m_SatInfoKeyspace(sat_info_keyspace)
598 , m_SatInfoConnection(std::move(sat_info_connection))
600 , m_RegistrySection(registry_section)
620 return p ? p->GetBlobKeyspace(sat) : nullopt;
626 return p ? p->GetNAKeyspaces() : vector<SSatInfoEntry>();
638 return p ? p->GetIPGKeyspace() : nullopt;
644 return p ? p->GetMaxBlobKeyspaceSat() : -1;
650 return p ? p->Get(name) :
"";
677 for (
auto sat_info: rows) {
678 if (sat_info.IsSecureSat()) {
680 secure_connection->Keyspace(), sat_info.sat, secure_connection,
m_Timeout
692 auto schema = make_shared<CSatInfoSchema>();
705 shared_ptr<CSatInfoSchema>& new_schema,
706 shared_ptr<CSatInfoSchema>
const& old_schema,
707 vector<SSatInfoEntry>&& sat_info,
715 for (
auto& entry : sat_info) {
720 auto sat_secure_users = secure_users[entry.sat];
721 auto result = new_schema->x_AddSatInfoEntry(entry, old_schema,
m_Registry, registry_section, sat_secure_users);
743 (new_schema->m_ResolverKeyspace.keyspace.empty() || !new_schema->m_ResolverKeyspace.connection)
748 if (new_schema->GetMaxBlobKeyspaceSat() == -1) {
762 if (messages->IsEmpty()) {
768 if (old_messages && *old_messages == *messages) {
786 auto msg = make_shared<string>(message);
#define BEGIN_IDBLOB_SCOPE
CassConsistency TCassConsistency
static shared_ptr< CCassConnectionFactory > s_Create()
static constexpr int16_t kCassDefaultPort
static constexpr TCassConsistency kLocalQuorum
@ eQueryFailedRestartable
Helper hook-up class that installs default logging/registry/locking (but only if they have not yet be...
shared_ptr< CPSGMessages > m_SatInfoMessages
ESatInfoRefreshMessagesResult RefreshMessages(bool apply)
Refresh information for messages database {sat_info3.messages}.
optional< SSatInfoEntry > GetBlobKeyspace(int32_t sat) const
Get blob keyspace connection by sat id.
shared_ptr< CSatInfoSchema > GetSchema() const
Get configuration schema snapshot.
ESatInfoRefreshSchemaResult RefreshSchema(bool apply)
Refresh information for configuration database {sat_info3.sat2keyspace}.
CSatInfoSchemaProvider(string const &sat_info_keyspace, string const &domain, shared_ptr< CCassConnection > sat_info_connection, shared_ptr< IRegistry const > registry, string const ®istry_section)
vector< SSatInfoEntry > GetNAKeyspaces() const
Get list of BioseqNA keyspaces connections.
string m_SecureSatRegistrySection
bool m_ResolverKeyspaceRequired
optional< chrono::milliseconds > m_Timeout
shared_ptr< CCassConnection > x_GetSatInfoConnection() const
shared_ptr< CPSGMessages > GetMessages() const
Get messages snapshot.
void SetSatInfoConnection(shared_ptr< CCassConnection > sat_info_connection)
Changes Cassandra connection used to communicate with sat_info3.
string GetMessage(string const &name) const
Get configured message by name.
SSatInfoEntry GetResolverKeyspace() const
Get connection to resolver keyspace.
shared_ptr< IRegistry const > m_Registry
shared_ptr< string > m_RefreshErrorMessage
shared_ptr< CSatInfoSchema > m_SatInfoSchema
string GetRefreshErrorMessage() const
Get detailed message for last refresh operation (common for RefreshSchema and RefreshMessages).
shared_ptr< CCassConnection > m_SatInfoConnection
void x_SetRefreshErrorMessage(string const &message)
optional< ESatInfoRefreshSchemaResult > x_PopulateNewSchema(shared_ptr< CSatInfoSchema > &new_schema, shared_ptr< CSatInfoSchema > const &old_schema, vector< SSatInfoEntry > &&sat_info, map< int32_t, set< string >> &&secure_users)
int32_t GetMaxBlobKeyspaceSat() const
Get max id value for existing blob sat.
optional< SSatInfoEntry > GetIPGKeyspace() const
Get connection to IPG keyspace.
map< string, shared_ptr< CCassConnection > > m_Service2Cluster
shared_ptr< CCassConnection > x_GetConnectionByService(string const &service, string const ®istry_section) const
optional< ESatInfoRefreshSchemaResult > x_AddConnection(shared_ptr< CCassConnection > const &connection, string const ®istry_section, string const &service, bool is_default)
map< string, shared_ptr< CCassConnection > > m_Point2Cluster
optional< SSatInfoEntry > GetIPGKeyspace() const
Get connection to IPG keyspace.
optional< ESatInfoRefreshSchemaResult > x_AddSatInfoEntry(SSatInfoEntry entry, shared_ptr< CSatInfoSchema > const &old_schema, shared_ptr< IRegistry const > const ®istry, string const ®istry_section, set< string > const &secure_users)
optional< ESatInfoRefreshSchemaResult > x_ResolveServiceName(string const &service, string const ®istry_section, vector< string > &connection_points)
int32_t GetMaxBlobKeyspaceSat() const
Get max id value for existing blob sat.
vector< SSatInfoEntry > GetNAKeyspaces() const
Get list of BioseqNA keyspaces connections.
shared_ptr< CCassConnection > m_DefaultConnection
map< int32_t, set< string > > m_SecureSatUsers
shared_ptr< CCassConnection > x_GetConnectionByConnectionPoint(string const &connection_point) const
SSatInfoEntry m_ResolverKeyspace
vector< SSatInfoEntry > m_BioseqNaKeyspaces
string ToString() const
Print internal state of CSatInfoSchema.
optional< ESatInfoRefreshSchemaResult > x_ResolveConnectionByServiceName(string service, shared_ptr< CSatInfoSchema > const &old_schema, shared_ptr< IRegistry const > const ®istry, string const ®istry_section, shared_ptr< CCassConnection > &connection)
SSatInfoEntry GetResolverKeyspace() const
Get connection to resolver keyspace.
map< int32_t, SSatInfoEntry > m_BlobKeyspaces
optional< SSatInfoEntry > m_IPGKeyspace
optional< chrono::milliseconds > m_ResolveTimeout
string m_DefaultRegistrySection
static bool s_Resolve(const string &service, vector< pair< string, int >> &result, TSERV_Type serv_type=fSERV_Any)
const_iterator find(const key_type &key) const
const_iterator find(const key_type &key) const
static const char * schema
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
TErrCode GetErrCode(void) const
Get error code.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
void Info(CExceptionArgs_Base &args)
virtual const string & Get(const string §ion, const string &name, TFlags flags=0) const
Get the parameter value.
#define END_SCOPE(ns)
End the previously defined scope.
#define BEGIN_SCOPE(ns)
Define a new scope.
static string HostPortToString(unsigned int host, unsigned short port)
See SOCK_HostPortToString()
static unsigned int gethostbyname(const string &host, ESwitch log=eOff)
Return 0 on error.
static bool isip(const string &host, bool fullquad=false)
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
static bool SplitInTwo(const CTempString str, const CTempString delim, string &str1, string &str2, TSplitFlags flags=0)
Split a string into two pieces using the specified delimiters.
@ fConvErr_NoThrow
Do not throw an exception on error.
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
constexpr auto sort(_Init &&init)
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
#define row(bind, expected)
static const char *const kChunkTableDefault
static const char *const kChunkTableBig
set< string > m_SecureUsers
ECassSchemaType schema_type
shared_ptr< CCassConnection > GetConnection() const
Get public satellite connection.
bool IsSecureSat() const
Is satellite requires secure access.
string ToString(string const &prefix) const
Get string representation for debug.
shared_ptr< CCassConnection > GetSecureConnection(string const &username) const
Get secure satellite connection.
shared_ptr< CCassConnection > connection
shared_ptr< CCassConnection > m_SecureConnection