ecl-queries.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include <stdio.h>
  14. #include "jlog.hpp"
  15. #include "jfile.hpp"
  16. #include "jargv.hpp"
  17. #include "build-config.h"
  18. #include "ws_workunits.hpp"
  19. #include "eclcmd.hpp"
  20. #include "eclcmd_common.hpp"
  21. #include "eclcmd_core.hpp"
  22. #define INIFILE "ecl.ini"
  23. #define SYSTEMCONFDIR CONFIG_DIR
  24. #define DEFAULTINIFILE "ecl.ini"
  25. #define SYSTEMCONFFILE ENV_CONF_FILE
  26. //=========================================================================================
  27. class ActiveQueryMap
  28. {
  29. public:
  30. ActiveQueryMap(IConstWUQuerySetDetail &qs) : queryMap(createPTree())
  31. {
  32. IArrayOf<IConstQuerySetAlias> &aliases = qs.getAliases();
  33. ForEachItemIn(i, aliases)
  34. addMappedAlias(aliases.item(i).getId(), aliases.item(i).getName());
  35. }
  36. void addMappedAlias(const char *queryid, const char *alias)
  37. {
  38. if (queryid && *queryid && alias && *alias)
  39. ensureMappedQuery(queryid)->addProp("Alias", alias);
  40. }
  41. IPropertyTree *ensureMappedQuery(const char *queryid)
  42. {
  43. VStringBuffer xpath("Query[@id='%s']", queryid);
  44. IPropertyTree *query = queryMap->getPropTree(xpath.str());
  45. if (!query)
  46. {
  47. query = queryMap->addPropTree("Query", createPTree());
  48. query->setProp("@id", queryid);
  49. }
  50. return query;
  51. }
  52. bool isActive(const char *queryid)
  53. {
  54. VStringBuffer xpath("Query[@id='%s']", queryid);
  55. return queryMap->hasProp(xpath.str());
  56. }
  57. IPropertyTreeIterator *getActiveNames(const char *queryid)
  58. {
  59. VStringBuffer xpath("Query[@id='%s']/Alias", queryid);
  60. return queryMap->getElements(xpath.str());
  61. }
  62. private:
  63. Linked<IPropertyTree> queryMap;
  64. };
  65. #define QUERYLIST_SHOW_UNFLAGGED 0x01
  66. #define QUERYLIST_SHOW_ACTIVE 0x02
  67. #define QUERYLIST_SHOW_SUSPENDED 0x04
  68. #define QUERYLIST_SHOW_CLUSTER_SUSPENDED 0x08
  69. #define QUERYLIST_SHOW_INACTIVE (QUERYLIST_SHOW_UNFLAGGED | QUERYLIST_SHOW_SUSPENDED | QUERYLIST_SHOW_CLUSTER_SUSPENDED)
  70. class EclCmdQueriesList : public EclCmdCommon
  71. {
  72. public:
  73. EclCmdQueriesList() : flags(0), optInactive(false)
  74. {
  75. }
  76. virtual bool parseCommandLineOptions(ArgvIterator &iter)
  77. {
  78. if (iter.done())
  79. {
  80. usage();
  81. return false;
  82. }
  83. for (; !iter.done(); iter.next())
  84. {
  85. const char *arg = iter.query();
  86. if (*arg!='-')
  87. {
  88. optTargetCluster.set(arg);
  89. continue;
  90. }
  91. if (iter.matchOption(optTargetCluster, ECLOPT_CLUSTER_DEPRECATED)||iter.matchOption(optTargetCluster, ECLOPT_CLUSTER_DEPRECATED_S))
  92. continue;
  93. if (iter.matchOption(optTargetCluster, ECLOPT_TARGET)||iter.matchOption(optTargetCluster, ECLOPT_TARGET_S))
  94. continue;
  95. if (iter.matchFlag(optInactive, ECLOPT_INACTIVE))
  96. continue;
  97. StringAttr temp;
  98. if (iter.matchOption(temp, ECLOPT_SHOW))
  99. {
  100. for (const char *ch = temp.sget(); *ch; ch++)
  101. {
  102. switch (*ch)
  103. {
  104. case 'A':
  105. flags |= QUERYLIST_SHOW_ACTIVE;
  106. break;
  107. case 'S':
  108. flags |= QUERYLIST_SHOW_SUSPENDED;
  109. break;
  110. case 'X':
  111. flags |= QUERYLIST_SHOW_CLUSTER_SUSPENDED;
  112. break;
  113. case 'U':
  114. flags |= QUERYLIST_SHOW_UNFLAGGED;
  115. break;
  116. default:
  117. fprintf(stderr, "Unrecognized --show flag = %c", *ch);
  118. return false;
  119. }
  120. }
  121. continue;
  122. }
  123. if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
  124. return false;
  125. }
  126. return true;
  127. }
  128. virtual bool finalizeOptions(IProperties *globals)
  129. {
  130. if (optInactive)
  131. {
  132. if (flags)
  133. {
  134. fputs("--show and --inactive should not be used together.\n\n", stderr);
  135. return false;
  136. }
  137. flags = QUERYLIST_SHOW_INACTIVE;
  138. }
  139. if (!EclCmdCommon::finalizeOptions(globals))
  140. return false;
  141. return true;
  142. }
  143. void outputQuery(IConstQuerySetQuery &query, ActiveQueryMap &queryMap)
  144. {
  145. const char *queryid = query.getId();
  146. bool isActive = queryMap.isActive(queryid);
  147. bool suspendedOnCluster = false;
  148. ForEachItemIn(idx, query.getClusters())
  149. {
  150. IConstClusterQueryState &state = query.getClusters().item(idx);
  151. if (strieq(state.getState(), "Suspended"))
  152. {
  153. suspendedOnCluster = true;
  154. break;
  155. }
  156. }
  157. if (flags)
  158. {
  159. if (isActive && !(flags & QUERYLIST_SHOW_ACTIVE))
  160. return;
  161. if (query.getSuspended() && !(flags & QUERYLIST_SHOW_SUSPENDED))
  162. return;
  163. if (suspendedOnCluster && !(flags & QUERYLIST_SHOW_CLUSTER_SUSPENDED))
  164. return;
  165. if (!isActive && !query.getSuspended() && !(flags & QUERYLIST_SHOW_UNFLAGGED))
  166. return;
  167. }
  168. StringBuffer line(" ");
  169. line.append(suspendedOnCluster ? 'X' : ' ');
  170. line.append(query.getSuspended() ? 'S' : ' ');
  171. line.append(isActive ? 'A' : ' ');
  172. line.append(' ').append(queryid);
  173. if (!query.getTimeLimit_isNull())
  174. {
  175. if (line.length() < 34)
  176. line.appendN(34 - line.length(), ' ');
  177. line.append(' ').append(query.getTimeLimit());
  178. }
  179. if (!query.getWarnTimeLimit_isNull())
  180. {
  181. if (line.length() < 41)
  182. line.appendN(41 - line.length(), ' ');
  183. line.append(' ').append(query.getWarnTimeLimit());
  184. }
  185. if (query.getPriority())
  186. {
  187. if (line.length() < 48)
  188. line.appendN(48 - line.length(), ' ');
  189. line.append(' ').append(query.getPriority());
  190. }
  191. if (query.getMemoryLimit())
  192. {
  193. if (line.length() < 53)
  194. line.appendN(53 - line.length(), ' ');
  195. line.append(' ').append(query.getMemoryLimit());
  196. }
  197. if (query.getComment())
  198. {
  199. if (line.length() < 64)
  200. line.appendN(64 - line.length(), ' ');
  201. line.append(' ').append(query.getComment());
  202. }
  203. fputs(line.append('\n').str(), stdout);
  204. }
  205. void outputQueryset(IConstWUQuerySetDetail &qs)
  206. {
  207. ActiveQueryMap queryMap(qs);
  208. if (qs.getQuerySetName())
  209. fprintf(stdout, "\nTarget: %s\n", qs.getQuerySetName());
  210. fputs("\n", stdout);
  211. fputs(" Time Warn Memory\n", stdout);
  212. fputs("Flags Query Id Limit Limit Pri Limit Comment\n", stdout);
  213. fputs("----- ---------------------------- ------ ------ ---- ---------- ------------\n", stdout);
  214. IArrayOf<IConstQuerySetQuery> &queries = qs.getQueries();
  215. ForEachItemIn(id, queries)
  216. outputQuery(queries.item(id), queryMap);
  217. }
  218. virtual int processCMD()
  219. {
  220. Owned<IClientWsWorkunits> client = createCmdClient(WsWorkunits, *this);
  221. Owned<IClientWUMultiQuerySetDetailsRequest> req = client->createWUMultiQuerysetDetailsRequest();
  222. req->setQuerySetName(optTargetCluster.get());
  223. req->setClusterName(optTargetCluster.get());
  224. req->setFilterType("All");
  225. Owned<IClientWUMultiQuerySetDetailsResponse> resp = client->WUMultiQuerysetDetails(req);
  226. if (resp->getExceptions().ordinality())
  227. outputMultiExceptions(resp->getExceptions());
  228. else
  229. {
  230. IArrayOf<IConstWUQuerySetDetail> &querysets = resp->getQuerysets();
  231. ForEachItemIn(i, querysets)
  232. outputQueryset(querysets.item(i));
  233. }
  234. return 0;
  235. }
  236. virtual void usage()
  237. {
  238. fputs("\nUsage:\n"
  239. "\n"
  240. "The 'queries list' command displays a list of the queries published to one\n"
  241. "or more target clusters. If a target is provided the querysets associated with\n"
  242. "that cluster will be shown. If no queryset or cluster is specified all targets\n"
  243. "are shown.\n"
  244. "\n"
  245. "ecl queries list [<target>][--show=<flags>]\n\n"
  246. " Options:\n"
  247. " <target> Name of target cluster to get list of queries for\n"
  248. " --show=<flags> Show only queries with matching flags\n"
  249. " --inactive Show only queries that do not have an active alias\n"
  250. " Flags:\n"
  251. " A Query is active\n"
  252. " S Query is suspended in queryset\n"
  253. //not yet " X Query is suspended on selected cluster\n"
  254. " U Query with no flags set\n"
  255. " Common Options:\n",
  256. stdout);
  257. EclCmdCommon::usage();
  258. }
  259. private:
  260. StringAttr optTargetCluster;
  261. unsigned flags;
  262. bool optInactive;
  263. };
  264. class EclCmdQueriesCopy : public EclCmdCommon
  265. {
  266. public:
  267. EclCmdQueriesCopy() : optActivate(false), optNoReload(false), optMsToWait(10000), optDontCopyFiles(false), optOverwrite(false), optNoForeign(false)
  268. {
  269. optTimeLimit = (unsigned) -1;
  270. optWarnTimeLimit = (unsigned) -1;
  271. }
  272. virtual bool parseCommandLineOptions(ArgvIterator &iter)
  273. {
  274. if (iter.done())
  275. {
  276. usage();
  277. return false;
  278. }
  279. for (; !iter.done(); iter.next())
  280. {
  281. const char *arg = iter.query();
  282. if (*arg!='-')
  283. {
  284. if (optSourceQueryPath.isEmpty())
  285. optSourceQueryPath.set(arg);
  286. else if (optTargetCluster.isEmpty())
  287. optTargetCluster.set(arg);
  288. else
  289. {
  290. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  291. return false;
  292. }
  293. continue;
  294. }
  295. if (iter.matchOption(optDaliIP, ECLOPT_DALIIP))
  296. continue;
  297. if (iter.matchOption(optSourceProcess, ECLOPT_SOURCE_PROCESS))
  298. continue;
  299. if (iter.matchFlag(optActivate, ECLOPT_ACTIVATE)||iter.matchFlag(optActivate, ECLOPT_ACTIVATE_S))
  300. continue;
  301. if (iter.matchFlag(optNoReload, ECLOPT_NORELOAD))
  302. continue;
  303. if (iter.matchOption(optTargetCluster, ECLOPT_CLUSTER_DEPRECATED)||iter.matchOption(optTargetCluster, ECLOPT_CLUSTER_DEPRECATED_S))
  304. continue;
  305. if (iter.matchOption(optTargetCluster, ECLOPT_TARGET)||iter.matchOption(optTargetCluster, ECLOPT_TARGET_S))
  306. continue;
  307. if (iter.matchFlag(optDontCopyFiles, ECLOPT_DONT_COPY_FILES))
  308. continue;
  309. if (iter.matchFlag(optNoForeign, ECLOPT_NO_FOREIGN))
  310. continue;
  311. if (iter.matchOption(optMsToWait, ECLOPT_WAIT))
  312. continue;
  313. if (iter.matchOption(optTimeLimit, ECLOPT_TIME_LIMIT))
  314. continue;
  315. if (iter.matchOption(optWarnTimeLimit, ECLOPT_WARN_TIME_LIMIT))
  316. continue;
  317. if (iter.matchOption(optMemoryLimit, ECLOPT_MEMORY_LIMIT))
  318. continue;
  319. if (iter.matchOption(optPriority, ECLOPT_PRIORITY))
  320. continue;
  321. if (iter.matchOption(optComment, ECLOPT_COMMENT))
  322. continue;
  323. if (iter.matchFlag(optOverwrite, ECLOPT_OVERWRITE)||iter.matchFlag(optOverwrite, ECLOPT_OVERWRITE_S))
  324. continue;
  325. if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
  326. return false;
  327. }
  328. return true;
  329. }
  330. virtual bool finalizeOptions(IProperties *globals)
  331. {
  332. if (!EclCmdCommon::finalizeOptions(globals))
  333. return false;
  334. if (optSourceQueryPath.isEmpty() && optTargetCluster.isEmpty())
  335. {
  336. fputs("source and target must both be specified.\n\n", stderr);
  337. return false;
  338. }
  339. if (optMemoryLimit.length() && !isValidMemoryValue(optMemoryLimit))
  340. {
  341. fprintf(stderr, "invalid --memoryLimit value of %s.\n\n", optMemoryLimit.get());
  342. return false;
  343. }
  344. if (optPriority.length() && !isValidPriorityValue(optPriority))
  345. {
  346. fprintf(stderr, "invalid --priority value of %s.\n\n", optPriority.get());
  347. return false;
  348. }
  349. return true;
  350. }
  351. virtual int processCMD()
  352. {
  353. Owned<IClientWsWorkunits> client = createCmdClient(WsWorkunits, *this);
  354. Owned<IClientWUQuerySetCopyQueryRequest> req = client->createWUQuerysetCopyQueryRequest();
  355. req->setSource(optSourceQueryPath.get());
  356. req->setTarget(optTargetCluster.get());
  357. req->setCluster(optTargetCluster.get());
  358. req->setDaliServer(optDaliIP.get());
  359. req->setSourceProcess(optSourceProcess);
  360. req->setActivate(optActivate);
  361. req->setOverwrite(optOverwrite);
  362. req->setDontCopyFiles(optDontCopyFiles);
  363. req->setWait(optMsToWait);
  364. req->setNoReload(optNoReload);
  365. req->setAllowForeignFiles(!optNoForeign);
  366. if (optTimeLimit != (unsigned) -1)
  367. req->setTimeLimit(optTimeLimit);
  368. if (optWarnTimeLimit != (unsigned) -1)
  369. req->setWarnTimeLimit(optWarnTimeLimit);
  370. if (!optMemoryLimit.isEmpty())
  371. req->setMemoryLimit(optMemoryLimit);
  372. if (!optPriority.isEmpty())
  373. req->setPriority(optPriority);
  374. if (optComment.get()) //allow empty
  375. req->setComment(optComment);
  376. Owned<IClientWUQuerySetCopyQueryResponse> resp = client->WUQuerysetCopyQuery(req);
  377. if (resp->getExceptions().ordinality())
  378. outputMultiExceptions(resp->getExceptions());
  379. if (resp->getQueryId() && *resp->getQueryId())
  380. fprintf(stdout, "%s/%s\n\n", optTargetQuerySet.sget(), resp->getQueryId());
  381. return 0;
  382. }
  383. virtual void usage()
  384. {
  385. fputs("\nUsage:\n"
  386. "\n"
  387. "The 'queries copy' command copies a query from one queryset to another.\n"
  388. "\n"
  389. "A query can be copied from one HPCC environment to another by using a path\n"
  390. "which begins with '//' followed by the IP and Port of the source EclWatch\n"
  391. "and then followed by the source queryset and query.\n"
  392. "\n"
  393. "ecl queries copy <source_query_path> <target> [--activate]\n"
  394. "\n"
  395. "ecl queries copy //IP:Port/queryset/query <target> [--activate]\n"
  396. "ecl queries copy queryset/query <target> [--activate]\n"
  397. "\n"
  398. " Options:\n"
  399. " <source_query_path> Path of query to copy\n"
  400. " in the form: //ip:port/queryset/query\n"
  401. " or: queryset/query\n"
  402. " <target> Name of target cluster to copy the query to\n"
  403. " --no-files Do not copy files referenced by query\n"
  404. " --daliip=<ip> For file copying if remote version < 3.8\n"
  405. " --source-process Process cluster to copy files from\n"
  406. " -A, --activate Activate the new query\n"
  407. " --no-reload Do not request a reload of the (roxie) cluster\n"
  408. " -O, --overwrite Overwrite existing files\n"
  409. " --no-foreign Fail if foreign files are used in query (roxie)\n"
  410. " --wait=<ms> Max time to wait in milliseconds\n"
  411. " --timeLimit=<sec> Value to set for query timeLimit configuration\n"
  412. " --warnTimeLimit=<sec> Value to set for query warnTimeLimit configuration\n"
  413. " --memoryLimit=<mem> Value to set for query memoryLimit configuration\n"
  414. " format <mem> as 500000B, 550K, 100M, 10G, 1T etc.\n"
  415. " --priority=<val> Set the priority for this query. Value can be LOW,\n"
  416. " HIGH, SLA, NONE. NONE will clear current setting.\n"
  417. " --comment=<string> Set the comment associated with this query\n"
  418. " Common Options:\n",
  419. stdout);
  420. EclCmdCommon::usage();
  421. }
  422. private:
  423. StringAttr optSourceQueryPath;
  424. StringAttr optTargetQuerySet;
  425. StringAttr optTargetCluster;
  426. StringAttr optDaliIP;
  427. StringAttr optSourceProcess;
  428. StringAttr optMemoryLimit;
  429. StringAttr optPriority;
  430. StringAttr optComment;
  431. unsigned optMsToWait;
  432. unsigned optTimeLimit;
  433. unsigned optWarnTimeLimit;
  434. bool optActivate;
  435. bool optNoReload;
  436. bool optOverwrite;
  437. bool optDontCopyFiles;
  438. bool optNoForeign;
  439. };
  440. class EclCmdQueriesConfig : public EclCmdCommon
  441. {
  442. public:
  443. EclCmdQueriesConfig() : optNoReload(false), optMsToWait(10000)
  444. {
  445. optTimeLimit = (unsigned) -1;
  446. optWarnTimeLimit = (unsigned) -1;
  447. }
  448. virtual bool parseCommandLineOptions(ArgvIterator &iter)
  449. {
  450. if (iter.done())
  451. {
  452. usage();
  453. return false;
  454. }
  455. for (; !iter.done(); iter.next())
  456. {
  457. const char *arg = iter.query();
  458. if (*arg!='-')
  459. {
  460. if (optTargetCluster.isEmpty())
  461. optTargetCluster.set(arg);
  462. else if (optQueryId.isEmpty())
  463. optQueryId.set(arg);
  464. else
  465. {
  466. fprintf(stderr, "\nunrecognized argument %s\n", arg);
  467. return false;
  468. }
  469. continue;
  470. }
  471. if (iter.matchFlag(optNoReload, ECLOPT_NORELOAD))
  472. continue;
  473. if (iter.matchOption(optMsToWait, ECLOPT_WAIT))
  474. continue;
  475. if (iter.matchOption(optTimeLimit, ECLOPT_TIME_LIMIT))
  476. continue;
  477. if (iter.matchOption(optWarnTimeLimit, ECLOPT_WARN_TIME_LIMIT))
  478. continue;
  479. if (iter.matchOption(optMemoryLimit, ECLOPT_MEMORY_LIMIT))
  480. continue;
  481. if (iter.matchOption(optPriority, ECLOPT_PRIORITY))
  482. continue;
  483. if (iter.matchOption(optComment, ECLOPT_COMMENT))
  484. continue;
  485. if (EclCmdCommon::matchCommandLineOption(iter, true)!=EclCmdOptionMatch)
  486. return false;
  487. }
  488. return true;
  489. }
  490. virtual bool finalizeOptions(IProperties *globals)
  491. {
  492. if (!EclCmdCommon::finalizeOptions(globals))
  493. return false;
  494. if (optTargetCluster.isEmpty() || optQueryId.isEmpty())
  495. {
  496. fputs("Target and QueryId must both be specified.\n\n", stderr);
  497. return false;
  498. }
  499. if (optMemoryLimit.length() && !isValidMemoryValue(optMemoryLimit))
  500. {
  501. fprintf(stderr, "invalid --memoryLimit value of %s.\n\n", optMemoryLimit.get());
  502. return false;
  503. }
  504. if (optPriority.length() && !isValidPriorityValue(optPriority))
  505. {
  506. fprintf(stderr, "invalid --priority value of %s.\n\n", optPriority.get());
  507. return false;
  508. }
  509. return true;
  510. }
  511. virtual int processCMD()
  512. {
  513. Owned<IClientWsWorkunits> client = createCmdClient(WsWorkunits, *this);
  514. Owned<IClientWUQueryConfigRequest> req = client->createWUQueryConfigRequest();
  515. req->setTarget(optTargetCluster.get());
  516. req->setQueryId(optQueryId.get());
  517. req->setWait(optMsToWait);
  518. req->setNoReload(optNoReload);
  519. if (optTimeLimit != (unsigned) -1)
  520. req->setTimeLimit(optTimeLimit);
  521. if (optWarnTimeLimit != (unsigned) -1)
  522. req->setWarnTimeLimit(optWarnTimeLimit);
  523. if (!optMemoryLimit.isEmpty())
  524. req->setMemoryLimit(optMemoryLimit);
  525. if (!optPriority.isEmpty())
  526. req->setPriority(optPriority);
  527. if (optComment.get()) //allow empty
  528. req->setComment(optComment);
  529. Owned<IClientWUQueryConfigResponse> resp = client->WUQueryConfig(req);
  530. if (resp->getExceptions().ordinality())
  531. outputMultiExceptions(resp->getExceptions());
  532. IArrayOf<IConstWUQueryConfigResult> &results = resp->getResults();
  533. if (results.length())
  534. {
  535. fputs("configured:\n", stdout);
  536. ForEachItemIn(i, results)
  537. fprintf(stdout, " %s\n", results.item(i).getQueryId());
  538. }
  539. return 0;
  540. }
  541. virtual void usage()
  542. {
  543. fputs("\nUsage:\n"
  544. "\n"
  545. "The 'queries config' command updates query configuration values.\n"
  546. "\n"
  547. "ecl queries config <target> <queryid> [options]\n"
  548. "\n"
  549. " Options:\n"
  550. " <target> Name of target queryset containing query\n"
  551. " <queryid> Id of the query to configure\n"
  552. " --no-reload Do not request a reload of the (roxie) cluster\n"
  553. " --wait=<ms> Max time to wait in milliseconds\n"
  554. " --timeLimit=<sec> Value to set for query timeLimit configuration\n"
  555. " --warnTimeLimit=<sec> Value to set for query warnTimeLimit configuration\n"
  556. " --memoryLimit=<mem> Value to set for query memoryLimit configuration\n"
  557. " format <mem> as 500000B, 550K, 100M, 10G, 1T etc.\n"
  558. " --priority=<val> Set the priority for this query. Value can be LOW,\n"
  559. " HIGH, SLA, NONE. NONE will clear current setting.\n"
  560. " --comment=<string> Set the comment associated with this query\n"
  561. " Common Options:\n",
  562. stdout);
  563. EclCmdCommon::usage();
  564. }
  565. private:
  566. StringAttr optTargetCluster;
  567. StringAttr optQueryId;
  568. StringAttr optMemoryLimit;
  569. StringAttr optPriority;
  570. StringAttr optComment;
  571. unsigned optMsToWait;
  572. unsigned optTimeLimit;
  573. unsigned optWarnTimeLimit;
  574. bool optNoReload;
  575. };
  576. IEclCommand *createEclQueriesCommand(const char *cmdname)
  577. {
  578. if (!cmdname || !*cmdname)
  579. return NULL;
  580. if (strieq(cmdname, "list"))
  581. return new EclCmdQueriesList();
  582. if (strieq(cmdname, "config"))
  583. return new EclCmdQueriesConfig();
  584. if (strieq(cmdname, "copy"))
  585. return new EclCmdQueriesCopy();
  586. return NULL;
  587. }
  588. //=========================================================================================
  589. class EclQueriesCMDShell : public EclCMDShell
  590. {
  591. public:
  592. EclQueriesCMDShell(int argc, const char *argv[], EclCommandFactory _factory, const char *_version)
  593. : EclCMDShell(argc, argv, _factory, _version)
  594. {
  595. }
  596. virtual void usage()
  597. {
  598. fprintf(stdout,"\nUsage:\n\n"
  599. "ecl queries <command> [command options]\n\n"
  600. " Queries Commands:\n"
  601. " list list queries in queryset(s)\n"
  602. " config update query settings\n"
  603. " copy copy a query from one queryset to another\n"
  604. );
  605. }
  606. };
  607. static int doMain(int argc, const char *argv[])
  608. {
  609. EclQueriesCMDShell processor(argc, argv, createEclQueriesCommand, BUILD_TAG);
  610. return processor.run();
  611. }
  612. int main(int argc, const char *argv[])
  613. {
  614. InitModuleObjects();
  615. queryStderrLogMsgHandler()->setMessageFields(0);
  616. unsigned exitCode = doMain(argc, argv);
  617. releaseAtoms();
  618. exit(exitCode);
  619. }