0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
main.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; either version 3
9  * of the 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 Hypertable. If not, see <http://www.gnu.org/licenses/>
18  */
19 
20 #include <Common/Compat.h>
21 
22 #include "CephBroker.h"
23 
24 #include <FsBroker/Lib/Config.h>
26 
28 #include <AsyncComm/Comm.h>
29 
30 #include <Common/Config.h>
31 #include <Common/FileUtils.h>
32 #include <Common/Init.h>
33 #include <Common/Usage.h>
34 
35 #include <iostream>
36 #include <fstream>
37 #include <string>
38 
39 extern "C" {
40 #include <poll.h>
41 #include <sys/types.h>
42 #include <unistd.h>
43 }
44 
45 using namespace Hypertable;
46 using namespace Hypertable::FsBroker;
47 using namespace Config;
48 using namespace std;
49 
50 struct AppPolicy : Config::Policy {
51  static void init_options() {
52  cmdline_desc().add_options()
53  ("ceph-version", "Show Ceph version and exit")
54  ;
55  }
56 
57  static void init() {
58  alias("workers", "CephBroker.Workers");
59  alias("ceph_mon", "CephBroker.MonAddr");
60  alias("port", "CephBroker.Port");
61 
62  if (has("ceph-version")) {
63  cout <<" Ceph: "<< ceph_version(NULL, NULL, NULL) << endl;
64  quick_exit(EXIT_SUCCESS);
65  }
66  }
67 };
68 
69 typedef Meta::list<AppPolicy, FsBrokerPolicy, DefaultCommPolicy> Policies;
70 
71 int main (int argc, char **argv) {
72  // HT_INFOF("ceph/main attempting to create pieces %d", argc);
73  try {
74  init_with_policies<Policies>(argc, argv);
75  int port;
76  int worker_count = get_i32("CephBroker.Workers");
77 
78  if (has("CephBroker.Port"))
79  port = get_i16("CephBroker.Port");
80  else if (has("DfsBroker.Port"))
81  port = get_i16("DfsBroker.Port");
82  else
83  port = get_i16("FsBroker.Port");
84 
85  Comm *comm = Comm::instance();
86  ApplicationQueuePtr app_queue = make_shared<ApplicationQueue>(worker_count);
87  HT_INFOF("attemping to create new CephBroker with address %s", properties->get_str("CephBroker.MonAddr").c_str());
88  BrokerPtr broker = make_shared<CephBroker>(properties);
89  HT_INFO("Created CephBroker!");
91  make_shared<FsBroker::Lib::ConnectionHandlerFactory>(comm, app_queue, broker);
92  InetAddr listen_addr(INADDR_ANY, port);
93 
94  comm->listen(listen_addr, chfp);
95  app_queue->join();
96  }
97  catch(Exception &e) {
98  HT_ERROR_OUT << e << HT_END;
99  return 1;
100  }
101 
102  if (has("pidfile"))
103  FileUtils::unlink(get_str("pidfile"));
104 
105  return 0;
106 }
static Comm * instance()
Creates/returns singleton instance of the Comm class.
Definition: Comm.h:72
Interface and base of config policy.
Definition: Config.h:149
Meta::list< AppPolicy, FsBrokerPolicy, DefaultCommPolicy > Policies
Definition: main.cc:69
PropertiesPtr properties
This singleton map stores all options.
Definition: Config.cc:47
static bool unlink(const String &fname)
Unlinks (deletes) a file or directory.
Definition: FileUtils.cc:427
Helper class for printing usage banners on the command line.
File system broker definitions.
Definition: CephBroker.h:38
#define HT_INFO(msg)
Definition: Logger.h:271
STL namespace.
int main(int argc, char **argv)
Definition: main.cc:71
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
File system utility functions.
std::shared_ptr< ConnectionHandlerFactory > ConnectionHandlerFactoryPtr
Smart pointer to ConnectionHandlerFactory.
static void init_options()
Definition: main.cc:51
Encapsulate an internet address.
Definition: InetAddr.h:66
Compatibility Macros for C/C++.
Initialization helper for applications.
#define HT_END
Definition: Logger.h:220
static void init()
Definition: main.cc:57
#define HT_ERROR_OUT
Definition: Logger.h:301
std::shared_ptr< Broker > BrokerPtr
Smart pointer to Broker.
Definition: Broker.h:241
Hypertable definitions
Entry point to AsyncComm service.
Definition: Comm.h:61
Declarations for Comm.
#define HT_INFOF(msg,...)
Definition: Logger.h:272
This is a generic exception class for Hypertable.
Definition: Error.h:314
Declarations for ApplicationQueue.
Configuration settings.
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
std::shared_ptr< ApplicationQueue > ApplicationQueuePtr
Shared smart pointer to ApplicationQueue object.