summaryrefslogtreecommitdiffstats
path: root/src/rgw/rgw_main.h
blob: bbe5143518c5602e3942c6c9cbcf622494712e46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab ft=cpp

/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2022 Red Hat, Inc
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software
 * Foundation.  See file COPYING.
 *
 */

#pragma once

#include <vector>
#include <map>
#include <string>
#include "rgw_common.h"
#include "rgw_rest.h"
#include "rgw_frontend.h"
#include "rgw_period_pusher.h"
#include "rgw_realm_reloader.h"
#include "rgw_ldap.h"
#include "rgw_lua.h"
#include "rgw_dmclock_scheduler_ctx.h"
#include "rgw_ratelimit.h"


class RGWPauser : public RGWRealmReloader::Pauser {
  std::vector<Pauser*> pausers;

public:
  ~RGWPauser() override = default;

  void add_pauser(Pauser* pauser) {
    pausers.push_back(pauser);
  }

  void pause() override {
    std::for_each(pausers.begin(), pausers.end(), [](Pauser* p){p->pause();});
  }
  void resume(rgw::sal::Driver* driver) override {
    std::for_each(pausers.begin(), pausers.end(), [driver](Pauser* p){p->resume(driver);});
  }

};

namespace rgw {

namespace lua { class Background; }

class RGWLib;
class AppMain {
  /* several components should be initalized only if librgw is
    * also serving HTTP */
  bool have_http_frontend{false};
  bool nfs{false};

  std::vector<RGWFrontend*> fes;
  std::vector<RGWFrontendConfig*> fe_configs;
  std::multimap<string, RGWFrontendConfig*> fe_map;
  std::unique_ptr<rgw::LDAPHelper> ldh;
  OpsLogSink* olog;
  RGWREST rest;
  std::unique_ptr<rgw::lua::Background> lua_background;
  std::unique_ptr<rgw::auth::ImplicitTenants> implicit_tenant_context;
  std::unique_ptr<rgw::dmclock::SchedulerCtx> sched_ctx;
  std::unique_ptr<ActiveRateLimiter> ratelimiter;
  std::map<std::string, std::string> service_map_meta;
  // wow, realm reloader has a lot of parts
  std::unique_ptr<RGWRealmReloader> reloader;
  std::unique_ptr<RGWPeriodPusher> pusher;
  std::unique_ptr<RGWFrontendPauser> fe_pauser;
  std::unique_ptr<RGWRealmWatcher> realm_watcher;
  std::unique_ptr<RGWPauser> rgw_pauser;
  DoutPrefixProvider* dpp;
  RGWProcessEnv env;

public:
  AppMain(DoutPrefixProvider* dpp)
    : dpp(dpp)
    {}

  void shutdown(std::function<void(void)> finalize_async_signals
	       = []() { /* nada */});

  rgw::sal::Driver* get_driver() {
    return env.driver;
  }

  rgw::LDAPHelper* get_ldh() {
    return ldh.get();
  }

  void init_frontends1(bool nfs = false);
  void init_numa();
  void init_storage();
  void init_perfcounters();
  void init_http_clients();
  void cond_init_apis();
  void init_ldap();
  void init_opslog();
  int init_frontends2(RGWLib* rgwlib = nullptr);
  void init_tracepoints();
  void init_notification_endpoints();
  void init_lua();

  bool have_http() {
    return have_http_frontend;
  }

  static OpsLogFile* ops_log_file;
}; /* AppMain */
} // namespace rgw

static inline RGWRESTMgr *set_logging(RGWRESTMgr* mgr)
{
  mgr->set_logging(true);
  return mgr;
}

static inline RGWRESTMgr *rest_filter(rgw::sal::Driver* driver, int dialect, RGWRESTMgr* orig)
{
  RGWSyncModuleInstanceRef sync_module = driver->get_sync_module();
  if (sync_module) {
    return sync_module->get_rest_filter(dialect, orig);
  } else {
    return orig;
  }
}