FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sysadmin/src/HookManager.cpp at master · StarryInternet/sysadmin · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
StarryInternet
/
sysadmin
Public
Notifications
You must be signed in to change notification settings
Fork
8
Star
11
Code
Issues
10
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
sysadmin
/
src
/
HookManager.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
150 lines (134 loc) · 4.42 KB
Breadcrumbs
sysadmin
/
src
/
HookManager.cpp
Copy path
File metadata and controls
150 lines (134 loc) · 4.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#
include
"
HookManager.h
"
#
include
"
ExternalRunner.h
"
#
include
"
HookTable.h
"
#
include
"
HookUser.h
"
#
include
<
boost/assert.hpp
>
#
include
<
boost/none.hpp
>
#
include
<
boost/optional.hpp
>
#
include
<
log4cxx/logger.h
>
#
include
<
folly/futures/Promise.h
>
#
include
<
memory
>
namespace
{
log4cxx::LoggerPtr
spLogger
(log4cxx::Logger::getLogger(
"
HookManager
"
));
}
namespace
dm
=
decibel::messaging;
HookManager::HookManager
(std::unique_ptr<HookTable> pTable,
size_t
parallelHooks)
: mpTable(std::move(pTable))
, mParallelHooks(parallelHooks)
{
}
folly::Future<folly::Unit>
HookManager::HandleCommit
(
const
ConfigPairList& committed,
bool
run_services)
{
auto
hooks =
GetHooksToRun
(committed, run_services);
return
RunHooks
(hooks);
}
folly::Future<folly::Unit>
HookManager::RunHooks
(
const
HookManager::HookPipeline& hooks)
{
return
SplitSubprocessesAcrossCores
(hooks.
templates
,
mParallelHooks
).
thenValue
([
this
, hooks](
auto
/*
unused
*/
)
{
LOG4CXX_INFO
(spLogger,
"
Templates rendered and dumped, running services
"
);
auto
final_future =
folly::makeFuture
();
for
(
auto
rlPair : hooks.
services
)
{
final_future =
std::move
(final_future).
thenValue
([
this
, rlPair](
auto
/*
unused
*/
)
{
return
SplitSubprocessesAcrossCores
(rlPair.
second
,
mParallelHooks
);
});
}
return
final_future;
}).
thenError
(folly::
tag_t
<ExternalRunnerError>{}, [](
const
auto
& err)
{
LOG4CXX_ERROR
(spLogger,
"
Templater failed while running:
"
<< err.
what
());
throw
err;
});
}
HookManager::HookPipeline
HookManager::GetAllHooks
()
{
TemplatesToRender templatesToRender;
ServicesMap servicesToRun = mpTable->
GetOrderedServices
();
for
(
auto
templater: mpTable->
ByType
(HookType::
TEMPLATER
))
{
templatesToRender.
emplace
(templater);
}
return
HookManager::HookPipeline
(templatesToRender, servicesToRun);
}
HookManager::HookPipeline
HookManager::GetHooksToRun
(
const
ConfigPairList& committed,
bool
run_services)
{
TemplatesToRender templatesToRender;
ServicesMap servicesToRun;
ServicesMap allServices = mpTable->
GetOrderedServices
();
for
(
const
auto
& pair : committed)
{
for
(
auto
templater: mpTable->
ByType
(HookType::
TEMPLATER
))
{
if
(templater->
HasHook
(pair.
GetKey
()))
{
templatesToRender.
emplace
(templater);
}
}
if
(run_services)
{
for
(
auto
service: mpTable->
RunLevelOrder
(HookType::
SERVICE
))
{
if
(service->
HasHook
(pair.
GetKey
()))
{
size_t
rl = service->
RunLevel
();
if
(!servicesToRun.
count
(rl))
{
servicesToRun.
emplace
(rl, std::vector<std::shared_ptr<
const
HookUser>>());
}
if
(
std::find
(servicesToRun.
at
(rl).
begin
(),
servicesToRun.
at
(rl).
end
(),
service) == servicesToRun.
at
(rl).
end
())
{
servicesToRun.
at
(rl).
emplace_back
(service);
}
}
}
}
}
return
HookManager::HookPipeline
(templatesToRender, servicesToRun);
}
HookManager::HookDump
HookManager::DumpHooks
()
{
HookManager::HookDump dump;
dump.
first
= mpTable->
ByType
(HookType::
TEMPLATER
);
dump.
second
= mpTable->
ByType
(HookType::
SERVICE
);
return
dump;
}
folly::Future<
bool
>
HookManager::TriggerHook
(
const
std::string& name)
{
auto
hook = mpTable->
ByName
(name);
if
(hook)
{
TemplatesToRender t;
ServicesMap s;
if
((*hook)->
GetType
() == HookType::
TEMPLATER
)
{
t.
emplace
(hook.
get
());
}
else
{
//
run level doesnt matter here, since we are only running a single service
s.
emplace
(
1
, std::vector<std::shared_ptr<
const
HookUser>>());
s.
at
(
1
).
emplace_back
(hook.
get
());
}
return
RunHooks
(
HookManager::HookPipeline
(t, s)).
thenValue
([](
auto
/*
unused
*/
) {
return
true
; });
}
else
{
return
folly::makeFuture
(
false
);
}
}
size_t
HookManager::NumberOfTemplaters
()
const
{
return
mpTable->
ByType
(HookType::
TEMPLATER
).
size
();
}
size_t
HookManager::NumberOfServices
()
const
{
return
mpTable->
ByType
(HookType::
SERVICE
).
size
();
}
Back
|
FazBrowse Home
|
New Git URL