ws_workunitsQuerySets.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #include "ws_workunitsService.hpp"
  15. #include "ws_fs.hpp"
  16. #include "jlib.hpp"
  17. #include "daclient.hpp"
  18. #include "dalienv.hpp"
  19. #include "dadfs.hpp"
  20. #include "dfuwu.hpp"
  21. #include "eclhelper.hpp"
  22. const unsigned roxieQueryRoxieTimeOut = 60000;
  23. #define SDS_LOCK_TIMEOUT (5*60*1000) // 5mins, 30s a bit short
  24. bool isRoxieProcess(const char *process)
  25. {
  26. if (!process)
  27. return false;
  28. Owned<IRemoteConnection> conn = querySDS().connect("Environment", myProcessSession(), RTM_LOCK_READ, SDS_LOCK_TIMEOUT);
  29. if (!conn)
  30. return false;
  31. VStringBuffer xpath("Software/RoxieCluster[@name=\"%s\"]", process);
  32. return conn->queryRoot()->hasProp(xpath.str());
  33. }
  34. void doWuFileCopy(IClientFileSpray &fs, IEspWULogicalFileCopyInfo &info, const char *logicalname, const char *cluster, bool isRoxie, bool supercopy)
  35. {
  36. try
  37. {
  38. Owned<IClientCopy> req = fs.createCopyRequest();
  39. req->setSourceLogicalName(logicalname);
  40. req->setDestLogicalName(logicalname);
  41. req->setDestGroup(cluster);
  42. req->setSuperCopy(supercopy);
  43. if (isRoxie)
  44. req->setDestGroupRoxie("Yes");
  45. Owned<IClientCopyResponse> resp = fs.Copy(req);
  46. info.setDfuCopyWuid(resp->getResult());
  47. }
  48. catch (IException *e)
  49. {
  50. StringBuffer msg;
  51. info.setDfuCopyError(e->errorMessage(msg).str());
  52. }
  53. }
  54. bool copyWULogicalFiles(IEspContext &context, IConstWorkUnit &cw, const char *cluster, bool copyLocal, IEspWUCopyLogicalClusterFileSections &lfinfo)
  55. {
  56. if (isEmpty(cluster))
  57. throw MakeStringException(ECLWATCH_INVALID_CLUSTER_NAME, "copyWULogicalFiles Cluster parameter not set.");
  58. Owned<IUserDescriptor> udesc = createUserDescriptor();
  59. udesc->set(context.queryUserId(), context.queryPassword());
  60. IArrayOf<IEspWULogicalFileCopyInfo> foreign;
  61. IArrayOf<IEspWULogicalFileCopyInfo> onCluster;
  62. IArrayOf<IEspWULogicalFileCopyInfo> notOnCluster;
  63. IArrayOf<IEspWULogicalFileCopyInfo> notFound;
  64. Owned<IClientFileSpray> fs;
  65. if (copyLocal)
  66. {
  67. fs.setown(createFileSprayClient());
  68. VStringBuffer url("http://.:%d/FileSpray", 8010);
  69. fs->addServiceUrl(url.str());
  70. }
  71. bool isRoxie = isRoxieProcess(cluster);
  72. Owned<IConstWUGraphIterator> graphs = &cw.getGraphs(GraphTypeActivities);
  73. ForEach(*graphs)
  74. {
  75. Owned <IPropertyTree> xgmml = graphs->query().getXGMMLTree(false);
  76. Owned<IPropertyTreeIterator> iter = xgmml->getElements(".//node");
  77. ForEach(*iter)
  78. {
  79. try
  80. {
  81. IPropertyTree &node = iter->query();
  82. ThorActivityKind kind = (ThorActivityKind) node.getPropInt("att[@name='_kind']/@value", TAKnone);
  83. if(kind==TAKdiskwrite || kind==TAKindexwrite || kind==TAKcsvwrite || kind==TAKxmlwrite)
  84. continue;
  85. if (node.getPropBool("att[@name='_isSpill']/@value") || node.getPropBool("att[@name='_isTransformSpill']/@value"))
  86. continue;
  87. Owned<IEspWULogicalFileCopyInfo> info = createWULogicalFileCopyInfo();
  88. const char *logicalname = node.queryProp("att[@name='_indexFileName']/@value");
  89. if (logicalname)
  90. info->setIsIndex(true);
  91. else
  92. logicalname = node.queryProp("att[@name='_fileName']/@value");
  93. info->setLogicalName(logicalname);
  94. if (logicalname)
  95. {
  96. if (!strnicmp("~foreign::", logicalname, 10))
  97. foreign.append(*info.getClear());
  98. else
  99. {
  100. Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(logicalname, udesc);
  101. if(!df)
  102. notFound.append(*info.getClear());
  103. else if (df->findCluster(cluster)!=NotFound)
  104. {
  105. onCluster.append(*info.getClear());
  106. }
  107. else
  108. {
  109. StringArray clusters;
  110. df->getClusterNames(clusters);
  111. info->setClusters(clusters);
  112. if (copyLocal)
  113. {
  114. StringBuffer wuid;
  115. bool supercopy = queryDistributedFileDirectory().isSuperFile(logicalname, NULL, udesc);
  116. doWuFileCopy(*fs, *info, logicalname, cluster, isRoxie, supercopy);
  117. }
  118. notOnCluster.append(*info.getClear());
  119. }
  120. }
  121. }
  122. }
  123. catch(IException *e)
  124. {
  125. e->Release();
  126. }
  127. }
  128. lfinfo.setClusterName(cluster);
  129. lfinfo.setNotOnCluster(notOnCluster);
  130. lfinfo.setOnCluster(onCluster);
  131. lfinfo.setForeign(foreign);
  132. lfinfo.setNotFound(notFound);
  133. }
  134. return true;
  135. }
  136. void copyWULogicalFilesToTarget(IEspContext &context, IConstWUClusterInfo &clusterInfo, IConstWorkUnit &cw, IArrayOf<IConstWUCopyLogicalClusterFileSections> &clusterfiles, bool doLocalCopy)
  137. {
  138. const StringArray &thors = clusterInfo.getThorProcesses();
  139. ForEachItemIn(i, thors)
  140. {
  141. Owned<IEspWUCopyLogicalClusterFileSections> files = createWUCopyLogicalClusterFileSections();
  142. copyWULogicalFiles(context, cw, thors.item(i), doLocalCopy, *files);
  143. clusterfiles.append(*files.getClear());
  144. }
  145. SCMStringBuffer roxie;
  146. clusterInfo.getRoxieProcess(roxie);
  147. if (roxie.length())
  148. {
  149. Owned<IEspWUCopyLogicalClusterFileSections> files = createWUCopyLogicalClusterFileSections();
  150. copyWULogicalFiles(context, cw, roxie.str(), doLocalCopy, *files);
  151. clusterfiles.append(*files.getClear());
  152. }
  153. }
  154. bool CWsWorkunitsEx::onWUCopyLogicalFiles(IEspContext &context, IEspWUCopyLogicalFilesRequest &req, IEspWUCopyLogicalFilesResponse &resp)
  155. {
  156. if (isEmpty(req.getWuid()))
  157. throw MakeStringException(ECLWATCH_CANNOT_OPEN_WORKUNIT, "WUCopyLogicalFiles WUID parameter not set.");
  158. Owned<IWorkUnitFactory> factory = getWorkUnitFactory(context.querySecManager(), context.queryUser());
  159. Owned<IConstWorkUnit> cw = factory->openWorkUnit(req.getWuid(), false);
  160. if (!cw)
  161. throw MakeStringException(ECLWATCH_CANNOT_OPEN_WORKUNIT,"Cannot open workunit %s", req.getWuid());
  162. resp.setWuid(req.getWuid());
  163. SCMStringBuffer cluster;
  164. if (notEmpty(req.getCluster()))
  165. cluster.set(req.getCluster());
  166. else
  167. cw->getClusterName(cluster);
  168. Owned <IConstWUClusterInfo> clusterInfo = getTargetClusterInfo(cluster.str());
  169. IArrayOf<IConstWUCopyLogicalClusterFileSections> clusterfiles;
  170. copyWULogicalFilesToTarget(context, *clusterInfo, *cw, clusterfiles, req.getCopyLocal());
  171. resp.setClusterFiles(clusterfiles);
  172. return true;
  173. }
  174. bool CWsWorkunitsEx::onWUPublishWorkunit(IEspContext &context, IEspWUPublishWorkunitRequest & req, IEspWUPublishWorkunitResponse & resp)
  175. {
  176. if (isEmpty(req.getWuid()))
  177. throw MakeStringException(ECLWATCH_NO_WUID_SPECIFIED,"No Workunit ID has been specified.");
  178. Owned<IWorkUnitFactory> factory = getWorkUnitFactory(context.querySecManager(), context.queryUser());
  179. Owned<IConstWorkUnit> cw = factory->openWorkUnit(req.getWuid(), false);
  180. if (!cw)
  181. throw MakeStringException(ECLWATCH_CANNOT_OPEN_WORKUNIT,"Cannot find the workunit %s", req.getWuid());
  182. resp.setWuid(req.getWuid());
  183. SCMStringBuffer queryName;
  184. if (notEmpty(req.getJobName()))
  185. queryName.set(req.getJobName());
  186. else
  187. cw->getJobName(queryName).str();
  188. if (!queryName.length())
  189. throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Query/Job name not defined for publishing workunit %s", req.getWuid());
  190. SCMStringBuffer cluster;
  191. if (notEmpty(req.getCluster()))
  192. cluster.set(req.getCluster());
  193. else
  194. cw->getClusterName(cluster);
  195. if (!cluster.length())
  196. throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Cluster name not defined for publishing workunit %s", req.getWuid());
  197. Owned <IConstWUClusterInfo> clusterInfo = getTargetClusterInfo(cluster.str());
  198. SCMStringBuffer queryset;
  199. clusterInfo->getQuerySetName(queryset);
  200. WorkunitUpdate wu(&cw->lock());
  201. if (notEmpty(req.getJobName()))
  202. wu->setJobName(req.getJobName());
  203. StringBuffer queryId;
  204. addQueryToQuerySet(wu, queryset.str(), queryName.str(), NULL, (WUQueryActivationOptions)req.getActivate(), queryId);
  205. wu->commit();
  206. wu.clear();
  207. if (queryId.length())
  208. resp.setQueryId(queryId.str());
  209. resp.setQueryName(queryName.str());
  210. resp.setQuerySet(queryset.str());
  211. if (req.getCopyLocal() || req.getShowFiles())
  212. {
  213. IArrayOf<IConstWUCopyLogicalClusterFileSections> clusterfiles;
  214. copyWULogicalFilesToTarget(context, *clusterInfo, *cw, clusterfiles, req.getCopyLocal());
  215. resp.setClusterFiles(clusterfiles);
  216. }
  217. return true;
  218. }
  219. bool CWsWorkunitsEx::onWUQuerysets(IEspContext &context, IEspWUQuerysetsRequest & req, IEspWUQuerysetsResponse & resp)
  220. {
  221. Owned<IPropertyTree> queryRegistry = getQueryRegistryRoot();
  222. if (!queryRegistry)
  223. return false;
  224. IArrayOf<IEspQuerySet> querySets;
  225. Owned<IPropertyTreeIterator> it = queryRegistry->getElements("QuerySet");
  226. ForEach(*it)
  227. {
  228. Owned<IEspQuerySet> qs = createQuerySet("", "");
  229. qs->setQuerySetName(it->query().queryProp("@id"));
  230. querySets.append(*qs.getClear());
  231. }
  232. resp.setQuerysets(querySets);
  233. return true;
  234. }
  235. void gatherQuerySetQueryDetails(IPropertyTree *query, IEspQuerySetQuery *queryInfo)
  236. {
  237. queryInfo->setId(query->queryProp("@id"));
  238. queryInfo->setName(query->queryProp("@name"));
  239. queryInfo->setDll(query->queryProp("@dll"));
  240. queryInfo->setWuid(query->queryProp("@wuid"));
  241. queryInfo->setSuspended(query->getPropBool("@suspended", false));
  242. }
  243. void gatherQuerySetAliasDetails(IPropertyTree *alias, IEspQuerySetAlias *aliasInfo)
  244. {
  245. aliasInfo->setName(alias->queryProp("@name"));
  246. aliasInfo->setId(alias->queryProp("@id"));
  247. }
  248. void retrieveAllQuerysetDetails(IPropertyTree *registry, IArrayOf<IEspQuerySetQuery> &queries, IArrayOf<IEspQuerySetAlias> &aliases)
  249. {
  250. Owned<IPropertyTreeIterator> regQueries = registry->getElements("Query");
  251. ForEach(*regQueries)
  252. {
  253. IPropertyTree &query = regQueries->query();
  254. Owned<IEspQuerySetQuery> q = createQuerySetQuery();
  255. gatherQuerySetQueryDetails(&query, q);
  256. queries.append(*q.getClear());
  257. }
  258. Owned<IPropertyTreeIterator> regAliases = registry->getElements("Alias");
  259. ForEach(*regAliases)
  260. {
  261. IPropertyTree &alias = regAliases->query();
  262. Owned<IEspQuerySetAlias> a = createQuerySetAlias();
  263. gatherQuerySetAliasDetails(&alias, a);
  264. aliases.append(*a.getClear());
  265. }
  266. }
  267. void retrieveQuerysetDetailsFromAlias(IPropertyTree *registry, const char *name, IArrayOf<IEspQuerySetQuery> &queries, IArrayOf<IEspQuerySetAlias> &aliases)
  268. {
  269. StringBuffer xpath;
  270. xpath.append("Alias[@name='").append(name).append("']");
  271. IPropertyTree *alias = registry->queryPropTree(xpath);
  272. if (!alias)
  273. {
  274. DBGLOG("Alias %s not found", name);
  275. return;
  276. }
  277. Owned<IEspQuerySetAlias> a = createQuerySetAlias();
  278. gatherQuerySetAliasDetails(alias, a);
  279. xpath.clear().append("Query[@id='").append(a->getId()).append("']");
  280. aliases.append(*a.getClear());
  281. IPropertyTree *query = registry->queryPropTree(xpath);
  282. if (!query)
  283. {
  284. DBGLOG("No matching Query %s found for Alias %s", a->getId(), name);
  285. return;
  286. }
  287. Owned<IEspQuerySetQuery> q = createQuerySetQuery();
  288. gatherQuerySetQueryDetails(query, q);
  289. queries.append(*q.getClear());
  290. }
  291. void retrieveQuerysetDetailsFromQuery(IPropertyTree *registry, const char *value, const char *type, IArrayOf<IEspQuerySetQuery> &queries, IArrayOf<IEspQuerySetAlias> &aliases)
  292. {
  293. if (!strieq(type, "Id") && !strieq(type, "Name"))
  294. throw MakeStringException(ECLWATCH_INVALID_INPUT, "Unrecognized queryset filter type %s", type);
  295. StringBuffer attributeName(type);
  296. StringBuffer xpath;
  297. xpath.clear().append("Query[@").append(attributeName.toLowerCase()).append("='").append(value).append("']");
  298. IPropertyTree *query = registry->queryPropTree(xpath);
  299. if (!query)
  300. {
  301. DBGLOG("No matching Query %s found for %s", value, type);
  302. return;
  303. }
  304. Owned<IEspQuerySetQuery> q = createQuerySetQuery();
  305. gatherQuerySetQueryDetails(query, q);
  306. xpath.clear().append("Alias[@id='").append(q->getId()).append("']");
  307. queries.append(*q.getClear());
  308. Owned<IPropertyTreeIterator> regAliases = registry->getElements(xpath.str());
  309. ForEach(*regAliases)
  310. {
  311. IPropertyTree &alias = regAliases->query();
  312. Owned<IEspQuerySetAlias> a = createQuerySetAlias();
  313. gatherQuerySetAliasDetails(&alias, a);
  314. aliases.append(*a.getClear());
  315. }
  316. }
  317. void retrieveQuerysetDetails(IPropertyTree *registry, const char *type, const char *value, IArrayOf<IEspQuerySetQuery> &queries, IArrayOf<IEspQuerySetAlias> &aliases)
  318. {
  319. if (strieq(type, "All"))
  320. return retrieveAllQuerysetDetails(registry, queries, aliases);
  321. if (!value || !*value)
  322. return;
  323. if (strieq(type, "Alias"))
  324. return retrieveQuerysetDetailsFromAlias(registry, value, queries, aliases);
  325. return retrieveQuerysetDetailsFromQuery(registry, value, type, queries, aliases);
  326. }
  327. void retrieveQuerysetDetails(IArrayOf<IEspWUQuerySetDetail> &details, IPropertyTree *registry, const char *type, const char *value)
  328. {
  329. if (!registry)
  330. return;
  331. IArrayOf<IEspQuerySetQuery> queries;
  332. IArrayOf<IEspQuerySetAlias> aliases;
  333. retrieveQuerysetDetails(registry, type, value, queries, aliases);
  334. Owned<IEspWUQuerySetDetail> detail = createWUQuerySetDetail();
  335. detail->setQuerySetName(registry->queryProp("@id"));
  336. detail->setQueries(queries);
  337. detail->setAliases(aliases);
  338. details.append(*detail.getClear());
  339. }
  340. void retrieveQuerysetDetails(IArrayOf<IEspWUQuerySetDetail> &details, const char *queryset, const char *type, const char *value)
  341. {
  342. if (!queryset || !*queryset)
  343. return;
  344. Owned<IPropertyTree> registry = getQueryRegistry(queryset, true);
  345. if (!registry)
  346. return;
  347. retrieveQuerysetDetails(details, registry, type, value);
  348. }
  349. void retrieveQuerysetDetailsByCluster(IArrayOf<IEspWUQuerySetDetail> &details, const char *cluster, const char *queryset, const char *type, const char *value)
  350. {
  351. Owned<IConstWUClusterInfo> info = getTargetClusterInfo(cluster);
  352. if (!info)
  353. throw MakeStringException(ECLWATCH_CANNOT_RESOLVE_CLUSTER_NAME, "Cluster %s not found", cluster);
  354. SCMStringBuffer clusterQueryset;
  355. info->getQuerySetName(clusterQueryset);
  356. if (!clusterQueryset.length())
  357. throw MakeStringException(ECLWATCH_QUERYSET_NOT_FOUND, "No QuerySets found for cluster %s", cluster);
  358. if (notEmpty(queryset) && !strieq(clusterQueryset.str(), queryset))
  359. throw MakeStringException(ECLWATCH_QUERYSET_NOT_ON_CLUSTER, "Cluster %s not configured to load QuerySet %s", cluster, queryset);
  360. retrieveQuerysetDetails(details, clusterQueryset.str(), type, value);
  361. }
  362. void retrieveAllQuerysetDetails(IArrayOf<IEspWUQuerySetDetail> &details, const char *type, const char *value)
  363. {
  364. Owned<IPropertyTree> root = getQueryRegistryRoot();
  365. if (!root)
  366. throw MakeStringException(ECLWATCH_QUERYSET_NOT_FOUND, "QuerySet Registry not found");
  367. Owned<IPropertyTreeIterator> querysets = root->getElements("QuerySet");
  368. if (!root)
  369. throw MakeStringException(ECLWATCH_QUERYSET_NOT_FOUND, "QuerySet Registry not found");
  370. ForEach(*querysets)
  371. retrieveQuerysetDetails(details, &querysets->query(), type, value);
  372. }
  373. bool CWsWorkunitsEx::onWUQuerysetDetails(IEspContext &context, IEspWUQuerySetDetailsRequest & req, IEspWUQuerySetDetailsResponse & resp)
  374. {
  375. resp.setQuerySetName(req.getQuerySetName());
  376. Owned<IPropertyTree> registry = getQueryRegistry(req.getQuerySetName(), true);
  377. if (!registry)
  378. return false;
  379. IArrayOf<IEspQuerySetQuery> respQueries;
  380. IArrayOf<IEspQuerySetAlias> respAliases;
  381. retrieveQuerysetDetails(registry, req.getFilterTypeAsString(), req.getFilter(), respQueries, respAliases);
  382. resp.setQuerysetQueries(respQueries);
  383. resp.setQuerysetAliases(respAliases);
  384. return true;
  385. }
  386. bool CWsWorkunitsEx::onWUMultiQuerysetDetails(IEspContext &context, IEspWUMultiQuerySetDetailsRequest & req, IEspWUMultiQuerySetDetailsResponse & resp)
  387. {
  388. IArrayOf<IEspWUQuerySetDetail> respDetails;
  389. if (notEmpty(req.getClusterName()))
  390. retrieveQuerysetDetailsByCluster(respDetails, req.getClusterName(), req.getQuerySetName(), req.getFilterTypeAsString(), req.getFilter());
  391. else if (notEmpty(req.getQuerySetName()))
  392. retrieveQuerysetDetails(respDetails, req.getQuerySetName(), req.getFilterTypeAsString(), req.getFilter());
  393. else
  394. retrieveAllQuerysetDetails(respDetails, req.getFilterTypeAsString(), req.getFilter());
  395. resp.setQuerysets(respDetails);
  396. return true;
  397. }
  398. bool CWsWorkunitsEx::onWUQuerysetQueryAction(IEspContext &context, IEspWUQuerySetQueryActionRequest & req, IEspWUQuerySetQueryActionResponse & resp)
  399. {
  400. resp.setQuerySetName(req.getQuerySetName());
  401. resp.setAction(req.getAction());
  402. if (isEmpty(req.getQuerySetName()))
  403. throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Queryset name required");
  404. Owned<IPropertyTree> queryset = getQueryRegistry(req.getQuerySetName(), true);
  405. if (!queryset)
  406. throw MakeStringException(ECLWATCH_QUERYSET_NOT_FOUND, "Queryset %s not found", req.getQuerySetName());
  407. IArrayOf<IEspQuerySetQueryActionResult> results;
  408. ForEachItemIn(i, req.getQueries())
  409. {
  410. IConstQuerySetQueryActionItem& item=req.getQueries().item(i);
  411. Owned<IEspQuerySetQueryActionResult> result = createQuerySetQueryActionResult();
  412. try
  413. {
  414. VStringBuffer xpath("Query[@id='%s']", item.getQueryId());
  415. IPropertyTree *query = queryset->queryPropTree(xpath.str());
  416. if (!query)
  417. throw MakeStringException(ECLWATCH_QUERYID_NOT_FOUND, "Query %s/%s not found.", req.getQuerySetName(), item.getQueryId());
  418. switch (req.getAction())
  419. {
  420. case CQuerySetQueryActionTypes_ToggleSuspend:
  421. setQuerySuspendedState(queryset, item.getQueryId(), !item.getClientState().getSuspended());
  422. break;
  423. case CQuerySetQueryActionTypes_Suspend:
  424. setQuerySuspendedState(queryset, item.getQueryId(), true);
  425. break;
  426. case CQuerySetQueryActionTypes_Unsuspend:
  427. setQuerySuspendedState(queryset, item.getQueryId(), false);
  428. break;
  429. case CQuerySetQueryActionTypes_Activate:
  430. setQueryAlias(queryset, query->queryProp("@name"), item.getQueryId());
  431. break;
  432. case CQuerySetQueryActionTypes_Delete:
  433. removeAliasesFromNamedQuery(queryset, item.getQueryId());
  434. removeNamedQuery(queryset, item.getQueryId());
  435. break;
  436. case CQuerySetQueryActionTypes_RemoveAllAliases:
  437. removeAliasesFromNamedQuery(queryset, item.getQueryId());
  438. break;
  439. }
  440. result->setSuccess(true);
  441. query = queryset->queryPropTree(xpath.str()); // refresh
  442. if (query)
  443. result->setSuspended(query->getPropBool("@suspended"));
  444. }
  445. catch(IException *e)
  446. {
  447. StringBuffer msg;
  448. result->setMessage(e->errorMessage(msg).str());
  449. result->setCode(e->errorCode());
  450. result->setSuccess(false);
  451. }
  452. results.append(*result.getClear());
  453. }
  454. resp.setResults(results);
  455. return true;
  456. }
  457. bool CWsWorkunitsEx::onWUQuerysetAliasAction(IEspContext &context, IEspWUQuerySetAliasActionRequest &req, IEspWUQuerySetAliasActionResponse &resp)
  458. {
  459. resp.setQuerySetName(req.getQuerySetName());
  460. resp.setAction(req.getAction());
  461. if (isEmpty(req.getQuerySetName()))
  462. throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Queryset name required");
  463. Owned<IPropertyTree> queryset = getQueryRegistry(req.getQuerySetName(), true);
  464. if (!queryset)
  465. throw MakeStringException(ECLWATCH_QUERYSET_NOT_FOUND, "Queryset %s not found", req.getQuerySetName());
  466. IArrayOf<IEspQuerySetAliasActionResult> results;
  467. ForEachItemIn(i, req.getAliases())
  468. {
  469. IConstQuerySetAliasActionItem& item=req.getAliases().item(i);
  470. Owned<IEspQuerySetAliasActionResult> result = createQuerySetAliasActionResult();
  471. try
  472. {
  473. VStringBuffer xpath("Alias[@name='%s']", item.getName());
  474. IPropertyTree *alias = queryset->queryPropTree(xpath.str());
  475. if (!alias)
  476. throw MakeStringException(ECLWATCH_ALIAS_NOT_FOUND, "Alias %s/%s not found.", req.getQuerySetName(), item.getName());
  477. switch (req.getAction())
  478. {
  479. case CQuerySetAliasActionTypes_Deactivate:
  480. removeQuerySetAlias(req.getQuerySetName(), item.getName());
  481. break;
  482. }
  483. result->setSuccess(true);
  484. }
  485. catch(IException *e)
  486. {
  487. StringBuffer msg;
  488. result->setMessage(e->errorMessage(msg).str());
  489. result->setCode(e->errorCode());
  490. result->setSuccess(false);
  491. }
  492. results.append(*result.getClear());
  493. }
  494. resp.setResults(results);
  495. return true;
  496. }