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

Go to the SVN repository for this file.

1 /* $Id: osg_caller.cpp 98885 2023-01-19 14:51:41Z 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: base class for processors which may generate os_gateway
29  * fetches
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 
35 #include "osg_caller.hpp"
36 #include "osg_fetch.hpp"
37 #include "osg_connection.hpp"
38 #include "osg_processor_base.hpp"
40 
41 #include <corelib/request_ctx.hpp>
48 
49 
53 
54 
56 {
57 }
58 
59 
61 {
62 }
63 
64 
66 {
68  req->SetRequest().SetInit();
69  if ( 1 ) {
70  // set client name
71  CRef<CID2_Param> param(new CID2_Param);
72  param->SetName("log:client_name");
73  param->SetValue().push_back("pubseq_gateway");
74  req->SetParams().Set().push_back(param);
75  }
76  if ( 1 ) {
77  CRef<CID2_Param> param(new CID2_Param);
78  param->SetName("id2:allow");
79 
80  // allow new blob-state field in several ID2 replies
81  param->SetValue().push_back("*.blob-state");
82  // enable VDB-based WGS sequences
83  param->SetValue().push_back("vdb-wgs");
84  // enable VDB-based SNP sequences
85  param->SetValue().push_back("vdb-snp");
86  // enable VDB-based CDD sequences
87  param->SetValue().push_back("vdb-cdd");
88  req->SetParams().Set().push_back(param);
89  }
90  return req;
91 }
92 
93 
95 {
96  CID2_Request& req = fetch->GetRequest().GetNCObject();
98  packet.Set().push_back(fetch->GetRequest());
99  fetch.GetNCObject().ResetReplies();
100  m_Fetches.push_back(fetch);
101 }
102 
103 
104 static bool kAlwaysSendInit = false;
105 
106 
108 {
110  m_Fetches.clear();
111  if ( !fetches.empty() ) {
113  AddFetch(*packet, Ref(new COSGFetch(MakeInitRequest())));
114  }
115  for ( auto& f : fetches ) {
116  AddFetch(*packet, f);
117  }
118  }
119  return packet;
120 }
121 
122 
123 size_t COSGCaller::GetRequestIndex(const CID2_Reply& reply) const
124 {
125  auto serial_number = reply.GetSerial_number();
126  auto first_serial_number = m_RequestPacket->Get().front()->GetSerial_number();
127  size_t index = serial_number - first_serial_number;
128  if ( index >= m_Fetches.size() ) {
130  "Invalid OSG reply SN: "<<serial_number<<
131  " first: "<<first_serial_number<<
132  " count: "<<m_Fetches.size());
133  }
134  if ( m_Fetches[index]->EndOfReplies() ) {
136  "OSG reply after end-of-replies SN: "<<serial_number);
137  }
138  return index;
139 }
140 
141 
143 {
145 }
146 
147 
149 {
151  m_ConnectionPool = connection_pool;
154 }
155 
156 
158 {
159  if ( m_Connection ) {
162  m_ConnectionPool = null;
163  }
164 }
165 
166 
168 {
171  processor.NotifyOSGCallStart();
172  m_RequestPacket = MakePacket(processor.GetFetches());
173  _ASSERT(m_RequestPacket->Get().size() < 999999); // overflow guard
174  if ( !m_RequestPacket->Get().empty() ) {
175  if ( processor.NeedTrace() ) {
176  ostringstream str;
177  str << "OSG("<<m_Connection->GetConnectionID()<<") sending request: "
179  processor.SendTrace(str.str());
180  }
182  }
183  else {
184  if ( processor.NeedTrace() ) {
185  ostringstream str;
186  str << "OSG("<<m_Connection->GetConnectionID()<<") empty request packet";
187  processor.SendTrace(str.str());
188  }
189  }
190 }
191 
192 
194 {
198  size_t waiting_count = m_RequestPacket->Get().size();
199  while ( waiting_count > 0 ) {
200  if ( processor.NeedTrace() ) {
201  ostringstream str;
202  str << "OSG("<<m_Connection->GetConnectionID()<<") reading reply";
203  processor.SendTrace(str.str());
204  }
206  if ( processor.NeedTrace() ) {
207  ostringstream str;
208  str << "OSG("<<m_Connection->GetConnectionID()<<") received reply";
209  processor.SendTrace(str.str());
210  }
211  if ( reply->IsSetError() ) {
212  for ( auto& error : reply->GetError() ) {
213  if ( error->GetSeverity() == CID2_Error::eSeverity_failed_server ) {
214  NCBI_THROW_FMT(CPubseqGatewayException, eOutputNotInReadyState,
215  "OSG error reply: "<<MSerial_AsnText<<*error);
216  }
217  if ( error->GetSeverity() == CID2_Error::eSeverity_failed_connection ) {
218  NCBI_THROW_FMT(CPubseqGatewayException, eOutputNotInReadyState,
219  "OSG error reply: "<<MSerial_AsnText<<*error);
220  }
221  if ( error->GetSeverity() == CID2_Error::eSeverity_failed_command ) {
222  failed = error;
223  break;
224  }
225  }
226  }
227  size_t index = GetRequestIndex(*reply);
228  m_Fetches[index]->AddReply(move(reply));
229  if ( m_Fetches[index]->EndOfReplies() ) {
230  --waiting_count;
231  }
232  if ( !failed ) {
233  processor.NotifyOSGCallReply(*reply);
234  }
235  }
236  if ( processor.NeedTrace() ) {
237  ostringstream str;
238  str << "OSG("<<m_Connection->GetConnectionID()<<") releasing connection";
239  processor.SendTrace(str.str());
240  }
242  if ( failed ) {
243  NCBI_THROW_FMT(CPubseqGatewayException, eOutputNotInReadyState,
244  "OSG error reply: "<<MSerial_AsnText<<*failed);
245  }
246  processor.NotifyOSGCallEnd();
247 }
248 
249 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CID2_Param –.
Definition: ID2_Param.hpp:66
CID2_Reply –.
Definition: ID2_Reply.hpp:66
CID2_Request_Packet –.
CID2_Request –.
Definition: ID2_Request.hpp:66
CRef< CID2_Request_Packet > m_RequestPacket
Definition: osg_caller.hpp:102
void WaitForReplies(CPSGS_OSGProcessorBase &processor)
Definition: osg_caller.cpp:193
CRef< CID2_Request_Packet > MakePacket(const TFetches &fetches)
Definition: osg_caller.cpp:107
void ReleaseConnection()
Definition: osg_caller.cpp:157
CRef< CID2_Request > MakeInitRequest()
Definition: osg_caller.cpp:65
vector< CRef< COSGFetch > > m_Fetches
Definition: osg_caller.hpp:103
void AddFetch(CID2_Request_Packet &packet, const CRef< COSGFetch > &fetch)
Definition: osg_caller.cpp:94
size_t GetConnectionID() const
Definition: osg_caller.cpp:142
CRef< COSGConnection > m_Connection
Definition: osg_caller.hpp:101
virtual ~COSGCaller()
Definition: osg_caller.cpp:60
void SendRequest(CPSGS_OSGProcessorBase &processor)
Definition: osg_caller.cpp:167
bool EndOfReplies(const CID2_Reply &reply) const
CRef< COSGConnectionPool > m_ConnectionPool
Definition: osg_caller.hpp:100
size_t GetRequestIndex(const CID2_Reply &reply) const
Definition: osg_caller.cpp:123
void AllocateConnection(const CRef< COSGConnectionPool > &connection_pool)
Definition: osg_caller.cpp:148
vector< CRef< COSGFetch > > TFetches
Definition: osg_caller.hpp:65
void ReleaseConnection(CRef< COSGConnection > &conn)
CRef< COSGConnection > AllocateConnection()
bool InitRequestWasSent() const
size_t GetConnectionID() const
CRef< CID2_Reply > ReceiveReply()
void SendRequestPacket(const CID2_Request_Packet &packet)
int AllocateRequestSerialNumber()
void ResetReplies()
Definition: osg_fetch.cpp:84
const CRef< CID2_Request > & GetRequest() const
Definition: osg_fetch.hpp:68
virtual void NotifyOSGCallReply(const CID2_Reply &reply)
void SendTrace(const string &str)
const TFetches & GetFetches() const
int failed
Definition: dbmorecmds.c:10
#define NCBI_THROW_FMT(exception_class, err_code, message)
The same as NCBI_THROW but with message processed as output to ostream.
Definition: ncbiexpt.hpp:719
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
CRef< C > Ref(C *object)
Helper functions to get CRef<> and CConstRef<> objects.
Definition: ncbiobj.hpp:2015
TObjectType & GetNCObject(void) const
Get object.
Definition: ncbiobj.hpp:1187
void SetParams(TParams &value)
Assign a value to Params data member.
void SetSerial_number(TSerial_number value)
Assign a value to Serial_number data member.
Tdata & Set(void)
Assign a value to data member.
TSerial_number GetSerial_number(void) const
Get the Serial_number member data.
Definition: ID2_Reply_.hpp:830
void SetRequest(TRequest &value)
Assign a value to Request data member.
const Tdata & Get(void) const
Get the member data.
@ eSeverity_failed_command
command cannot be completed this time
Definition: ID2_Error_.hpp:86
@ eSeverity_failed_server
server cannot be used for a while
Definition: ID2_Error_.hpp:88
@ eSeverity_failed_connection
connection cannot be reused, reconnect is required
Definition: ID2_Error_.hpp:87
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
END_NCBI_NAMESPACE
Definition: osg_caller.cpp:252
BEGIN_NCBI_NAMESPACE
Definition: osg_caller.cpp:50
BEGIN_NAMESPACE(psg)
static bool kAlwaysSendInit
Definition: osg_caller.cpp:104
END_NAMESPACE(osg)
Defines CRequestContext class for NCBI C++ diagnostic API.
static const char * str(char *buf, int n)
Definition: stats.c:84
#define _ASSERT
Modified on Wed Feb 21 09:57:27 2024 by modify_doxy.py rev. 669887