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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
#include "raw_client.h"
#include "raw_requests.h"
#include "rpc_parameters_serialization.h"
#include <yt/cpp/mapreduce/common/helpers.h>
#include <yt/cpp/mapreduce/http/http.h>
#include <yt/cpp/mapreduce/http/requests.h>
#include <yt/cpp/mapreduce/http/retry_request.h>
#include <yt/cpp/mapreduce/interface/operation.h>
#include <library/cpp/yson/node/node_io.h>
namespace NYT::NDetail {
////////////////////////////////////////////////////////////////////////////////
THttpRawClient::THttpRawClient(const TClientContext& context)
: Context_(context)
{ }
TNode THttpRawClient::Get(
const TTransactionId& transactionId,
const TYPath& path,
const TGetOptions& options)
{
TMutationId mutationId;
THttpHeader header("GET", "get");
header.MergeParameters(NRawClient::SerializeParamsForGet(transactionId, Context_.Config->Prefix, path, options));
return NodeFromYsonString(RequestWithoutRetry(Context_, mutationId, header).Response);
}
TNode THttpRawClient::TryGet(
const TTransactionId& transactionId,
const TYPath& path,
const TGetOptions& options)
{
try {
return Get(transactionId, path, options);
} catch (const TErrorResponse& error) {
if (!error.IsResolveError()) {
throw;
}
return TNode();
}
}
void THttpRawClient::Set(
TMutationId& mutationId,
const TTransactionId& transactionId,
const TYPath& path,
const TNode& value,
const TSetOptions& options)
{
THttpHeader header("PUT", "set");
header.AddMutationId();
header.MergeParameters(NRawClient::SerializeParamsForSet(transactionId, Context_.Config->Prefix, path, options));
auto body = NodeToYsonString(value);
RequestWithoutRetry(Context_, mutationId, header, body);
}
bool THttpRawClient::Exists(
const TTransactionId& transactionId,
const TYPath& path,
const TExistsOptions& options)
{
TMutationId mutationId;
THttpHeader header("GET", "exists");
header.MergeParameters(NRawClient::SerializeParamsForExists(transactionId, Context_.Config->Prefix, path, options));
return ParseBoolFromResponse(RequestWithoutRetry(Context_, mutationId, header).Response);
}
void THttpRawClient::MultisetAttributes(
TMutationId& mutationId,
const TTransactionId& transactionId,
const TYPath& path,
const TNode::TMapType& value,
const TMultisetAttributesOptions& options)
{
THttpHeader header("PUT", "api/v4/multiset_attributes", false);
header.AddMutationId();
header.MergeParameters(NRawClient::SerializeParamsForMultisetAttributes(transactionId, Context_.Config->Prefix, path, options));
auto body = NodeToYsonString(value);
RequestWithoutRetry(Context_, mutationId, header, body);
}
TNodeId THttpRawClient::Create(
TMutationId& mutationId,
const TTransactionId& transactionId,
const TYPath& path,
const ENodeType& type,
const TCreateOptions& options)
{
THttpHeader header("POST", "create");
header.AddMutationId();
header.MergeParameters(NRawClient::SerializeParamsForCreate(transactionId, Context_.Config->Prefix, path, type, options));
return ParseGuidFromResponse(RequestWithoutRetry(Context_, mutationId, header).Response);
}
TNodeId THttpRawClient::CopyWithoutRetries(
const TTransactionId& transactionId,
const TYPath& sourcePath,
const TYPath& destinationPath,
const TCopyOptions& options)
{
TMutationId mutationId;
THttpHeader header("POST", "copy");
header.AddMutationId();
header.MergeParameters(NRawClient::SerializeParamsForCopy(transactionId, Context_.Config->Prefix, sourcePath, destinationPath, options));
return ParseGuidFromResponse(RequestWithoutRetry(Context_, mutationId, header).Response);
}
TNodeId THttpRawClient::CopyInsideMasterCell(
TMutationId& mutationId,
const TTransactionId& transactionId,
const TYPath& sourcePath,
const TYPath& destinationPath,
const TCopyOptions& options)
{
THttpHeader header("POST", "copy");
header.AddMutationId();
auto params = NRawClient::SerializeParamsForCopy(transactionId, Context_.Config->Prefix, sourcePath, destinationPath, options);
// Make cross cell copying disable.
params["enable_cross_cell_copying"] = false;
header.MergeParameters(params);
return ParseGuidFromResponse(RequestWithoutRetry(Context_, mutationId, header).Response);
}
TNodeId THttpRawClient::MoveWithoutRetries(
const TTransactionId& transactionId,
const TYPath& sourcePath,
const TYPath& destinationPath,
const TMoveOptions& options)
{
TMutationId mutationId;
THttpHeader header("POST", "move");
header.AddMutationId();
header.MergeParameters(NRawClient::SerializeParamsForMove(transactionId, Context_.Config->Prefix, sourcePath, destinationPath, options));
return ParseGuidFromResponse(RequestWithoutRetry(Context_, mutationId, header).Response);
}
TNodeId THttpRawClient::MoveInsideMasterCell(
TMutationId& mutationId,
const TTransactionId& transactionId,
const TYPath& sourcePath,
const TYPath& destinationPath,
const TMoveOptions& options)
{
THttpHeader header("POST", "move");
header.AddMutationId();
auto params = NRawClient::SerializeParamsForMove(transactionId, Context_.Config->Prefix, sourcePath, destinationPath, options);
// Make cross cell copying disable.
params["enable_cross_cell_copying"] = false;
header.MergeParameters(params);
return ParseGuidFromResponse(RequestWithoutRetry(Context_, mutationId, header).Response);
}
void THttpRawClient::Remove(
TMutationId& mutationId,
const TTransactionId& transactionId,
const TYPath& path,
const TRemoveOptions& options)
{
THttpHeader header("POST", "remove");
header.AddMutationId();
header.MergeParameters(NRawClient::SerializeParamsForRemove(transactionId, Context_.Config->Prefix, path, options));
RequestWithoutRetry(Context_, mutationId, header);
}
TNode::TListType THttpRawClient::List(
const TTransactionId& transactionId,
const TYPath& path,
const TListOptions& options)
{
TMutationId mutationId;
THttpHeader header("GET", "list");
TYPath updatedPath = AddPathPrefix(path, Context_.Config->Prefix);
// Translate "//" to "/"
// Translate "//some/constom/prefix/from/config/" to "//some/constom/prefix/from/config"
if (path.empty() && updatedPath.EndsWith('/')) {
updatedPath.pop_back();
}
header.MergeParameters(NRawClient::SerializeParamsForList(transactionId, Context_.Config->Prefix, updatedPath, options));
auto result = RequestWithoutRetry(Context_, mutationId, header);
return NodeFromYsonString(result.Response).AsList();
}
TNodeId THttpRawClient::Link(
TMutationId& mutationId,
const TTransactionId& transactionId,
const TYPath& targetPath,
const TYPath& linkPath,
const TLinkOptions& options)
{
THttpHeader header("POST", "link");
header.AddMutationId();
header.MergeParameters(NRawClient::SerializeParamsForLink(transactionId, Context_.Config->Prefix, targetPath, linkPath, options));
return ParseGuidFromResponse(RequestWithoutRetry(Context_, mutationId, header).Response);
}
TLockId THttpRawClient::Lock(
TMutationId& mutationId,
const TTransactionId& transactionId,
const TYPath& path,
ELockMode mode,
const TLockOptions& options)
{
THttpHeader header("POST", "lock");
header.AddMutationId();
header.MergeParameters(NRawClient::SerializeParamsForLock(transactionId, Context_.Config->Prefix, path, mode, options));
return ParseGuidFromResponse(RequestWithoutRetry(Context_, mutationId, header).Response);
}
void THttpRawClient::Unlock(
TMutationId& mutationId,
const TTransactionId& transactionId,
const TYPath& path,
const TUnlockOptions& options)
{
THttpHeader header("POST", "unlock");
header.AddMutationId();
header.MergeParameters(NRawClient::SerializeParamsForUnlock(transactionId, Context_.Config->Prefix, path, options));
RequestWithoutRetry(Context_, mutationId, header);
}
void THttpRawClient::Concatenate(
const TTransactionId& transactionId,
const TVector<TRichYPath>& sourcePaths,
const TRichYPath& destinationPath,
const TConcatenateOptions& options)
{
TMutationId mutationId;
THttpHeader header("POST", "concatenate");
header.AddMutationId();
header.MergeParameters(NRawClient::SerializeParamsForConcatenate(transactionId, Context_.Config->Prefix, sourcePaths, destinationPath, options));
RequestWithoutRetry(Context_, mutationId, header);
}
void THttpRawClient::PingTx(const TTransactionId& transactionId)
{
TMutationId mutationId;
THttpHeader header("POST", "ping_tx");
header.MergeParameters(NRawClient::SerializeParamsForPingTx(transactionId));
TRequestConfig requestConfig;
requestConfig.HttpConfig = NHttpClient::THttpConfig{
.SocketTimeout = Context_.Config->PingTimeout
};
RequestWithoutRetry(Context_, mutationId, header);
}
TOperationAttributes THttpRawClient::GetOperation(
const TOperationId& operationId,
const TGetOperationOptions& options)
{
TMutationId mutationId;
THttpHeader header("GET", "get_operation");
header.MergeParameters(NRawClient::SerializeParamsForGetOperation(operationId, options));
auto result = RequestWithoutRetry(Context_, mutationId, header);
return NRawClient::ParseOperationAttributes(NodeFromYsonString(result.Response));
}
TOperationAttributes THttpRawClient::GetOperation(
const TString& alias,
const TGetOperationOptions& options)
{
TMutationId mutationId;
THttpHeader header("GET", "get_operation");
header.MergeParameters(NRawClient::SerializeParamsForGetOperation(alias, options));
auto result = RequestWithoutRetry(Context_, mutationId, header);
return NRawClient::ParseOperationAttributes(NodeFromYsonString(result.Response));
}
void THttpRawClient::AbortOperation(
TMutationId& mutationId,
const TOperationId& operationId)
{
THttpHeader header("POST", "abort_op");
header.AddMutationId();
header.MergeParameters(NRawClient::SerializeParamsForAbortOperation(operationId));
RequestWithoutRetry(Context_, mutationId, header);
}
void THttpRawClient::CompleteOperation(
TMutationId& mutationId,
const TOperationId& operationId)
{
THttpHeader header("POST", "complete_op");
header.AddMutationId();
header.MergeParameters(NRawClient::SerializeParamsForCompleteOperation(operationId));
RequestWithoutRetry(Context_, mutationId, header);
}
void THttpRawClient::SuspendOperation(
TMutationId& mutationId,
const TOperationId& operationId,
const TSuspendOperationOptions& options)
{
THttpHeader header("POST", "suspend_op");
header.AddMutationId();
header.MergeParameters(NRawClient::SerializeParamsForSuspendOperation(operationId, options));
RequestWithoutRetry(Context_, mutationId, header);
}
void THttpRawClient::ResumeOperation(
TMutationId& mutationId,
const TOperationId& operationId,
const TResumeOperationOptions& options)
{
THttpHeader header("POST", "resume_op");
header.AddMutationId();
header.MergeParameters(NRawClient::SerializeParamsForResumeOperation(operationId, options));
RequestWithoutRetry(Context_, mutationId, header);
}
template <typename TKey>
static THashMap<TKey, i64> GetCounts(const TNode& countsNode)
{
THashMap<TKey, i64> counts;
for (const auto& entry : countsNode.AsMap()) {
counts.emplace(FromString<TKey>(entry.first), entry.second.AsInt64());
}
return counts;
}
TListOperationsResult THttpRawClient::ListOperations(const TListOperationsOptions& options)
{
TMutationId mutationId;
THttpHeader header("GET", "list_operations");
header.MergeParameters(NRawClient::SerializeParamsForListOperations(options));
auto responseInfo = RequestWithoutRetry(Context_, mutationId, header);
auto resultNode = NodeFromYsonString(responseInfo.Response);
const auto& operationNodesList = resultNode["operations"].AsList();
TListOperationsResult result;
result.Operations.reserve(operationNodesList.size());
for (const auto& operationNode : operationNodesList) {
result.Operations.push_back(NRawClient::ParseOperationAttributes(operationNode));
}
if (resultNode.HasKey("pool_counts")) {
result.PoolCounts = GetCounts<TString>(resultNode["pool_counts"]);
}
if (resultNode.HasKey("user_counts")) {
result.UserCounts = GetCounts<TString>(resultNode["user_counts"]);
}
if (resultNode.HasKey("type_counts")) {
result.TypeCounts = GetCounts<EOperationType>(resultNode["type_counts"]);
}
if (resultNode.HasKey("state_counts")) {
result.StateCounts = GetCounts<TString>(resultNode["state_counts"]);
}
if (resultNode.HasKey("failed_jobs_count")) {
result.WithFailedJobsCount = resultNode["failed_jobs_count"].AsInt64();
}
result.Incomplete = resultNode["incomplete"].AsBool();
return result;
}
void THttpRawClient::UpdateOperationParameters(
const TOperationId& operationId,
const TUpdateOperationParametersOptions& options)
{
TMutationId mutationId;
THttpHeader header("POST", "update_op_parameters");
header.MergeParameters(NRawClient::SerializeParamsForUpdateOperationParameters(operationId, options));
RequestWithoutRetry(Context_, mutationId, header);
}
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT::NDetail
|