0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MasterCommandInterpreter.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #include <Common/Compat.h>
23 
25 
28 
29 using namespace Hypertable;
30 using namespace Tools::client::master;
31 using namespace Hql;
32 using namespace std;
33 
34 MasterCommandInterpreter::MasterCommandInterpreter(Lib::Master::ClientPtr &master)
35  : m_master(master) {
36  HqlHelpText::install_master_client_text();
37 }
38 
39 
41  Hql::ParserState state;
42  Hql::Parser parser(state);
43  parse_info<> info;
44 
45  info = parse(line.c_str(), parser, space_p);
46 
47  if (info.full) {
48 
49  if (state.command == COMMAND_SHUTDOWN) {
50  m_master->shutdown();
51  }
52  else if (state.command == COMMAND_STATUS) {
53  Status status;
54  string output;
55  Status::Code code;
56  m_master->status(status);
57  status.get(&code, output);
58  if (!m_silent) {
59  cout << "Master " << Status::code_to_string(code);
60  if (!output.empty())
61  cout << " - " << output;
62  cout << endl;
63  }
64  return static_cast<int>(code);
65  }
66  else if (state.command == COMMAND_HELP) {
67  const char **text = HqlHelpText::get(state.str);
68  if (text) {
69  for (size_t i=0; text[i]; i++)
70  cout << text[i] << endl;
71  }
72  else
73  cout << endl << "no help for '" << state.str << "'" << endl << endl;
74  }
75  else
76  HT_THROW(Error::HQL_PARSE_ERROR, "unsupported command");
77  }
78  else
79  HT_THROW(Error::HQL_PARSE_ERROR, String("parse error at: ") + info.stop);
80  return 0;
81 }
82 
Holds Nagios-style program status information.
Definition: Status.h:42
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
STL namespace.
Code
Enumeration for status codes.
Definition: Status.h:47
bool status(ContextPtr &context, Timer &timer, Status &status)
Runs a status check on the master.
Definition: Utility.cc:408
Compatibility Macros for C/C++.
T get(const String &name)
Retrieves a configuration value.
Definition: Config.h:82
Hypertable definitions
std::shared_ptr< Client > ClientPtr
Smart pointer to Client.
Definition: Client.h:201
void get(Code *code, std::string &text) const
Gets status code and text.
Definition: Status.h:111
Declarations for HqlHelpText.
#define HT_THROW(_code_, _msg_)
Definition: Error.h:478
const char * code_to_string(int var_code)
Converts variable code to variable string.