bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
BESDataResponseHandler.cc
1// BESDataResponseHandler.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-2009 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 <libdap/DDS.h>
36#include <libdap/DataDDS.h>
37
38#include "BESDataResponseHandler.h"
39#include "BESDataDDSResponse.h"
40#include "BESRequestHandlerList.h"
41#include "BESDapNames.h"
42#include "BESDataNames.h"
43#include "BESContextManager.h"
44#include "TheBESKeys.h"
45#include "BESInternalError.h"
46#include "BESDebug.h"
47#include "BESTransmitter.h"
48
49#include "GlobalMetadataStore.h"
50
51using namespace bes;
52using namespace libdap;
53using namespace std;
54
55BESDataResponseHandler::BESDataResponseHandler(const string &name) :
56 BESResponseHandler(name), d_use_dmrpp(false), d_dmrpp_name(DMRPP_DEFAULT_NAME)
57{
58 d_use_dmrpp = TheBESKeys::TheKeys()->read_bool_key(USE_DMRPP_KEY, false); // defined in BESDapNames.h
59 d_dmrpp_name = TheBESKeys::TheKeys()->read_string_key(DMRPP_NAME_KEY, DMRPP_DEFAULT_NAME);
60}
61
62BESDataResponseHandler::~BESDataResponseHandler()
63{
64}
65
81{
82 dhi.action_name = DATA_RESPONSE_STR;
83
84 if (d_use_dmrpp) {
86
88 dhi.first_container();
89 if (mds) lock = mds->is_dmrpp_available(*(dhi.container));
90
91 // If we were able to lock the DMR++ it must exist; use it.
92 if (mds && lock()) {
93 BESDEBUG("dmrpp",
94 "In BESDataResponseHandler::execute(): Found a DMR++ response for '" << dhi.container->get_relative_name() << "'" << endl);
95
96 // Redirect the request to the DMR++ handler
97 dhi.container->set_container_type(d_dmrpp_name);
98
99 // Add information to the container so the dmrpp handler works
100 // This tells DMR++ handler to look for this in the MDS
101 dhi.container->set_attributes(MDS_HAS_DMRPP);
102 }
103 }
104
105#if 0
106 GlobalMetadataStore *mds = GlobalMetadataStore::get_instance(); // mds may be NULL
107
109 dhi.first_container();
110 if (mds) lock = mds->is_dmrpp_available(dhi.container->get_relative_name());
111
112 // If we were able to lock the DMR++ it must exist; use it.
113 if (mds && lock()) {
114 BESDEBUG("dmrpp", "In BESDataResponseHandler::execute(): Found a DMR++ response for '"
115 << dhi.container->get_relative_name() << "'" << endl);
116
117 // Redirect the request to the DMR++ handler
118 // FIXME How do we get this value in a repeatable way? From bes.conf, of course jhrg 5/31/18
119 dhi.container->set_container_type("dmrpp");
120
121 // Add information to the container so the dmrpp handler works
122 // This tells DMR++ handler to look for this in the MDS
123 dhi.container->set_attributes(MDS_HAS_DMRPP);
124 }
125#endif
126
127
128 bool rsl_found;
129 int response_size_limit = BESContextManager::TheManager()->get_context_int("max_response_size", rsl_found);
130
131 // NOTE: It is the responsibility of the specific request handler to set
132 // the BaseTypeFactory. It is set to NULL here
133 DDS *dds = new DDS(NULL, "virtual");
134 if (rsl_found)
135 dds->set_response_limit_kb(response_size_limit); // The default for this is zero
136
137 BESDataDDSResponse *bdds = new BESDataDDSResponse(dds);
138
139 dhi.first_container();
140 // Set the DAP protocol version requested by the client. 2/25/11 jhrg
141 if (!bdds->get_dap_client_protocol().empty()) {
142 dds->set_dap_version(bdds->get_dap_client_protocol());
143 }
144
145 d_response_object = bdds;
146
147 // This calls RequestHandlerList::execute_current()
148 BESRequestHandlerList::TheList()->execute_each(dhi);
149}
150
163{
164 if (d_response_object) {
165 transmitter->send_response( DATA_SERVICE, d_response_object, dhi);
166 }
167}
168
175void BESDataResponseHandler::dump(ostream &strm) const
176{
177 strm << BESIndent::LMarg << "BESDataResponseHandler::dump - (" << (void *) this << ")" << endl;
178 BESIndent::Indent();
180 BESIndent::UnIndent();
181}
182
184BESDataResponseHandler::DataResponseBuilder(const string &name)
185{
186 return new BESDataResponseHandler(name);
187}
188
void set_container_type(const std::string &type)
set the type of data that this container represents, such as cedar or netcdf.
std::string get_relative_name() const
Get the relative name of the object in this container.
void set_attributes(const std::string &attrs)
set desired attributes for this container
std::string get_dap_client_protocol() const
Return the dap version string sent by the client (e.g., the OLFS)
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
Structure storing information used by the BES to handle the request.
void first_container()
set the container pointer to the first container in the containers list
BESContainer * container
pointer to current container in this interface
response handler that builds an OPeNDAP Data DDS object
virtual void execute(BESDataHandlerInterface &dhi)
executes the command 'get data for <def_name>' by executing the request for each container in the spe...
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command
virtual void dump(std::ostream &strm) const
dumps information about this object
handler object that knows how to create a specific response object
void dump(std::ostream &strm) const override
dumps information about this object
static TheBESKeys * TheKeys()
Access to the singleton.
Definition TheBESKeys.cc:85
static bool read_bool_key(const std::string &key, bool default_value)
Read a boolean-valued key from the bes.conf file.
static std::string read_string_key(const std::string &key, const std::string &default_value)
Read a string-valued key from the bes.conf file.
Store the DAP metadata responses.
static GlobalMetadataStore * get_instance()
virtual MDSReadLock is_dmrpp_available(const std::string &name)
Is the DMR++ response for.
Unlock and close the MDS item when the ReadLock goes out of scope.