1 #ifndef OBJTOOLS__PUBSEQ_GATEWAY__PSG_CLIENT_HPP
2 #define OBJTOOLS__PUBSEQ_GATEWAY__PSG_CLIENT_HPP
46 #include <unordered_map>
49 #if defined(NCBI_THREADS) && defined(HAVE_LIBNGHTTP2) && defined(HAVE_LIBUV)
50 # define HAVE_PSG_CLIENT 1
54 #if defined(HAVE_PSG_CLIENT)
84 using unordered_map<string, set<string>>::unordered_map;
120 template<
typename TUserContext>
218 virtual string Repr()
const = 0;
234 :
m_Id(std::move(
id)),
242 :
m_Id(to_string(sat) +
"." + to_string(sat_key)),
247 string Repr()
const override;
273 string Repr()
const override;
318 shared_ptr<void> user_context = {},
320 :
CPSG_Request(std::move(user_context), std::move(request_context)),
326 shared_ptr<void> user_context = {},
400 shared_ptr<void> user_context = {},
402 :
CPSG_Request(std::move(user_context), std::move(request_context)),
408 shared_ptr<void> user_context = {},
465 shared_ptr<void> user_context = {},
467 :
CPSG_Request(std::move(user_context), std::move(request_context)),
509 shared_ptr<void> user_context = {},
511 :
CPSG_Request(std::move(user_context), std::move(request_context)),
523 shared_ptr<void> user_context = {},
530 template <
class... TArgs>
576 shared_ptr<void> user_context = {},
578 :
CPSG_Request(std::move(user_context), std::move(request_context)),
605 shared_ptr<void> user_context = {},
614 string x_GetId()
const override;
721 template <
class TDataId = CPSG_DataId>
722 const TDataId*
GetId()
const {
return dynamic_cast<const TDataId*
>(
m_Id.get()); }
745 template <
class TDataId = CPSG_DataId>
746 const TDataId*
GetId()
const {
return dynamic_cast<const TDataId*
>(
m_Id.get()); }
781 objects::CBioseq_set::EClass
GetClass()
const;
821 template <
class TDataId = CPSG_DataId>
822 const TDataId*
GetId()
const {
return dynamic_cast<const TDataId*
>(
m_Id.get()); }
910 CPSG_Request_Resolve::TIncludeInfo
IncludedInfo()
const;
986 template <
class TDataId = CPSG_DataId>
987 const TDataId*
GetId()
const {
return dynamic_cast<const TDataId*
>(
m_Id.get()); }
1171 bool SendRequest(shared_ptr<CPSG_Request> request,
1297 using TNewItem =
function<void(
const shared_ptr<CPSG_ReplyItem>&)>;
1346 list<pair<shared_ptr<CPSG_Reply>, list<shared_ptr<CPSG_ReplyItem>>>>
m_Replies;
User-defined methods of the data storage class.
Bio-id (such as accession)
CPSG_BioId(string id, TType type={})
const string & GetId() const
Get ID.
CPSG_BioId(const objects::CSeq_id_Handle &seq_id_handle)
CPSG_BioId(const CSeq_id &seq_id)
TType GetType() const
Get type.
string Repr() const
Get tilde-separated string representation of this bio ID (e.g. for logging)
Bio-sequence metainfo – result of the bio-id resolution.
CPSG_BioId GetCanonicalId() const
Get canonical bio-id for the bioseq (usually "accession.version")
TState GetState() const
State of this exact bio-sequence's seq-id.
TState GetChainState() const
State of the bio-sequence's seq-id chain, i.e.
objects::CSeq_inst::TMol GetMoleculeType() const
The bioseq's molecule type (DNA, RNA, protein, etc)
CPSG_BioIds GetOtherIds() const
Get non-canonical bio-ids (aliases) for the bioseq.
TTaxId GetTaxId() const
Get the bioseq's taxonomy ID.
CTime GetDateChanged() const
Date when the bioseq was changed last time.
CPSG_Request_Resolve::TIncludeInfo IncludedInfo() const
What data is immediately available now.
Uint8 GetLength() const
Length of bio-sequence.
CPSG_BlobId GetBlobId() const
Get coordinates of the TSE blob that contains the bioseq itself.
int GetHash() const
Get the bioseq's (pre-calculated) hash.
unique_ptr< CPSG_DataId > m_Id
unique_ptr< istream > m_Stream
const TDataId * GetId() const
Get data ID.
CPSG_BlobData(unique_ptr< CPSG_DataId > id)
istream & GetStream() const
Get the stream from which to read the item's content.
const string & GetId() const
Get ID.
const TLastModified & GetLastModified() const
Get last modified.
CPSG_BlobId(string id, TLastModified last_modified={})
Mainstream blob ID ctor - from a string ID.
CPSG_BlobId(int sat, int sat_key, TLastModified last_modified={})
Historical blob ID system – based on the "satellite" and the "key" inside it.
TLastModified m_LastModified
string Repr() const override
Get tilde-separated string representation of this blob ID (e.g. for logging)
Blob data meta information.
const TDataId * GetId() const
Get data ID.
bool IsSuppressed() const
Return TRUE if the blob data is "suppressed".
CTime GetOriginalLoadDate() const
Date when the blob data was first loaded into the database.
bool IsWithdrawn() const
Return TRUE if the blob data is "withdrawn".
objects::CBioseq_set::EClass GetClass() const
Class of this blob data.
string GetFormat() const
Get data serialization format: asn.1, asn1-text, json, xml, ...
CTime GetHupReleaseDate() const
Date when the blob data will be released for public use.
string GetDivision() const
Internal division value (used by various dumpers)
CPSG_BlobInfo(unique_ptr< CPSG_DataId > id)
Uint8 GetStorageSize() const
Get size of the blob data (as it is stored)
string GetCompression() const
Get data compression algorithm: gzip, bzip2, zip, compress, nlmzip, ...
unique_ptr< CPSG_DataId > m_Id
bool IsDead() const
Return TRUE if the blob data is "dead".
string GetId2Info() const
Get ID2 info.
Uint8 GetSize() const
Get size of the real (before any compression or encryption) blob data.
Uint8 GetNChunks() const
Get number of Cassandra data chunks that constitute this blob data.
Uint8 GetOwner() const
Blob data owner's ID.
string GetUsername() const
Name of the user who loaded this blob data.
const string & GetId2Info() const
Get ID2 info.
string Repr() const override
Get tilde-separated string representation of this chunk ID (e.g. for logging)
int GetId2Chunk() const
Get ID2 chunk number.
CPSG_ChunkId(int id2_chunk, string id2_info)
virtual string Repr() const =0
Get tilde-separated string representation of this data ID (e.g. for logging)
virtual ~CPSG_DataId()=default
A class derived from the queue class that additionally allows to run event loop.
bool RunOnce(CDeadline deadline)
Wait once for events in the queue and process any.
bool Run(CDeadline deadline)
Process everything in the queue until it's empty or times out.
CPSG_EventLoop(CPSG_EventLoop &&)
function< void(EPSG_Status, const shared_ptr< CPSG_ReplyItem > &)> TItemComplete
bool IsEmpty() const
Check whether the queue was stopped/reset, is now empty and all processing is complete.
CPSG_EventLoop & operator=(CPSG_EventLoop &&)
CPSG_EventLoop()
Creates an uninitialized instance.
function< void(EPSG_Status, const shared_ptr< CPSG_Reply > &)> TReplyComplete
function< void(const shared_ptr< CPSG_ReplyItem > &)> TNewItem
TReplyComplete m_ReplyComplete
TItemComplete m_ItemComplete
list< pair< shared_ptr< CPSG_Reply >, list< shared_ptr< CPSG_ReplyItem > > > > m_Replies
virtual const char * GetErrCodeString(void) const override
Get error code interpreted as text.
NCBI_EXCEPTION_DEFAULT(CPSG_Exception, CException)
Ipg info – result of the IPG resolution.
string GetNucleotide() const
Get nucleotide.
string GetProtein() const
Get protein.
Int8 GetIpg() const
Get Ipg.
TState GetGbState() const
Get state.
TTaxId GetTaxId() const
Get taxonomy ID.
Named Annotations (NAs) metainfo – reply to CPSG_Request_NamedAnnotInfo.
string GetId2AnnotInfo() const
Base64 encoded asn.1 of ID2-Seq-annot-Info.
CPSG_BlobId GetBlobId() const
Coordinates of the blob that contains the NA data.
const string & GetName() const
Name of the annotation.
objects::CID2S_Seq_annot_Info TId2AnnotInfo
Detailed ID2-Seq-annot-Info structures (from GetId2AnnotInfo, decoded)
list< CRef< TId2AnnotInfo > > TId2AnnotInfoList
CPSG_NamedAnnotInfo(string name)
TId2AnnotInfoList GetId2AnnotInfoList() const
Named Annotations (NAs) status – reply to CPSG_Request_NamedAnnotInfo.
list< TId2AnnotStatus > TId2AnnotStatusList
pair< string, EPSG_Status > TId2AnnotStatus
Individual NA statuses.
TId2AnnotStatusList GetId2AnnotStatusList() const
EProgressStatus m_ProgressStatus
EProgressStatus GetProgressStatus() const
Get progress status.
CPSG_Processor(EProgressStatus progress_status)
A queue to retrieve data (accession resolution info; bio-sequence; annotation blobs) from the storage...
bool SendRequest(shared_ptr< CPSG_Request > request, CDeadline deadline)
Push request into the queue.
shared_ptr< void > TApiLock
Get an API lock.
CPSG_Queue(CPSG_Queue &&)
unique_ptr< SImpl > m_Impl
bool IsEmpty() const
Check whether the queue was stopped/reset and is now empty.
shared_ptr< CPSG_Reply > GetNextReply(CDeadline deadline)
Get the next reply which has started arriving from the server.
bool WaitForEvents(CDeadline deadline)
Wait for events on this queue, on replies returned by this queue and/or on reply items returned by th...
CPSG_Queue()
Creates an uninitialized instance.
CPSG_Queue & operator=(CPSG_Queue &&)
void SetUserArgs(SPSG_UserArgs user_args)
Set arbitrary URL arguments to add to every request.
void Reset()
Stop accepting new requests and cancel all requests whose replies have not been returned yet.
shared_ptr< CPSG_Reply > SendRequestAndGetReply(shared_ptr< CPSG_Request > request, CDeadline deadline)
Push request into the queue and get corresponding reply.
void Stop()
Stop accepting new requests.
bool IsInitialized() const
Check whether the queue has been initialized.
void SetRequestFlags(CPSG_Request::TFlags request_flags)
Set request flags.
static TApiLock GetApiLock()
bool RejectsRequests() const
Is the queue in a state (possibly temporary) when requests get immediately rejected.
A self-containing part of the reply, e.g. a meta-data or a data blob.
SPSG_Message GetNextMessage(EDiagSev min_severity=eDiag_Error) const
Unstructured text containing auxiliary info about the result – such as messages and errors that came ...
const string & GetProcessorId()
Get processor ID.
shared_ptr< CPSG_Reply > m_Reply
virtual ~CPSG_ReplyItem()
EPSG_Status GetStatus(CDeadline deadline) const
Get the final result of this blob's retrieval.
unique_ptr< SImpl > m_Impl
shared_ptr< CPSG_Reply > GetReply() const
Get the reply that contains this item.
CPSG_ReplyItem(EType type)
@ eEndOfReply
No more items expected in the (overall!) reply.
PSG reply – corresponds to a PSG request.
shared_ptr< const CPSG_Request > m_Request
shared_ptr< CPSG_ReplyItem > GetNextItem(CDeadline deadline)
Get the next item which has started arriving from the server.
SPSG_Message GetNextMessage(EDiagSev min_severity=eDiag_Error) const
Unstructured text containing auxiliary info about the result – such as messages and errors that came ...
EPSG_Status GetStatus(CDeadline deadline) const
Get the final result of this whole reply's retrieval.
shared_ptr< const CPSG_Request > GetRequest() const
Get the request that resulted in this reply.
unique_ptr< SImpl > m_Impl
Request to the PSG server (by bio-id, for a biodata specific info and data)
vector< CPSG_BlobId > TExcludeTSEs
EType x_GetType() const override
const TExcludeTSEs & GetExcludeTSEs() const
void SetAccSubstitution(EPSG_AccSubstitution acc_substitution)
Set substitution policy for version-less primary seq-ids.
string x_GetId() const override
void ExcludeTSE(CPSG_BlobId blob_id)
void SetResendTimeout(CTimeout resend_timeout)
Set resend timeout.
EPSG_BioIdResolution GetBioIdResolution() const
EIncludeData
Specify which info and data is needed.
@ eSmartTSE
If ID2 split is available, return split info blob only.
@ eSlimTSE
If ID2 split is available, return split info blob only.
@ eDefault
Server default.
@ eWholeTSE
If ID2 split is available, return all split blobs.
@ eOrigTSE
Return all Cassandra data chunks of the blob itself.
void IncludeData(EIncludeData include)
TExcludeTSEs m_ExcludeTSEs
EPSG_BioIdResolution m_BioIdResolution
EIncludeData GetIncludeData() const
CPSG_Request_Biodata(CPSG_BioId bio_id, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
const CPSG_BioId & GetBioId() const
void x_GetAbsPathRef(ostream &) const override
EPSG_AccSubstitution m_AccSubstitution
EIncludeData m_IncludeData
CPSG_Request_Biodata(CPSG_BioId bio_id, EPSG_BioIdResolution bio_id_resolution, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
Request to the PSG server (by blob-id, for a particular blob of data)
CPSG_Request_Blob(CPSG_BlobId blob_id, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
EIncludeData GetIncludeData() const
string x_GetId() const override
EIncludeData m_IncludeData
void IncludeData(EIncludeData include)
const CPSG_BlobId & GetBlobId() const
EType x_GetType() const override
void x_GetAbsPathRef(ostream &) const override
void x_GetAbsPathRef(ostream &) const override
EType x_GetType() const override
string x_GetId() const override
CPSG_Request_Chunk(CPSG_ChunkId chunk_id, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
const CPSG_ChunkId & GetChunkId() const
const TNucleotide & GetNucleotide() const
void x_GetAbsPathRef(ostream &) const override
EType x_GetType() const override
string x_GetId() const override
const string & GetProtein() const
CPSG_Request_IpgResolve(string protein, Int8 ipg={}, TNucleotide nucleotide={}, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
CNullable< string > TNucleotide
Request meta-information for the named annotations which are defined on the bioseq.
objects::CSeq_id::ESNPScaleLimit ESNPScaleLimit
Scale-limit parameter for SNP annotations.
CPSG_Request_NamedAnnotInfo(CPSG_BioIds bio_ids, TAnnotNames annot_names, EPSG_BioIdResolution bio_id_resolution, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
const CPSG_BioId & GetBioId() const
EPSG_BioIdResolution m_BioIdResolution
vector< string > TAnnotNames
Names of the named annotations.
CPSG_Request_NamedAnnotInfo(CPSG_BioIds bio_ids, TAnnotNames annot_names, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
CPSG_Request_NamedAnnotInfo(CPSG_BioId bio_id, TArgs &&... args)
ESNPScaleLimit m_SNPScaleLimit
void SetAccSubstitution(EPSG_AccSubstitution acc_substitution)
Set substitution policy for version-less primary seq-ids.
void SetSNPScaleLimit(ESNPScaleLimit snp_scale_limit)
const CPSG_BioIds & GetBioIds() const
EPSG_BioIdResolution GetBioIdResolution() const
void x_GetAbsPathRef(ostream &) const override
EType x_GetType() const override
void IncludeData(EIncludeData include)
ESNPScaleLimit GetSNPScaleLimit() const
const TAnnotNames & GetAnnotNames() const
string x_GetId() const override
EPSG_AccSubstitution m_AccSubstitution
EIncludeData m_IncludeData
EIncludeData GetIncludeData() const
Request to the PSG server (by bio-id, for a biodata specific info and data)
string x_GetId() const override
CPSG_Request_Resolve(CPSG_BioId bio_id, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
DECLARE_SAFE_FLAGS_TYPE(EIncludeInfo, TIncludeInfo)
EIncludeInfo
Specify which info and data is needed Some processors may provide more than the flags prescribe Alway...
@ fName
Requests name to use for canonical bio-id.
EPSG_BioIdResolution GetBioIdResolution() const
EPSG_AccSubstitution m_AccSubstitution
TIncludeInfo m_IncludeInfo
void IncludeInfo(TIncludeInfo include)
EPSG_BioIdResolution m_BioIdResolution
TIncludeInfo GetIncludeInfo() const
void x_GetAbsPathRef(ostream &) const override
CPSG_Request_Resolve(CPSG_BioId bio_id, EPSG_BioIdResolution bio_id_resolution, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
void SetAccSubstitution(EPSG_AccSubstitution acc_substitution)
Set substitution policy for version-less primary seq-ids.
EType x_GetType() const override
const CPSG_BioId & GetBioId() const
Request to the PSG server (see "CPSG_Request_*" below)
void SetUserArgs(SPSG_UserArgs user_args)
Set arbitrary URL arguments to add to this request.
virtual string x_GetId() const =0
virtual EType x_GetType() const =0
CRef< CRequestContext > m_RequestContext
virtual void x_GetAbsPathRef(ostream &) const =0
virtual ~CPSG_Request()=default
DECLARE_SAFE_FLAGS_TYPE(EFlags, TFlags)
shared_ptr< void > m_UserContext
void SetFlags(TOptionalFlags flags)
Set flags.
CRef< CRequestContext > GetRequestContext() const
Get request context.
void SetRequestContext(CRef< CRequestContext > request_context)
Set request context.
EType GetType() const
Get request type.
shared_ptr< TUserContext > GetUserContext() const
Get the user-provided context.
CPSG_Request(shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
TSeconds m_SentSecondsAgo
const TSeconds & GetSentSecondsAgo() const
Seconds passed since the blob was last sent to the client.
const TDataId * GetId() const
Get data ID.
EReason GetReason() const
const TSeconds & GetTimeUntilResend() const
Seconds before the blob will be sent to the client.
unique_ptr< CPSG_DataId > m_Id
TSeconds m_TimeUntilResend
CPSG_SkippedBlob(unique_ptr< CPSG_DataId > id, EReason reason, TSeconds sent_seconds_ago, TSeconds time_until_resend)
CTimeout – Timeout interval.
SStrictId_Tax::TId TTaxId
Taxon id type.
static CRequestContext & GetRequestContext(void)
Shortcut to CDiagContextThreadData::GetThreadData().GetRequestContext()
CRef< CRequestContext > Clone(void) const
Copy current request context to a new one.
EDiagSev
Severity level for the posted diagnostics.
@ eDiag_Error
Error message.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
EErrCode
Error types that an application can generate.
void GetLabel(string *label, ELabelType type=eDefault, TLabelFlags flags=fLabel_Default) const
Append a label for this Seq-id to the supplied string.
@ eFastaContent
Like eFasta, but without any tag.
int64_t Int8
8-byte (64-bit) signed integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Int8 TSeconds
Number of seconds.
@ eDefault
Default timeout (to be interpreted by the client code)
static void text(MDB_val *v)
constexpr bool empty(list< Ts... >) noexcept
Miscellaneous common-use basic types and functionality.
Defines: CTimeFormat - storage class for time format.
EPSG_AccSubstitution
Whether and how to substitute version-less primary seq-ids with the "more unique" secondary seq-ids.
@ Never
No substitution whatsoever - return exact raw accession info.
@ Default
Substitute always (default)
@ Limited
Substitute only if the resolved record's seq_id_type is GI(12)
EPSG_Status
Retrieval result.
@ eSuccess
Successfully retrieved.
@ eInProgress
Retrieval is not finalized yet, more info may come.
@ eForbidden
User is not authorized for the retrieval.
@ eCanceled
Request canceled.
@ eError
An error was encountered while trying to send request or to read and to process the reply.
vector< CPSG_BioId > CPSG_BioIds
EPSG_BioIdResolution
Whether to try to resolve provided seq-ids before use.
@ Resolve
Try to resolve provided seq-ids.
@ NoResolve
Use provided seq-ids as is.
DECLARE_SAFE_FLAGS(CPSG_Request::EFlags)
static bool GetSeqId(const T &d, set< string > &labels, const string name="", bool detect=false, bool found=false)
Defines CRequestContext class for NCBI C++ diagnostic API.
Arbitrary request URL arguments.
SPSG_UserArgs(const string &query)
SPSG_UserArgs(const CUrlArgs &url_args)
Allow construction from a CUrlArgs instance or using CUrlArgs parsing.