bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
FONcRequestHandler.cc
1// FONcRequestHandler.cc
2
3// This file is part of bes, A C++ back-end server implementation framework
4// for the OPeNDAP Data Access Protocol.
5
6// Copyright (c) 2004,2005 University Corporation for Atmospheric Research
7// Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact University Corporation for Atmospheric Research at
24// 3080 Center Green Drive, Boulder, CO 80301
25
26// (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27// Please read the full copyright statement in the file COPYRIGHT_UCAR.
28//
29// Authors:
30// pwest Patrick West <pwest@ucar.edu>
31// jgarcia Jose Garcia <jgarcia@ucar.edu>
32
33#include "config.h"
34
35#include <string>
36#include <sstream>
37
38#include <BESResponseHandler.h>
39#include <BESResponseNames.h>
40#include <BESVersionInfo.h>
41#include <BESDataNames.h>
42#include <BESDataNames.h>
43#include <TheBESKeys.h>
44#include <BESDebug.h>
45#include <BESUtil.h>
46
47#include "FONcRequestHandler.h"
48#include "FONcNames.h"
49
50std::string FONcRequestHandler::temp_dir;
51bool FONcRequestHandler::byte_to_short;
52bool FONcRequestHandler::use_compression;
53bool FONcRequestHandler::use_shuffle;
54unsigned long long FONcRequestHandler::chunk_size;
55bool FONcRequestHandler::classic_model;
56bool FONcRequestHandler::reduce_dim;
57bool FONcRequestHandler::no_global_attrs;
58unsigned long long FONcRequestHandler::request_max_size_kb;
59bool FONcRequestHandler::nc3_classic_format;
60
61using namespace std;
62
72static void read_key_value(const string &key_name, bool &key, const bool default_value)
73{
74 bool key_found = false;
75 string value;
76 TheBESKeys::TheKeys()->get_value(key_name, value, key_found);
77 // 'key' holds the string value at this point if key_found is true
78 if (key_found) {
79 value = BESUtil::lowercase(value);
80 key = (value == "true" || value == "yes");
81 }
82 else {
83 key = default_value;
84 }
85}
86
87static void read_key_value(const string &key_name, string &key, const string &default_value)
88{
89 bool key_found = false;
90 TheBESKeys::TheKeys()->get_value(key_name, key, key_found);
91 // 'key' holds the string value at this point if key_found is true
92 if (key_found) {
94 }
95 else {
96 key = default_value;
97 }
98}
99
100static void read_key_value(const string &key_name, size_t &key, const int default_value)
101{
102 bool key_found = false;
103 string value;
104 TheBESKeys::TheKeys()->get_value(key_name, value, key_found);
105 // 'key' holds the string value at this point if key_found is true
106 if (key_found) {
107 istringstream iss(value);
108 iss >> key;
109 // if (iss.eof() || iss.bad() || iss.fail()) key = default_value;
110 if (iss.bad() || iss.fail()) key = default_value;
111 }
112 else {
113 key = default_value;
114 }
115}
116
117static void read_key_value(const string &key_name, unsigned long long &key, const unsigned long long default_value)
118{
119 bool key_found = false;
120 string value;
121 TheBESKeys::TheKeys()->get_value(key_name, value, key_found);
122 // 'key' holds the string value at this point if key_found is true
123 if (key_found) {
124 try {
125 key = stoull(value);
126 }
127 catch (const std::invalid_argument& ia) {
128 key = default_value;
129 }
130 }
131 else {
132 key = default_value;
133 }
134}
135
136
146 : BESRequestHandler( name )
147{
150
151 if (FONcRequestHandler::temp_dir.empty()) {
152 read_key_value(FONC_TEMP_DIR_KEY, FONcRequestHandler::temp_dir, FONC_TEMP_DIR);
153 }
154
155 // Not currently used. jhrg 11/30/15
156 read_key_value(FONC_BYTE_TO_SHORT_KEY, FONcRequestHandler::byte_to_short, FONC_BYTE_TO_SHORT);
157
158 read_key_value(FONC_USE_COMP_KEY, FONcRequestHandler::use_compression, FONC_USE_COMP);
159
160 read_key_value(FONC_USE_SHUFFLE_KEY, FONcRequestHandler::use_shuffle, FONC_USE_SHUFFLE);
161
162 read_key_value(FONC_CHUNK_SIZE_KEY, FONcRequestHandler::chunk_size, FONC_CHUNK_SIZE);
163
164 read_key_value(FONC_CLASSIC_MODEL_KEY, FONcRequestHandler::classic_model, FONC_CLASSIC_MODEL);
165
166 read_key_value(FONC_REDUCE_DIM_KEY, FONcRequestHandler::reduce_dim, FONC_REDUCE_DIM);
167
168 read_key_value(FONC_NO_GLOBAL_ATTRS_KEY, FONcRequestHandler::no_global_attrs, FONC_NO_GLOBAL_ATTRS);
169
170 read_key_value(FONC_REQUEST_MAX_SIZE_KB_KEY, FONcRequestHandler::request_max_size_kb, FONC_REQUEST_MAX_SIZE_KB);
171
172 read_key_value(FONC_NC3_CLASSIC_FORMAT_KEY, FONcRequestHandler::nc3_classic_format, FONC_NC3_CLASSIC_FORMAT);
173
174 BESDEBUG("fonc", "FONcRequestHandler::temp_dir: " << FONcRequestHandler::temp_dir << endl);
175 BESDEBUG("fonc", "FONcRequestHandler::byte_to_short: " << FONcRequestHandler::byte_to_short << endl);
176 BESDEBUG("fonc", "FONcRequestHandler::use_compression: " << FONcRequestHandler::use_compression << endl);
177 BESDEBUG("fonc", "FONcRequestHandler::use_shuffle: " << FONcRequestHandler::use_shuffle << endl);
178 BESDEBUG("fonc", "FONcRequestHandler::chunk_size: " << FONcRequestHandler::chunk_size << endl);
179 BESDEBUG("fonc", "FONcRequestHandler::classic_model: " << FONcRequestHandler::classic_model << endl);
180 BESDEBUG("fonc", "FONcRequestHandler::reduce_dim: " << FONcRequestHandler::reduce_dim << endl);
181 BESDEBUG("fonc", "FONcRequestHandler::turn_off_global_attrs: " << FONcRequestHandler::no_global_attrs << endl);
182 BESDEBUG("fonc", "FONcRequestHandler::request_max_size_kb: " << FONcRequestHandler::request_max_size_kb << endl);
183 BESDEBUG("fonc", "FONcRequestHandler::nc3_classic_format " << FONcRequestHandler::nc3_classic_format << endl);
184}
185
191
204{
205 BESResponseObject *response = dhi.response_handler->get_response_object();
206 BESInfo *info = dynamic_cast<BESInfo *>(response);
207 if (!info) throw BESInternalError("cast error", __FILE__, __LINE__);
208
209 bool found = false;
210 string key = "FONc.Reference";
211 string ref;
212 TheBESKeys::TheKeys()->get_value(key, ref, found);
213 if (ref.empty()) ref = "https://docs.opendap.org/index.php/BES_-_Modules_-_FileOut_Netcdf";
214 map<string, string, std::less<>> attrs;
215 attrs["name"] = MODULE_NAME;
216 attrs["version"] = MODULE_VERSION;
217 attrs["reference"] = ref;
218 info->begin_tag("module", &attrs);
219 info->end_tag("module");
220
221 return true;
222}
223
232{
233 BESResponseObject *response = dhi.response_handler->get_response_object();
234 BESVersionInfo *info = dynamic_cast<BESVersionInfo *>(response);
235 if (!info) throw BESInternalError("cast error", __FILE__, __LINE__);
236
237 info->add_module(MODULE_NAME, MODULE_VERSION);
238
239 return true;
240}
241
248void
249FONcRequestHandler::dump( ostream &strm ) const
250{
251 strm << BESIndent::LMarg << "FONcRequestHandler::dump - ("
252 << (void *)this << ")" << endl ;
253 BESIndent::Indent() ;
255 BESIndent::UnIndent() ;
256}
257
Structure storing information used by the BES to handle the request.
informational response object
Definition BESInfo.h:63
exception thrown if internal error encountered
virtual bool add_method(const std::string &name, p_request_handler_method method)
add a handler method to the request handler that knows how to fill in a specific response object
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual BESResponseObject * get_response_object()
return the current response object
Abstract base class representing a specific set of information in response to a request to the BES.
static std::string lowercase(const std::string &s)
Definition BESUtil.cc:257
static void trim_if_trailing_slash(std::string &value)
If the string ends in a slash, remove it This function works for empty strings (doing nothing)....
Definition BESUtil.cc:113
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual ~FONcRequestHandler(void)
Any cleanup that needs to take place.
FONcRequestHandler(const std::string &name)
Constructor for FileOut NetCDF module.
static bool build_help(BESDataHandlerInterface &dhi)
adds help information for FileOut NetCDF to a help request
static bool build_version(BESDataHandlerInterface &dhi)
add version information to a version response
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
static TheBESKeys * TheKeys()
Access to the singleton.
Definition TheBESKeys.cc:85