66 vector<SSatInfoEntry>
result;
69 auto columns = connection->GetColumnNames(keyspace,
"sat2keyspace");
70 bool flags_column_exists = find(cbegin(columns), cend(columns),
"flags") != cend(columns);
71 string flags_cql = flags_column_exists ?
", flags" :
"";
72 auto query = connection->NewQuery();
74 "SELECT sat, keyspace_name, schema_type, service" + flags_cql +
" FROM "
75 + keyspace +
".sat2keyspace WHERE domain = ?", 1);
76 query->BindStr(0, domain);
80 row.
sat =
query->FieldGetInt32Value(0);
84 if (flags_column_exists) {
106 return a.sat <
b.sat;
113 shared_ptr<CPSGMessages>
116 auto result = make_shared<CPSGMessages>();
120 auto query = connection->NewQuery();
121 query->SetSQL(
"SELECT name, value FROM " + keyspace +
".messages WHERE domain = ?", 1);
122 query->BindStr(0, domain);
126 query->FieldGetStrValue(0),
127 query->FieldGetStrValueDef(1,
"")
147 auto query = connection->NewQuery();
148 query->SetSQL(
"SELECT username FROM " + keyspace +
".web_user WHERE sat = ?", 1);
149 query->BindInt32(0, sat);
152 auto username =
query->FieldGetStrValueDef(0,
"");
153 if (!username.empty()) {
188 vector<SSatInfoEntry>
const& rows,
189 string const& secure_registry_section,
195 for (
auto const& row : rows) {
201 if (row.IsSecureSat()) {
202 for (
auto user: secure_users[row.sat]) {
211 shared_ptr<CCassConnection>
213 shared_ptr<IRegistry const>
const&
registry,
214 string const& section,
215 string const& service,
220 factory->LoadConfig(
registry.get(), section);
221 if (!service.empty()) {
222 factory->SetServiceName(service);
224 if (reset_namespace) {
225 factory->SetDataNamespace(
"");
227 auto connection = factory->CreateInstance();
228 connection->Connect();
232 inline string GetServiceKey(
string const& service,
string const& registry_section)
234 return registry_section +
"|" + service;
239 return registry_section +
"|" + peer +
":" + to_string(port);
246 auto itr = m_BlobKeyspaces.find(sat);
248 itr != cend(m_BlobKeyspaces)
293 shared_ptr<CCassConnection>
const& connection,
294 string const& registry_section,
295 string const& service,
299 for (
auto peer : connection->GetLocalPeersAddressList(
"")) {
313 string const& service,
string const& registry_section, vector<string>& connection_points)
315 connection_points.clear();
321 bool is_hostlist = (service.find(
':') != string::npos)
322 || (service.find(
' ') != string::npos)
323 || (service.find(
',') != string::npos);
327 ERR_POST(
Info <<
"CSatInfoSchema::x_AddClusterByServiceName uses service name: '" << service <<
"'");
330 ERR_POST(
Info <<
"CSatInfoSchema::x_AddClusterByServiceName failed to resolve LBSM service name: '" << service <<
"'");
333 ERR_POST(
Info <<
"CSatInfoSchema::x_AddClusterByServiceName resolved service name: '" << service <<
"' => '" << hosts <<
"'");
336 ERR_POST(
Info <<
"CSatInfoSchema::x_AddClusterByServiceName uses host list: '" << service <<
"'");
340 vector<string> items;
342 for (
auto item : items) {
344 string item_port_token;
349 if (item_host.empty()) {
359 connection_points.push_back(
369 shared_ptr<CSatInfoSchema>
const& old_schema,
370 shared_ptr<IRegistry const>
const&
registry,
371 string const& registry_section,
372 shared_ptr<CCassConnection>& connection
376 if (service.empty()) {
382 service =
registry->
Get(registry_section,
"service");
393 vector<string> connection_points;
398 for (
auto const& connection_point : connection_points) {
408 connection = old_schema->x_GetConnectionByService(service, registry_section);
413 for (
auto const& connection_point : connection_points) {
414 connection = old_schema->x_GetConnectionByConnectionPoint(connection_point);
434 shared_ptr<CSatInfoSchema>
const& old_schema,
435 shared_ptr<IRegistry const>
const&
registry,
436 string const& registry_section,
440 shared_ptr<CCassConnection> connection;
445 if (!secure_users.
empty()) {
497 s <<
"\n" <<
prefix <<
" - '" << user <<
"'";
500 string secure_users = s.str();
501 secure_users = secure_users.empty() ?
"{}" : secure_users;
503 +
", schema: "+ to_string(
static_cast<int>(
schema_type))
505 +
", service: '" +
service +
"'"
506 +
", flags: " + to_string(
flags)
509 +
", secure_users: " + secure_users;
521 bool user_allowed_to_read = user_entry != cend(
m_SecureUsers);
522 if (user_allowed_to_read) {
541 s <<
"Blob keyspaces: \n";
543 s << sat.second.ToString(
" ") <<
"\n";
545 s <<
"BioseqNA keyspaces: \n";
547 s << sat.ToString(
" ") <<
"\n";
549 s <<
"Resolver keyspace: \n";
551 s <<
"IPG keyspace: \n";
553 s <<
"Secure sat users: \n";
555 s <<
" " << sat_users.first <<
"\n";
556 for (
auto user : sat_users.second) {
557 s <<
" - '" << user <<
"'\n";
562 s <<
"m_Point2Cluster: \n";
564 s <<
" " << item.first <<
" : &" << to_string(
reinterpret_cast<intptr_t>(item.second.get())) <<
"\n";
566 s <<
"m_Service2Cluster: \n";
568 s <<
" " << item.first <<
" : &" << to_string(
reinterpret_cast<intptr_t>(item.second.get())) <<
"\n";
574 string const& sat_info_keyspace,
575 string const& domain,
576 shared_ptr<CCassConnection> sat_info_connection,
577 shared_ptr<IRegistry const>
registry,
578 string const& registry_section
580 : m_SatInfoKeyspace(sat_info_keyspace)
582 , m_SatInfoConnection(move(sat_info_connection))
584 , m_RegistrySection(registry_section)
604 return p ? p->GetBlobKeyspace(sat) : nullopt;
610 return p ? p->GetNAKeyspaces() : vector<SSatInfoEntry>();
622 return p ? p->GetIPGKeyspace() : nullopt;
628 return p ? p->GetMaxBlobKeyspaceSat() : -1;
634 return p ? p->Get(name) :
"";
661 for (
auto sat_info: rows) {
662 if (sat_info.IsSecureSat()) {
663 secure_users[sat_info.sat] =
ReadSecureSatUsers(secure_connection->Keyspace(), sat_info.sat, secure_connection);
674 auto schema = make_shared<CSatInfoSchema>();
686 shared_ptr<CSatInfoSchema>& new_schema,
687 shared_ptr<CSatInfoSchema>
const& old_schema,
688 vector<SSatInfoEntry>&& sat_info,
696 for (
auto& entry : sat_info) {
701 auto sat_secure_users = secure_users[entry.sat];
702 auto result = new_schema->x_AddSatInfoEntry(entry, old_schema,
m_Registry, registry_section, sat_secure_users);
724 (new_schema->m_ResolverKeyspace.keyspace.empty() || !new_schema->m_ResolverKeyspace.connection)
729 if (new_schema->GetMaxBlobKeyspaceSat() == -1) {
743 if (messages->IsEmpty()) {
749 if (old_messages && *old_messages == *messages) {
767 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
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
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
#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 const char * prefix[]
static const char * schema
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