0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
hypertable.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 
24 #include <Hypertable/Lib/Config.h>
25 #include <Hypertable/Lib/Client.h>
27 
28 #include <Tools/Lib/CommandShell.h>
29 
31 #include <Common/Init.h>
32 
33 using namespace Hypertable;
34 using namespace Config;
35 using namespace std;
36 
37 namespace {
38 
39  struct AppPolicy : Config::Policy {
40  static void init_options() {
41  cmdline_desc().add_options()
42  ("no-log-sync", boo()->default_value(false),
43  "Don't sync rangeserver commit logs on autoflush")
44  ("output-only", "Display status output and exit with status 0")
45  ("profile", "Send profiling output to stderr")
46  ("namespace", str()->default_value(""),
47  "Automatically use specified namespace when starting")
48  ("silent-startup", "Squelch output during startup")
49  ;
50  alias("no-log-sync", "Hypertable.HqlInterpreter.Mutator.NoLogSync");
51  }
52  };
53 
54 }
55 
56 typedef Meta::list<AppPolicy, CommandShellPolicy, DefaultCommPolicy> Policies;
57 
58 
59 int main(int argc, char **argv) {
60  CommandShellPtr shell;
61  CommandInterpreterPtr interp;
62  Client *hypertable;
63  int status {};
64  bool silent {};
65  bool output_only {};
66 
67  try {
68  init_with_policies<Policies>(argc, argv);
69  bool profile = has("profile");
70  output_only = has("output-only");
71  silent = has("silent") && get_bool("silent");
72 
73  if (has("silent-startup")) {
75  hypertable = new Hypertable::Client();
76  }
77  else
78  hypertable = new Hypertable::Client();
79  interp = make_shared<HqlCommandInterpreter>(hypertable, profile);
80  shell = make_shared<CommandShell>("hypertable", "Hypertable", interp, properties);
81  shell->set_namespace(get_str("namespace"));
82  interp->set_silent(shell->silent());
83  interp->set_test_mode(shell->test_mode());
84 
85  status = shell->run();
86  }
87  catch(Exception &e) {
88  if (!silent) {
89  cout << "Hypertable CRITICAL - " << Error::get_text(e.code());
90  const char *msg = e.what();
91  if (msg && *msg)
92  cout << " - " << msg;
93  cout << endl;
94  }
95  quick_exit(output_only ? 0 : 2);
96  }
97  quick_exit(status);
98 }
Interface and base of config policy.
Definition: Config.h:149
PropertiesPtr properties
This singleton map stores all options.
Definition: Config.cc:47
Po::typed_value< String > * str(String *v=0)
Definition: Properties.h:166
STL namespace.
Desc & cmdline_desc(const char *usage)
A macro which definds global functions like get_bool(), get_str(), get_i16() etc. ...
Definition: Config.cc:72
bool has(const String &name)
Check existence of a configuration value.
Definition: Config.h:57
Declaration for ConsoleOutputSquelcher.
Meta::list< AppPolicy, CommandShellPolicy, DefaultCommPolicy > Policies
Definition: hypertable.cc:56
const char * get_text(int error)
Returns a descriptive error message.
Definition: Error.cc:330
bool status(ContextPtr &context, Timer &timer, Status &status)
Runs a status check on the master.
Definition: Utility.cc:408
Compatibility Macros for C/C++.
Po::typed_value< bool > * boo(bool *v=0)
Definition: Properties.h:162
Initialization helper for applications.
std::shared_ptr< CommandInterpreter > CommandInterpreterPtr
std::shared_ptr< CommandShell > CommandShellPtr
Definition: CommandShell.h:91
Hypertable definitions
Declarations for HqlCommandInterpreter.
Temporarily redirects stdout and stderr to /dev/null.
This is a generic exception class for Hypertable.
Definition: Error.h:314
int main(int argc, char **argv)
Definition: hypertable.cc:59
void alias(const String &cmdline_opt, const String &file_opt, bool overwrite)
Setup command line option alias for config file option.
Definition: Config.cc:607
int code() const
Returns the error code.
Definition: Error.h:391