bes  Updated for version 3.20.6
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 <DDS.h>
36 #include <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 
51 using namespace bes;
52 using namespace libdap;
53 using namespace std;
54 
55 BESDataResponseHandler::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 
62 BESDataResponseHandler::~BESDataResponseHandler()
63 {
64 }
65 
81 {
82  dhi.action_name = DATA_RESPONSE_STR;
83 
84  if (d_use_dmrpp) {
85  GlobalMetadataStore *mds = GlobalMetadataStore::get_instance(); // mds may be NULL
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(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 
175 void BESDataResponseHandler::dump(ostream &strm) const
176 {
177  strm << BESIndent::LMarg << "BESDataResponseHandler::dump - (" << (void *) this << ")" << endl;
178  BESIndent::Indent();
180  BESIndent::UnIndent();
181 }
182 
184 BESDataResponseHandler::DataResponseBuilder(const string &name)
185 {
186  return new BESDataResponseHandler(name);
187 }
188 
BESDataHandlerInterface::container
BESContainer * container
pointer to current container in this interface
Definition: BESDataHandlerInterface.h:75
bes::GlobalMetadataStore::MDSReadLock
Unlock and close the MDS item when the ReadLock goes out of scope.
Definition: GlobalMetadataStore.h:193
BESContainer::set_attributes
void set_attributes(const std::string &attrs)
set desired attributes for this container
Definition: BESContainer.h:170
BESDataResponseHandler
response handler that builds an OPeNDAP Data DDS object
Definition: BESDataResponseHandler.h:56
BESDataResponseHandler::execute
virtual void execute(BESDataHandlerInterface &dhi)
executes the command 'get data for <def_name>' by executing the request for each container in the spe...
Definition: BESDataResponseHandler.cc:80
BESDataResponseHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESDataResponseHandler.cc:175
BESDataResponseHandler::transmit
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command
Definition: BESDataResponseHandler.cc:162
TheBESKeys::read_string_key
std::string read_string_key(const std::string &key, const std::string &default_value)
Read a string-valued key from the bes.conf file.
Definition: TheBESKeys.cc:351
BESResponseHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESResponseHandler.cc:102
BESContainer::get_relative_name
std::string get_relative_name() const
Get the relative name of the object in this container.
Definition: BESContainer.h:186
BESRequestHandlerList::execute_each
virtual void execute_each(BESDataHandlerInterface &dhi)
for each container in the given data handler interface, execute the given request
Definition: BESRequestHandlerList.cc:167
TheBESKeys::read_bool_key
bool read_bool_key(const std::string &key, bool default_value)
Read a boolean-valued key from the bes.conf file.
Definition: TheBESKeys.cc:326
libdap
Definition: BESDapFunctionResponseCache.h:35
bes::GlobalMetadataStore
Store the DAP metadata responses.
Definition: GlobalMetadataStore.h:89
TheBESKeys::TheKeys
static TheBESKeys * TheKeys()
Definition: TheBESKeys.cc:62
BESContextManager::get_context_int
virtual int get_context_int(const std::string &name, bool &found)
Get the value of the given context and return it as an integer.
Definition: BESContextManager.cc:99
BESResponseHandler
handler object that knows how to create a specific response object
Definition: BESResponseHandler.h:77
BESTransmitter
Definition: BESTransmitter.h:47
BESDataDDSResponse
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
Definition: BESDataDDSResponse.h:46
BESDapResponse::get_dap_client_protocol
std::string get_dap_client_protocol() const
Return the dap version string sent by the client (e.g., the OLFS)
Definition: BESDapResponse.h:64
bes::GlobalMetadataStore::is_dmrpp_available
virtual MDSReadLock is_dmrpp_available(const std::string &name)
Is the DMR++ response for.
Definition: GlobalMetadataStore.cc:928
BESDataHandlerInterface::first_container
void first_container()
set the container pointer to the first container in the containers list
Definition: BESDataHandlerInterface.h:135
BESContainer::set_container_type
void set_container_type(const std::string &type)
set the type of data that this container represents, such as cedar or netcdf.
Definition: BESContainer.h:161
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56