bes  Updated for version 3.17.4
BESBasicInterface.cc
1 // BESBasicInterface.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 <iostream>
34 #include <sstream>
35 
36 using std::endl;
37 using std::stringstream;
38 
39 #include "BESBasicInterface.h"
40 #include "BESInterface.h"
41 #include "BESLog.h"
42 #include "BESDebug.h"
43 #include "BESReturnManager.h"
44 #include "BESSyntaxUserError.h"
45 #include "BESInternalError.h"
46 #include "BESAggFactory.h"
47 #include "BESAggregationServer.h"
48 #include "BESTransmitterNames.h"
49 #include "BESDataNames.h"
50 
58  BESInterface(strm)
59 {
60 }
61 
62 BESBasicInterface::~BESBasicInterface()
63 {
64 }
65 
74 int BESBasicInterface::execute_request(const string &from)
75 {
76  return BESInterface::execute_request(from);
77 }
78 
89 {
90  // dhi has not been filled in at this point, so let's set a default
91  // transmitter given the protocol. The transmitter might change after
92  // parsing a request and given a return manager to use. This is done in
93  // build_data_plan.
94  //
95  // The reason I moved this from the build_data_plan method is because a
96  // registered initialization routine might throw an exception and we
97  // will need to transmit the exception info, which needs a transmitter.
98  // If an exception happens before this then the exception info is just
99  // printed to cout (see BESInterface::transmit_data()). -- pcw 09/05/06
100  BESDEBUG("bes", "Finding " << BASIC_TRANSMITTER << " transmitter ... " << endl);
101 
102  _transmitter = BESReturnManager::TheManager()->find_transmitter( BASIC_TRANSMITTER);
103  if (!_transmitter) {
104  string s = (string) "Unable to find transmitter " + BASIC_TRANSMITTER;
105  throw BESInternalError(s, __FILE__, __LINE__);
106  }
107  BESDEBUG("bes", "OK" << endl);
108 
110 }
111 
115 {
117 }
118 
124 {
125  BESDEBUG("bes", "Entering: " << __PRETTY_FUNCTION__ << endl);
126 
127  // The derived class build_data_request_plan should be run first to
128  // parse the incoming request. Once parsed we can determine if there is
129  // a return command
130 
131  // The default _transmitter (either basic or http depending on the
132  // protocol passed) has been set in initialize. If the parsed command
133  // sets a RETURN_CMD (a different transmitter) then look it up here. If
134  // it's set but not found then this is an error. If it's not set then
135  // just use the defaults.
136  if (_dhi->data[RETURN_CMD] != "") {
137  BESDEBUG("bes", "Finding transmitter: " << _dhi->data[RETURN_CMD] << " ... " << endl);
138 
139  _transmitter = BESReturnManager::TheManager()->find_transmitter(_dhi->data[RETURN_CMD]);
140  if (!_transmitter) {
141  string s = (string) "Unable to find transmitter " + _dhi->data[RETURN_CMD];
142  throw BESSyntaxUserError(s, __FILE__, __LINE__);
143  }
144  BESDEBUG("bes", "OK" << endl);
145  }
146 }
147 
156 {
157  if (BESLog::TheLog()->is_verbose()) {
158  *(BESLog::TheLog()) << _dhi->data[SERVER_PID] << " from " << _dhi->data[REQUEST_FROM] << " ["
159  << _dhi->data[DATA_REQUEST] << "] executing" << endl;
160  }
162 }
163 
172 {
173  if (_dhi->data[AGG_CMD] == "") {
174  if (BESLog::TheLog()->is_verbose()) {
175  *(BESLog::TheLog()) << _dhi->data[SERVER_PID] << " from " << _dhi->data[REQUEST_FROM] << " ["
176  << _dhi->data[DATA_REQUEST] << "]" << " not aggregating, command empty" << endl;
177  }
178  }
179  else {
180  BESAggregationServer *agg = BESAggFactory::TheFactory()->find_handler(_dhi->data[AGG_HANDLER]);
181  if (!agg) {
182  if (BESLog::TheLog()->is_verbose()) {
183  *(BESLog::TheLog()) << _dhi->data[SERVER_PID] << " from " << _dhi->data[REQUEST_FROM] << " ["
184  << _dhi->data[DATA_REQUEST] << "]" << " not aggregating, no handler" << endl;
185  }
186  }
187  else {
188  if (BESLog::TheLog()->is_verbose()) {
189  *(BESLog::TheLog()) << _dhi->data[SERVER_PID] << " from " << _dhi->data[REQUEST_FROM] << " ["
190  << _dhi->data[DATA_REQUEST] << "] aggregating" << endl;
191  }
192  }
193  }
195 }
196 
205 {
206  if (BESLog::TheLog()->is_verbose()) {
207  *(BESLog::TheLog()) << _dhi->data[SERVER_PID] << " from " << _dhi->data[REQUEST_FROM] << " ["
208  << _dhi->data[DATA_REQUEST] << "] transmitting" << endl;
209  }
211 }
212 
218 {
219  string result = "completed";
220  if (_dhi->error_info) result = "failed";
221  if (BESLog::TheLog()->is_verbose()) {
222  *(BESLog::TheLog()) << _dhi->data[SERVER_PID] << " from " << _dhi->data[REQUEST_FROM] << " ["
223  << _dhi->data[DATA_REQUEST] << "] " << result << endl;
224  }
225 }
226 
236 {
238  if (BESLog::TheLog()->is_verbose()) {
239  *(BESLog::TheLog()) << _dhi->data[SERVER_PID] << " from " << _dhi->data[REQUEST_FROM] << " ["
240  << _dhi->data[DATA_REQUEST] << "] cleaning" << endl;
241  }
242 }
243 
250 void BESBasicInterface::dump(ostream &strm) const
251 {
252  strm << BESIndent::LMarg << "BESBasicInterface::dump - (" << (void *) this << ")" << endl;
253  BESIndent::Indent();
254  BESInterface::dump(strm);
255  BESIndent::UnIndent();
256 
257 }
258 
virtual void dump(ostream &strm) const
dumps information about this object
exception thrown if inernal error encountered
virtual void initialize()
Initialize the BES object.
bool is_verbose()
Returns true if verbose logging is requested.
Definition: BESLog.h:161
virtual void transmit_data()
Transmit the resulting response object.
virtual void transmit_data()
Transmit the response object.
virtual void build_data_request_plan()
Build the data request plan using the BESCmdParser.
error thrown if there is a user syntax error in the request or any other user error ...
BESBasicInterface(ostream *strm)
Instantiate a BESBasicInterface object given an output stream for the response object.
virtual void log_status()
Log the status of the request to the BESLog file.
Entry point into BES, building responses to given requests.
Definition: BESInterface.h:123
virtual void invoke_aggregation()
Invoke the aggregation server, if there is one.
virtual void validate_data_request()
Validate the incoming request information.
virtual void clean()
Clean up after the request.
virtual void invoke_aggregation()
Aggregate the resulting response object.
map< string, string > data
the map of string data that will be required for the current request.
virtual BESAggregationServer * find_handler(const string &handler_name)
returns the aggregation handler with the given name in the list
virtual void validate_data_request()
Validate the incoming request information.
BESInfo * error_info
error information object
virtual void execute_data_request_plan()
Execute the data request plan.
Abstraction representing mechanism for aggregating data.
virtual void execute_data_request_plan()
Execute the data request plan.
virtual void initialize()
Initialize the BES.
virtual void clean()
Clean up after the request is completed.
virtual int execute_request(const string &from)
Override execute_request in order to register memory pool.
virtual void dump(ostream &strm) const
dumps information about this object