forked from ydb-platform/nbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfault_injection.cpp
84 lines (63 loc) · 1.87 KB
/
fault_injection.cpp
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
#include "fault_injection.h"
#include <cloud/storage/core/libs/common/error.h>
#include <library/cpp/lwtrace/all.h>
#include <util/string/cast.h>
namespace NCloud::NBlockStore {
namespace {
////////////////////////////////////////////////////////////////////////////////
ui32 GetCode(const NLWTrace::TCustomAction& action)
{
if (action.OptsSize() == 0) {
return E_FAIL;
}
const auto& opt = action.GetOpts(0);
EWellKnownResultCodes code;
if (TryFromString(opt, code)) {
return code;
}
return FromString<ui32>(opt);
}
TString GetMessage(const NLWTrace::TCustomAction& action)
{
if (action.OptsSize() > 1) {
return action.GetOpts(1);
}
return {};
}
////////////////////////////////////////////////////////////////////////////////
class TServiceErrorActionExecutor final
: public NLWTrace::TCustomActionExecutor
{
private:
const ui32 Code;
const TString Message;
public:
TServiceErrorActionExecutor(
NLWTrace::TProbe* probe,
const NLWTrace::TCustomAction& action,
NLWTrace::TSession* session)
: NLWTrace::TCustomActionExecutor(probe, true /* destructive */)
, Code(GetCode(action))
, Message(GetMessage(action))
{
Y_UNUSED(probe);
Y_UNUSED(session);
}
private:
bool DoExecute(NLWTrace::TOrbit& orbit, const NLWTrace::TParams& params) override
{
Y_UNUSED(orbit);
Y_UNUSED(params);
throw TServiceError(Code) << Message;
}
};
} // namespace
////////////////////////////////////////////////////////////////////////////////
NLWTrace::TCustomActionExecutor* CreateServiceErrorActionExecutor(
NLWTrace::TProbe* probe,
const NLWTrace::TCustomAction& action,
NLWTrace::TSession* session)
{
return new TServiceErrorActionExecutor(probe, action, session);
}
} // namespace NCloud::NBlockStore