NCBI C++ ToolKit
osg_getblob.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: osg_getblob.cpp 99336 2023-03-13 14:22:34Z vasilche $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Eugene Vasilchenko
27  *
28  * File Description: processor for data from OSG
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include "osg_getblob.hpp"
35 #include "osg_fetch.hpp"
36 #include "osg_connection.hpp"
37 
38 #include <objects/id2/id2__.hpp>
41 
42 
46 
47 
49  const CRef<COSGConnectionPool>& pool,
50  const shared_ptr<CPSGS_Request>& request,
51  const shared_ptr<CPSGS_Reply>& reply,
52  TProcessorPriority priority)
53  : CPSGS_OSGProcessorBase(enabled_flags, pool, request, reply, priority)
54 {
55 }
56 
57 
59 {
61 }
62 
63 
65 {
66  return "OSG-getblob";
67 }
68 
69 
71 {
73 }
74 
75 
77  shared_ptr<CPSGS_Request>& request)
78 {
79  return IsEnabledOSGBlob(enabled_flags, ParsePSGBlobId(request->GetRequest<SPSGS_BlobBySatSatKeyRequest>().m_BlobId));
80 }
81 
82 
84 {
85  auto& psg_req = GetRequest()->GetRequest<SPSGS_BlobBySatSatKeyRequest>();
86  m_ApplyCDDFix = false;
87  m_EmptyCDDReceived = false;
88  if ( auto blob_id = ParsePSGBlobId(psg_req.m_BlobId) ) {
89  if ( IsCDDBlob(*blob_id) ) {
91  }
92  CRef<CID2_Request> osg_req(new CID2_Request);
93  auto& req = osg_req->SetRequest().SetGet_blob_info();
94  req.SetBlob_id().SetBlob_id(*blob_id);
95  // TODO: blob version?
96  req.SetGet_data();
97  AddRequest(osg_req);
98  }
99 }
100 
101 
103 {
104  if ( !reply.GetReply().IsGet_blob() ) {
105  return false;
106  }
107  const CID2_Reply_Get_Blob& reply_get_blob = reply.GetReply().GetGet_blob();
108  if ( !reply_get_blob.IsSetData() ) {
109  return false;
110  }
111  const CID2_Reply_Data& data = reply_get_blob.GetData();
112  if ( data.GetData_type() != data.eData_type_seq_entry ||
113  data.GetData_format() != data.eData_format_asn_binary ||
115  return false;
116  }
117  // minimal Seq-entry with no data
118  const size_t kEmptySeqEntrySize = 24;
119  return data.GetData().size() == 1 && data.GetData().front()->size() == kEmptySeqEntrySize;
120 }
121 
122 
124 {
125  if ( m_ApplyCDDFix ) {
126  m_EmptyCDDReceived = false;
128  }
129 }
130 
131 
133 {
134  if ( m_ApplyCDDFix ) {
135  if ( IsEmptyCDDBlob(reply) ) {
136  m_EmptyCDDReceived = true;
137  }
138  }
139 }
140 
141 
143 {
144  if ( m_ApplyCDDFix ) {
145  if ( m_EmptyCDDReceived &&
146  m_RequestTime.Elapsed() > GetConnectionPool().GetCDDRetryTimeout() ) {
147  NCBI_THROW(CPubseqGatewayException, eRequestCanceled, "no CDD due to OSG timeout");
148  }
149  }
150 }
151 
152 
154 {
155  for ( auto& f : GetFetches() ) {
156  for ( auto& r : f->GetReplies() ) {
157  switch ( r->GetReply().Which() ) {
160  // do nothing
161  break;
164  if ( m_Blob ) {
165  if ( SignalStartProcessing() == ePSGS_Cancel ) {
167  return;
168  }
169  }
170  break;
173  if ( m_SplitInfo ) {
174  if ( SignalStartProcessing() == ePSGS_Cancel ) {
175  return;
176  }
177  }
178  break;
179  default:
180  PSG_ERROR(GetName()<<": "
181  "Unknown reply to "<<MSerial_AsnText<<*f->GetRequest()<<"\n"<<*r);
182  break;
183  }
184  }
185  }
186  if ( IsCanceled() ) {
187  return;
188  }
189  if ( SignalStartProcessing() == ePSGS_Cancel ) {
191  return;
192  }
193  if ( s_SimulateError() ) {
195  return;
196  }
197  SendBlob();
198 }
199 
200 
202  const CRef<COSGConnectionPool>& pool,
203  const shared_ptr<CPSGS_Request>& request,
204  const shared_ptr<CPSGS_Reply>& reply,
205  TProcessorPriority priority)
206  : CPSGS_OSGProcessorBase(enabled_flags, pool, request, reply, priority)
207 {
208 }
209 
210 
212 {
213  StopAsyncThread();
214 }
215 
216 
218 {
219  return "OSG-gettsechunk";
220 }
221 
222 
224 {
225  return kOSGProcessorGroupName;
226 }
227 
228 
230  shared_ptr<CPSGS_Request>& request)
231 {
232  return IsEnabledOSGBlob(enabled_flags, ParsePSGId2Info(request->GetRequest<SPSGS_TSEChunkRequest>().m_Id2Info).tse_id);
233 }
234 
235 
237 {
238  auto& psg_req = GetRequest()->GetRequest<SPSGS_TSEChunkRequest>();
239  if ( auto parsed = ParsePSGId2Info(psg_req.m_Id2Info) ) {
240  x_SetSplitVersion(*parsed.tse_id, parsed.split_version);
241  CRef<CID2_Request> osg_req(new CID2_Request);
242  auto& req = osg_req->SetRequest().SetGet_chunks();
243  req.SetBlob_id(*parsed.tse_id);
244  req.SetSplit_version(parsed.split_version);
245  req.SetChunks().push_back(CID2S_Chunk_Id(psg_req.m_Id2Chunk));
246  AddRequest(osg_req);
247  }
248 }
249 
250 
252 {
253  for ( auto& f : GetFetches() ) {
254  for ( auto& r : f->GetReplies() ) {
255  switch ( r->GetReply().Which() ) {
258  // do nothing
259  break;
262  if ( m_Chunk ) {
263  if ( SignalStartProcessing() == ePSGS_Cancel ) {
265  return;
266  }
267  }
268  break;
269  default:
270  PSG_ERROR(GetName()<<": "
271  "Unknown reply to "<<MSerial_AsnText<<*f->GetRequest()<<"\n"<<*r);
272  break;
273  }
274  }
275  }
276  if ( IsCanceled() ) {
277  return;
278  }
279  if ( SignalStartProcessing() == ePSGS_Cancel ) {
281  return;
282  }
283  if ( s_SimulateError() ) {
285  return;
286  }
287  SendBlob();
288 }
289 
290 
CID2S_Chunk_Id –.
CID2_Reply_Get_Blob –.
CID2_Reply –.
Definition: ID2_Reply.hpp:66
CID2_Request –.
Definition: ID2_Request.hpp:66
double GetCDDRetryTimeout() const
static CRef< CID2_Blob_Id > ParsePSGBlobId(const SPSGS_BlobId &blob_id)
void ProcessBlobReply(const CID2_Reply &reply)
static bool IsEnabledOSGBlob(TEnabledFlags enabled_flags, const CID2_Blob_Id &blob_id)
CConstRef< CID2S_Reply_Get_Split_Info > m_SplitInfo
CConstRef< CID2_Reply_Get_Blob > m_Blob
CConstRef< CID2S_Reply_Get_Chunk > m_Chunk
void x_SetSplitVersion(const CID2_Blob_Id &osg_blob_id, TID2SplitVersion split_version)
static bool IsCDDBlob(const CID2_Blob_Id &blob_id)
static SParsedId2Info ParsePSGId2Info(const string &idsss2_info)
static bool CanProcess(TEnabledFlags enabled_flags, shared_ptr< CPSGS_Request > &request)
Definition: osg_getblob.cpp:76
virtual void NotifyOSGCallEnd() override
virtual void ProcessReplies() override
virtual string GetGroupName() const override
Tells the processor group name.
Definition: osg_getblob.cpp:70
virtual ~CPSGS_OSGGetBlob()
Definition: osg_getblob.cpp:58
static bool IsEmptyCDDBlob(const CID2_Reply &reply)
CPSGS_OSGGetBlob(TEnabledFlags enabled_flags, const CRef< COSGConnectionPool > &pool, const shared_ptr< CPSGS_Request > &request, const shared_ptr< CPSGS_Reply > &reply, TProcessorPriority priority)
Definition: osg_getblob.cpp:48
virtual void NotifyOSGCallStart() override
virtual void NotifyOSGCallReply(const CID2_Reply &reply) override
virtual string GetName() const override
Tells the processor name (used in logging and tracing)
Definition: osg_getblob.cpp:64
virtual void CreateRequests() override
Definition: osg_getblob.cpp:83
CStopWatch m_RequestTime
Definition: osg_getblob.hpp:69
virtual string GetName() const override
Tells the processor name (used in logging and tracing)
virtual string GetGroupName() const override
Tells the processor group name.
virtual ~CPSGS_OSGGetChunks()
static bool CanProcess(TEnabledFlags enabled_flags, shared_ptr< CPSGS_Request > &request)
virtual void ProcessReplies() override
CPSGS_OSGGetChunks(TEnabledFlags enabled_flags, const CRef< COSGConnectionPool > &pool, const shared_ptr< CPSGS_Request > &request, const shared_ptr< CPSGS_Reply > &reply, TProcessorPriority priority)
virtual void CreateRequests() override
void AddRequest(const CRef< CID2_Request > &req)
const TFetches & GetFetches() const
COSGConnectionPool & GetConnectionPool() const
shared_ptr< CPSGS_Request > GetRequest(void) const
Provides the user request.
EPSGS_StartProcessing SignalStartProcessing(void)
A processor should call the method when it decides that it successfully started processing the reques...
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
double Restart(void)
Return time elapsed since first Start() or last Restart() call (in seconds).
Definition: ncbitime.hpp:2817
double Elapsed(void) const
Return time elapsed since first Start() or last Restart() call (in seconds).
Definition: ncbitime.hpp:2776
TData_compression GetData_compression(void) const
Get the Data_compression member data.
const TData & GetData(void) const
Get the Data member data.
TData_format GetData_format(void) const
Get the Data_format member data.
const TGet_blob & GetGet_blob(void) const
Get the variant data.
Definition: ID2_Reply_.cpp:230
bool IsGet_blob(void) const
Check if variant Get_blob is selected.
Definition: ID2_Reply_.hpp:787
const TReply & GetReply(void) const
Get the Reply member data.
Definition: ID2_Reply_.hpp:940
TData_type GetData_type(void) const
Get the Data_type member data.
const TData & GetData(void) const
Get the Data member data.
void SetRequest(TRequest &value)
Assign a value to Request data member.
bool IsSetData(void) const
whole blob or blob skeleton not set if error occurred Check if a value has been assigned to Data data...
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
END_NCBI_NAMESPACE
BEGIN_NCBI_NAMESPACE
Definition: osg_getblob.cpp:43
BEGIN_NAMESPACE(psg)
END_NAMESPACE(osg)
const string kOSGProcessorGroupName
#define PSG_ERROR(message)
int TProcessorPriority
Modified on Fri Mar 01 10:09:08 2024 by modify_doxy.py rev. 669887