bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
ShowBesKeyResponseHandler.cc
1// -*- mode: c++; c-basic-offset:4 -*-
2//
3// ShowBesKeyResponseHandler.cc
4//
5// This file is part of the BES default command set
6//
7// Copyright (c) 2018 OPeNDAP, Inc.
8// Author: Nathan Potter <ndp@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25// Please read the full copyright statement in the file COPYRIGHT_URI.
26//
27
28#include "config.h"
29
30#include <sys/types.h>
31#include <sys/stat.h>
32#include <unistd.h>
33#include <time.h>
34
35#include <cerrno>
36#include <cstring>
37
38#include <sstream>
39#include <fstream>
40
41#include "ShowBesKeyCommand.h"
42#include "ShowBesKeyResponseHandler.h"
43
44#include "BESDebug.h"
45#include "BESError.h"
46#include "BESInfo.h"
47#include "BESInfoList.h"
48#include "BESDataNames.h"
49#include "TheBESKeys.h"
50
51#include "BESStopWatch.h"
52
53using namespace std;
54
55const auto MODULE = "bes";
56#define prolog std::string("ShowBesKeyResponseHandler::").append(__func__).append("() - ")
57
58ShowBesKeyResponseHandler::ShowBesKeyResponseHandler(const string &name) :
60{
61}
62
63ShowBesKeyResponseHandler::~ShowBesKeyResponseHandler()
64{
65}
66
78{
79
80 BES_STOPWATCH_START_DHI(MODULE, prolog + "Timing", &dhi);
81
82 BESInfo *info = BESInfoList::TheList()->build_info();
83 d_response_object = info;
84
85 string requested_bes_key = dhi.data[BES_KEY];
86
87 BESDEBUG(SBK_DEBUG_KEY, __func__ << "() - requested key: " << requested_bes_key << endl);
88
89 vector<string> key_values;
90 getBesKeyValue(requested_bes_key, key_values);
91
92 map<string, string, std::less<>> attrs;
93
94 attrs[KEY] = requested_bes_key;
95
96 info->begin_response(SHOW_BES_KEY_RESPONSE_STR, &attrs, dhi);
97
98 // I think we can replace/remove 'emptyAttrs' and pass nullptr in its place.
99 // jhrg 11/26/18
100 map<string, string, std::less<>> emptyAttrs;
101 for(unsigned long i = 0; i < key_values.size(); ++i)
102 info->add_tag("value", key_values[i], &emptyAttrs);
103
104 // end the response object
105 info->end_response();
106
107}
108
121{
122 if (d_response_object) {
123 BESInfo *info = dynamic_cast<BESInfo *>(d_response_object);
124 if (!info) throw BESInternalError("cast error", __FILE__, __LINE__);
125 info->transmit(transmitter, dhi);
126 }
127}
128
135void ShowBesKeyResponseHandler::dump(ostream &strm) const
136{
137 strm << BESIndent::LMarg << "ShowBesKeyResponseHandler::dump - (" << (void *) this << ")" << std::endl;
138 BESIndent::Indent();
140 BESIndent::UnIndent();
141}
142
144ShowBesKeyResponseHandler::ShowBesKeyResponseBuilder(const string &name)
145{
146 return new ShowBesKeyResponseHandler(name);
147}
148
149void ShowBesKeyResponseHandler::getBesKeyValue(string key, vector<string> &values)
150{
151 bool found;
152
153 TheBESKeys::TheKeys()->get_values(key, values, found);
154 if (!found) {
155 BESDEBUG(SBK_DEBUG_KEY, __func__ << "() Failed to located BES key '" << key << "'" << endl);
156 throw BESError("Ouch! The Key name '"+key+"' was not found in BESKeys",BES_NOT_FOUND_ERROR, __FILE__, __LINE__);
157 }
158}
159
Structure storing information used by the BES to handle the request.
std::map< std::string, std::string > data
the map of string data that will be required for the current request.
informational response object
Definition BESInfo.h:63
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)=0
transmit the informational object
virtual void begin_response(const std::string &response_name, BESDataHandlerInterface &dhi)
begin the informational response
Definition BESInfo.cc:120
exception thrown if internal error encountered
handler object that knows how to create a specific response object
void dump(std::ostream &strm) const override
dumps information about this object
Response handler that returns the value(s) of a BES key.
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command using the specified transmitter object
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual void execute(BESDataHandlerInterface &dhi)
executes the command 'show catalog|leaves [for <node>];' by returning nodes or leaves at the top leve...
static TheBESKeys * TheKeys()
Access to the singleton.
Definition TheBESKeys.cc:85
void get_values(const std::string &s, std::vector< std::string > &vals, bool &found)
Retrieve the values of a given key, if set.