bes  Updated for version 3.20.5
ShowNodeCommand.cc
1 // ShowNodeCommand.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) 2018 OPeNDAP, Inc
7 // Author: James Gallagher <jgallagher@opendap.org>
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 OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 
25 #include "config.h"
26 
27 #include "BESContainerStorageList.h"
28 
29 #include "BESNames.h"
30 #include "BESDataNames.h"
31 #include "BESXMLUtils.h"
32 #include "BESUtil.h"
33 #include "BESSyntaxUserError.h"
34 #include "BESDebug.h"
35 
36 #include "ShowNodeCommand.h"
37 
38 using namespace bes;
39 
40 ShowNodeCommand::ShowNodeCommand(const BESDataHandlerInterface &base_dhi) :
41  BESXMLCommand(base_dhi)
42 {
43 }
44 
66 void ShowNodeCommand::parse_request(xmlNode *node)
67 {
68  string name;
69  string value;
70  map<string, string> props;
71  BESXMLUtils::GetNodeInfo(node, name, value, props);
72  if (name != NODE_RESPONSE_STR) {
73  string err = "The specified command " + name + " is not a showNode command";
74  throw BESSyntaxUserError(err, __FILE__, __LINE__);
75  }
76 
77  // the action is the same for show catalog and show info
78  d_xmlcmd_dhi.action = NODE_RESPONSE;
79 
80  d_cmd_log_info = "show node";
81 
82  // node is an optional property, so could be empty string
83  d_xmlcmd_dhi.data[CONTAINER] = props["node"];
84 
85  if (!d_xmlcmd_dhi.data[CONTAINER].empty()) {
86  d_cmd_log_info.append(" for ").append(d_xmlcmd_dhi.data[CONTAINER]);
87  }
88 
89  // catalog is an optional property, so could be empty string
90  // Dropped this because the catalog name is going to be in the path. ndp 8/8/18
91  // d_xmlcmd_dhi.data[CATALOG] = props["catalog"];
92 
93  if (!d_xmlcmd_dhi.data[CATALOG].empty()) {
94  d_cmd_log_info.append(" in catalog ").append(d_xmlcmd_dhi.data[CATALOG]);
95  }
96 
97  d_cmd_log_info += ";";
98 
99  // Get the response handler for the action (dhi.action == show.node)
100  set_response();
101 }
102 
109 void ShowNodeCommand::dump(ostream &strm) const
110 {
111  strm << BESIndent::LMarg << "ShowNodeCommand::dump - (" << (void *) this << ")" << endl;
112  BESIndent::Indent();
113  BESXMLCommand::dump(strm);
114  BESIndent::UnIndent();
115 }
116 
126 {
127  return new ShowNodeCommand(base_dhi);
128 }
129 
virtual void dump(ostream &strm) const
dumps information about this object
static void GetNodeInfo(xmlNode *node, string &name, string &value, map< string, string > &props)
get the name, value if any, and any properties for the specified node
Definition: BESXMLUtils.cc:101
static BESXMLCommand * CommandBuilder(const BESDataHandlerInterface &base_dhi)
A command builder suitable for BESXMLCommand::add_command()
error thrown if there is a user syntax error in the request or any other user error
virtual void set_response()
The request has been parsed, use the command action name to set the response handler.
virtual void dump(ostream &strm) const
dumps information about this object
Structure storing information used by the BES to handle the request.
map< string, string > data
the map of string data that will be required for the current request.
Base class for the BES's commands.
Definition: BESXMLCommand.h:63
string action
the response object requested, e.g. das, dds
std::string d_cmd_log_info
Used only for the log.
Definition: BESXMLCommand.h:74