aboutsummaryrefslogtreecommitdiff
path: root/zenserver/compute/function.h
blob: 2ddddabb455d408b757a8184f87dadd55b96b9f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include <zencore/zencore.h>

#if !defined(ZEN_WITH_COMPUTE_SERVICES)
#	define ZEN_WITH_COMPUTE_SERVICES 1
#endif

#if ZEN_WITH_COMPUTE_SERVICES

#	include <zencore/compactbinary.h>
#	include <zencore/iohash.h>
#	include <zencore/logging.h>
#	include <zenhttp/httpserver.h>

#	include <filesystem>
#	include <unordered_map>

namespace zen {

class CasStore;
class CidStore;
class UpstreamApply;
class CloudCacheClient;
class AuthMgr;

struct UpstreamAuthConfig;
struct CloudCacheClientOptions;

/**
 * Lambda style compute function service
 */
class HttpFunctionService : public HttpService
{
public:
	HttpFunctionService(CasStore&					   Store,
						CidStore&					   InCidStore,
						const CloudCacheClientOptions& ComputeOptions,
						const CloudCacheClientOptions& StorageOptions,
						const UpstreamAuthConfig&	   ComputeAuthConfig,
						const UpstreamAuthConfig&	   StorageAuthConfig,
						AuthMgr&					   Mgr);
	~HttpFunctionService();

	virtual const char* BaseUri() const override;
	virtual void		HandleRequest(HttpServerRequest& Request) override;

private:
	spdlog::logger&				   Log() { return m_Log; }
	spdlog::logger&				   m_Log;
	HttpRequestRouter			   m_Router;
	CasStore&					   m_CasStore;
	CidStore&					   m_CidStore;
	std::unique_ptr<UpstreamApply> m_UpstreamApply;

	struct WorkerDesc
	{
		CbObject Descriptor;
	};

	[[nodiscard]] HttpResponseCode ExecActionUpstream(const WorkerDesc& Worker, CbObject& Object);
	[[nodiscard]] HttpResponseCode ExecActionUpstreamResult(const IoHash& WorkerId, CbObject& Object);

	[[nodiscard]] HttpResponseCode ExecActionUpstream(const WorkerDesc& Worker, CbObject Action, CbObject& Object);
	[[nodiscard]] HttpResponseCode ExecActionUpstreamResult(const IoHash& WorkerId, const IoHash& ActionId, CbPackage& Package);

	RwLock								   m_WorkerLock;
	std::unordered_map<IoHash, WorkerDesc> m_WorkerMap;
};

}  // namespace zen

#endif	// ZEN_WITH_COMPUTE_SERVICES