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 | |
| parent | add trace command to enable/disable tracing at runtime (#416) (diff) | |
| download | zen-c7d4dc6a4d13881028d566f5ce501335e47e48bf.tar.xz 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')
| -rw-r--r-- | src/zen/cmds/admin_cmd.cpp (renamed from src/zen/cmds/scrub.cpp) | 71 | ||||
| -rw-r--r-- | src/zen/cmds/admin_cmd.h (renamed from src/zen/cmds/scrub.h) | 18 | ||||
| -rw-r--r-- | src/zen/cmds/bench_cmd.cpp (renamed from src/zen/cmds/bench.cpp) | 2 | ||||
| -rw-r--r-- | src/zen/cmds/bench_cmd.h (renamed from src/zen/cmds/bench.h) | 0 | ||||
| -rw-r--r-- | src/zen/cmds/cache_cmd.cpp (renamed from src/zen/cmds/cache.cpp) | 2 | ||||
| -rw-r--r-- | src/zen/cmds/cache_cmd.h (renamed from src/zen/cmds/cache.h) | 0 | ||||
| -rw-r--r-- | src/zen/cmds/copy_cmd.cpp (renamed from src/zen/cmds/copy.cpp) | 2 | ||||
| -rw-r--r-- | src/zen/cmds/copy_cmd.h (renamed from src/zen/cmds/copy.h) | 0 | ||||
| -rw-r--r-- | src/zen/cmds/dedup_cmd.cpp (renamed from src/zen/cmds/dedup.cpp) | 2 | ||||
| -rw-r--r-- | src/zen/cmds/dedup_cmd.h (renamed from src/zen/cmds/dedup.h) | 0 | ||||
| -rw-r--r-- | src/zen/cmds/hash_cmd.cpp (renamed from src/zen/cmds/hash.cpp) | 2 | ||||
| -rw-r--r-- | src/zen/cmds/hash_cmd.h (renamed from src/zen/cmds/hash.h) | 0 | ||||
| -rw-r--r-- | src/zen/cmds/jobs.cpp | 82 | ||||
| -rw-r--r-- | src/zen/cmds/jobs.h | 27 | ||||
| -rw-r--r-- | src/zen/cmds/print_cmd.cpp (renamed from src/zen/cmds/print.cpp) | 2 | ||||
| -rw-r--r-- | src/zen/cmds/print_cmd.h (renamed from src/zen/cmds/print.h) | 0 | ||||
| -rw-r--r-- | src/zen/cmds/projectstore_cmd.cpp (renamed from src/zen/cmds/projectstore.cpp) | 2 | ||||
| -rw-r--r-- | src/zen/cmds/projectstore_cmd.h (renamed from src/zen/cmds/projectstore.h) | 0 | ||||
| -rw-r--r-- | src/zen/cmds/rpcreplay_cmd.cpp (renamed from src/zen/cmds/rpcreplay.cpp) | 2 | ||||
| -rw-r--r-- | src/zen/cmds/rpcreplay_cmd.h (renamed from src/zen/cmds/rpcreplay.h) | 0 | ||||
| -rw-r--r-- | src/zen/cmds/serve_cmd.cpp (renamed from src/zen/cmds/serve.cpp) | 2 | ||||
| -rw-r--r-- | src/zen/cmds/serve_cmd.h (renamed from src/zen/cmds/serve.h) | 0 | ||||
| -rw-r--r-- | src/zen/cmds/status_cmd.cpp (renamed from src/zen/cmds/status.cpp) | 2 | ||||
| -rw-r--r-- | src/zen/cmds/status_cmd.h (renamed from src/zen/cmds/status.h) | 0 | ||||
| -rw-r--r-- | src/zen/cmds/top_cmd.cpp (renamed from src/zen/cmds/top.cpp) | 2 | ||||
| -rw-r--r-- | src/zen/cmds/top_cmd.h (renamed from src/zen/cmds/top.h) | 0 | ||||
| -rw-r--r-- | src/zen/cmds/trace_cmd.cpp (renamed from src/zen/cmds/trace.cpp) | 2 | ||||
| -rw-r--r-- | src/zen/cmds/trace_cmd.h (renamed from src/zen/cmds/trace.h) | 0 | ||||
| -rw-r--r-- | src/zen/cmds/up_cmd.cpp (renamed from src/zen/cmds/up.cpp) | 2 | ||||
| -rw-r--r-- | src/zen/cmds/up_cmd.h (renamed from src/zen/cmds/up.h) | 0 | ||||
| -rw-r--r-- | src/zen/cmds/version_cmd.cpp (renamed from src/zen/cmds/version.cpp) | 2 | ||||
| -rw-r--r-- | src/zen/cmds/version_cmd.h (renamed from src/zen/cmds/version.h) | 0 | ||||
| -rw-r--r-- | src/zen/zen.cpp | 31 |
33 files changed, 117 insertions, 140 deletions
diff --git a/src/zen/cmds/scrub.cpp b/src/zen/cmds/admin_cmd.cpp index 4b47082a0..0aef968a9 100644 --- a/src/zen/cmds/scrub.cpp +++ b/src/zen/cmds/admin_cmd.cpp @@ -1,7 +1,8 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include "scrub.h" +#include "admin_cmd.h" #include <zencore/logging.h> +#include <zenhttp/formatters.h> #include <zenhttp/httpclient.h> #include <zenhttp/httpcommon.h> @@ -198,4 +199,72 @@ GcStatusCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) return 1; } +//////////////////////////////////////////// + +JobCommand::JobCommand() +{ + 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("", "j", "jobid", "Job id", cxxopts::value(m_JobId), "<jobid>"); + m_Options.add_option("", "c", "cancel", "Cancel job id", cxxopts::value(m_Cancel), "<cancel>"); +} + +JobCommand::~JobCommand() = default; + +int +JobCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) +{ + ZEN_UNUSED(GlobalOptions); + + using namespace std::literals; + + if (!ParseOptions(argc, argv)) + { + return 0; + } + + m_HostName = ResolveTargetHostSpec(m_HostName); + + if (m_HostName.empty()) + { + throw OptionParseException("unable to resolve server specification"); + } + + HttpClient Http(m_HostName); + + if (m_Cancel) + { + if (m_JobId == 0) + { + ZEN_ERROR("Job id must be given"); + return 1; + } + } + std::string Url = m_JobId != 0 ? fmt::format("/admin/jobs/{}", m_JobId) : "/admin/jobs"; + + if (m_Cancel) + { + if (HttpClient::Response Result = Http.Delete(Url, HttpClient::Accept(ZenContentType::kJSON))) + { + ZEN_CONSOLE("{}", Result); + } + else + { + Result.ThrowError("failed cancelling job"sv); + return 1; + } + } + else if (HttpClient::Response Result = Http.Get(Url, HttpClient::Accept(ZenContentType::kJSON))) + { + ZEN_CONSOLE("{}", Result.AsText()); + } + else + { + Result.ThrowError("failed fetching job info"sv); + return 1; + } + + return 0; +} + } // namespace zen diff --git a/src/zen/cmds/scrub.h b/src/zen/cmds/admin_cmd.h index ee8b4fdbb..6caab7138 100644 --- a/src/zen/cmds/scrub.h +++ b/src/zen/cmds/admin_cmd.h @@ -55,4 +55,22 @@ private: std::string m_HostName; }; +//////////////////////////////////////////// + +class JobCommand : public ZenCmdBase +{ +public: + JobCommand(); + ~JobCommand(); + + virtual int Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override; + virtual cxxopts::Options& Options() override { return m_Options; } + +private: + cxxopts::Options m_Options{"jobs", "Show/cancel zen background jobs"}; + std::string m_HostName; + std::uint64_t m_JobId = 0; + bool m_Cancel = 0; +}; + } // namespace zen diff --git a/src/zen/cmds/bench.cpp b/src/zen/cmds/bench_cmd.cpp index a2986ce16..06b8967a3 100644 --- a/src/zen/cmds/bench.cpp +++ b/src/zen/cmds/bench_cmd.cpp @@ -1,6 +1,6 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include "bench.h" +#include "bench_cmd.h" #include <zencore/except.h> #include <zencore/filesystem.h> diff --git a/src/zen/cmds/bench.h b/src/zen/cmds/bench_cmd.h index 8a8bd4a7c..8a8bd4a7c 100644 --- a/src/zen/cmds/bench.h +++ b/src/zen/cmds/bench_cmd.h diff --git a/src/zen/cmds/cache.cpp b/src/zen/cmds/cache_cmd.cpp index 15c24f9ee..1bf6ee60e 100644 --- a/src/zen/cmds/cache.cpp +++ b/src/zen/cmds/cache_cmd.cpp @@ -1,6 +1,6 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include "cache.h" +#include "cache_cmd.h" #include <zencore/except.h> #include <zencore/filesystem.h> diff --git a/src/zen/cmds/cache.h b/src/zen/cmds/cache_cmd.h index 1f368bdec..1f368bdec 100644 --- a/src/zen/cmds/cache.h +++ b/src/zen/cmds/cache_cmd.h diff --git a/src/zen/cmds/copy.cpp b/src/zen/cmds/copy_cmd.cpp index 6fff973ba..9f689e5bb 100644 --- a/src/zen/cmds/copy.cpp +++ b/src/zen/cmds/copy_cmd.cpp @@ -1,6 +1,6 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include "copy.h" +#include "copy_cmd.h" #include <zencore/filesystem.h> #include <zencore/fmtutils.h> diff --git a/src/zen/cmds/copy.h b/src/zen/cmds/copy_cmd.h index 549114160..549114160 100644 --- a/src/zen/cmds/copy.h +++ b/src/zen/cmds/copy_cmd.h diff --git a/src/zen/cmds/dedup.cpp b/src/zen/cmds/dedup_cmd.cpp index b48fb8c2d..d496cf404 100644 --- a/src/zen/cmds/dedup.cpp +++ b/src/zen/cmds/dedup_cmd.cpp @@ -1,6 +1,6 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include "dedup.h" +#include "dedup_cmd.h" #include <zencore/blake3.h> #include <zencore/filesystem.h> diff --git a/src/zen/cmds/dedup.h b/src/zen/cmds/dedup_cmd.h index 6318704f5..6318704f5 100644 --- a/src/zen/cmds/dedup.h +++ b/src/zen/cmds/dedup_cmd.h diff --git a/src/zen/cmds/hash.cpp b/src/zen/cmds/hash_cmd.cpp index cc59ed46e..d1f7a1975 100644 --- a/src/zen/cmds/hash.cpp +++ b/src/zen/cmds/hash_cmd.cpp @@ -1,6 +1,6 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include "hash.h" +#include "hash_cmd.h" #include <zencore/blake3.h> #include <zencore/logging.h> diff --git a/src/zen/cmds/hash.h b/src/zen/cmds/hash_cmd.h index e5ee071e9..e5ee071e9 100644 --- a/src/zen/cmds/hash.h +++ b/src/zen/cmds/hash_cmd.h diff --git a/src/zen/cmds/jobs.cpp b/src/zen/cmds/jobs.cpp deleted file mode 100644 index 137c321af..000000000 --- a/src/zen/cmds/jobs.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#include "jobs.h" - -#include <zencore/fmtutils.h> -#include <zencore/logging.h> -#include <zencore/string.h> -#include <zencore/uid.h> -#include <zenhttp/formatters.h> -#include <zenhttp/httpclient.h> - -namespace zen { - -//////////////////////////////////////////// - -JobCommand::JobCommand() -{ - 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("", "j", "jobid", "Job id", cxxopts::value(m_JobId), "<jobid>"); - m_Options.add_option("", "c", "cancel", "Cancel job id", cxxopts::value(m_Cancel), "<cancel>"); -} - -JobCommand::~JobCommand() = default; - -int -JobCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) -{ - ZEN_UNUSED(GlobalOptions); - - using namespace std::literals; - - if (!ParseOptions(argc, argv)) - { - return 0; - } - - m_HostName = ResolveTargetHostSpec(m_HostName); - - if (m_HostName.empty()) - { - throw OptionParseException("unable to resolve server specification"); - } - - HttpClient Http(m_HostName); - - if (m_Cancel) - { - if (m_JobId == 0) - { - ZEN_ERROR("Job id must be given"); - return 1; - } - } - std::string Url = m_JobId != 0 ? fmt::format("/admin/jobs/{}", m_JobId) : "/admin/jobs"; - - if (m_Cancel) - { - if (HttpClient::Response Result = Http.Delete(Url, HttpClient::Accept(ZenContentType::kJSON))) - { - ZEN_CONSOLE("{}", Result); - } - else - { - Result.ThrowError("failed cancelling job"sv); - return 1; - } - } - else if (HttpClient::Response Result = Http.Get(Url, HttpClient::Accept(ZenContentType::kJSON))) - { - ZEN_CONSOLE("{}", Result.AsText()); - } - else - { - Result.ThrowError("failed fetching job info"sv); - return 1; - } - - return 0; -} - -} // namespace zen diff --git a/src/zen/cmds/jobs.h b/src/zen/cmds/jobs.h deleted file mode 100644 index 2c523f24a..000000000 --- a/src/zen/cmds/jobs.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#pragma once - -#include "../zen.h" - -namespace zen { - -//////////////////////////////////////////// - -class JobCommand : public ZenCmdBase -{ -public: - JobCommand(); - ~JobCommand(); - - virtual int Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override; - virtual cxxopts::Options& Options() override { return m_Options; } - -private: - cxxopts::Options m_Options{"jobs", "Show/cancel zen background jobs"}; - std::string m_HostName; - std::uint64_t m_JobId = 0; - bool m_Cancel = 0; -}; - -} // namespace zen diff --git a/src/zen/cmds/print.cpp b/src/zen/cmds/print_cmd.cpp index a3a9bb3cc..acffb2002 100644 --- a/src/zen/cmds/print.cpp +++ b/src/zen/cmds/print_cmd.cpp @@ -1,6 +1,6 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include "print.h" +#include "print_cmd.h" #include <zencore/compactbinarypackage.h> #include <zencore/compactbinaryvalidation.h> diff --git a/src/zen/cmds/print.h b/src/zen/cmds/print_cmd.h index 09d91830a..09d91830a 100644 --- a/src/zen/cmds/print.h +++ b/src/zen/cmds/print_cmd.h diff --git a/src/zen/cmds/projectstore.cpp b/src/zen/cmds/projectstore_cmd.cpp index edeff7d85..5795b3190 100644 --- a/src/zen/cmds/projectstore.cpp +++ b/src/zen/cmds/projectstore_cmd.cpp @@ -1,6 +1,6 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include "projectstore.h" +#include "projectstore_cmd.h" #include <zencore/compactbinarybuilder.h> #include <zencore/filesystem.h> diff --git a/src/zen/cmds/projectstore.h b/src/zen/cmds/projectstore_cmd.h index fd1590423..fd1590423 100644 --- a/src/zen/cmds/projectstore.h +++ b/src/zen/cmds/projectstore_cmd.h diff --git a/src/zen/cmds/rpcreplay.cpp b/src/zen/cmds/rpcreplay_cmd.cpp index 349025791..9e43280e1 100644 --- a/src/zen/cmds/rpcreplay.cpp +++ b/src/zen/cmds/rpcreplay_cmd.cpp @@ -1,6 +1,6 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include "rpcreplay.h" +#include "rpcreplay_cmd.h" #include <zencore/compactbinarybuilder.h> #include <zencore/filesystem.h> diff --git a/src/zen/cmds/rpcreplay.h b/src/zen/cmds/rpcreplay_cmd.h index 742e5ec5b..742e5ec5b 100644 --- a/src/zen/cmds/rpcreplay.h +++ b/src/zen/cmds/rpcreplay_cmd.h diff --git a/src/zen/cmds/serve.cpp b/src/zen/cmds/serve_cmd.cpp index 72afc105d..c8117774b 100644 --- a/src/zen/cmds/serve.cpp +++ b/src/zen/cmds/serve_cmd.cpp @@ -1,6 +1,6 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include "serve.h" +#include "serve_cmd.h" #include <zencore/blake3.h> #include <zencore/compactbinarybuilder.h> diff --git a/src/zen/cmds/serve.h b/src/zen/cmds/serve_cmd.h index 007038d84..007038d84 100644 --- a/src/zen/cmds/serve.h +++ b/src/zen/cmds/serve_cmd.h diff --git a/src/zen/cmds/status.cpp b/src/zen/cmds/status_cmd.cpp index 1afe191b7..cc936835a 100644 --- a/src/zen/cmds/status.cpp +++ b/src/zen/cmds/status_cmd.cpp @@ -1,6 +1,6 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include "status.h" +#include "status_cmd.h" #include <zencore/fmtutils.h> #include <zencore/logging.h> diff --git a/src/zen/cmds/status.h b/src/zen/cmds/status_cmd.h index 98f72e651..98f72e651 100644 --- a/src/zen/cmds/status.h +++ b/src/zen/cmds/status_cmd.h diff --git a/src/zen/cmds/top.cpp b/src/zen/cmds/top_cmd.cpp index 6aed6fe1b..568ee76c9 100644 --- a/src/zen/cmds/top.cpp +++ b/src/zen/cmds/top_cmd.cpp @@ -1,6 +1,6 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include "top.h" +#include "top_cmd.h" #include <zencore/fmtutils.h> #include <zencore/logging.h> diff --git a/src/zen/cmds/top.h b/src/zen/cmds/top_cmd.h index 83410587b..83410587b 100644 --- a/src/zen/cmds/top.h +++ b/src/zen/cmds/top_cmd.h diff --git a/src/zen/cmds/trace.cpp b/src/zen/cmds/trace_cmd.cpp index f8968a680..fee4dd6bc 100644 --- a/src/zen/cmds/trace.cpp +++ b/src/zen/cmds/trace_cmd.cpp @@ -1,6 +1,6 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include "trace.h" +#include "trace_cmd.h" #include <zencore/logging.h> #include <zenhttp/httpclient.h> #include <zenhttp/httpcommon.h> diff --git a/src/zen/cmds/trace.h b/src/zen/cmds/trace_cmd.h index 7b2d15fb1..7b2d15fb1 100644 --- a/src/zen/cmds/trace.h +++ b/src/zen/cmds/trace_cmd.h diff --git a/src/zen/cmds/up.cpp b/src/zen/cmds/up_cmd.cpp index d1ae0794a..b07fb6ec8 100644 --- a/src/zen/cmds/up.cpp +++ b/src/zen/cmds/up_cmd.cpp @@ -1,6 +1,6 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include "up.h" +#include "up_cmd.h" #include <zencore/filesystem.h> #include <zencore/logging.h> diff --git a/src/zen/cmds/up.h b/src/zen/cmds/up_cmd.h index 510cc865e..510cc865e 100644 --- a/src/zen/cmds/up.h +++ b/src/zen/cmds/up_cmd.h diff --git a/src/zen/cmds/version.cpp b/src/zen/cmds/version_cmd.cpp index ba83b527d..bd31862b4 100644 --- a/src/zen/cmds/version.cpp +++ b/src/zen/cmds/version_cmd.cpp @@ -1,6 +1,6 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include "version.h" +#include "version_cmd.h" #include <zencore/config.h> #include <zencore/filesystem.h> diff --git a/src/zen/cmds/version.h b/src/zen/cmds/version_cmd.h index 0e37e91a0..0e37e91a0 100644 --- a/src/zen/cmds/version.h +++ b/src/zen/cmds/version_cmd.h diff --git a/src/zen/zen.cpp b/src/zen/zen.cpp index 8449c7a43..23dce850f 100644 --- a/src/zen/zen.cpp +++ b/src/zen/zen.cpp @@ -5,22 +5,21 @@ #include "zen.h" -#include "cmds/bench.h" -#include "cmds/cache.h" -#include "cmds/copy.h" -#include "cmds/dedup.h" -#include "cmds/hash.h" -#include "cmds/jobs.h" -#include "cmds/print.h" -#include "cmds/projectstore.h" -#include "cmds/rpcreplay.h" -#include "cmds/scrub.h" -#include "cmds/serve.h" -#include "cmds/status.h" -#include "cmds/top.h" -#include "cmds/trace.h" -#include "cmds/up.h" -#include "cmds/version.h" +#include "cmds/admin_cmd.h" +#include "cmds/bench_cmd.h" +#include "cmds/cache_cmd.h" +#include "cmds/copy_cmd.h" +#include "cmds/dedup_cmd.h" +#include "cmds/hash_cmd.h" +#include "cmds/print_cmd.h" +#include "cmds/projectstore_cmd.h" +#include "cmds/rpcreplay_cmd.h" +#include "cmds/serve_cmd.h" +#include "cmds/status_cmd.h" +#include "cmds/top_cmd.h" +#include "cmds/trace_cmd.h" +#include "cmds/up_cmd.h" +#include "cmds/version_cmd.h" #include "cmds/vfs_cmd.h" #include <zencore/filesystem.h> |