00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <iostream>
00034 #include <sstream>
00035
00036 using std::endl ;
00037 using std::stringstream ;
00038
00039 #include "BESCmdInterface.h"
00040 #include "BESCmdParser.h"
00041 #include "BESInterface.h"
00042 #include "BESLog.h"
00043 #include "BESDebug.h"
00044 #include "BESBasicHttpTransmitter.h"
00045 #include "BESReturnManager.h"
00046 #include "BESSyntaxUserError.h"
00047 #include "BESInternalError.h"
00048 #include "BESAggFactory.h"
00049 #include "BESAggregationServer.h"
00050 #include "BESTransmitterNames.h"
00051 #include "BESDataNames.h"
00052
00060 BESCmdInterface::BESCmdInterface()
00061 : BESInterface()
00062 {
00063 }
00064
00065 BESCmdInterface::BESCmdInterface( const string &cmd, ostream *strm )
00066 : BESInterface( strm )
00067 {
00068 _dhi.data[DATA_REQUEST] = cmd ;
00069 }
00070
00071 BESCmdInterface::~BESCmdInterface()
00072 {
00073 clean() ;
00074 }
00075
00084 int
00085 BESCmdInterface::execute_request( const string &from )
00086 {
00087 return BESInterface::execute_request( from ) ;
00088 }
00089
00099 void
00100 BESCmdInterface::initialize()
00101 {
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 string protocol = _dhi.transmit_protocol ;
00113 if( protocol != "HTTP" )
00114 {
00115 BESDEBUG( "bes", "Finding " << BASIC_TRANSMITTER << " transmitter ... " )
00116 _transmitter = BESReturnManager::TheManager()->find_transmitter( BASIC_TRANSMITTER ) ;
00117 if( !_transmitter )
00118 {
00119 string s = (string)"Unable to find transmitter "
00120 + BASIC_TRANSMITTER ;
00121 throw BESInternalError( s, __FILE__, __LINE__ ) ;
00122 }
00123 BESDEBUG( "bes", "OK" << endl )
00124 }
00125 else
00126 {
00127 BESDEBUG( "bes", "Finding " << HTTP_TRANSMITTER << " transmitter ... " )
00128 _transmitter = BESReturnManager::TheManager()->find_transmitter( HTTP_TRANSMITTER ) ;
00129 if( !_transmitter )
00130 {
00131 string s = (string)"Unable to find transmitter "
00132 + HTTP_TRANSMITTER ;
00133 throw BESInternalError( s, __FILE__, __LINE__ ) ;
00134 }
00135 BESDEBUG( "bes", "OK" << endl )
00136 }
00137
00138 BESInterface::initialize() ;
00139 }
00140
00143 void
00144 BESCmdInterface::validate_data_request()
00145 {
00146 BESInterface::validate_data_request() ;
00147 }
00148
00153 void
00154 BESCmdInterface::build_data_request_plan()
00155 {
00156 BESDEBUG( "bes", "building request plan for: "<< _dhi.data[DATA_REQUEST] << " ...")
00157 if( BESLog::TheLog()->is_verbose() )
00158 {
00159 *(BESLog::TheLog()) << _dhi.data[SERVER_PID]
00160 << " from " << _dhi.data[REQUEST_FROM]
00161 << " [" << _dhi.data[DATA_REQUEST] << "] building"
00162 << endl ;
00163 }
00164 BESCmdParser::parse( _dhi.data[DATA_REQUEST], _dhi ) ;
00165 BESDEBUG( "bes", " OK" << endl )
00166
00167
00168
00169
00170
00171
00172 if( _dhi.data[RETURN_CMD] != "" )
00173 {
00174 BESDEBUG( "bes", "Finding transmitter: " << _dhi.data[RETURN_CMD] << " ... " )
00175 _transmitter = BESReturnManager::TheManager()->find_transmitter( _dhi.data[RETURN_CMD] ) ;
00176 if( !_transmitter )
00177 {
00178 string s = (string)"Unable to find transmitter "
00179 + _dhi.data[RETURN_CMD] ;
00180 throw BESSyntaxUserError( s, __FILE__, __LINE__ ) ;
00181 }
00182 BESDEBUG( "bes", "OK" << endl )
00183 }
00184
00185 if( BESDebug::IsSet( "bes" ) ) _dhi.dump( *(BESDebug::GetStrm()) ) ;
00186 }
00187
00195 void
00196 BESCmdInterface::execute_data_request_plan()
00197 {
00198 if( BESLog::TheLog()->is_verbose() )
00199 {
00200 *(BESLog::TheLog()) << _dhi.data[SERVER_PID]
00201 << " from " << _dhi.data[REQUEST_FROM]
00202 << " [" << _dhi.data[DATA_REQUEST] << "] executing"
00203 << endl ;
00204 }
00205 BESInterface::execute_data_request_plan() ;
00206 }
00207
00215 void
00216 BESCmdInterface::invoke_aggregation()
00217 {
00218 if( _dhi.data[AGG_CMD] == "" )
00219 {
00220 if( BESLog::TheLog()->is_verbose() )
00221 {
00222 *(BESLog::TheLog()) << _dhi.data[SERVER_PID]
00223 << " from " << _dhi.data[REQUEST_FROM]
00224 << " [" << _dhi.data[DATA_REQUEST] << "]"
00225 << " not aggregating, command empty"
00226 << endl ;
00227 }
00228 }
00229 else
00230 {
00231 BESAggregationServer *agg = BESAggFactory::TheFactory()->find_handler( _dhi.data[AGG_HANDLER] ) ;
00232 if( !agg )
00233 {
00234 if( BESLog::TheLog()->is_verbose() )
00235 {
00236 *(BESLog::TheLog()) << _dhi.data[SERVER_PID]
00237 << " from " << _dhi.data[REQUEST_FROM]
00238 << " [" << _dhi.data[DATA_REQUEST] << "]"
00239 << " not aggregating, no handler"
00240 << endl ;
00241 }
00242 }
00243 else
00244 {
00245 if( BESLog::TheLog()->is_verbose() )
00246 {
00247 *(BESLog::TheLog()) << _dhi.data[SERVER_PID]
00248 << " from " << _dhi.data[REQUEST_FROM]
00249 << " [" << _dhi.data[DATA_REQUEST]
00250 << "] aggregating" << endl ;
00251 }
00252
00253
00254 }
00255 }
00256 BESInterface::invoke_aggregation() ;
00257 }
00258
00266 void
00267 BESCmdInterface::transmit_data()
00268 {
00269 if( BESLog::TheLog()->is_verbose() )
00270 {
00271 *(BESLog::TheLog()) << _dhi.data[SERVER_PID]
00272 << " from " << _dhi.data[REQUEST_FROM]
00273 << " [" << _dhi.data[DATA_REQUEST]
00274 << "] transmitting" << endl ;
00275 }
00276 BESInterface::transmit_data() ;
00277 }
00278
00283 void
00284 BESCmdInterface::log_status()
00285 {
00286 string result = "completed" ;
00287 if( _dhi.error_info )
00288 result = "failed" ;
00289 if( BESLog::TheLog()->is_verbose() )
00290 {
00291 *(BESLog::TheLog()) << _dhi.data[SERVER_PID]
00292 << " from " << _dhi.data[REQUEST_FROM]
00293 << " [" << _dhi.data[DATA_REQUEST] << "] "
00294 << result << endl ;
00295 }
00296 }
00297
00306 void
00307 BESCmdInterface::clean()
00308 {
00309 BESInterface::clean() ;
00310 if( BESLog::TheLog()->is_verbose() )
00311 {
00312 *(BESLog::TheLog()) << _dhi.data[SERVER_PID]
00313 << " from " << _dhi.data[REQUEST_FROM]
00314 << " [" << _dhi.data[DATA_REQUEST] << "] cleaning"
00315 << endl ;
00316 }
00317 }
00318
00325 void
00326 BESCmdInterface::dump( ostream &strm ) const
00327 {
00328 strm << BESIndent::LMarg << "BESCmdInterface::dump - ("
00329 << (void *)this << ")" << endl ;
00330 BESIndent::Indent() ;
00331 BESInterface::dump( strm ) ;
00332 BESIndent::UnIndent() ;
00333
00334
00335 }
00336