aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-08-07 13:02:02 +0200
committerStefan Boberg <[email protected]>2021-08-07 13:02:02 +0200
commit0a85e531f5a0632c1d8c617635ae7eb75f27abf1 (patch)
treeff8e080b6486f606decce94a156733e5a41c95a2
parentAdded support for defining test/non-test server environments (diff)
downloadzen-0a85e531f5a0632c1d8c617635ae7eb75f27abf1.tar.xz
zen-0a85e531f5a0632c1d8c617635ae7eb75f27abf1.zip
Added some new management commands
-rw-r--r--zen/cmds/run.cpp4
-rw-r--r--zen/cmds/status.cpp22
-rw-r--r--zen/cmds/status.h18
-rw-r--r--zen/cmds/up.cpp59
-rw-r--r--zen/cmds/up.h31
-rw-r--r--zen/zen.cpp32
6 files changed, 155 insertions, 11 deletions
diff --git a/zen/cmds/run.cpp b/zen/cmds/run.cpp
index b9bb8e9a3..d833b1d66 100644
--- a/zen/cmds/run.cpp
+++ b/zen/cmds/run.cpp
@@ -61,10 +61,10 @@ RunCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
throw cxxopts::OptionParseException("run command requires a command to run!");
}
- ZenTestEnvironment TestEnv;
+ ZenServerEnvironment TestEnv;
std::filesystem::path ProgramBaseDir = std::filesystem::path(argv[0]).parent_path();
std::filesystem::path TestBaseDir = ProgramBaseDir.parent_path().parent_path() / ".test";
- TestEnv.Initialize(ProgramBaseDir, TestBaseDir);
+ TestEnv.InitializeForTest(ProgramBaseDir, TestBaseDir);
std::filesystem::path TestDir = TestEnv.CreateNewTestDir();
diff --git a/zen/cmds/status.cpp b/zen/cmds/status.cpp
new file mode 100644
index 000000000..798be9f3e
--- /dev/null
+++ b/zen/cmds/status.cpp
@@ -0,0 +1,22 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include "status.h"
+
+#include <spdlog/spdlog.h>
+#include <memory>
+
+StatusCommand::StatusCommand()
+{
+}
+
+StatusCommand::~StatusCommand() = default;
+
+int
+StatusCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
+{
+ ZEN_UNUSED(GlobalOptions, argc, argv);
+
+ return 0;
+}
diff --git a/zen/cmds/status.h b/zen/cmds/status.h
new file mode 100644
index 000000000..bb439f340
--- /dev/null
+++ b/zen/cmds/status.h
@@ -0,0 +1,18 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include "../zen.h"
+
+class StatusCommand : public ZenCmdBase
+{
+public:
+ StatusCommand();
+ ~StatusCommand();
+
+ virtual int Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override;
+ virtual cxxopts::Options* Options() override { return &m_Options; }
+
+private:
+ cxxopts::Options m_Options{"status", "Show zen status"};
+};
diff --git a/zen/cmds/up.cpp b/zen/cmds/up.cpp
new file mode 100644
index 000000000..8cc1f8eca
--- /dev/null
+++ b/zen/cmds/up.cpp
@@ -0,0 +1,59 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include "up.h"
+
+#include <zencore/filesystem.h>
+#include <zenserverprocess.h>
+
+#include <spdlog/spdlog.h>
+#include <memory>
+
+UpCommand::UpCommand()
+{
+}
+
+UpCommand::~UpCommand() = default;
+
+int
+UpCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
+{
+ ZEN_UNUSED(GlobalOptions, argc, argv);
+
+ std::filesystem::path ExePath = zen::GetRunningExecutablePath();
+
+ ZenServerEnvironment ServerEnvironment;
+ ServerEnvironment.Initialize(ExePath.parent_path());
+ ZenServerInstance Server(ServerEnvironment);
+ Server.SpawnServer();
+
+ int Timeout = 10000;
+
+ if (!Server.WaitUntilReady(Timeout))
+ {
+ spdlog::error("zen server launch failed (timed out)");
+ }
+ else
+ {
+ spdlog::info("zen server up");
+ }
+
+ return 0;
+}
+
+//////////////////////////////////////////////////////////////////////////
+
+DownCommand::DownCommand()
+{
+}
+
+DownCommand::~DownCommand() = default;
+
+int
+DownCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
+{
+ ZEN_UNUSED(GlobalOptions, argc, argv);
+
+ return 0;
+}
diff --git a/zen/cmds/up.h b/zen/cmds/up.h
new file mode 100644
index 000000000..a3c6eaa06
--- /dev/null
+++ b/zen/cmds/up.h
@@ -0,0 +1,31 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include "../zen.h"
+
+class UpCommand : public ZenCmdBase
+{
+public:
+ UpCommand();
+ ~UpCommand();
+
+ virtual int Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override;
+ virtual cxxopts::Options* Options() override { return &m_Options; }
+
+private:
+ cxxopts::Options m_Options{"up", "Bring up zen service"};
+};
+
+class DownCommand : public ZenCmdBase
+{
+public:
+ DownCommand();
+ ~DownCommand();
+
+ virtual int Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override;
+ virtual cxxopts::Options* Options() override { return &m_Options; }
+
+private:
+ cxxopts::Options m_Options{"down", "Bring down zen service"};
+};
diff --git a/zen/zen.cpp b/zen/zen.cpp
index 6e06d6c49..03abff6d0 100644
--- a/zen/zen.cpp
+++ b/zen/zen.cpp
@@ -13,7 +13,9 @@
#include "cmds/deploy.h"
#include "cmds/hash.h"
#include "cmds/run.h"
+#include "cmds/status.h"
#include "cmds/top.h"
+#include "cmds/up.h"
#include <zencore/scopeguard.h>
#include <zencore/string.h>
@@ -123,21 +125,28 @@ main(int argc, char** argv)
ChunkCommand ChunkCmd;
RunTestsCommand RunTestsCmd;
RunCommand RunCmd;
+ StatusCommand StatusCmd;
TopCommand TopCmd;
+ UpCommand UpCmd;
+ DownCommand DownCmd;
const struct CommandInfo
{
const char* CmdName;
ZenCmdBase* Cmd;
+ const char* CmdSummary;
} Commands[] = {
- {"chunk", &ChunkCmd},
- {"copy", &CopyCmd},
- {"deploy", &DeployCmd},
- {"dedup", &DedupCmd},
- {"hash", &HashCmd},
- {"runtests", &RunTestsCmd},
- {"run", &RunCmd},
- {"top", &TopCmd},
+ {"chunk", &ChunkCmd, "Perform chunking"},
+ {"copy", &CopyCmd, "Copy file(s)"},
+ {"deploy", &DeployCmd, "Deploy data"},
+ {"dedup", &DedupCmd, "Dedup files"},
+ {"hash", &HashCmd, "Compute file hashes"},
+ {"runtests", &RunTestsCmd, "Run zen tests"},
+ {"run", &RunCmd, "Remote execution"},
+ {"status", &StatusCmd, "Show zen status"},
+ {"top", &TopCmd, "Monitor zen server activity"},
+ {"up", &UpCmd, "Bring zen server up"},
+ {"down", &DownCmd, "Bring zen server down"},
};
// Build set containing available commands
@@ -246,12 +255,17 @@ main(int argc, char** argv)
for (const auto& CmdInfo : Commands)
{
- printf("\n-- %s\n%s\n", CmdInfo.CmdName, CmdInfo.Cmd->Options()->help().c_str());
+ printf(" %-10s %s\n", CmdInfo.CmdName, CmdInfo.CmdSummary);
}
exit(0);
}
+ if (GlobalOptions.IsDebug)
+ {
+ spdlog::set_level(spdlog::level::debug);
+ }
+
for (const CommandInfo& CmdInfo : Commands)
{
if (_stricmp(SubCommand.c_str(), CmdInfo.CmdName) == 0)