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

Go to the SVN repository for this file.

1 /* $Id: netschedule_api_expt.cpp 62891 2014-05-14 18:53:54Z kazimird $
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  * Author: Maxim Didenko
27  *
28  * File Description:
29  * Implementation of NetSchedule API.
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 
35 #include <util/static_map.hpp>
37 
38 
40 
43  {"eAccessDenied", CNetScheduleException::eAccessDenied},
44  {"eAffinityNotFound", CNetScheduleException::eAffinityNotFound},
45  {"eAuthenticationError", CNetScheduleException::eAuthenticationError},
46  {"eCommandIsNotAllowed", CNetScheduleException::eCommandIsNotAllowed},
47  {"eDataTooLong", CNetScheduleException::eDataTooLong},
48  {"eDuplicateName", CNetScheduleException::eDuplicateName},
49  {"eGroupNotFound", CNetScheduleException::eGroupNotFound},
50  {"eInternalError", CNetScheduleException::eInternalError},
51  {"eInvalidAuthToken", CNetScheduleException::eInvalidAuthToken},
52  {"eInvalidClient", CNetScheduleException::eInvalidClient},
53  {"eInvalidJobStatus", CNetScheduleException::eInvalidJobStatus},
54  {"eInvalidParameter", CNetScheduleException::eInvalidParameter},
55  {"eJobNotFound", CNetScheduleException::eJobNotFound},
56  {"eKeyFormatError", CNetScheduleException::eKeyFormatError},
57  {"eObsoleteCommand", CNetScheduleException::eObsoleteCommand},
58  {"ePrefAffExpired", CNetScheduleException::ePrefAffExpired},
59  {"eProtocolSyntaxError", CNetScheduleException::eProtocolSyntaxError},
60  {"eShuttingDown", CNetScheduleException::eShuttingDown},
61  {"eSubmitsDisabled", CNetScheduleException::eSubmitsDisabled},
62  {"eTooManyPendingJobs", CNetScheduleException::eTooManyPendingJobs},
63  {"eTooManyPreferredAffinities", CNetScheduleException::eTooManyPreferredAffinities},
64  {"eTryAgain", CNetScheduleException::eTryAgain},
65  {"eUnknownQueue", CNetScheduleException::eUnknownQueue},
66  {"eUnknownQueueClass", CNetScheduleException::eUnknownQueueClass},
67  {"eUnknownService", CNetScheduleException::eUnknownService},
68 };
71 
73 {
74  TNSExceptionMap::const_iterator it = s_NSExceptionMap.find(name.c_str());
75  if (it == s_NSExceptionMap.end())
76  return CException::eInvalid;
77  return it->second;
78 }
79 
81 {
82  return GetErrCodeString(GetErrCode());
83 }
84 
86  CException::TErrCode err_code)
87 {
88  switch (err_code) {
89  case eInternalError: return "eInternalError";
90  case eProtocolSyntaxError: return "eProtocolSyntaxError";
91  case eAuthenticationError: return "eAuthenticationError";
92  case eKeyFormatError: return "eKeyFormatError";
93  case eJobNotFound: return "eJobNotFound";
94  case eGroupNotFound: return "eGroupNotFound";
95  case eAffinityNotFound: return "eAffinityNotFound";
96  case eInvalidJobStatus: return "eInvalidJobStatus";
97  case eUnknownQueue: return "eUnknownQueue";
98  case eUnknownQueueClass: return "eUnknownQueueClass";
99  case eUnknownService: return "eUnknownService";
100  case eTooManyPendingJobs: return "eTooManyPendingJobs";
101  case eDataTooLong: return "eDataTooLong";
102  case eInvalidClient: return "eInvalidClient";
104  return "eClientDataVersionMismatch";
105  case eAccessDenied: return "eAccessDenied";
106  case eSubmitsDisabled: return "eSubmitsDisabled";
107  case eShuttingDown: return "eShuttingDown";
108  case eDuplicateName: return "eDuplicateName";
109  case eObsoleteCommand: return "eObsoleteCommand";
110  case eInvalidParameter: return "eInvalidParameter";
111  case eInvalidAuthToken: return "eInvalidAuthToken";
113  return "eTooManyPreferredAffinities";
114  case ePrefAffExpired: return "ePrefAffExpired";
115  case eTryAgain: return "eTryAgain";
116  default: return "eInvalid";
117  }
118 }
119 
121 {
122  switch (GetErrCode()) {
123  default: /* Including eInternalError */ return 500;
124  case eProtocolSyntaxError: return 400;
125  case eAuthenticationError: return 401;
126  case eKeyFormatError: return 400;
127  case eJobNotFound: return 404;
128  case eGroupNotFound: return 404;
129  case eAffinityNotFound: return 404;
130  case eInvalidJobStatus: return 409;
131  case eUnknownQueue: return 404;
132  case eUnknownQueueClass: return 404;
133  case eUnknownService: return 404;
134  case eTooManyPendingJobs: return 503;
135  case eDataTooLong: return 413;
136  case eInvalidClient: return 400;
137  case eClientDataVersionMismatch: return 304;
138  case eAccessDenied: return 401;
139  case eSubmitsDisabled: return 503;
140  case eShuttingDown: return 400;
141  case eDuplicateName: return 409;
142  case eObsoleteCommand: return 501;
143  case eInvalidParameter: return 400;
144  case eInvalidAuthToken: return 401;
145  case eTooManyPreferredAffinities: return 503;
146  case ePrefAffExpired: return 404;
147  case eTryAgain: return 503;
148  }
149 }
150 
152  CException::TErrCode err_code)
153 {
154  switch (err_code) {
155  case eInternalError:
156  return "NetSchedule server internal error";
158  return "NetSchedule server cannot parse the client command";
160  return "NetSchedule server received incomplete client authentication";
161  case eJobNotFound:
162  return "The job is not found";
163  case eGroupNotFound:
164  return "The job group is not found";
165  case eAffinityNotFound:
166  return "The job affinity is not found";
167  case eInvalidJobStatus:
168  return "The job status does not support the requested operation";
169  case eUnknownQueue:
170  return "The queue is not found";
171  case eUnknownQueueClass:
172  return "The queue class is not found";
173  case eUnknownService:
174  return "The service is not found";
175  case eDataTooLong:
176  return "The provided data are too long";
177  case eInvalidClient:
178  return "The command requires a non-anonymous client";
180  return "The client data cannot be set because the data "
181  "version doesn't match";
182  case eAccessDenied:
183  return "Not enough privileges to perform the requested operation";
184  case eSubmitsDisabled:
185  return "Cannot submit a job because submits are disabled";
186  case eShuttingDown:
187  return "NetSchedule refuses command execution because "
188  "it is shutting down";
189  case eDuplicateName:
190  return "A dynamic queue cannot be created because "
191  "another queue with the same name already exists";
192  case eObsoleteCommand:
193  return "The command is obsolete and will be ignored";
194  case eInvalidParameter:
195  return "Invalid value for a command argument";
196  case eInvalidAuthToken:
197  return "The requested job operation is rejected "
198  "because the provided authorization token is invalid";
200  return "There is no room for a new preferred affinity";
201  case ePrefAffExpired:
202  return "The preferred affinities expired and were reset "
203  "because the worker node did not communicate within "
204  "the timeout. The command execution is refused.";
205  case eTryAgain:
206  return "BerkleyDB has too many incomplete transactions at the moment. "
207  "Try again later.";
208  default:
209  return GetErrCodeString(err_code);
210  }
211 }
212 
class CStaticArrayMap<> provides access to a static array in much the same way as CStaticArraySet<>,...
Definition: static_map.hpp:175
TBase::const_iterator const_iterator
Definition: static_map.hpp:179
TErrCode GetErrCode(void) const
Get error code.
Definition: ncbiexpt.cpp:453
int TErrCode
Definition: ncbiexpt.hpp:889
@ eInvalid
To be used ONLY as a return value; please, NEVER throw an exception with this code.
Definition: ncbiexpt.hpp:885
unsigned ErrCodeToHTTPStatusCode() const
static const char * GetErrCodeDescription(CException::TErrCode err_code)
virtual const char * GetErrCodeString() const override
Get error code interpreted as text.
static CException::TErrCode GetCode(const string &name)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
CStaticArrayMap< const char *, CException::TErrCode, PNocase_CStr > TNSExceptionMap
SStaticPair< const char *, CException::TErrCode > TExceptionMapElem
DEFINE_STATIC_ARRAY_MAP(TNSExceptionMap, s_NSExceptionMap, s_NSExceptionArray)
static const TExceptionMapElem s_NSExceptionArray[]
Template structure SStaticPair is simlified replacement of STL pair<> Main reason of introducing this...
Definition: static_set.hpp:60
Modified on Tue Nov 28 02:30:08 2023 by modify_doxy.py rev. 669887