diff options
| author | Dan Engelbrecht <[email protected]> | 2023-01-13 07:08:02 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-01-13 07:08:02 -0800 |
| commit | 61f18d2de7f37aa03aa09d55562d05c6da033eb2 (patch) | |
| tree | 217828004ee4417b6f2be80a7bf778b808798e4d /zen/cmds/scrub.cpp | |
| parent | Add info (GET) endpoints for structured cache (#211) (diff) | |
| download | archived-zen-61f18d2de7f37aa03aa09d55562d05c6da033eb2.tar.xz archived-zen-61f18d2de7f37aa03aa09d55562d05c6da033eb2.zip | |
zen command line tool improvements (#212)
- Feature: zen command line tool `cache-info` to show cache, namespace or bucket info
- Feature: zen command line tool `project-info` to show store, project or oplog info
- Feature: zen command line tool `project-drop` to drop project or oplog
- Feature: zen command line tool `gc` to trigger a GC run
- Feature: zen command line tool `gc-info` to check status of GC
- Improvement: zen command line tool now fails on any unrecognized arguments
- Improvement: zen command line tool now displays extra help for all sub-commands
- Improvement: host address can now be configured for zen command line tool `drop` command
changelog
Diffstat (limited to 'zen/cmds/scrub.cpp')
| -rw-r--r-- | zen/cmds/scrub.cpp | 116 |
1 files changed, 114 insertions, 2 deletions
diff --git a/zen/cmds/scrub.cpp b/zen/cmds/scrub.cpp index c0fe8ca61..27ff5e0ac 100644 --- a/zen/cmds/scrub.cpp +++ b/zen/cmds/scrub.cpp @@ -1,7 +1,12 @@ // Copyright Epic Games, Inc. All Rights Reserved. #include "scrub.h" -#include <zenutil/zenserverprocess.h> +#include <zencore/logging.h> +#include <zenhttp/httpcommon.h> + +ZEN_THIRD_PARTY_INCLUDES_START +#include <cpr/cpr.h> +ZEN_THIRD_PARTY_INCLUDES_END using namespace std::literals; @@ -9,6 +14,8 @@ 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("http://localhost:1337"), "<hosturl>"); } ScrubCommand::~ScrubCommand() = default; @@ -25,6 +32,26 @@ ScrubCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) GcCommand::GcCommand() { + m_Options.add_options()("h,help", "Print help"); + m_Options.add_option("", "u", "hosturl", "Host URL", cxxopts::value(m_HostName)->default_value("http://localhost:1337"), "<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() @@ -36,7 +63,92 @@ GcCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) { ZEN_UNUSED(GlobalOptions, argc, argv); - return 0; + if (!ParseOptions(argc, argv)) + { + return 0; + } + + 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("http://localhost:1337"), "<hosturl>"); +} + +GcStatusCommand::~GcStatusCommand() +{ +} + +int +GcStatusCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) +{ + ZEN_UNUSED(GlobalOptions, argc, argv); + + if (!ParseOptions(argc, argv)) + { + return 0; + } + + 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 |