rpc_parameters_serialization.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. #include "rpc_parameters_serialization.h"
  2. #include <yt/cpp/mapreduce/common/helpers.h>
  3. #include <yt/cpp/mapreduce/interface/config.h>
  4. #include <yt/cpp/mapreduce/interface/client_method_options.h>
  5. #include <yt/cpp/mapreduce/interface/operation.h>
  6. #include <yt/cpp/mapreduce/interface/serialize.h>
  7. #include <library/cpp/yson/node/node.h>
  8. #include <library/cpp/yson/node/node_io.h>
  9. #include <library/cpp/yson/node/node_builder.h>
  10. #include <util/generic/guid.h>
  11. #include <util/string/cast.h>
  12. namespace NYT::NDetail::NRawClient {
  13. using ::ToString;
  14. ////////////////////////////////////////////////////////////////////
  15. static void SetTransactionIdParam(TNode* node, const TTransactionId& transactionId)
  16. {
  17. if (transactionId != TTransactionId()) {
  18. (*node)["transaction_id"] = GetGuidAsString(transactionId);
  19. }
  20. }
  21. static void SetOperationIdParam(TNode* node, const TOperationId& operationId)
  22. {
  23. (*node)["operation_id"] = GetGuidAsString(operationId);
  24. }
  25. static void SetAliasParam(TNode* node, const TString& alias)
  26. {
  27. (*node)["operation_alias"] = alias;
  28. }
  29. static void SetPathParam(TNode* node, const TString& pathPrefix, const TYPath& path)
  30. {
  31. TYPath updatedPath = AddPathPrefix(path, pathPrefix);
  32. // Translate "//" to "/"
  33. // Translate "//some/constom/prefix/from/config/" to "//some/constom/prefix/from/config"
  34. if (path.empty() && updatedPath.EndsWith('/')) {
  35. updatedPath.pop_back();
  36. }
  37. (*node)["path"] = std::move(updatedPath);
  38. }
  39. static TNode SerializeAttributeFilter(const TAttributeFilter& attributeFilter)
  40. {
  41. TNode result = TNode::CreateList();
  42. for (const auto& attribute : attributeFilter.Attributes_) {
  43. result.Add(attribute);
  44. }
  45. return result;
  46. }
  47. static TNode SerializeAttributeFilter(const TOperationAttributeFilter& attributeFilter)
  48. {
  49. TNode result = TNode::CreateList();
  50. for (const auto& attribute : attributeFilter.Attributes_) {
  51. result.Add(ToString(attribute));
  52. }
  53. return result;
  54. }
  55. template <typename TOptions>
  56. static void SetFirstLastTabletIndex(TNode* node, const TOptions& options)
  57. {
  58. if (options.FirstTabletIndex_) {
  59. (*node)["first_tablet_index"] = *options.FirstTabletIndex_;
  60. }
  61. if (options.LastTabletIndex_) {
  62. (*node)["last_tablet_index"] = *options.LastTabletIndex_;
  63. }
  64. }
  65. static TString GetDefaultTransactionTitle()
  66. {
  67. const auto processState = TProcessState::Get();
  68. TStringStream res;
  69. res << "User transaction. Created by: " << processState->UserName << " on " << processState->FqdnHostName
  70. << " client: " << processState->ClientVersion << " pid: " << processState->Pid;
  71. if (!processState->CommandLine.empty()) {
  72. res << " program: " << processState->CommandLine[0];
  73. } else {
  74. res << " command line is unknown probably NYT::Initialize was never called";
  75. }
  76. #ifndef NDEBUG
  77. res << " build: debug";
  78. #endif
  79. return res.Str();
  80. }
  81. template <typename T>
  82. void SerializeMasterReadOptions(TNode* node, const TMasterReadOptions<T>& options)
  83. {
  84. if (options.ReadFrom_) {
  85. (*node)["read_from"] = ToString(*options.ReadFrom_);
  86. }
  87. }
  88. ////////////////////////////////////////////////////////////////////
  89. TNode SerializeParamsForCreate(
  90. const TTransactionId& transactionId,
  91. const TString& pathPrefix,
  92. const TYPath& path,
  93. ENodeType type,
  94. const TCreateOptions& options)
  95. {
  96. TNode result;
  97. SetTransactionIdParam(&result, transactionId);
  98. SetPathParam(&result, pathPrefix, path);
  99. result["recursive"] = options.Recursive_;
  100. result["type"] = ToString(type);
  101. result["ignore_existing"] = options.IgnoreExisting_;
  102. result["force"] = options.Force_;
  103. if (options.Attributes_) {
  104. result["attributes"] = *options.Attributes_;
  105. }
  106. return result;
  107. }
  108. TNode SerializeParamsForRemove(
  109. const TTransactionId& transactionId,
  110. const TString& pathPrefix,
  111. const TYPath& path,
  112. const TRemoveOptions& options)
  113. {
  114. TNode result;
  115. SetTransactionIdParam(&result, transactionId);
  116. SetPathParam(&result, pathPrefix, path);
  117. result["recursive"] = options.Recursive_;
  118. result["force"] = options.Force_;
  119. return result;
  120. }
  121. TNode SerializeParamsForExists(
  122. const TTransactionId& transactionId,
  123. const TString& pathPrefix,
  124. const TYPath& path,
  125. const TExistsOptions& options)
  126. {
  127. TNode result;
  128. SetTransactionIdParam(&result, transactionId);
  129. SetPathParam(&result, pathPrefix, path);
  130. SerializeMasterReadOptions(&result, options);
  131. return result;
  132. }
  133. TNode SerializeParamsForGet(
  134. const TTransactionId& transactionId,
  135. const TString& pathPrefix,
  136. const TYPath& path,
  137. const TGetOptions& options)
  138. {
  139. TNode result;
  140. SetTransactionIdParam(&result, transactionId);
  141. SetPathParam(&result, pathPrefix, path);
  142. SerializeMasterReadOptions(&result, options);
  143. if (options.AttributeFilter_) {
  144. result["attributes"] = SerializeAttributeFilter(*options.AttributeFilter_);
  145. }
  146. if (options.MaxSize_) {
  147. result["max_size"] = *options.MaxSize_;
  148. }
  149. return result;
  150. }
  151. TNode SerializeParamsForSet(
  152. const TTransactionId& transactionId,
  153. const TString& pathPrefix,
  154. const TYPath& path,
  155. const TSetOptions& options)
  156. {
  157. TNode result;
  158. SetTransactionIdParam(&result, transactionId);
  159. SetPathParam(&result, pathPrefix, path);
  160. result["recursive"] = options.Recursive_;
  161. if (options.Force_) {
  162. result["force"] = *options.Force_;
  163. }
  164. return result;
  165. }
  166. TNode SerializeParamsForMultisetAttributes(
  167. const TTransactionId& transactionId,
  168. const TString& pathPrefix,
  169. const TYPath& path,
  170. [[maybe_unused]] const TMultisetAttributesOptions& options)
  171. {
  172. TNode result;
  173. SetTransactionIdParam(&result, transactionId);
  174. SetPathParam(&result, pathPrefix, path);
  175. if (options.Force_) {
  176. result["force"] = *options.Force_;
  177. }
  178. return result;
  179. }
  180. TNode SerializeParamsForList(
  181. const TTransactionId& transactionId,
  182. const TString& pathPrefix,
  183. const TYPath& path,
  184. const TListOptions& options)
  185. {
  186. TNode result;
  187. SetTransactionIdParam(&result, transactionId);
  188. SetPathParam(&result, pathPrefix, path);
  189. SerializeMasterReadOptions(&result, options);
  190. if (options.MaxSize_) {
  191. result["max_size"] = *options.MaxSize_;
  192. }
  193. if (options.AttributeFilter_) {
  194. result["attributes"] = SerializeAttributeFilter(*options.AttributeFilter_);
  195. }
  196. return result;
  197. }
  198. TNode SerializeParamsForCopy(
  199. const TTransactionId& transactionId,
  200. const TString& pathPrefix,
  201. const TYPath& sourcePath,
  202. const TYPath& destinationPath,
  203. const TCopyOptions& options)
  204. {
  205. TNode result;
  206. SetTransactionIdParam(&result, transactionId);
  207. result["source_path"] = AddPathPrefix(sourcePath, pathPrefix);
  208. result["destination_path"] = AddPathPrefix(destinationPath, pathPrefix);
  209. result["recursive"] = options.Recursive_;
  210. result["force"] = options.Force_;
  211. result["preserve_account"] = options.PreserveAccount_;
  212. if (options.PreserveExpirationTime_) {
  213. result["preserve_expiration_time"] = *options.PreserveExpirationTime_;
  214. }
  215. return result;
  216. }
  217. TNode SerializeParamsForMove(
  218. const TTransactionId& transactionId,
  219. const TString& pathPrefix,
  220. const TYPath& sourcePath,
  221. const TYPath& destinationPath,
  222. const TMoveOptions& options)
  223. {
  224. TNode result;
  225. SetTransactionIdParam(&result, transactionId);
  226. result["source_path"] = AddPathPrefix(sourcePath, pathPrefix);
  227. result["destination_path"] = AddPathPrefix(destinationPath, pathPrefix);
  228. result["recursive"] = options.Recursive_;
  229. result["force"] = options.Force_;
  230. result["preserve_account"] = options.PreserveAccount_;
  231. if (options.PreserveExpirationTime_) {
  232. result["preserve_expiration_time"] = *options.PreserveExpirationTime_;
  233. }
  234. return result;
  235. }
  236. TNode SerializeParamsForLink(
  237. const TTransactionId& transactionId,
  238. const TString& pathPrefix,
  239. const TYPath& targetPath,
  240. const TYPath& linkPath,
  241. const TLinkOptions& options)
  242. {
  243. TNode result;
  244. SetTransactionIdParam(&result, transactionId);
  245. result["target_path"] = AddPathPrefix(targetPath, pathPrefix);
  246. result["link_path"] = AddPathPrefix(linkPath, pathPrefix);
  247. result["recursive"] = options.Recursive_;
  248. result["ignore_existing"] = options.IgnoreExisting_;
  249. result["force"] = options.Force_;
  250. if (options.Attributes_) {
  251. result["attributes"] = *options.Attributes_;
  252. }
  253. return result;
  254. }
  255. TNode SerializeParamsForLock(
  256. const TTransactionId& transactionId,
  257. const TString& pathPrefix,
  258. const TYPath& path,
  259. ELockMode mode,
  260. const TLockOptions& options)
  261. {
  262. TNode result;
  263. SetTransactionIdParam(&result, transactionId);
  264. SetPathParam(&result, pathPrefix, path);
  265. result["mode"] = ToString(mode);
  266. result["waitable"] = options.Waitable_;
  267. if (options.AttributeKey_) {
  268. result["attribute_key"] = *options.AttributeKey_;
  269. }
  270. if (options.ChildKey_) {
  271. result["child_key"] = *options.ChildKey_;
  272. }
  273. return result;
  274. }
  275. TNode SerializeParamsForUnlock(
  276. const TTransactionId& transactionId,
  277. const TString& pathPrefix,
  278. const TYPath& path,
  279. const TUnlockOptions& options)
  280. {
  281. TNode result;
  282. SetTransactionIdParam(&result, transactionId);
  283. SetPathParam(&result, pathPrefix, path);
  284. Y_UNUSED(options);
  285. return result;
  286. }
  287. TNode SerializeParamsForConcatenate(
  288. const TTransactionId& transactionId,
  289. const TString& pathPrefix,
  290. const TVector<TRichYPath>& sourcePaths,
  291. const TRichYPath& destinationPath,
  292. const TConcatenateOptions& options)
  293. {
  294. TNode result;
  295. SetTransactionIdParam(&result, transactionId);
  296. {
  297. auto actualDestination = destinationPath;
  298. actualDestination.Path(AddPathPrefix(actualDestination.Path_, pathPrefix));
  299. if (options.Append_) {
  300. actualDestination.Append(*options.Append_);
  301. }
  302. result["destination_path"] = PathToNode(actualDestination);
  303. }
  304. auto& sourcePathsNode = result["source_paths"];
  305. for (const auto& path : sourcePaths) {
  306. auto actualSource = path;
  307. actualSource.Path(AddPathPrefix(actualSource.Path_, pathPrefix));
  308. sourcePathsNode.Add(PathToNode(actualSource));
  309. }
  310. return result;
  311. }
  312. TNode SerializeParamsForPingTx(
  313. const TTransactionId& transactionId)
  314. {
  315. TNode result;
  316. SetTransactionIdParam(&result, transactionId);
  317. return result;
  318. }
  319. TNode SerializeParamsForListOperations(
  320. const TListOperationsOptions& options)
  321. {
  322. TNode result = TNode::CreateMap();
  323. if (options.FromTime_) {
  324. result["from_time"] = ToString(*options.FromTime_);
  325. }
  326. if (options.ToTime_) {
  327. result["to_time"] = ToString(*options.ToTime_);
  328. }
  329. if (options.CursorTime_) {
  330. result["cursor_time"] = ToString(*options.CursorTime_);
  331. }
  332. if (options.CursorDirection_) {
  333. result["cursor_direction"] = ToString(*options.CursorDirection_);
  334. }
  335. if (options.Pool_) {
  336. result["pool"] = *options.Pool_;
  337. }
  338. if (options.Filter_) {
  339. result["filter"] = *options.Filter_;
  340. }
  341. if (options.User_) {
  342. result["user"] = *options.User_;
  343. }
  344. if (options.State_) {
  345. result["state"] = *options.State_;
  346. }
  347. if (options.Type_) {
  348. result["type"] = ToString(*options.Type_);
  349. }
  350. if (options.WithFailedJobs_) {
  351. result["with_failed_jobs"] = *options.WithFailedJobs_;
  352. }
  353. if (options.IncludeCounters_) {
  354. result["include_counters"] = *options.IncludeCounters_;
  355. }
  356. if (options.IncludeArchive_) {
  357. result["include_archive"] = *options.IncludeArchive_;
  358. }
  359. if (options.Limit_) {
  360. result["limit"] = *options.Limit_;
  361. }
  362. return result;
  363. }
  364. TNode SerializeParamsForGetOperation(const std::variant<TString, TOperationId>& aliasOrOperationId, const TGetOperationOptions& options)
  365. {
  366. auto includeRuntime = options.IncludeRuntime_;
  367. TNode result;
  368. std::visit([&] (const auto& value) {
  369. using TValue = std::decay_t<decltype(value)>;
  370. if constexpr (std::is_same_v<TValue, TString>) {
  371. SetAliasParam(&result, value);
  372. if (includeRuntime.Empty()) {
  373. // Getting operation by operation alias requires enabling this option.
  374. // So enable it unless user explicitly set it.
  375. includeRuntime = true;
  376. }
  377. } else if constexpr (std::is_same_v<TValue, TOperationId>) {
  378. SetOperationIdParam(&result, value);
  379. } else {
  380. static_assert(std::is_same_v<TValue, void>, "unreachable");
  381. }
  382. }, aliasOrOperationId);
  383. if (options.AttributeFilter_) {
  384. result["attributes"] = SerializeAttributeFilter(*options.AttributeFilter_);
  385. }
  386. if (includeRuntime.Defined()) {
  387. result["include_runtime"] = *includeRuntime;
  388. }
  389. return result;
  390. }
  391. TNode SerializeParamsForAbortOperation(const TOperationId& operationId)
  392. {
  393. TNode result;
  394. SetOperationIdParam(&result, operationId);
  395. return result;
  396. }
  397. TNode SerializeParamsForCompleteOperation(const TOperationId& operationId)
  398. {
  399. TNode result;
  400. SetOperationIdParam(&result, operationId);
  401. return result;
  402. }
  403. TNode SerializeParamsForSuspendOperation(
  404. const TOperationId& operationId,
  405. const TSuspendOperationOptions& options)
  406. {
  407. TNode result;
  408. SetOperationIdParam(&result, operationId);
  409. if (options.AbortRunningJobs_) {
  410. result["abort_running_jobs"] = *options.AbortRunningJobs_;
  411. }
  412. return result;
  413. }
  414. TNode SerializeParamsForResumeOperation(
  415. const TOperationId& operationId,
  416. const TResumeOperationOptions& options)
  417. {
  418. TNode result;
  419. SetOperationIdParam(&result, operationId);
  420. Y_UNUSED(options);
  421. return result;
  422. }
  423. TNode SerializeParamsForUpdateOperationParameters(
  424. const TOperationId& operationId,
  425. const TUpdateOperationParametersOptions& options)
  426. {
  427. TNode result;
  428. SetOperationIdParam(&result, operationId);
  429. TNode& parameters = result["parameters"];
  430. if (options.Pool_) {
  431. parameters["pool"] = *options.Pool_;
  432. }
  433. if (options.Weight_) {
  434. parameters["weight"] = *options.Weight_;
  435. }
  436. if (!options.Owners_.empty()) {
  437. parameters["owners"] = TNode::CreateList();
  438. for (const auto& owner : options.Owners_) {
  439. parameters["owners"].Add(owner);
  440. }
  441. }
  442. if (options.SchedulingOptionsPerPoolTree_) {
  443. parameters["scheduling_options_per_pool_tree"] = TNode::CreateMap();
  444. for (const auto& entry : options.SchedulingOptionsPerPoolTree_->Options_) {
  445. auto schedulingOptionsNode = TNode::CreateMap();
  446. const auto& schedulingOptions = entry.second;
  447. if (schedulingOptions.Pool_) {
  448. schedulingOptionsNode["pool"] = *schedulingOptions.Pool_;
  449. }
  450. if (schedulingOptions.Weight_) {
  451. schedulingOptionsNode["weight"] = *schedulingOptions.Weight_;
  452. }
  453. if (schedulingOptions.ResourceLimits_) {
  454. auto resourceLimitsNode = TNode::CreateMap();
  455. const auto& resourceLimits = *schedulingOptions.ResourceLimits_;
  456. if (resourceLimits.UserSlots_) {
  457. resourceLimitsNode["user_slots"] = *resourceLimits.UserSlots_;
  458. }
  459. if (resourceLimits.Memory_) {
  460. resourceLimitsNode["memory"] = *resourceLimits.Memory_;
  461. }
  462. if (resourceLimits.Cpu_) {
  463. resourceLimitsNode["cpu"] = *resourceLimits.Cpu_;
  464. }
  465. if (resourceLimits.Network_) {
  466. resourceLimitsNode["network"] = *resourceLimits.Network_;
  467. }
  468. schedulingOptionsNode["resource_limits"] = std::move(resourceLimitsNode);
  469. }
  470. parameters["scheduling_options_per_pool_tree"][entry.first] = std::move(schedulingOptionsNode);
  471. }
  472. }
  473. return result;
  474. }
  475. TNode SerializeParamsForGetJob(
  476. const TOperationId& operationId,
  477. const TJobId& jobId,
  478. const TGetJobOptions& /* options */)
  479. {
  480. TNode result;
  481. SetOperationIdParam(&result, operationId);
  482. result["job_id"] = GetGuidAsString(jobId);
  483. return result;
  484. }
  485. TNode SerializeParamsForListJobs(
  486. const TOperationId& operationId,
  487. const TListJobsOptions& options)
  488. {
  489. TNode result;
  490. SetOperationIdParam(&result, operationId);
  491. if (options.Type_) {
  492. result["type"] = ToString(*options.Type_);
  493. }
  494. if (options.State_) {
  495. result["state"] = ToString(*options.State_);
  496. }
  497. if (options.Address_) {
  498. result["address"] = *options.Address_;
  499. }
  500. if (options.WithStderr_) {
  501. result["with_stderr"] = *options.WithStderr_;
  502. }
  503. if (options.WithSpec_) {
  504. result["with_spec"] = *options.WithSpec_;
  505. }
  506. if (options.WithFailContext_) {
  507. result["with_fail_context"] = *options.WithFailContext_;
  508. }
  509. if (options.SortField_) {
  510. result["sort_field"] = ToString(*options.SortField_);
  511. }
  512. if (options.SortOrder_) {
  513. result["sort_order"] = ToString(*options.SortOrder_);
  514. }
  515. if (options.Offset_) {
  516. result["offset"] = *options.Offset_;
  517. }
  518. if (options.Limit_) {
  519. result["limit"] = *options.Limit_;
  520. }
  521. if (options.IncludeCypress_) {
  522. result["include_cypress"] = *options.IncludeCypress_;
  523. }
  524. if (options.IncludeArchive_) {
  525. result["include_archive"] = *options.IncludeArchive_;
  526. }
  527. if (options.IncludeControllerAgent_) {
  528. result["include_controller_agent"] = *options.IncludeControllerAgent_;
  529. }
  530. return result;
  531. }
  532. TNode SerializeParametersForInsertRows(
  533. const TString& pathPrefix,
  534. const TYPath& path,
  535. const TInsertRowsOptions& options)
  536. {
  537. TNode result;
  538. SetPathParam(&result, pathPrefix, path);
  539. if (options.Aggregate_) {
  540. result["aggregate"] = *options.Aggregate_;
  541. }
  542. if (options.Update_) {
  543. result["update"] = *options.Update_;
  544. }
  545. if (options.Atomicity_) {
  546. result["atomicity"] = ToString(*options.Atomicity_);
  547. }
  548. if (options.Durability_) {
  549. result["durability"] = ToString(*options.Durability_);
  550. }
  551. if (options.RequireSyncReplica_) {
  552. result["require_sync_replica"] = *options.RequireSyncReplica_;
  553. }
  554. return result;
  555. }
  556. TNode SerializeParametersForDeleteRows(
  557. const TString& pathPrefix,
  558. const TYPath& path,
  559. const TDeleteRowsOptions& options)
  560. {
  561. TNode result;
  562. SetPathParam(&result, pathPrefix, path);
  563. if (options.Atomicity_) {
  564. result["atomicity"] = ToString(*options.Atomicity_);
  565. }
  566. if (options.Durability_) {
  567. result["durability"] = ToString(*options.Durability_);
  568. }
  569. if (options.RequireSyncReplica_) {
  570. result["require_sync_replica"] = *options.RequireSyncReplica_;
  571. }
  572. return result;
  573. }
  574. TNode SerializeParametersForTrimRows(
  575. const TString& pathPrefix,
  576. const TYPath& path,
  577. const TTrimRowsOptions& /* options*/)
  578. {
  579. TNode result;
  580. SetPathParam(&result, pathPrefix, path);
  581. return result;
  582. }
  583. TNode SerializeParamsForParseYPath(const TRichYPath& path)
  584. {
  585. TNode result;
  586. result["path"] = PathToNode(path);
  587. return result;
  588. }
  589. TNode SerializeParamsForEnableTableReplica(
  590. const TReplicaId& replicaId)
  591. {
  592. TNode result;
  593. result["replica_id"] = GetGuidAsString(replicaId);
  594. return result;
  595. }
  596. TNode SerializeParamsForDisableTableReplica(
  597. const TReplicaId& replicaId)
  598. {
  599. TNode result;
  600. result["replica_id"] = GetGuidAsString(replicaId);
  601. return result;
  602. }
  603. TNode SerializeParamsForAlterTableReplica(const TReplicaId& replicaId, const TAlterTableReplicaOptions& options)
  604. {
  605. TNode result;
  606. result["replica_id"] = GetGuidAsString(replicaId);
  607. if (options.Enabled_) {
  608. result["enabled"] = *options.Enabled_;
  609. }
  610. if (options.Mode_) {
  611. result["mode"] = ToString(*options.Mode_);
  612. }
  613. return result;
  614. }
  615. TNode SerializeParamsForFreezeTable(
  616. const TString& pathPrefix,
  617. const TYPath& path,
  618. const TFreezeTableOptions& options)
  619. {
  620. TNode result;
  621. SetPathParam(&result, pathPrefix, path);
  622. SetFirstLastTabletIndex(&result, options);
  623. return result;
  624. }
  625. TNode SerializeParamsForUnfreezeTable(
  626. const TString& pathPrefix,
  627. const TYPath& path,
  628. const TUnfreezeTableOptions& options)
  629. {
  630. TNode result;
  631. SetPathParam(&result, pathPrefix, path);
  632. SetFirstLastTabletIndex(&result, options);
  633. return result;
  634. }
  635. TNode SerializeParamsForAlterTable(
  636. const TTransactionId& transactionId,
  637. const TString& pathPrefix,
  638. const TYPath& path,
  639. const TAlterTableOptions& options)
  640. {
  641. TNode result;
  642. SetTransactionIdParam(&result, transactionId);
  643. SetPathParam(&result, pathPrefix, path);
  644. if (options.Dynamic_) {
  645. result["dynamic"] = *options.Dynamic_;
  646. }
  647. if (options.Schema_) {
  648. TNode schema;
  649. {
  650. TNodeBuilder builder(&schema);
  651. Serialize(*options.Schema_, &builder);
  652. }
  653. result["schema"] = schema;
  654. }
  655. if (options.UpstreamReplicaId_) {
  656. result["upstream_replica_id"] = GetGuidAsString(*options.UpstreamReplicaId_);
  657. }
  658. return result;
  659. }
  660. TNode SerializeParamsForGetTableColumnarStatistics(
  661. const TTransactionId& transactionId,
  662. const TVector<TRichYPath>& paths,
  663. const TGetTableColumnarStatisticsOptions& options)
  664. {
  665. TNode result;
  666. SetTransactionIdParam(&result, transactionId);
  667. for (const auto& path : paths) {
  668. result["paths"].Add(PathToNode(path));
  669. }
  670. if (options.FetcherMode_) {
  671. result["fetcher_mode"] = ToString(*options.FetcherMode_);
  672. }
  673. return result;
  674. }
  675. TNode SerializeParamsForGetTablePartitions(
  676. const TTransactionId& transactionId,
  677. const TVector<TRichYPath>& paths,
  678. const TGetTablePartitionsOptions& options)
  679. {
  680. TNode result;
  681. SetTransactionIdParam(&result, transactionId);
  682. for (const auto& path : paths) {
  683. result["paths"].Add(PathToNode(path));
  684. }
  685. result["partition_mode"] = ToString(options.PartitionMode_);
  686. result["data_weight_per_partition"] = options.DataWeightPerPartition_;
  687. if (options.MaxPartitionCount_) {
  688. result["max_partition_count"] = *options.MaxPartitionCount_;
  689. }
  690. result["adjust_data_weight_per_partition"] = options.AdjustDataWeightPerPartition_;
  691. return result;
  692. }
  693. TNode SerializeParamsForGetFileFromCache(
  694. const TTransactionId& transactionId,
  695. const TString& md5Signature,
  696. const TYPath& cachePath,
  697. const TGetFileFromCacheOptions&)
  698. {
  699. TNode result;
  700. SetTransactionIdParam(&result, transactionId);
  701. result["md5"] = md5Signature;
  702. result["cache_path"] = cachePath;
  703. return result;
  704. }
  705. TNode SerializeParamsForPutFileToCache(
  706. const TTransactionId& transactionId,
  707. const TString& pathPrefix,
  708. const TYPath& filePath,
  709. const TString& md5Signature,
  710. const TYPath& cachePath,
  711. const TPutFileToCacheOptions& options)
  712. {
  713. TNode result;
  714. SetTransactionIdParam(&result, transactionId);
  715. SetPathParam(&result, pathPrefix, filePath);
  716. result["md5"] = md5Signature;
  717. result["cache_path"] = cachePath;
  718. if (options.PreserveExpirationTimeout_) {
  719. result["preserve_expiration_timeout"] = *options.PreserveExpirationTimeout_;
  720. }
  721. return result;
  722. }
  723. TNode SerializeParamsForSkyShareTable(
  724. const TString& serverName,
  725. const TString& pathPrefix,
  726. const std::vector<TYPath>& tablePaths,
  727. const TSkyShareTableOptions& options)
  728. {
  729. TNode result;
  730. if (tablePaths.size() == 1) {
  731. SetPathParam(&result, pathPrefix, tablePaths[0]);
  732. } else {
  733. auto pathList = TNode::CreateList();
  734. for (const auto& p : tablePaths) {
  735. pathList.Add(AddPathPrefix(p, pathPrefix));
  736. }
  737. result["paths"] = pathList;
  738. }
  739. result["cluster"] = serverName;
  740. if (options.KeyColumns_) {
  741. auto keyColumnsList = TNode::CreateList();
  742. for (const auto& s : options.KeyColumns_->Parts_) {
  743. if (s.empty()) {
  744. continue;
  745. }
  746. keyColumnsList.Add(s);
  747. }
  748. result["key_columns"] = keyColumnsList;
  749. }
  750. if (options.EnableFastbone_) {
  751. result["enable_fastbone"] = *options.EnableFastbone_;
  752. }
  753. return result;
  754. }
  755. TNode SerializeParamsForCheckPermission(
  756. const TString& user,
  757. EPermission permission,
  758. const TString& pathPrefix,
  759. const TYPath& path,
  760. const TCheckPermissionOptions& options)
  761. {
  762. TNode result;
  763. SetPathParam(&result, pathPrefix, path);
  764. result["path"] = path;
  765. result["user"] = user;
  766. result["permission"] = ToString(permission);
  767. if (!options.Columns_.empty()) {
  768. result["columns"] = TNode::CreateList();
  769. result["columns"].AsList().assign(options.Columns_.begin(), options.Columns_.end());
  770. }
  771. return result;
  772. }
  773. TNode SerializeParamsForGetTabletInfos(
  774. const TString& pathPrefix,
  775. const TYPath& path,
  776. const TVector<int>& tabletIndexes,
  777. const TGetTabletInfosOptions& options)
  778. {
  779. Y_UNUSED(options);
  780. TNode result;
  781. SetPathParam(&result, pathPrefix, path);
  782. result["tablet_indexes"] = TNode::CreateList();
  783. result["tablet_indexes"].AsList().assign(tabletIndexes.begin(), tabletIndexes.end());
  784. return result;
  785. }
  786. TNode SerializeParamsForAbortTransaction(const TTransactionId& transactionId)
  787. {
  788. TNode result;
  789. SetTransactionIdParam(&result, transactionId);
  790. return result;
  791. }
  792. TNode SerializeParamsForCommitTransaction(const TTransactionId& transactionId)
  793. {
  794. TNode result;
  795. SetTransactionIdParam(&result, transactionId);
  796. return result;
  797. }
  798. TNode SerializeParamsForStartTransaction(
  799. const TTransactionId& parentTransactionId,
  800. TDuration txTimeout,
  801. const TStartTransactionOptions& options)
  802. {
  803. TNode result;
  804. SetTransactionIdParam(&result, parentTransactionId);
  805. result["timeout"] = static_cast<i64>((options.Timeout_.GetOrElse(txTimeout).MilliSeconds()));
  806. if (options.Deadline_) {
  807. result["deadline"] = ToString(options.Deadline_);
  808. }
  809. if (options.PingAncestors_) {
  810. result["ping_ancestor_transactions"] = true;
  811. }
  812. if (options.Attributes_ && !options.Attributes_->IsMap()) {
  813. ythrow TApiUsageError() << "Attributes must be a Map node";
  814. }
  815. auto attributes = options.Attributes_.GetOrElse(TNode::CreateMap());
  816. if (options.Title_) {
  817. attributes["title"] = *options.Title_;
  818. } else if (!attributes.HasKey("title")) {
  819. attributes["title"] = GetDefaultTransactionTitle();
  820. }
  821. result["attributes"] = attributes;
  822. return result;
  823. }
  824. ////////////////////////////////////////////////////////////////////////////////
  825. } // namespace NYT::NDetail::NRawClient