blob: ebd76caddd603781e4261a0b381926c2550f4cab (
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
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
151
152
153
154
155
156
157
158
159
160
161
|
#pragma once
#include "public.h"
#include "interned_attributes.h"
#include "permission.h"
#include <yt/yt/core/yson/consumer.h>
#include <yt/yt/core/yson/string.h>
#include <yt/yt/core/misc/error.h>
#include <yt/yt/core/actions/future.h>
#include <optional>
namespace NYT::NYTree {
////////////////////////////////////////////////////////////////////////////////
struct ISystemAttributeProvider
{
virtual ~ISystemAttributeProvider() = default;
//! Describes a system attribute.
struct TAttributeDescriptor
{
TInternedAttributeKey InternedKey = InvalidInternedAttribute;
bool Present = true;
bool Opaque = false;
bool Custom = false;
bool Writable = false;
bool Removable = false;
bool Replicated = false;
bool Mandatory = false;
bool External = false;
EPermissionSet ModifyPermission = EPermission::Write;
TAttributeDescriptor& SetPresent(bool value)
{
Present = value;
return *this;
}
TAttributeDescriptor& SetOpaque(bool value)
{
Opaque = value;
return *this;
}
TAttributeDescriptor& SetCustom(bool value)
{
Custom = value;
return *this;
}
TAttributeDescriptor& SetWritable(bool value)
{
Writable = value;
return *this;
}
TAttributeDescriptor& SetRemovable(bool value)
{
Removable = value;
return *this;
}
TAttributeDescriptor& SetReplicated(bool value)
{
Replicated = value;
return *this;
}
TAttributeDescriptor& SetMandatory(bool value)
{
Mandatory = value;
return *this;
}
TAttributeDescriptor& SetExternal(bool value)
{
External = value;
return *this;
}
TAttributeDescriptor& SetWritePermission(EPermission value)
{
ModifyPermission = value;
return *this;
}
TAttributeDescriptor(TInternedAttributeKey key)
: InternedKey(key)
{ }
};
//! Populates the list of all system attributes supported by this object.
/*!
* \note
* Must not clear #attributes since additional items may be added in inheritors.
*/
virtual void ListSystemAttributes(std::vector<TAttributeDescriptor>* descriptors) = 0;
//! Returns a (typically cached) set consisting of all non-custom attributes keys.
//! \see TAttributeDescriptor::Custom
//! \see ListSystemAttributes
virtual const THashSet<TInternedAttributeKey>& GetBuiltinAttributeKeys() = 0;
//! Gets the value of a builtin attribute.
/*!
* \returns |false| if there is no builtin attribute with the given key.
*/
virtual bool GetBuiltinAttribute(TInternedAttributeKey key, NYson::IYsonConsumer* consumer) = 0;
//! Asynchronously gets the value of a builtin attribute.
/*!
* \returns A future representing attribute value or null if there is no such async builtin attribute.
*/
virtual TFuture<NYson::TYsonString> GetBuiltinAttributeAsync(TInternedAttributeKey key) = 0;
//! Sets the value of a builtin attribute.
/*!
* \returns |false| if there is no writable builtin attribute with the given key.
*/
virtual bool SetBuiltinAttribute(TInternedAttributeKey key, const NYson::TYsonString& value) = 0;
//! Removes the builtin attribute.
/*!
* \returns |false| if there is no removable builtin attribute with the given key.
*/
virtual bool RemoveBuiltinAttribute(TInternedAttributeKey key) = 0;
//! Permission to set/remove non-builtin attributes.
/*!
* \returns permission to set/remove non-builtin attributes.
*/
virtual EPermission GetCustomAttributeModifyPermission();
// Extension methods.
//! Similar to its interface counterpart, but reserves the vector beforehand.
void ReserveAndListSystemAttributes(std::vector<TAttributeDescriptor>* descriptors);
//! Similar to its interface counterpart, but populates a map rather than a vector.
void ListSystemAttributes(std::map<TInternedAttributeKey, TAttributeDescriptor>* descriptors);
//! Populates the list of all builtin attributes supported by this object.
void ListBuiltinAttributes(std::vector<TAttributeDescriptor>* descriptors);
//! Returns an instance of TAttributeDescriptor matching a given #key or null if no such
//! builtin attribute is known.
std::optional<TAttributeDescriptor> FindBuiltinAttributeDescriptor(TInternedAttributeKey key);
//! Wraps #GetBuiltinAttribute and returns the YSON string instead
//! of writing it into a consumer.
NYson::TYsonString FindBuiltinAttribute(TInternedAttributeKey key);
};
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT::NYTree
|