]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: more flexible frotnend handler config
authorYehuda Sadeh <yehuda@inktank.com>
Tue, 29 Oct 2013 21:09:29 +0000 (14:09 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Tue, 5 Nov 2013 18:20:26 +0000 (10:20 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/common/config_opts.h
src/rgw/rgw_main.cc
src/rgw/rgw_mongoose.cc
src/rgw/rgw_mongoose.h

index ef9d4bd0746b6e509e245ac0342c1e50edaffef3..05a04a7ffee8a0ea5a3b483be0aabe1f9bc418bb 100644 (file)
@@ -727,7 +727,7 @@ OPTION(rgw_bucket_quota_ttl, OPT_INT, 600) // time for cached bucket stats to be
 OPTION(rgw_bucket_quota_soft_threshold, OPT_DOUBLE, 0.95) // threshold from which we don't rely on cached info for quota decisions
 OPTION(rgw_bucket_quota_cache_size, OPT_INT, 10000) // number of entries in bucket quota cache
 
-OPTION(rgw_standalone_server_port, OPT_INT, 0) // 0 means disabled
+OPTION(rgw_frontends, OPT_STR, "") // alternative front ends
 
 OPTION(mutex_perf_counter, OPT_BOOL, false) // enable/disable mutex perf counter
 
index adfadc907893b9ca1038a944d04f78ab3bf0051d..40fd3c5985fea5325d9fcb71b7537ba0a4a1b7ef 100644 (file)
@@ -134,6 +134,7 @@ struct RGWProcessEnv {
   RGWRados *store;
   RGWREST *rest;
   OpsLogSocket *olog;
+  int port;
 };
 
 class RGWProcess {
@@ -459,7 +460,7 @@ static int mongoose_callback(struct mg_connection *conn) {
   OpsLogSocket *olog = pe->olog;
 
   RGWRequest *req = new RGWRequest;
-  RGWMongoose client_io(conn);
+  RGWMongoose client_io(conn, pe->port);
 
   client_io.init(g_ceph_context);
 
@@ -642,39 +643,78 @@ int main(int argc, const char **argv)
     olog->init(g_conf->rgw_ops_log_socket_path);
   }
 
-  bool use_mongoose = (g_conf->rgw_standalone_server_port != 0);
-  struct mg_context *ctx = NULL;
-  RGWProcessEnv pe = { store, &rest, olog };
-
-  if (use_mongoose) {
-    char port_buf[32];
-    snprintf(port_buf, sizeof(port_buf), "%d", (int)g_conf->rgw_standalone_server_port);
-
-    char thread_pool_buf[32];
-    snprintf(thread_pool_buf, sizeof(thread_pool_buf), "%d", (int)g_conf->rgw_thread_pool_size);
-    const char *options[] = {"listening_ports", port_buf, "enable_keep_alive", "yes", "num_threads", thread_pool_buf, NULL};
-
-    struct mg_callbacks cb;
-    memset((void *)&cb, 0, sizeof(cb));
-    cb.begin_request = mongoose_callback;
-    ctx = mg_start(&cb, &pe, (const char **)&options);
-    assert(ctx);
-  }
-
-  RGWProcess *pprocess = new RGWProcess(g_ceph_context, &pe, g_conf->rgw_thread_pool_size);
-
   init_async_signal_handler();
   register_async_signal_handler(SIGHUP, sighup_handler);
   register_async_signal_handler(SIGTERM, handle_sigterm);
   register_async_signal_handler(SIGINT, handle_sigterm);
   register_async_signal_handler(SIGUSR1, handle_sigterm);
-
   sighandler_alrm = signal(SIGALRM, godown_alarm);
 
+  string frontend_frameworks = g_conf->rgw_frontends;
+
+  list<string> frontends;
+
+  get_str_list(g_conf->rgw_frontends, frontends);
+
+  map<string, int> fe_map;
+
+  for (list<string>::iterator iter = frontends.begin(); iter != frontends.end(); ++iter) {
+    string& f = *iter;
+    string framework;
+    int port;
+    int pos = f.find (':');
+    if (pos >= 0) {
+      framework = f.substr(0, pos);
+      string port_str = f.substr(pos + 1);
+      string err;
+      port = strict_strtol(port_str.c_str(), 10, &err);
+      if (!err.empty()) {
+        cerr << "error parsing frontend config for framework " << framework << ": " << err << std::endl;
+        return EINVAL;
+      }
+    } else {
+      framework = f;
+      port = 0;
+    }
+
+    fe_map[framework] = port;
+  }
+
+  struct mg_context *mongoose_ctx = NULL;
+  RGWProcessEnv *mongoose_pe = NULL;
+  
+  RGWProcessEnv fcgi_pe = { store, &rest, olog, 0 };
+
+  RGWProcess *pprocess = new RGWProcess(g_ceph_context, &fcgi_pe, g_conf->rgw_thread_pool_size);
+
+  for (map<string, int>::iterator fiter = fe_map.begin(); fiter != fe_map.end(); ++fiter) {
+    int port = fiter->second;
+    dout(0) << "handler: " << fiter->first << ":" << port << dendl;
+    if (fiter->first == "fastcgi" || fiter->first == "fcgi") {
+      // later
+    } else if (fiter->first == "mongoose") {
+      mongoose_pe = new RGWProcessEnv;
+      *mongoose_pe = { store, &rest, olog, port };
+      char port_buf[32];
+      snprintf(port_buf, sizeof(port_buf), "%d", port);
+
+      char thread_pool_buf[32];
+      snprintf(thread_pool_buf, sizeof(thread_pool_buf), "%d", (int)g_conf->rgw_thread_pool_size);
+      const char *options[] = {"listening_ports", port_buf, "enable_keep_alive", "yes", "num_threads", thread_pool_buf, NULL};
+
+      struct mg_callbacks cb;
+      memset((void *)&cb, 0, sizeof(cb));
+      cb.begin_request = mongoose_callback;
+      mongoose_ctx = mg_start(&cb, mongoose_pe, (const char **)&options);
+      assert(mongoose_ctx);
+    }
+  }
+
+
   pprocess->run();
 
-  if (use_mongoose) {
-    mg_stop(ctx);
+  if (mongoose_ctx) {
+    mg_stop(mongoose_ctx);
   }
 
   derr << "shutting down" << dendl;
@@ -686,6 +726,7 @@ int main(int argc, const char **argv)
   shutdown_async_signal_handler();
 
   delete pprocess;
+  delete mongoose_pe;
 
   if (do_swift) {
     swift_finalize();
index 416cde03a3bce75d4a593da9ee676e1690a166b1..3aa493fec794b0ff9f3900559a28c6aa6cd90986 100644 (file)
@@ -20,7 +20,7 @@ int RGWMongoose::write_data(const char *buf, int len)
   return mg_write(conn, buf, len);
 }
 
-RGWMongoose::RGWMongoose(mg_connection *_conn) : conn(_conn), header_done(false), sent_header(false), has_content_length(false),
+RGWMongoose::RGWMongoose(mg_connection *_conn, int _port) : conn(_conn), port(_port), header_done(false), sent_header(false), has_content_length(false),
                                                  explicit_keepalive(false)
 {
 }
@@ -116,9 +116,9 @@ void RGWMongoose::init_env(CephContext *cct)
   env.set("REMOTE_USER", info->remote_user);
   env.set("SCRIPT_URI", info->uri); /* FIXME */
 
-  char port[16];
-  snprintf(port, sizeof(port), "%d", cct->_conf->rgw_standalone_server_port);
-  env.set("SERVER_PORT", port);
+  char port_buf[16];
+  snprintf(port_buf, sizeof(port_buf), "%d", port);
+  env.set("SERVER_PORT", port_buf);
 }
 
 int RGWMongoose::send_status(const char *status, const char *status_name)
index 09bfa38156bb78aa380603b8d1714c04d85fc550..c1df9f08a5bb9fa2c567c83585a132ce12777498 100644 (file)
@@ -14,6 +14,8 @@ class RGWMongoose : public RGWClientIO
   bufferlist header_data;
   bufferlist data;
 
+  int port;
+
   bool header_done;
   bool sent_header;
   bool has_content_length;
@@ -31,7 +33,7 @@ public:
   int complete_request();
   int send_content_length(uint64_t len);
 
-  RGWMongoose(mg_connection *_conn);
+  RGWMongoose(mg_connection *_conn, int _port);
   void flush();
 };