Initial commit

This commit is contained in:
dev
2025-02-27 21:53:53 +08:00
commit 815e55e4c0
1291 changed files with 185445 additions and 0 deletions

View File

@@ -0,0 +1 @@
target_add_lib(core-service core-service-fbs)

View File

@@ -0,0 +1,14 @@
#include "CoreService.h"
#include "core/service/ops/Include.h"
#include "core/utils/runOp.h"
#define DEFINE_SERDE_SERVICE_METHOD_FULL(svc, name, Name, id, reqtype, rsptype) \
CoTryTask<rsptype> svc##Service::name(serde::CallContext &ctx, const reqtype &req) { \
Name##Operation op(std::move(req)); \
CO_INVOKE_OP_INFO(op, ctx.peer()); \
}
namespace hf3fs::core {
#include "fbs/core/service/CoreServiceDef.h"
} // namespace hf3fs::core

View File

@@ -0,0 +1,14 @@
#pragma once
#include "common/serde/CallContext.h"
#include "fbs/core/service/CoreServiceBase.h"
namespace hf3fs::core {
class CoreService : public serde::ServiceWrapper<CoreService, CoreServiceBase> {
public:
#define DEFINE_SERDE_SERVICE_METHOD_FULL(svc, name, Name, id, reqtype, rsptype) \
CoTryTask<rsptype> name(serde::CallContext &ctx, const reqtype &req);
#include "fbs/core/service/CoreServiceDef.h"
};
} // namespace hf3fs::core

View File

@@ -0,0 +1,19 @@
#pragma once
#include "core/utils/ServiceOperation.h"
#include "fbs/core/service/Rpc.h"
namespace hf3fs::core {
struct EchoOperation : ServiceOperationWithMetric<"CoreService", "Echo", "op"> {
EchoMessage req;
explicit EchoOperation(EchoMessage r)
: req(std::move(r)) {}
String toStringImpl() const final { return "Echo"; }
CoTryTask<EchoMessage> handle() { co_return req; }
};
} // namespace hf3fs::core

View File

@@ -0,0 +1,24 @@
#pragma once
#include "common/app/ApplicationBase.h"
#include "core/utils/ServiceOperation.h"
#include "fbs/core/service/Rpc.h"
namespace hf3fs::core {
struct GetConfigOperation : ServiceOperationWithMetric<"CoreService", "GetConfig", "op"> {
GetConfigReq req;
explicit GetConfigOperation(GetConfigReq r)
: req(std::move(r)) {}
String toStringImpl() const final { return "GetConfig"; }
CoTryTask<GetConfigRsp> handle() {
auto cfg = ApplicationBase::getConfigString(req.configKey);
CO_RETURN_ON_ERROR(cfg);
co_return GetConfigRsp::create(std::move(*cfg));
}
};
} // namespace hf3fs::core

View File

@@ -0,0 +1,24 @@
#pragma once
#include "common/app/ApplicationBase.h"
#include "core/utils/ServiceOperation.h"
#include "fbs/core/service/Rpc.h"
namespace hf3fs::core {
struct GetLastConfigUpdateRecordOperation
: ServiceOperationWithMetric<"CoreService", "GetLastConfigUpdateRecord", "op"> {
GetLastConfigUpdateRecordReq req;
explicit GetLastConfigUpdateRecordOperation(GetLastConfigUpdateRecordReq r)
: req(std::move(r)) {}
String toStringImpl() const final { return "GetLastConfigUpdateRecord"; }
CoTryTask<GetLastConfigUpdateRecordRsp> handle() {
auto res = ApplicationBase::getLastConfigUpdateRecord();
co_return GetLastConfigUpdateRecordRsp::create(std::move(res));
}
};
} // namespace hf3fs::core

View File

@@ -0,0 +1,24 @@
#pragma once
#include "common/app/ApplicationBase.h"
#include "core/utils/ServiceOperation.h"
#include "fbs/core/service/Rpc.h"
namespace hf3fs::core {
struct HotUpdateConfigOperation : ServiceOperationWithMetric<"CoreService", "HotUpdateConfig", "op"> {
HotUpdateConfigReq req;
explicit HotUpdateConfigOperation(HotUpdateConfigReq r)
: req(std::move(r)) {}
String toStringImpl() const final { return "HotUpdateConfig"; }
CoTryTask<HotUpdateConfigRsp> handle() {
auto res = ApplicationBase::hotUpdateConfig(req.update, req.render);
CO_RETURN_ON_ERROR(res);
co_return HotUpdateConfigRsp::create();
}
};
} // namespace hf3fs::core

View File

@@ -0,0 +1,8 @@
#pragma once
#include "EchoOperation.h"
#include "GetConfigOperation.h"
#include "GetLastConfigUpdateRecordOperation.h"
#include "HotUpdateConfigOperation.h"
#include "RenderConfigOperation.h"
#include "ShutdownOperation.h"

View File

@@ -0,0 +1,29 @@
#pragma once
#include "common/app/ApplicationBase.h"
#include "core/utils/ServiceOperation.h"
#include "fbs/core/service/Rpc.h"
namespace hf3fs::core {
struct RenderConfigOperation : ServiceOperationWithMetric<"CoreService", "RenderConfig", "op"> {
RenderConfigReq req;
explicit RenderConfigOperation(RenderConfigReq r)
: req(std::move(r)) {}
String toStringImpl() const final { return "RenderConfig"; }
CoTryTask<RenderConfigRsp> handle() {
auto res = ApplicationBase::renderConfig(req.configTemplate, req.testUpdate, req.isHotUpdate);
CO_RETURN_ON_ERROR(res);
auto &[content, updateRes] = *res;
if (updateRes) {
co_return RenderConfigRsp::create(std::move(content), Status(StatusCode::kOK), std::move(*updateRes));
} else {
co_return RenderConfigRsp::create(std::move(content), std::move(updateRes.error()));
}
}
};
} // namespace hf3fs::core

View File

@@ -0,0 +1,24 @@
#pragma once
#include "common/app/ApplicationBase.h"
#include "common/utils/suicide.h"
#include "core/utils/ServiceOperation.h"
#include "fbs/core/service/Rpc.h"
namespace hf3fs::core {
struct ShutdownOperation : ServiceOperationWithMetric<"CoreService", "Shutdown", "op"> {
ShutdownReq req_;
explicit ShutdownOperation(ShutdownReq req)
: req_(std::move(req)) {}
String toStringImpl() const final { return "Shutdown"; }
CoTryTask<ShutdownRsp> handle() {
CO_RETURN_ON_ERROR(suicide(req_.graceful));
co_return ShutdownRsp::create();
}
};
} // namespace hf3fs::core