Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup static variables in header files #2890

Merged
merged 3 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ jobs:
-DENABLE_ASAN=on \
-DENABLE_TESTING=on \
-B build
echo "::set-output name=j::6"
echo "::set-output name=t::10"
echo "::set-output name=j::6"
echo "::set-output name=t::10"
;;
esac
- name: Make
Expand Down
4 changes: 4 additions & 0 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
#include "version/Version.h"
#include "webservice/Common.h"

DECLARE_int32(ws_meta_http_port);
DECLARE_int32(ws_meta_h2_port);

DEFINE_uint32(expired_time_factor, 5, "The factor of expired time based on heart beat interval");
DEFINE_int32(heartbeat_interval_secs, 10, "Heartbeat interval in seconds");
DEFINE_int32(meta_client_retry_times, 3, "meta client retry times, 0 means no retry");
DEFINE_int32(meta_client_retry_interval_secs, 1, "meta client sleep interval between retry");
DEFINE_int32(meta_client_timeout_ms, 60 * 1000, "meta client timeout");
DEFINE_string(cluster_id_path, "cluster.id", "file path saved clusterId");
DEFINE_int32(check_plan_killed_frequency, 8, "check plan killed every 1<<n times");

namespace nebula {
namespace meta {

Expand Down
2 changes: 2 additions & 0 deletions src/meta/http/MetaHttpDownloadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "webservice/Common.h"
#include "webservice/WebService.h"

DECLARE_int32(ws_storage_http_port);

namespace nebula {
namespace meta {

Expand Down
3 changes: 3 additions & 0 deletions src/meta/http/MetaHttpIngestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include "webservice/Common.h"
#include "webservice/WebService.h"

DECLARE_int32(ws_storage_http_port);
DECLARE_int32(ws_storage_h2_port);

DEFINE_int32(meta_ingest_thread_num, 3, "Meta daemon's ingest thread number");

namespace nebula {
Expand Down
5 changes: 3 additions & 2 deletions src/webservice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ nebula_add_library(
GetFlagsHandler.cpp
SetFlagsHandler.cpp
GetStatsHandler.cpp
Router.cpp
StatusHandler.cpp
Router.cpp
StatusHandler.cpp
)

set_target_properties(ws_obj PROPERTIES COMPILE_FLAGS "-Wno-error=format-security")

nebula_add_library(
Expand Down
14 changes: 14 additions & 0 deletions src/webservice/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@

#include "webservice/Common.h"

#include <gflags/gflags.h>

DEFINE_int32(ws_meta_http_port, 11000, "Port to listen on Meta with HTTP protocol");
DEFINE_int32(ws_meta_h2_port, 11002, "Port to listen on Meta with HTTP/2 protocol");
DEFINE_int32(ws_storage_http_port, 12000, "Port to listen on Storage with HTTP protocol");
DEFINE_int32(ws_storage_h2_port, 12002, "Port to listen on Storage with HTTP/2 protocol");

namespace nebula {

std::unordered_map<HttpStatusCode, std::string> WebServiceUtils::kStatusStringMap_ = {
{HttpStatusCode::OK, "OK"},
{HttpStatusCode::BAD_REQUEST, "Bad Request"},
{HttpStatusCode::FORBIDDEN, "Forbidden"},
{HttpStatusCode::NOT_FOUND, "Not Found"},
{HttpStatusCode::METHOD_NOT_ALLOWED, "Method Not Allowed"},
};

} // namespace nebula
23 changes: 8 additions & 15 deletions src/webservice/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
#ifndef WEBSERVICE_COMMON_H_
#define WEBSERVICE_COMMON_H_

#include "common/base/Base.h"

DECLARE_int32(ws_meta_http_port);
DECLARE_int32(ws_meta_h2_port);
DECLARE_int32(ws_storage_http_port);
DECLARE_int32(ws_storage_h2_port);
#include <cstdint>
#include <string>
#include <unordered_map>

namespace nebula {

Expand All @@ -23,27 +20,23 @@ enum class HttpCode {
E_ILLEGAL_ARGUMENT = -3,
};

enum class HttpStatusCode {
enum class HttpStatusCode : int32_t {
OK = 200,
BAD_REQUEST = 400,
FORBIDDEN = 403,
NOT_FOUND = 404,
METHOD_NOT_ALLOWED = 405,
};

static std::map<HttpStatusCode, std::string> statusStringMap{
{HttpStatusCode::OK, "OK"},
{HttpStatusCode::BAD_REQUEST, "Bad Request"},
{HttpStatusCode::FORBIDDEN, "Forbidden"},
{HttpStatusCode::NOT_FOUND, "Not Found"},
{HttpStatusCode::METHOD_NOT_ALLOWED, "Method Not Allowed"}};

class WebServiceUtils final {
public:
static int32_t to(HttpStatusCode code) { return static_cast<int32_t>(code); }
static std::string toString(HttpStatusCode code) { return kStatusStringMap_[code]; }

static std::string toString(HttpStatusCode code) { return statusStringMap[code]; }
private:
static std::unordered_map<HttpStatusCode, std::string> kStatusStringMap_;
};

} // namespace nebula

#endif // WEBSERVICE_COMMON_H_
2 changes: 2 additions & 0 deletions src/webservice/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ nebula_add_test(
OBJECTS
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:base_obj>
$<TARGET_OBJECTS:process_obj>
$<TARGET_OBJECTS:fs_obj>
Expand All @@ -31,6 +32,7 @@ nebula_add_test(
OBJECTS
$<TARGET_OBJECTS:http_client_obj>
$<TARGET_OBJECTS:ws_obj>
$<TARGET_OBJECTS:ws_common_obj>
$<TARGET_OBJECTS:base_obj>
$<TARGET_OBJECTS:process_obj>
$<TARGET_OBJECTS:fs_obj>
Expand Down