1 #ifndef PSGS_REQUEST__HPP
2 #define PSGS_REQUEST__HPP
3 
4 /*  $Id: psgs_request.hpp 629837 2021-04-22 12:47:49Z ivanov $
5  * ===========================================================================
6  *
7  *                            PUBLIC DOMAIN NOTICE
8  *               National Center for Biotechnology Information
9  *
10  *  This software/database is a "United States Government Work" under the
11  *  terms of the United States Copyright Act.  It was written as part of
12  *  the author's official duties as a United States Government employee and
13  *  thus cannot be copyrighted.  This software/database is freely available
14  *  to the public for use. The National Library of Medicine and the U.S.
15  *  Government have not placed any restriction on its use or reproduction.
16  *
17  *  Although all reasonable efforts have been taken to ensure the accuracy
18  *  and reliability of the software and data, the NLM and the U.S.
19  *  Government do not and cannot warrant the performance or results that
20  *  may be obtained by using this software or data. The NLM and the U.S.
21  *  Government disclaim all warranties, express or implied, including
22  *  warranties of performance, merchantability or fitness for any particular
23  *  purpose.
24  *
25  *  Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Sergey Satskiy
30  *
31  * File Description: PSG server requests
32  *
33  */
34 
35 #include <corelib/request_ctx.hpp>
36 #include <objtools/pubseq_gateway/impl/cassandra/bioseq_info/record.hpp>
37 #include <objtools/pubseq_gateway/impl/cassandra/blob_task/fetch_split_history.hpp>
38 #include <connect/services/json_over_uttp.hpp>
39 #include <chrono>
40 #include <string>
41 #include <vector>
42 
43 #include "pubseq_gateway_exception.hpp"
44 #include "pubseq_gateway_types.hpp"
45 
46 USING_NCBI_SCOPE;
47 USING_IDBLOB_SCOPE;
48 
49 
50 // Mostly for timing collection
51 typedef chrono::high_resolution_clock::time_point  TPSGS_HighResolutionTimePoint;
52 
53 
54 // Blob identifier consists of two integers: sat and sat key.
55 // The blob sat eventually needs to be resolved to a sat name.
56 struct SPSGS_BlobId
57 {
SPSGS_BlobIdSPSGS_BlobId58     SPSGS_BlobId()
59     {}
60 
SPSGS_BlobIdSPSGS_BlobId61     SPSGS_BlobId(const string &  blob_id) :
62         m_Id(blob_id)
63     {}
64 
65     SPSGS_BlobId(const SPSGS_BlobId &) = default;
66     SPSGS_BlobId(SPSGS_BlobId &&) = default;
67     SPSGS_BlobId &  operator=(const SPSGS_BlobId &) = default;
68     SPSGS_BlobId &  operator=(SPSGS_BlobId &&) = default;
69 
GetIdSPSGS_BlobId70     string GetId(void) const
71     {
72         return m_Id;
73     }
74 
operator <SPSGS_BlobId75     bool operator < (const SPSGS_BlobId &  other) const
76     {
77         return m_Id < other.m_Id;
78     }
79 
operator ==SPSGS_BlobId80     bool operator == (const SPSGS_BlobId &  other) const
81     {
82         return m_Id == other.m_Id;
83     }
84 
operator !=SPSGS_BlobId85     bool operator != (const SPSGS_BlobId &  other) const
86     {
87         return !this->operator==(other);
88     }
89 
90     string      m_Id;
91 };
92 
93 
94 // Forward declaration
95 // CPSGS_Request uses unique_ptr to SPSGS_RequestBase and
96 // SPSGS_RequestBase uses the request type from CPSGS_Request
97 struct SPSGS_RequestBase;
98 
99 class CPSGS_Request
100 {
101 public:
102     enum EPSGS_Type {
103         ePSGS_ResolveRequest,
104         ePSGS_BlobBySeqIdRequest,
105         ePSGS_BlobBySatSatKeyRequest,
106         ePSGS_AnnotationRequest,
107         ePSGS_TSEChunkRequest,
108 
109         ePSGS_UnknownRequest
110     };
111 
TypeToString(EPSGS_Type req_type)112     static string TypeToString(EPSGS_Type  req_type)
113     {
114         switch (req_type) {
115             case ePSGS_ResolveRequest:          return "ResolveRequest";
116             case ePSGS_BlobBySeqIdRequest:      return "BlobBySeqIdRequest";
117             case ePSGS_BlobBySatSatKeyRequest:  return "BlobBySatSatKeyRequest";
118             case ePSGS_AnnotationRequest:       return "AnnotationRequest";
119             case ePSGS_TSEChunkRequest:         return "TSEChunkRequest";
120             case ePSGS_UnknownRequest:          return "UnknownRequest";
121             default: break;
122         }
123         return "UnknownRequestTypeValue";
124     }
125 
126 public:
127     CPSGS_Request();
128     CPSGS_Request(unique_ptr<SPSGS_RequestBase> req,
129                   CRef<CRequestContext>  request_context);
130 
131     EPSGS_Type  GetRequestType(void) const;
GetRequestId(void) const132     size_t  GetRequestId(void) const
133     {
134         return m_RequestId;
135     }
136 
GetRequest(void)137     template<typename TRequest> TRequest& GetRequest(void)
138     {
139         if (m_Request) {
140             TRequest*   req = dynamic_cast<TRequest *>(m_Request.get());
141             if (req != nullptr)
142                 return *req;
143         }
144 
145         NCBI_THROW(CPubseqGatewayException, eInvalidUserRequestType,
146                    "User request type mismatch. Stored type: " +
147                    x_RequestTypeToString(GetRequestType()));
148     }
149 
150     CRef<CRequestContext>  GetRequestContext(void);
151     void SetRequestContext(void);
152     TPSGS_HighResolutionTimePoint GetStartTimestamp(void) const;
153     bool NeedTrace(void);
154     virtual string GetName(void) const;
155     virtual CJsonNode Serialize(void) const;
156 
157     CPSGS_Request(const CPSGS_Request &) = default;
158     CPSGS_Request(CPSGS_Request &&) = default;
159     CPSGS_Request &  operator=(const CPSGS_Request &) = default;
160     CPSGS_Request &  operator=(CPSGS_Request &&) = default;
161 
162 private:
163     string x_RequestTypeToString(EPSGS_Type  type) const;
164 
165 private:
166     unique_ptr<SPSGS_RequestBase>   m_Request;
167     CRef<CRequestContext>           m_RequestContext;
168     size_t                          m_RequestId;
169 };
170 
171 
172 
173 // Base struct for all requests: any request can be traceable and has a start
174 // time
175 struct SPSGS_RequestBase
176 {
177     // Use cache option comes from the user (the URL 'use_cache' parameter)
178     enum EPSGS_CacheAndDbUse {
179         ePSGS_CacheOnly,
180         ePSGS_DbOnly,
181         ePSGS_CacheAndDb,       // Default
182 
183         ePSGS_UnknownUseCache
184     };
185 
CacheAndDbUseToStringSPSGS_RequestBase186     static string  CacheAndDbUseToString(EPSGS_CacheAndDbUse  option)
187     {
188         switch (option) {
189             case ePSGS_CacheOnly:       return "CacheOnly";
190             case ePSGS_DbOnly:          return "DbOnly";
191             case ePSGS_CacheAndDb:      return "CacheAndDb";
192             case ePSGS_UnknownUseCache: return "UnknownUseCache";
193             default: break;
194         }
195         return "UnknownCacheAndDbUseOptionValue";
196     }
197 
198     // The accession substitution option comes from the user (the URL
199     // 'acc_substitution' parameter)
200     enum EPSGS_AccSubstitutioOption {
201         ePSGS_DefaultAccSubstitution,       // Default
202         ePSGS_LimitedAccSubstitution,
203         ePSGS_NeverAccSubstitute,
204 
205         ePSGS_UnknownAccSubstitution
206     };
207 
AccSubstitutioOptionToStringSPSGS_RequestBase208     static string AccSubstitutioOptionToString(EPSGS_AccSubstitutioOption option)
209     {
210         switch (option) {
211             case ePSGS_DefaultAccSubstitution:  return "DefaultAccSubstitution";
212             case ePSGS_LimitedAccSubstitution:  return "LimitedAccSubstitution";
213             case ePSGS_NeverAccSubstitute:      return "NeverAccSubstitute";
214             case ePSGS_UnknownAccSubstitution:  return "UnknownAccSubstitution";
215             default: break;
216         }
217         return "UnknownAccSubstitutioOptionValue";
218     }
219 
220     enum EPSGS_Trace {
221         ePSGS_NoTracing,
222         ePSGS_WithTracing
223     };
224 
TraceToStringSPSGS_RequestBase225     static string TraceToString(EPSGS_Trace  trace)
226     {
227         switch (trace) {
228             case ePSGS_NoTracing:   return "NoTracing";
229             case ePSGS_WithTracing: return "WithTracing";
230             default:    break;
231         }
232         return "UnknownTraceOptionValue";
233     }
234 
235     int                             m_Hops;
236     EPSGS_Trace                     m_Trace;
237     TPSGS_HighResolutionTimePoint   m_StartTimestamp;
238     vector<string>                  m_EnabledProcessors;
239     vector<string>                  m_DisabledProcessors;
240 
SPSGS_RequestBaseSPSGS_RequestBase241     SPSGS_RequestBase() :
242         m_Hops(0),
243         m_Trace(ePSGS_NoTracing),
244         m_StartTimestamp(chrono::high_resolution_clock::now())
245     {}
246 
SPSGS_RequestBaseSPSGS_RequestBase247     SPSGS_RequestBase(int  hops,
248                       EPSGS_Trace  trace,
249                       const vector<string> &  enabled_processors,
250                       const vector<string> &  disabled_processors,
251                       const TPSGS_HighResolutionTimePoint &  start) :
252         m_Hops(hops), m_Trace(trace), m_StartTimestamp(start),
253         m_EnabledProcessors(enabled_processors),
254         m_DisabledProcessors(disabled_processors)
255     {}
256 
~SPSGS_RequestBaseSPSGS_RequestBase257     virtual ~SPSGS_RequestBase() {}
258 
259     virtual CPSGS_Request::EPSGS_Type GetRequestType(void) const = 0;
260     virtual string GetName(void) const = 0;
261     virtual CJsonNode Serialize(void) const = 0;
262 
GetTraceSPSGS_RequestBase263     virtual EPSGS_Trace GetTrace(void) const
264     {
265         return m_Trace;
266     }
267 
GetStartTimestampSPSGS_RequestBase268     virtual TPSGS_HighResolutionTimePoint GetStartTimestamp(void) const
269     {
270         return m_StartTimestamp;
271     }
272 
273     SPSGS_RequestBase(const SPSGS_RequestBase &) = default;
274     SPSGS_RequestBase(SPSGS_RequestBase &&) = default;
275     SPSGS_RequestBase &  operator=(const SPSGS_RequestBase &) = default;
276     SPSGS_RequestBase &  operator=(SPSGS_RequestBase &&) = default;
277 };
278 
279 
280 // Resolve request parsed parameters
281 struct SPSGS_ResolveRequest : public SPSGS_RequestBase
282 {
283     // The output format may come from the user (the URL 'fmt' parameter)
284     enum EPSGS_OutputFormat {
285         ePSGS_ProtobufFormat,
286         ePSGS_JsonFormat,
287         ePSGS_NativeFormat,         // Default: the server decides between
288                                     // protobuf and json
289 
290         ePSGS_UnknownFormat
291     };
292 
OutputFormatToStringSPSGS_ResolveRequest293     static string OutputFormatToString(EPSGS_OutputFormat  format)
294     {
295         switch (format) {
296             case ePSGS_ProtobufFormat:  return "ProtobufFormat";
297             case ePSGS_JsonFormat:      return "JsonFormat";
298             case ePSGS_NativeFormat:    return "NativeFormat";
299             case ePSGS_UnknownFormat:   return "UnknownFormat";
300             default: break;
301         }
302         return "UnknownFormatOptionValue";
303     }
304 
305     // The user can specify what fields of the bioseq_info should be included
306     // into the server response.
307     // Pretty much copied from the client; the justfication for copying is:
308     // "it will be decoupled with the client type"
309     enum EPSGS_BioseqIncludeData {
310         fPSGS_CanonicalId = (1 << 1),
311         fPSGS_SeqIds = (1 << 2),
312         fPSGS_MoleculeType = (1 << 3),
313         fPSGS_Length = (1 << 4),
314         fPSGS_State = (1 << 5),
315         fPSGS_BlobId = (1 << 6),
316         fPSGS_TaxId = (1 << 7),
317         fPSGS_Hash = (1 << 8),
318         fPSGS_DateChanged = (1 << 9),
319         fPSGS_Gi = (1 << 10),
320         fPSGS_Name = (1 << 11),
321         fPSGS_SeqState = (1 << 12),
322 
323         fPSGS_AllBioseqFields = fPSGS_CanonicalId | fPSGS_SeqIds |
324                                 fPSGS_MoleculeType | fPSGS_Length |
325                                 fPSGS_State | fPSGS_BlobId | fPSGS_TaxId |
326                                 fPSGS_Hash | fPSGS_DateChanged | fPSGS_Gi |
327                                 fPSGS_Name | fPSGS_SeqState,
328         fPSGS_BioseqKeyFields = fPSGS_CanonicalId | fPSGS_Gi
329     };
330 
331     // Bit-set of EPSGS_BioseqIncludeData flags
332     typedef int TPSGS_BioseqIncludeData;
333 
334 
335     string                      m_SeqId;
336     int                         m_SeqIdType;
337     TPSGS_BioseqIncludeData     m_IncludeDataFlags;
338     EPSGS_OutputFormat          m_OutputFormat;
339     EPSGS_CacheAndDbUse         m_UseCache;
340     EPSGS_AccSubstitutioOption  m_AccSubstOption;
341 
SPSGS_ResolveRequestSPSGS_ResolveRequest342     SPSGS_ResolveRequest(const string &  seq_id,
343                          int  seq_id_type,
344                          TPSGS_BioseqIncludeData  include_data_flags,
345                          EPSGS_OutputFormat  output_format,
346                          EPSGS_CacheAndDbUse  use_cache,
347                          EPSGS_AccSubstitutioOption  subst_option,
348                          int  hops,
349                          EPSGS_Trace  trace,
350                          const vector<string> &  enabled_processors,
351                          const vector<string> &  disabled_processors,
352                          const TPSGS_HighResolutionTimePoint &  start_timestamp) :
353         SPSGS_RequestBase(hops, trace,
354                           enabled_processors, disabled_processors,
355                           start_timestamp),
356         m_SeqId(seq_id), m_SeqIdType(seq_id_type),
357         m_IncludeDataFlags(include_data_flags),
358         m_OutputFormat(output_format),
359         m_UseCache(use_cache),
360         m_AccSubstOption(subst_option)
361     {}
362 
SPSGS_ResolveRequestSPSGS_ResolveRequest363     SPSGS_ResolveRequest() :
364         m_SeqIdType(-1),
365         m_IncludeDataFlags(0),
366         m_OutputFormat(ePSGS_UnknownFormat),
367         m_UseCache(ePSGS_UnknownUseCache),
368         m_AccSubstOption(ePSGS_UnknownAccSubstitution)
369     {}
370 
GetRequestTypeSPSGS_ResolveRequest371     virtual CPSGS_Request::EPSGS_Type GetRequestType(void) const
372     {
373         return CPSGS_Request::ePSGS_ResolveRequest;
374     }
375 
GetNameSPSGS_ResolveRequest376     virtual string GetName(void) const
377     {
378         return "ID/resolve";
379     }
380 
381     virtual CJsonNode Serialize(void) const;
382 
383     SPSGS_ResolveRequest(const SPSGS_ResolveRequest &) = default;
384     SPSGS_ResolveRequest(SPSGS_ResolveRequest &&) = default;
385     SPSGS_ResolveRequest &  operator=(const SPSGS_ResolveRequest &) = default;
386     SPSGS_ResolveRequest &  operator=(SPSGS_ResolveRequest &&) = default;
387 };
388 
389 
390 struct SPSGS_BlobRequestBase : public SPSGS_RequestBase
391 {
392     // The TSE option comes from the user (the URL 'tse' parameter)
393     enum EPSGS_TSEOption {
394         ePSGS_NoneTSE,
395         ePSGS_SlimTSE,
396         ePSGS_SmartTSE,
397         ePSGS_WholeTSE,
398         ePSGS_OrigTSE,      // Default value
399 
400         ePSGS_UnknownTSE
401     };
402 
TSEOptionToStringSPSGS_BlobRequestBase403     static string TSEOptionToString(EPSGS_TSEOption  option)
404     {
405         switch (option) {
406             case ePSGS_NoneTSE:     return "NoneTSE";
407             case ePSGS_SlimTSE:     return "SlimTSE";
408             case ePSGS_SmartTSE:    return "SmartTSE";
409             case ePSGS_WholeTSE:    return "WholeTSE";
410             case ePSGS_OrigTSE:     return "OrigTSE";
411             case ePSGS_UnknownTSE:  return "UnknownTSE";
412             default: break;
413         }
414         return "UnknownOptionValue";
415     }
416 
417 
418     EPSGS_TSEOption         m_TSEOption;
419     EPSGS_CacheAndDbUse     m_UseCache;
420     string                  m_ClientId;
421 
422     // Both cases: by seq_id/seq_id_type and by sat/sat_key store the
423     // required blob id here.
424     // When the seq_id/seq_id_type is resolved to sat/sat_key the m_BlobId
425     // is populated
426     SPSGS_BlobId            m_BlobId;
427 
428     // Processing fields: they are not coming from the client and used while
429     // the request is in process.
430     // Helps to avoid unnecessery cache updates;
431     // - only the one who added will remove
432     // - only the one who added will set completed once
433     bool                    m_ExcludeBlobCacheAdded;
434     bool                    m_ExcludeBlobCacheCompleted;
435 
SPSGS_BlobRequestBaseSPSGS_BlobRequestBase436     SPSGS_BlobRequestBase(EPSGS_TSEOption  tse_option,
437                           EPSGS_CacheAndDbUse  use_cache,
438                           const string &  client_id,
439                           int  hops,
440                           EPSGS_Trace  trace,
441                           const vector<string> &  enabled_processors,
442                           const vector<string> &  disabled_processors,
443                           const TPSGS_HighResolutionTimePoint &  start_timestamp) :
444         SPSGS_RequestBase(hops, trace,
445                           enabled_processors, disabled_processors,
446                           start_timestamp),
447         m_TSEOption(tse_option),
448         m_UseCache(use_cache),
449         m_ClientId(client_id),
450         m_ExcludeBlobCacheAdded(false),
451         m_ExcludeBlobCacheCompleted(false)
452     {}
453 
SPSGS_BlobRequestBaseSPSGS_BlobRequestBase454     SPSGS_BlobRequestBase() :
455         m_TSEOption(ePSGS_UnknownTSE),
456         m_UseCache(ePSGS_UnknownUseCache),
457         m_ExcludeBlobCacheAdded(false),
458         m_ExcludeBlobCacheCompleted(false)
459     {}
460 
461     SPSGS_BlobRequestBase(const SPSGS_BlobRequestBase &) = default;
462     SPSGS_BlobRequestBase(SPSGS_BlobRequestBase &&) = default;
463     SPSGS_BlobRequestBase &  operator=(const SPSGS_BlobRequestBase &) = default;
464     SPSGS_BlobRequestBase &  operator=(SPSGS_BlobRequestBase &&) = default;
465 };
466 
467 
468 // Blob by seq_id request (eBlobBySeqIdRequest)
469 struct SPSGS_BlobBySeqIdRequest : public SPSGS_BlobRequestBase
470 {
471     string                          m_SeqId;
472     int                             m_SeqIdType;
473     vector<string>                  m_ExcludeBlobs;
474     EPSGS_AccSubstitutioOption      m_AccSubstOption;
475     bool                            m_AutoBlobSkipping;
476 
SPSGS_BlobBySeqIdRequestSPSGS_BlobBySeqIdRequest477     SPSGS_BlobBySeqIdRequest(const string &  seq_id,
478                              int  seq_id_type,
479                              vector<string> &  exclude_blobs,
480                              EPSGS_TSEOption  tse_option,
481                              EPSGS_CacheAndDbUse  use_cache,
482                              EPSGS_AccSubstitutioOption  subst_option,
483                              bool  auto_blob_skipping,
484                              const string &  client_id,
485                              int  hops,
486                              EPSGS_Trace  trace,
487                              const vector<string> &  enabled_processors,
488                              const vector<string> &  disabled_processors,
489                              const TPSGS_HighResolutionTimePoint &  start_timestamp) :
490         SPSGS_BlobRequestBase(tse_option, use_cache, client_id, hops, trace,
491                               enabled_processors, disabled_processors,
492                               start_timestamp),
493         m_SeqId(seq_id),
494         m_SeqIdType(seq_id_type),
495         m_ExcludeBlobs(move(exclude_blobs)),
496         m_AccSubstOption(subst_option),
497         m_AutoBlobSkipping(auto_blob_skipping)
498     {}
499 
SPSGS_BlobBySeqIdRequestSPSGS_BlobBySeqIdRequest500     SPSGS_BlobBySeqIdRequest() :
501         m_SeqIdType(-1),
502         m_AccSubstOption(ePSGS_UnknownAccSubstitution),
503         m_AutoBlobSkipping(true)
504     {}
505 
GetRequestTypeSPSGS_BlobBySeqIdRequest506     virtual CPSGS_Request::EPSGS_Type GetRequestType(void) const
507     {
508         return CPSGS_Request::ePSGS_BlobBySeqIdRequest;
509     }
510 
GetNameSPSGS_BlobBySeqIdRequest511     virtual string GetName(void) const
512     {
513         return "ID/get";
514     }
515 
516     virtual CJsonNode Serialize(void) const;
517 
518     SPSGS_BlobBySeqIdRequest(const SPSGS_BlobBySeqIdRequest &) = default;
519     SPSGS_BlobBySeqIdRequest(SPSGS_BlobBySeqIdRequest &&) = default;
520     SPSGS_BlobBySeqIdRequest &  operator=(const SPSGS_BlobBySeqIdRequest &) = default;
521     SPSGS_BlobBySeqIdRequest &  operator=(SPSGS_BlobBySeqIdRequest &&) = default;
522 };
523 
524 
525 // Blob by sat/sat_key request (eBlobBySatSatKeyRequest)
526 struct SPSGS_BlobBySatSatKeyRequest : public SPSGS_BlobRequestBase
527 {
528     CBlobRecord::TTimestamp         m_LastModified;
529 
SPSGS_BlobBySatSatKeyRequestSPSGS_BlobBySatSatKeyRequest530     SPSGS_BlobBySatSatKeyRequest(const SPSGS_BlobId &  blob_id,
531                                  CBlobRecord::TTimestamp  last_modified,
532                                  EPSGS_TSEOption  tse_option,
533                                  EPSGS_CacheAndDbUse  use_cache,
534                                  const string &  client_id,
535                                  int  hops,
536                                  EPSGS_Trace  trace,
537                                  const vector<string> &  enabled_processors,
538                                  const vector<string> &  disabled_processors,
539                                  const TPSGS_HighResolutionTimePoint &  start_timestamp) :
540         SPSGS_BlobRequestBase(tse_option, use_cache, client_id, hops, trace,
541                               enabled_processors, disabled_processors,
542                               start_timestamp),
543         m_LastModified(last_modified)
544     {
545         m_BlobId = blob_id;
546     }
547 
SPSGS_BlobBySatSatKeyRequestSPSGS_BlobBySatSatKeyRequest548     SPSGS_BlobBySatSatKeyRequest() :
549         m_LastModified(INT64_MIN)
550     {}
551 
GetRequestTypeSPSGS_BlobBySatSatKeyRequest552     virtual CPSGS_Request::EPSGS_Type GetRequestType(void) const
553     {
554         return CPSGS_Request::ePSGS_BlobBySatSatKeyRequest;
555     }
556 
GetNameSPSGS_BlobBySatSatKeyRequest557     virtual string GetName(void) const
558     {
559         return "ID/getblob";
560     }
561 
562     virtual CJsonNode Serialize(void) const;
563 
564     SPSGS_BlobBySatSatKeyRequest(const SPSGS_BlobBySatSatKeyRequest &) = default;
565     SPSGS_BlobBySatSatKeyRequest(SPSGS_BlobBySatSatKeyRequest &&) = default;
566     SPSGS_BlobBySatSatKeyRequest &  operator=(const SPSGS_BlobBySatSatKeyRequest &) = default;
567     SPSGS_BlobBySatSatKeyRequest &  operator=(SPSGS_BlobBySatSatKeyRequest &&) = default;
568 };
569 
570 
571 struct SPSGS_AnnotRequest : public SPSGS_RequestBase
572 {
SPSGS_AnnotRequestSPSGS_AnnotRequest573     SPSGS_AnnotRequest(const string &  seq_id,
574                        int  seq_id_type,
575                        vector<string> &  names,
576                        EPSGS_CacheAndDbUse  use_cache,
577                        SPSGS_BlobRequestBase::EPSGS_TSEOption  tse_option,
578                        int  hops,
579                        EPSGS_Trace  trace,
580                        const vector<string> &  enabled_processors,
581                        const vector<string> &  disabled_processors,
582                        const TPSGS_HighResolutionTimePoint &  start_timestamp) :
583         SPSGS_RequestBase(hops, trace,
584                           enabled_processors, disabled_processors,
585                           start_timestamp),
586         m_SeqId(seq_id),
587         m_SeqIdType(seq_id_type),
588         m_Names(move(names)),
589         m_UseCache(use_cache),
590         m_TSEOption(tse_option),
591         m_Lock(false),
592         m_ProcessedBioseqInfo(kUnknownPriority)
593     {}
594 
SPSGS_AnnotRequestSPSGS_AnnotRequest595     SPSGS_AnnotRequest() :
596         m_SeqIdType(-1),
597         m_UseCache(ePSGS_UnknownUseCache),
598         m_TSEOption(SPSGS_BlobRequestBase::EPSGS_TSEOption::ePSGS_UnknownTSE),
599         m_Lock(false),
600         m_ProcessedBioseqInfo(kUnknownPriority)
601     {}
602 
603     SPSGS_AnnotRequest(const SPSGS_AnnotRequest &) = default;
604     SPSGS_AnnotRequest(SPSGS_AnnotRequest &&) = default;
605     SPSGS_AnnotRequest &  operator=(const SPSGS_AnnotRequest &) = default;
606     SPSGS_AnnotRequest &  operator=(SPSGS_AnnotRequest &&) = default;
607 
GetRequestTypeSPSGS_AnnotRequest608     virtual CPSGS_Request::EPSGS_Type GetRequestType(void) const
609     {
610         return CPSGS_Request::ePSGS_AnnotationRequest;
611     }
612 
GetNameSPSGS_AnnotRequest613     virtual string GetName(void) const
614     {
615         return "ID/get_na";
616     }
617 
618     virtual CJsonNode Serialize(void) const;
619 
620     // Facilities to work with the list of already processed names
621 
622     // If the given name is already in the list then the priority
623     // of the processor which has registered it before is returned
624     // If the given name is not in the list then kUnknownPriority constant is
625     // returned.
626     // The highest priority will be stored together with the name.
627     TProcessorPriority RegisterProcessedName(TProcessorPriority  priority,
628                                              const string &  name);
629 
630     // If bioseq info has already been sent then the priority of the processor
631     // which sent it will be returned. Otherwise kUnknownPriority constant is
632     // returned.
633     // The highest priority of all the calls will be stored.
634     TProcessorPriority RegisterBioseqInfo(TProcessorPriority  priority);
635 
636     // Names which have not been processed by a processor which priority
637     // is higher than given
638     vector<string> GetNotProcessedName(TProcessorPriority  priority);
639 
640     vector<pair<TProcessorPriority, string>>  GetProcessedNames(void) const;
641 
642 public:
643     string                                      m_SeqId;
644     int                                         m_SeqIdType;
645     vector<string>                              m_Names;
646     EPSGS_CacheAndDbUse                         m_UseCache;
647     SPSGS_BlobRequestBase::EPSGS_TSEOption      m_TSEOption;
648 
649 private:
650     // A list of names which have been already processed by some processors
651     mutable atomic<bool>                        m_Lock;
652     TProcessorPriority                          m_ProcessedBioseqInfo;
653     vector<pair<TProcessorPriority, string>>    m_Processed;
654 };
655 
656 
657 struct SPSGS_TSEChunkRequest : public SPSGS_RequestBase
658 {
659     int64_t                             m_Id2Chunk;
660     string                              m_Id2Info;
661     EPSGS_CacheAndDbUse                 m_UseCache;
662 
SPSGS_TSEChunkRequestSPSGS_TSEChunkRequest663     SPSGS_TSEChunkRequest(int64_t  id2_chunk,
664                           const string &  id2_info,
665                           EPSGS_CacheAndDbUse  use_cache,
666                           int  hops,
667                           EPSGS_Trace  trace,
668                           const vector<string> &  enabled_processors,
669                           const vector<string> &  disabled_processors,
670                           const TPSGS_HighResolutionTimePoint &  start_timestamp) :
671         SPSGS_RequestBase(hops, trace,
672                           enabled_processors, disabled_processors,
673                           start_timestamp),
674         m_Id2Chunk(id2_chunk),
675         m_Id2Info(id2_info),
676         m_UseCache(use_cache)
677     {}
678 
SPSGS_TSEChunkRequestSPSGS_TSEChunkRequest679     SPSGS_TSEChunkRequest() :
680         m_Id2Chunk(INT64_MIN),
681         m_UseCache(ePSGS_UnknownUseCache)
682     {}
683 
GetRequestTypeSPSGS_TSEChunkRequest684     virtual CPSGS_Request::EPSGS_Type GetRequestType(void) const
685     {
686         return CPSGS_Request::ePSGS_TSEChunkRequest;
687     }
688 
GetNameSPSGS_TSEChunkRequest689     virtual string GetName(void) const
690     {
691         return "ID/get_tse_chunk";
692     }
693 
694     virtual CJsonNode Serialize(void) const;
695 
696     SPSGS_TSEChunkRequest(const SPSGS_TSEChunkRequest &) = default;
697     SPSGS_TSEChunkRequest(SPSGS_TSEChunkRequest &&) = default;
698     SPSGS_TSEChunkRequest &  operator=(const SPSGS_TSEChunkRequest &) = default;
699     SPSGS_TSEChunkRequest &  operator=(SPSGS_TSEChunkRequest &&) = default;
700 };
701 
702 
703 #endif  // PSGS_REQUEST__HPP
704 
705