1 #ifndef NETSCHEDULE_QUEUE_PARAMETERS__HPP
2 #define NETSCHEDULE_QUEUE_PARAMETERS__HPP
3
4 /* $Id: ns_queue_parameters.hpp 601644 2020-02-11 19:47:28Z satskyse $
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: Anatoliy Kuznetsov, Victor Joukov
30 *
31 * File Description: Queue parameters
32 *
33 */
34
35 #include <string>
36 #include <connect/services/json_over_uttp.hpp>
37
38 #include "ns_precise_time.hpp"
39
40
41 BEGIN_NCBI_SCOPE
42
43 class IRegistry;
44
45
46 // Queue parameters
47 struct SQueueParameters
48 {
49 SQueueParameters();
50
51 // Returns true if evrything is OK with the linked sections
52 bool ReadQueueClass(const IRegistry & reg, const string & sname,
53 vector<string> & warnings);
54 // Returns true if evrything is OK with the linked sections
55 bool ReadQueue(const IRegistry & reg, const string & sname,
56 const map<string, SQueueParameters,
57 PNocase> & queue_classes,
58 vector<string> & warnings);
59
60 // Transit parameters; stored in memory and in the DB but not present
61 // in the config files.
62 int kind; // 0 - static, 1 - dynamic
63 bool delete_request;
64
65 // General parameters, reconfigurable at run time
66 string qclass;
67 CNSPreciseTime timeout;
68 CNSPreciseTime notif_hifreq_interval;
69 CNSPreciseTime notif_hifreq_period;
70 unsigned int notif_lofreq_mult;
71 CNSPreciseTime notif_handicap;
72 unsigned int dump_buffer_size;
73 unsigned int dump_client_buffer_size;
74 unsigned int dump_aff_buffer_size;
75 unsigned int dump_group_buffer_size;
76 CNSPreciseTime run_timeout;
77 CNSPreciseTime read_timeout;
78 string program_name;
79 unsigned int failed_retries;
80 unsigned int read_failed_retries;
81 unsigned int max_jobs_per_client;
82 CNSPreciseTime blacklist_time;
83 CNSPreciseTime read_blacklist_time;
84 unsigned int max_input_size;
85 unsigned int max_output_size;
86 string subm_hosts;
87 string wnode_hosts;
88 string reader_hosts;
89 CNSPreciseTime wnode_timeout;
90 CNSPreciseTime reader_timeout;
91 CNSPreciseTime pending_timeout;
92 CNSPreciseTime max_pending_wait_timeout;
93 CNSPreciseTime max_pending_read_wait_timeout;
94 string description;
95 bool scramble_job_keys;
96 CNSPreciseTime client_registry_timeout_worker_node;
97 unsigned int client_registry_min_worker_nodes;
98 CNSPreciseTime client_registry_timeout_admin;
99 unsigned int client_registry_min_admins;
100 CNSPreciseTime client_registry_timeout_submitter;
101 unsigned int client_registry_min_submitters;
102 CNSPreciseTime client_registry_timeout_reader;
103 unsigned int client_registry_min_readers;
104 CNSPreciseTime client_registry_timeout_unknown;
105 unsigned int client_registry_min_unknowns;
106 map<string,
107 string> linked_sections;
108
109 // These fields are not for reading/writing/printing
110 // It is used for QINF2 command which should print this status
111 // together with the queue parameters. So it is handy to have it here and
112 // set when parameters are retrieved.
113 bool refuse_submits;
114 int pause_status;
115 size_t max_aff_slots;
116 size_t aff_slots_used;
117 size_t max_group_slots;
118 size_t group_slots_used;
119 size_t max_scope_slots;
120 size_t scope_slots_used;
121 size_t clients;
122 size_t groups;
123 size_t gc_backlog;
124 size_t notif_count;
125
126 public:
127 CJsonNode Diff(const SQueueParameters & other,
128 bool include_class_cmp,
129 bool include_description) const;
130 string GetPrintableParameters(bool include_class,
131 bool url_encoded) const;
132 string ConfigSection(bool is_class) const;
133 CNSPreciseTime CalculateRuntimePrecision(void) const;
134
135
136 // Parameters are always: registry and section name
137 string ReadClass(const IRegistry &, const string &,
138 vector<string> &);
139 CNSPreciseTime ReadTimeout(const IRegistry &, const string &,
140 vector<string> &);
141 CNSPreciseTime ReadNotifHifreqInterval(const IRegistry &, const string &,
142 vector<string> &);
143 CNSPreciseTime ReadNotifHifreqPeriod(const IRegistry &, const string &,
144 vector<string> &);
145 unsigned int ReadNotifLofreqMult(const IRegistry &, const string &,
146 vector<string> &);
147 CNSPreciseTime ReadNotifHandicap(const IRegistry &, const string &,
148 vector<string> &);
149 unsigned int ReadDumpBufferSize(const IRegistry &, const string &,
150 vector<string> &);
151 unsigned int ReadDumpClientBufferSize(const IRegistry &, const string &,
152 vector<string> &);
153 unsigned int ReadDumpAffBufferSize(const IRegistry &, const string &,
154 vector<string> &);
155 unsigned int ReadDumpGroupBufferSize(const IRegistry &, const string &,
156 vector<string> &);
157 CNSPreciseTime ReadRunTimeout(const IRegistry &, const string &,
158 vector<string> &);
159 CNSPreciseTime ReadReadTimeout(const IRegistry &, const string &,
160 vector<string> &);
161 string ReadProgram(const IRegistry &, const string &,
162 vector<string> &);
163 unsigned int ReadFailedRetries(const IRegistry &, const string &,
164 vector<string> &);
165 unsigned int ReadReadFailedRetries(const IRegistry &, const string &,
166 vector<string> &,
167 unsigned int failed_retries);
168 unsigned int ReadMaxJobsPerClient(const IRegistry &, const string &,
169 vector<string> &);
170 CNSPreciseTime ReadBlacklistTime(const IRegistry &, const string &,
171 vector<string> &);
172 CNSPreciseTime ReadReadBlacklistTime(const IRegistry &, const string &,
173 vector<string> &,
174 const CNSPreciseTime &);
175 unsigned int ReadMaxInputSize(const IRegistry &, const string &,
176 vector<string> &);
177 unsigned int ReadMaxOutputSize(const IRegistry &, const string &,
178 vector<string> &);
179 string ReadSubmHosts(const IRegistry &, const string &,
180 vector<string> &);
181 string ReadWnodeHosts(const IRegistry &, const string &,
182 vector<string> &);
183 string ReadReaderHosts(const IRegistry &, const string &,
184 vector<string> &);
185 CNSPreciseTime ReadWnodeTimeout(const IRegistry &, const string &,
186 vector<string> &);
187 CNSPreciseTime ReadReaderTimeout(const IRegistry &, const string &,
188 vector<string> &);
189 CNSPreciseTime ReadPendingTimeout(const IRegistry &, const string &,
190 vector<string> &);
191 CNSPreciseTime ReadMaxPendingWaitTimeout(const IRegistry &,
192 const string &,
193 vector<string> &);
194 CNSPreciseTime ReadMaxPendingReadWaitTimeout(const IRegistry &,
195 const string &,
196 vector<string> &);
197 string ReadDescription(const IRegistry &, const string &,
198 vector<string> &);
199 bool ReadScrambleJobKeys(const IRegistry &, const string &,
200 vector<string> &);
201 CNSPreciseTime ReadClientRegistryTimeoutWorkerNode(const IRegistry &,
202 const string &,
203 vector<string> &);
204 unsigned int ReadClientRegistryMinWorkerNodes(const IRegistry &,
205 const string &,
206 vector<string> &);
207 CNSPreciseTime ReadClientRegistryTimeoutAdmin(const IRegistry &,
208 const string &,
209 vector<string> &);
210 unsigned int ReadClientRegistryMinAdmins(const IRegistry &,
211 const string &,
212 vector<string> &);
213 CNSPreciseTime ReadClientRegistryTimeoutSubmitter(const IRegistry &,
214 const string &,
215 vector<string> &);
216 unsigned int ReadClientRegistryMinSubmitters(const IRegistry &,
217 const string &,
218 vector<string> &);
219 CNSPreciseTime ReadClientRegistryTimeoutReader(const IRegistry &,
220 const string &,
221 vector<string> &);
222 unsigned int ReadClientRegistryMinReaders(const IRegistry &,
223 const string &,
224 vector<string> &);
225 CNSPreciseTime ReadClientRegistryTimeoutUnknown(const IRegistry &,
226 const string &,
227 vector<string> &);
228 unsigned int ReadClientRegistryMinUnknowns(const IRegistry &,
229 const string &,
230 vector<string> &);
231 map<string,
232 string> ReadLinkedSections(const IRegistry &,
233 const string & sname,
234 vector<string> & warnings,
235 bool * linked_sections_ok);
236 };
237
238
239 template<typename TValueType>
AddParameterToDiff(CJsonNode & output,const string & param_name,const TValueType & value_from,const TValueType & value_to)240 void AddParameterToDiff(CJsonNode & output,
241 const string & param_name,
242 const TValueType & value_from,
243 const TValueType & value_to)
244 {
245 CJsonNode values = CJsonNode::NewArrayNode();
246 values.AppendString(to_string(value_from));
247 values.AppendString(to_string(value_to));
248 output.SetByKey(param_name, values);
249 }
250
251 template<> inline
AddParameterToDiff(CJsonNode & output,const string & param_name,const string & value_from,const string & value_to)252 void AddParameterToDiff(CJsonNode & output,
253 const string & param_name,
254 const string & value_from,
255 const string & value_to)
256 {
257 CJsonNode values = CJsonNode::NewArrayNode();
258 values.AppendString(NStr::PrintableString(value_from));
259 values.AppendString(NStr::PrintableString(value_to));
260 output.SetByKey(param_name, values);
261 }
262
263 template<> inline
AddParameterToDiff(CJsonNode & output,const string & param_name,const bool & value_from,const bool & value_to)264 void AddParameterToDiff(CJsonNode & output,
265 const string & param_name,
266 const bool & value_from,
267 const bool & value_to)
268 {
269 CJsonNode values = CJsonNode::NewArrayNode();
270 values.AppendBoolean(value_from);
271 values.AppendBoolean(value_to);
272 output.SetByKey(param_name, values);
273 }
274
275 template<> inline
AddParameterToDiff(CJsonNode & output,const string & param_name,const double & value_from,const double & value_to)276 void AddParameterToDiff(CJsonNode & output,
277 const string & param_name,
278 const double & value_from,
279 const double & value_to)
280 {
281 CJsonNode values = CJsonNode::NewArrayNode();
282 values.AppendDouble(value_from);
283 values.AppendDouble(value_to);
284 output.SetByKey(param_name, values);
285 }
286
287 template<> inline
AddParameterToDiff(CJsonNode & output,const string & param_name,const long & value_from,const long & value_to)288 void AddParameterToDiff(CJsonNode & output,
289 const string & param_name,
290 const long & value_from,
291 const long & value_to)
292 {
293 CJsonNode values = CJsonNode::NewArrayNode();
294 values.AppendInteger(value_from);
295 values.AppendInteger(value_to);
296 output.SetByKey(param_name, values);
297 }
298
299
300
301 END_NCBI_SCOPE
302
303 #endif
304
305