diff options
| author | Dan Engelbrecht <[email protected]> | 2023-09-22 08:22:06 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-22 14:22:06 +0200 |
| commit | c7d4dc6a4d13881028d566f5ce501335e47e48bf (patch) | |
| tree | 493110da583a8e5d97fe05e14f23469ee6244d2b /src/zen/cmds/scrub.cpp | |
| parent | add trace command to enable/disable tracing at runtime (#416) (diff) | |
| download | archived-zen-c7d4dc6a4d13881028d566f5ce501335e47e48bf.tar.xz archived-zen-c7d4dc6a4d13881028d566f5ce501335e47e48bf.zip | |
Collect all zen admin-related commands into admin.h/.cpp (#418)
* move commands in scrub.h/cpp to admin_cmd.h/cpp
* move job command into admin_cmd.h/.cpp
* admin -> admin_cmd
* bench -> bench_cmd
* cache -> cache_cmd
* copy -> copy_cmd
* dedup -> dedup_cmd
* hash -> hash_cmd
* print -> print_cmd
* projectstore -> projectstore_cmd
* rpcreplay -> rpcreplay_cmd
* serve -> serve_cmd
* status -> status_cmd
* top -> top_cmd
* trace -> trace_cmd
* up -> up_cmd
* version -> version_cmd
Diffstat (limited to 'src/zen/cmds/scrub.cpp')
| -rw-r--r-- | src/zen/cmds/scrub.cpp | 201 |
1 files changed, 0 insertions, 201 deletions
diff --git a/src/zen/cmds/scrub.cpp b/src/zen/cmds/scrub.cpp deleted file mode 100644 index 4b47082a0..000000000 --- a/src/zen/cmds/scrub.cpp +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#include "scrub.h" -#include <zencore/logging.h> -#include <zenhttp/httpclient.h> -#include <zenhttp/httpcommon.h> - -ZEN_THIRD_PARTY_INCLUDES_START -#include <cpr/cpr.h> -ZEN_THIRD_PARTY_INCLUDES_END - -using namespace std::literals; - -namespace zen { - -ScrubCommand::ScrubCommand() -{ - m_Options.add_options()("h,help", "Print help"); - m_Options.add_option("", "u", "hosturl", "Host URL", cxxopts::value(m_HostName)->default_value(""), "<hosturl>"); -} - -ScrubCommand::~ScrubCommand() = default; - -int -ScrubCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) -{ - ZEN_UNUSED(GlobalOptions); - - if (!ParseOptions(argc, argv)) - { - return 0; - } - - m_HostName = ResolveTargetHostSpec(m_HostName); - - if (m_HostName.empty()) - { - throw OptionParseException("unable to resolve server specification"); - } - - zen::HttpClient Http(m_HostName); - - if (zen::HttpClient::Response Response = Http.Post("/admin/scrub"sv)) - { - ZEN_CONSOLE("OK: {}", Response.ToText()); - - return 0; - } - else if (int StatusCode = (int)Response.StatusCode) - { - ZEN_ERROR("scrub start failed: {}: {} ({})", - (int)Response.StatusCode, - ReasonStringForHttpResultCode((int)Response.StatusCode), - Response.AsText()); - } - else - { - ZEN_ERROR("scrub start failed: {}", Response.AsText()); - } - - return 1; -} - -////////////////////////////////////////////////////////////////////////// - -GcCommand::GcCommand() -{ - m_Options.add_options()("h,help", "Print help"); - m_Options.add_option("", "u", "hosturl", "Host URL", cxxopts::value(m_HostName)->default_value(""), "<hosturl>"); - m_Options.add_option("", - "s", - "smallobjects", - "Collect small objects", - cxxopts::value(m_SmallObjects)->default_value("false"), - "<smallobjects>"); - m_Options.add_option("", - "m", - "maxcacheduration", - "Max cache lifetime (in seconds)", - cxxopts::value(m_MaxCacheDuration)->default_value("0"), - "<maxcacheduration>"); - m_Options.add_option("", - "d", - "disksizesoftlimit", - "Max disk usage size (in bytes)", - cxxopts::value(m_DiskSizeSoftLimit)->default_value("0"), - "<disksizesoftlimit>"); -} - -GcCommand::~GcCommand() -{ -} - -int -GcCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) -{ - ZEN_UNUSED(GlobalOptions); - - if (!ParseOptions(argc, argv)) - { - return 0; - } - - m_HostName = ResolveTargetHostSpec(m_HostName); - - if (m_HostName.empty()) - { - throw OptionParseException("unable to resolve server specification"); - } - - cpr::Parameters Params; - if (m_SmallObjects) - { - Params.Add({"smallobjects", "true"}); - } - if (m_MaxCacheDuration != 0) - { - Params.Add({"maxcacheduration", fmt::format("{}", m_MaxCacheDuration)}); - } - if (m_DiskSizeSoftLimit != 0) - { - Params.Add({"disksizesoftlimit", fmt::format("{}", m_DiskSizeSoftLimit)}); - } - - cpr::Session Session; - Session.SetHeader(cpr::Header{{"Accept", "application/json"}}); - Session.SetUrl({fmt::format("{}/admin/gc", m_HostName)}); - Session.SetParameters(Params); - - cpr::Response Result = Session.Post(); - - if (zen::IsHttpSuccessCode(Result.status_code)) - { - ZEN_CONSOLE("OK: {}", Result.text); - return 0; - } - - if (Result.status_code) - { - ZEN_ERROR("GC start failed: {}: {} ({})", Result.status_code, Result.reason, Result.text); - } - else - { - ZEN_ERROR("GC start failed: {}", Result.error.message); - } - - return 1; -} - -GcStatusCommand::GcStatusCommand() -{ - m_Options.add_options()("h,help", "Print help"); - m_Options.add_option("", "u", "hosturl", "Host URL", cxxopts::value(m_HostName)->default_value(""), "<hosturl>"); -} - -GcStatusCommand::~GcStatusCommand() -{ -} - -int -GcStatusCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) -{ - ZEN_UNUSED(GlobalOptions); - - if (!ParseOptions(argc, argv)) - { - return 0; - } - - m_HostName = ResolveTargetHostSpec(m_HostName); - - if (m_HostName.empty()) - { - throw OptionParseException("unable to resolve server specification"); - } - - cpr::Session Session; - Session.SetHeader(cpr::Header{{"Accept", "application/json"}}); - Session.SetUrl({fmt::format("{}/admin/gc", m_HostName)}); - - cpr::Response Result = Session.Get(); - - if (zen::IsHttpSuccessCode(Result.status_code)) - { - ZEN_CONSOLE("OK: {}", Result.text); - return 0; - } - - if (Result.status_code) - { - ZEN_ERROR("GC status failed: {}: {} ({})", Result.status_code, Result.reason, Result.text); - } - else - { - ZEN_ERROR("GC status failed: {}", Result.error.message); - } - - return 1; -} - -} // namespace zen |