mirror of
https://github.com/CHN-beta/hpcstat.git
synced 2026-01-11 18:29:53 +08:00
基本完成
This commit is contained in:
15
include/hpcstat/common.hpp
Normal file
15
include/hpcstat/common.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
# pragma once
|
||||
# include <optional>
|
||||
# include <string>
|
||||
# include <filesystem>
|
||||
# include <vector>
|
||||
|
||||
namespace hpcstat
|
||||
{
|
||||
// run a program, wait until it exit, return its stdout if it return 0, otherwise nullopt
|
||||
std::optional<std::string> exec
|
||||
(std::filesystem::path program, std::vector<std::string> args, std::optional<std::string> stdin = std::nullopt);
|
||||
|
||||
// get current time
|
||||
long now();
|
||||
}
|
||||
12
include/hpcstat/env.hpp
Normal file
12
include/hpcstat/env.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
# pragma once
|
||||
# include <optional>
|
||||
# include <string>
|
||||
|
||||
namespace hpcstat::env
|
||||
{
|
||||
// check if the program is running in an interactive shell
|
||||
bool interactive();
|
||||
|
||||
// get the value of an environment variable
|
||||
std::optional<std::string> env(std::string name, bool required = false);
|
||||
}
|
||||
10
include/hpcstat/keys.hpp
Normal file
10
include/hpcstat/keys.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
# pragma once
|
||||
# include <string>
|
||||
# include <map>
|
||||
|
||||
namespace hpcstat
|
||||
{
|
||||
// valid keys
|
||||
struct Key { std::string PubkeyFilename; std::string Username; };
|
||||
extern std::map<std::string, Key> Keys;
|
||||
}
|
||||
14
include/hpcstat/lfs.hpp
Normal file
14
include/hpcstat/lfs.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
# pragma once
|
||||
# include <optional>
|
||||
# include <utility>
|
||||
# include <string>
|
||||
# include <vector>
|
||||
# include <map>
|
||||
|
||||
namespace hpcstat::lfs
|
||||
{
|
||||
std::optional<std::pair<unsigned, std::string>> bsub(std::vector<std::string> args);
|
||||
// JobId -> { SubmitTime, Status, CpuTime }
|
||||
std::optional<std::map<unsigned, std::tuple<std::string, std::string, double>>> bjobs_list();
|
||||
std::optional<std::string> bjobs_detail(unsigned jobid);
|
||||
}
|
||||
87
include/hpcstat/sql.hpp
Normal file
87
include/hpcstat/sql.hpp
Normal file
@@ -0,0 +1,87 @@
|
||||
# pragma once
|
||||
# include <set>
|
||||
# include <zxorm/zxorm.hpp>
|
||||
# include <zpp_bits.h>
|
||||
|
||||
namespace hpcstat::sql
|
||||
{
|
||||
struct LoginData
|
||||
{
|
||||
unsigned Id = 0; long Time;
|
||||
std::string Key, SessionId, Signature = "";
|
||||
std::optional<std::string> Subaccount, Ip;
|
||||
bool Interactive;
|
||||
using serialize = zpp::bits::members<8>;
|
||||
};
|
||||
using LoginTable = zxorm::Table
|
||||
<
|
||||
"login", LoginData,
|
||||
zxorm::Column<"id", &LoginData::Id, zxorm::PrimaryKey<>>,
|
||||
zxorm::Column<"time", &LoginData::Time>,
|
||||
zxorm::Column<"key", &LoginData::Key>,
|
||||
zxorm::Column<"session_id", &LoginData::SessionId>,
|
||||
zxorm::Column<"signature", &LoginData::Signature>,
|
||||
zxorm::Column<"sub_account", &LoginData::Subaccount>,
|
||||
zxorm::Column<"ip", &LoginData::Ip>,
|
||||
zxorm::Column<"interactive", &LoginData::Interactive>
|
||||
>;
|
||||
struct LogoutData { unsigned Id = 0; long Time; std::string SessionId; };
|
||||
using LogoutTable = zxorm::Table
|
||||
<
|
||||
"logout", LogoutData,
|
||||
zxorm::Column<"id", &LogoutData::Id, zxorm::PrimaryKey<>>,
|
||||
zxorm::Column<"time", &LogoutData::Time>,
|
||||
zxorm::Column<"sessionid", &LogoutData::SessionId>
|
||||
>;
|
||||
struct SubmitJobData
|
||||
{
|
||||
unsigned Id = 0;
|
||||
long Time;
|
||||
unsigned JobId;
|
||||
std::string Key, SessionId, SubmitDir, JobCommand, Signature = "";
|
||||
std::optional<std::string> Subaccount, Ip;
|
||||
using serialize = zpp::bits::members<10>;
|
||||
};
|
||||
using SubmitJobTable = zxorm::Table
|
||||
<
|
||||
"submitjob", SubmitJobData,
|
||||
zxorm::Column<"id", &SubmitJobData::Id, zxorm::PrimaryKey<>>,
|
||||
zxorm::Column<"time", &SubmitJobData::Time>,
|
||||
zxorm::Column<"job_id", &SubmitJobData::JobId>,
|
||||
zxorm::Column<"key", &SubmitJobData::Key>,
|
||||
zxorm::Column<"session_id", &SubmitJobData::SessionId>,
|
||||
zxorm::Column<"submit_dir", &SubmitJobData::SubmitDir>,
|
||||
zxorm::Column<"job_command", &SubmitJobData::JobCommand>,
|
||||
zxorm::Column<"signature", &SubmitJobData::Signature>,
|
||||
zxorm::Column<"sub_account", &SubmitJobData::Subaccount>,
|
||||
zxorm::Column<"ip", &SubmitJobData::Ip>
|
||||
>;
|
||||
struct FinishJobData
|
||||
{
|
||||
unsigned Id = 0;
|
||||
long Time;
|
||||
unsigned JobId;
|
||||
std::string JobResult, SubmitTime, Signature = "";
|
||||
double CpuTime;
|
||||
using serialize = zpp::bits::members<7>;
|
||||
};
|
||||
using FinishJobTable = zxorm::Table
|
||||
<
|
||||
"finishjob", FinishJobData,
|
||||
zxorm::Column<"id", &FinishJobData::Id, zxorm::PrimaryKey<>>,
|
||||
zxorm::Column<"time", &FinishJobData::Time>,
|
||||
zxorm::Column<"job_id", &FinishJobData::JobId>,
|
||||
zxorm::Column<"job_result", &FinishJobData::JobResult>,
|
||||
zxorm::Column<"submit_time", &FinishJobData::SubmitTime>,
|
||||
zxorm::Column<"signature", &FinishJobData::Signature>,
|
||||
zxorm::Column<"cpu_time", &FinishJobData::CpuTime>
|
||||
>;
|
||||
// 序列化任意数据,用于之后签名
|
||||
std::string serialize(auto data);
|
||||
// 初始化数据库
|
||||
bool initdb();
|
||||
// 将数据写入数据库
|
||||
bool writedb(auto value);
|
||||
// 查询 bjobs -a 的结果中,有哪些是已经被写入到数据库中的(按照任务 id 和提交时间计算),返回未被写入的任务 id
|
||||
std::optional<std::set<unsigned>> finishjob_remove_existed(std::map<unsigned, std::string> jobid_submit_time);
|
||||
}
|
||||
13
include/hpcstat/ssh.hpp
Normal file
13
include/hpcstat/ssh.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
# pragma once
|
||||
# include <optional>
|
||||
# include <string>
|
||||
|
||||
namespace hpcstat::ssh
|
||||
{
|
||||
// get a valid public key fingerprint
|
||||
std::optional<std::string> fingerprint();
|
||||
// sign a message with the key of specified fingerprint
|
||||
std::optional<std::string> sign(std::string message, std::string fingerprint);
|
||||
// verify a message with the key of specified fingerprint
|
||||
bool verify(std::string message, std::string signature, std::string fingerprint);
|
||||
}
|
||||
Reference in New Issue
Block a user