ws_workunitsService.hpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. #ifndef _ESPWIZ_ws_workunits_HPP__
  14. #define _ESPWIZ_ws_workunits_HPP__
  15. #include "ws_workunits_esp.ipp"
  16. #include "workunit.hpp"
  17. #include "ws_workunitsHelpers.hpp"
  18. #include "dasds.hpp"
  19. #ifdef _USE_ZLIB
  20. #include "zcrypt.hpp"
  21. #endif
  22. #define UFO_RELOAD_TARGETS_CHANGED_PMID 0x01
  23. #define UFO_RELOAD_MAPPED_QUERIES 0x02
  24. #define UFO_REMOVE_QUERIES_NOT_IN_QUERYSET 0x04
  25. class QueryFilesInUse : public CInterface, implements ISDSSubscription
  26. {
  27. mutable CriticalSection crit;
  28. MapStringTo<IUserDescriptor *> roxieUserMap;
  29. IArrayOf<IUserDescriptor> roxieUsers;
  30. Owned<IPropertyTree> tree;
  31. SubscriptionId qsChange;
  32. SubscriptionId pmChange;
  33. SubscriptionId psChange;
  34. bool aborting;
  35. public:
  36. IMPLEMENT_IINTERFACE;
  37. QueryFilesInUse() : aborting(false), qsChange(0), pmChange(0), psChange(0)
  38. {
  39. tree.setown(createPTree("QueryFilesInUse"));
  40. updateUsers();
  41. }
  42. void updateUsers()
  43. {
  44. Owned<IStringIterator> clusters = getTargetClusters("RoxieCluster", NULL);
  45. ForEach(*clusters)
  46. {
  47. SCMStringBuffer target;
  48. clusters->str(target);
  49. Owned<IConstWUClusterInfo> info = getTargetClusterInfo(target.str());
  50. Owned<IUserDescriptor> user = createUserDescriptor();
  51. user->set(info->getLdapUser(), info->getLdapPassword());
  52. roxieUserMap.setValue(target.str(), user);
  53. roxieUsers.append(*user.getClear());
  54. }
  55. }
  56. const char *getPackageMap(const char *target)
  57. {
  58. VStringBuffer xpath("%s/@pmid", target);
  59. return tree->queryProp(xpath);
  60. }
  61. void loadTarget(IPropertyTree *tree, const char *target, unsigned flags);
  62. void loadTargets(IPropertyTree *tree, unsigned flags);
  63. void reload(unsigned flags)
  64. {
  65. Owned<IPropertyTree> t = createPTreeFromIPT(tree);
  66. loadTargets(t, flags);
  67. CriticalBlock b(crit);
  68. tree.setown(t.getClear());
  69. }
  70. virtual void notify(SubscriptionId subid, const char *xpath, SDSNotifyFlags flags, unsigned valueLen, const void *valueData)
  71. {
  72. Linked<QueryFilesInUse> me = this; // Ensure that I am not released by the notify call (which would then access freed memory to release the critsec)
  73. if (subid == qsChange)
  74. reload(UFO_REMOVE_QUERIES_NOT_IN_QUERYSET);
  75. else if (subid == pmChange)
  76. reload(UFO_RELOAD_MAPPED_QUERIES);
  77. else if (subid == psChange)
  78. reload(UFO_RELOAD_TARGETS_CHANGED_PMID);
  79. }
  80. virtual void subscribe()
  81. {
  82. CriticalBlock b(crit);
  83. try
  84. {
  85. qsChange = querySDS().subscribe("QuerySets", *this, true);
  86. pmChange = querySDS().subscribe("PackageMaps", *this, true);
  87. psChange = querySDS().subscribe("PackageSets", *this, true);
  88. }
  89. catch (IException *E)
  90. {
  91. //TBD failure to subscribe implies dali is down...
  92. E->Release();
  93. }
  94. }
  95. virtual void unsubscribe()
  96. {
  97. CriticalBlock b(crit);
  98. try
  99. {
  100. if (qsChange)
  101. querySDS().unsubscribe(qsChange);
  102. if (pmChange)
  103. querySDS().unsubscribe(pmChange);
  104. if (psChange)
  105. querySDS().unsubscribe(psChange);
  106. }
  107. catch (IException *E)
  108. {
  109. E->Release();
  110. }
  111. qsChange = 0;
  112. pmChange = 0;
  113. psChange = 0;
  114. }
  115. void abort()
  116. {
  117. aborting=true;
  118. CriticalBlock b(crit);
  119. }
  120. IPropertyTreeIterator *findQueriesUsingFile(const char *target, const char *lfn);
  121. StringBuffer &toStr(StringBuffer &s)
  122. {
  123. CriticalBlock b(crit);
  124. return toXML(tree, s);
  125. }
  126. };
  127. class QueryFilesInUseUpdateThread : public Thread
  128. {
  129. QueryFilesInUse &filesInUse;
  130. public:
  131. QueryFilesInUseUpdateThread(QueryFilesInUse &_filesInUse) : filesInUse(_filesInUse) {}
  132. virtual int run()
  133. {
  134. filesInUse.reload(0);
  135. return 0;
  136. }
  137. virtual void start()
  138. {
  139. Thread::start();
  140. }
  141. };
  142. class CWsWorkunitsEx : public CWsWorkunits
  143. {
  144. public:
  145. IMPLEMENT_IINTERFACE;
  146. CWsWorkunitsEx(){port=8010;}
  147. virtual ~CWsWorkunitsEx()
  148. {
  149. filesInUse.unsubscribe();
  150. filesInUse.abort();
  151. };
  152. virtual void init(IPropertyTree *cfg, const char *process, const char *service);
  153. virtual void setContainer(IEspContainer * container)
  154. {
  155. CWsWorkunits::setContainer(container);
  156. m_sched.setContainer(container);
  157. }
  158. void refreshValidClusters();
  159. bool isValidCluster(const char *cluster);
  160. void deploySharedObject(IEspContext &context, IEspWUDeployWorkunitRequest & req, IEspWUDeployWorkunitResponse & resp, const char *dir, const char *xml=NULL);
  161. void deploySharedObject(IEspContext &context, StringBuffer &wuid, const char *filename, const char *cluster, const char *name, const MemoryBuffer &obj, const char *dir, const char *xml=NULL);
  162. unsigned getGraphIdsByQueryId(const char *target, const char *queryId, StringArray& graphIds);
  163. bool getQueryFiles(const char* query, const char* target, StringArray& logicalFiles, IArrayOf<IEspQuerySuperFile> *superFiles);
  164. void getGraphsByQueryId(const char *target, const char *queryId, const char *graphName, const char *subGraphId, IArrayOf<IEspECLGraphEx>& ECLGraphs);
  165. bool onWUQuery(IEspContext &context, IEspWUQueryRequest &req, IEspWUQueryResponse &resp);
  166. bool onWUPublishWorkunit(IEspContext &context, IEspWUPublishWorkunitRequest & req, IEspWUPublishWorkunitResponse & resp);
  167. bool onWUQuerysets(IEspContext &context, IEspWUQuerysetsRequest & req, IEspWUQuerysetsResponse & resp);
  168. bool onWUQuerysetDetails(IEspContext &context, IEspWUQuerySetDetailsRequest & req, IEspWUQuerySetDetailsResponse & resp);
  169. bool onWUMultiQuerysetDetails(IEspContext &context, IEspWUMultiQuerySetDetailsRequest &req, IEspWUMultiQuerySetDetailsResponse &resp);
  170. bool onWUQuerysetQueryAction(IEspContext &context, IEspWUQuerySetQueryActionRequest & req, IEspWUQuerySetQueryActionResponse & resp);
  171. bool onWUQuerysetAliasAction(IEspContext &context, IEspWUQuerySetAliasActionRequest &req, IEspWUQuerySetAliasActionResponse &resp);
  172. bool onWUQueryConfig(IEspContext &context, IEspWUQueryConfigRequest &req, IEspWUQueryConfigResponse &resp);
  173. bool onWUQuerysetCopyQuery(IEspContext &context, IEspWUQuerySetCopyQueryRequest &req, IEspWUQuerySetCopyQueryResponse &resp);
  174. bool onWUCopyLogicalFiles(IEspContext &context, IEspWUCopyLogicalFilesRequest &req, IEspWUCopyLogicalFilesResponse &resp);
  175. bool onWUQueryDetails(IEspContext &context, IEspWUQueryDetailsRequest & req, IEspWUQueryDetailsResponse & resp);
  176. bool onWUListQueries(IEspContext &context, IEspWUListQueriesRequest &req, IEspWUListQueriesResponse &resp);
  177. bool onWUListQueriesUsingFile(IEspContext &context, IEspWUListQueriesUsingFileRequest &req, IEspWUListQueriesUsingFileResponse &resp);
  178. bool onWUInfo(IEspContext &context, IEspWUInfoRequest &req, IEspWUInfoResponse &resp);
  179. bool onWUInfoDetails(IEspContext &context, IEspWUInfoRequest &req, IEspWUInfoResponse &resp);
  180. bool onWUFile(IEspContext &context,IEspWULogFileRequest &req, IEspWULogFileResponse &resp);
  181. bool onWUResult(IEspContext &context,IEspWUResultRequest &req, IEspWUResultResponse &resp);
  182. bool onWUResultView(IEspContext &context, IEspWUResultViewRequest &req, IEspWUResultViewResponse &resp);
  183. bool onWUResultSummary(IEspContext &context, IEspWUResultSummaryRequest &req, IEspWUResultSummaryResponse &resp);
  184. bool onWUResultBin(IEspContext &context, IEspWUResultBinRequest &req, IEspWUResultBinResponse &resp);
  185. bool onWUGraphInfo(IEspContext &context,IEspWUGraphInfoRequest &req, IEspWUGraphInfoResponse &resp);
  186. bool onWUGVCGraphInfo(IEspContext &context,IEspWUGVCGraphInfoRequest &req, IEspWUGVCGraphInfoResponse &resp);
  187. bool onWUProcessGraph(IEspContext &context,IEspWUProcessGraphRequest &req, IEspWUProcessGraphResponse &resp);
  188. bool onGVCAjaxGraph(IEspContext &context, IEspGVCAjaxGraphRequest &req, IEspGVCAjaxGraphResponse &resp);
  189. bool onWUAction(IEspContext &context, IEspWUActionRequest &req, IEspWUActionResponse &resp);
  190. bool onWUShowScheduled(IEspContext &context, IEspWUShowScheduledRequest &req, IEspWUShowScheduledResponse &resp);
  191. bool onWUUpdate(IEspContext &context, IEspWUUpdateRequest &req, IEspWUUpdateResponse &resp);
  192. bool onWUDelete(IEspContext &context, IEspWUDeleteRequest &req, IEspWUDeleteResponse &resp);
  193. bool onWUProtect(IEspContext &context, IEspWUProtectRequest &req, IEspWUProtectResponse &resp);
  194. bool onWUAbort(IEspContext &context, IEspWUAbortRequest &req, IEspWUAbortResponse &resp);
  195. bool onWUSchedule(IEspContext &context, IEspWUScheduleRequest &req, IEspWUScheduleResponse &resp);
  196. bool onWUSubmit(IEspContext &context, IEspWUSubmitRequest &req, IEspWUSubmitResponse &resp);
  197. bool onWURun(IEspContext &context, IEspWURunRequest &req, IEspWURunResponse &resp);
  198. bool onWUCreate(IEspContext &context, IEspWUCreateRequest &req, IEspWUCreateResponse &resp);
  199. bool onWUCreateAndUpdate(IEspContext &context, IEspWUUpdateRequest &req, IEspWUUpdateResponse &resp);
  200. bool onWUResubmit(IEspContext &context, IEspWUResubmitRequest &req, IEspWUResubmitResponse &resp);
  201. bool onWUPushEvent(IEspContext &context, IEspWUPushEventRequest &req, IEspWUPushEventResponse &resp);
  202. bool onWUExport(IEspContext &context, IEspWUExportRequest &req, IEspWUExportResponse &resp);
  203. bool onWUWaitCompiled(IEspContext &context, IEspWUWaitRequest &req, IEspWUWaitResponse &resp);
  204. bool onWUWaitComplete(IEspContext &context, IEspWUWaitRequest &req, IEspWUWaitResponse &resp);
  205. bool onWUSyntaxCheckECL(IEspContext &context, IEspWUSyntaxCheckRequest &req, IEspWUSyntaxCheckResponse &resp);
  206. bool onWUCompileECL(IEspContext &context, IEspWUCompileECLRequest &req, IEspWUCompileECLResponse &resp);
  207. bool onWUJobList(IEspContext &context, IEspWUJobListRequest &req, IEspWUJobListResponse &resp);
  208. bool onWUQueryGetGraph(IEspContext& context, IEspWUQueryGetGraphRequest& req, IEspWUQueryGetGraphResponse& resp);
  209. bool onWUGetGraph(IEspContext& context, IEspWUGetGraphRequest& req, IEspWUGetGraphResponse& resp);
  210. bool onWUGraphTiming(IEspContext& context, IEspWUGraphTimingRequest& req, IEspWUGraphTimingResponse& resp);
  211. bool onWUGetDependancyTrees(IEspContext& context, IEspWUGetDependancyTreesRequest& req, IEspWUGetDependancyTreesResponse& resp);
  212. bool onWUListLocalFileRequired(IEspContext& context, IEspWUListLocalFileRequiredRequest& req, IEspWUListLocalFileRequiredResponse& resp);
  213. bool onWUAddLocalFileToWorkunit(IEspContext& context, IEspWUAddLocalFileToWorkunitRequest& req, IEspWUAddLocalFileToWorkunitResponse& resp);
  214. bool onWUClusterJobQueueXLS(IEspContext &context, IEspWUClusterJobQueueXLSRequest &req, IEspWUClusterJobQueueXLSResponse &resp);
  215. bool onWUClusterJobQueueLOG(IEspContext &context,IEspWUClusterJobQueueLOGRequest &req, IEspWUClusterJobQueueLOGResponse &resp);
  216. bool onWUClusterJobXLS(IEspContext &context, IEspWUClusterJobXLSRequest &req, IEspWUClusterJobXLSResponse &resp);
  217. bool onWUClusterJobSummaryXLS(IEspContext &context, IEspWUClusterJobSummaryXLSRequest &req, IEspWUClusterJobSummaryXLSResponse &resp);
  218. bool onWUCDebug(IEspContext &context, IEspWUDebugRequest &req, IEspWUDebugResponse &resp);
  219. bool onWUDeployWorkunit(IEspContext &context, IEspWUDeployWorkunitRequest & req, IEspWUDeployWorkunitResponse & resp);
  220. void setPort(unsigned short _port){port=_port;}
  221. bool isQuerySuspended(const char* query, IConstWUClusterInfo *clusterInfo, unsigned wait, StringBuffer& errorMessage);
  222. bool onWUCreateZAPInfo(IEspContext &context, IEspWUCreateZAPInfoRequest &req, IEspWUCreateZAPInfoResponse &resp);
  223. bool onWUGetZAPInfo(IEspContext &context, IEspWUGetZAPInfoRequest &req, IEspWUGetZAPInfoResponse &resp);
  224. private:
  225. #ifdef _USE_ZLIB
  226. void addProcessLogfile(IZZIPor* zipper, Owned<IConstWorkUnit> &cwu, WsWuInfo &winfo, const char * process, PointerArray &mbArr);
  227. #endif
  228. unsigned awusCacheMinutes;
  229. StringBuffer queryDirectory;
  230. StringAttr daliServers;
  231. Owned<DataCache> dataCache;
  232. Owned<ArchivedWuCache> archivedWuCache;
  233. StringAttr sashaServerIp;
  234. unsigned short sashaServerPort;
  235. BoolHash validClusters;
  236. CriticalSection crit;
  237. WUSchedule m_sched;
  238. unsigned short port;
  239. Owned<IPropertyTree> directories;
  240. public:
  241. QueryFilesInUse filesInUse;
  242. };
  243. class CWsWorkunitsSoapBindingEx : public CWsWorkunitsSoapBinding
  244. {
  245. public:
  246. CWsWorkunitsSoapBindingEx(IPropertyTree *cfg, const char *name, const char *process, http_soap_log_level llevel) : CWsWorkunitsSoapBinding(cfg, name, process, llevel)
  247. {
  248. wswService = NULL;
  249. VStringBuffer xpath("Software/EspProcess[@name=\"%s\"]/EspBinding[@name=\"%s\"]/BatchWatch", process, name);
  250. batchWatchFeaturesOnly = cfg->getPropBool(xpath.str(), false);
  251. }
  252. virtual void getNavigationData(IEspContext &context, IPropertyTree & data)
  253. {
  254. if (!batchWatchFeaturesOnly)
  255. {
  256. IPropertyTree *folder = ensureNavFolder(data, "ECL", "Run Ecl code and review Ecl workunits", NULL, false, 2);
  257. ensureNavLink(*folder, "Search Workunits", "/WsWorkunits/WUQuery?form_", "Search Workunits", NULL, NULL, 1);
  258. ensureNavLink(*folder, "Browse Workunits", "/WsWorkunits/WUQuery", "Browse Workunits", NULL, NULL, 2);
  259. ensureNavLink(*folder, "ECL Playground", "/esp/files/stub.htm?Widget=ECLPlaygroundWidget", "ECL Editor, Executor, Graph and Result Viewer", NULL, NULL, 4);
  260. IPropertyTree *folderQueryset = ensureNavFolder(data, "Queries", NULL, NULL, false, 3);
  261. ensureNavLink(*folderQueryset, "Browse", "/WsWorkunits/WUQuerySets", "Browse Published Queries");
  262. IPropertyTree *folderTP = CEspBinding::ensureNavFolder(data, "Tech Preview", "Technical Preview");
  263. IPropertyTree *eclWatchTP = CEspBinding::ensureNavLink(*folderTP, "ECL Watch", "/esp/files/stub.htm?Widget=HPCCPlatformWidget", "ECL Watch", NULL, NULL, 1);
  264. eclWatchTP->setProp("@target", "_blank");
  265. }
  266. }
  267. int onGetForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method);
  268. int onGet(CHttpRequest* request, CHttpResponse* response);
  269. virtual void addService(const char * name, const char * host, unsigned short port, IEspService & service)
  270. {
  271. wswService = dynamic_cast<CWsWorkunitsEx*>(&service);
  272. if (wswService)
  273. wswService->setPort(port);
  274. CWsWorkunitsSoapBinding::addService(name, host, port, service);
  275. }
  276. private:
  277. bool batchWatchFeaturesOnly;
  278. CWsWorkunitsEx *wswService;
  279. };
  280. #endif