ws_smcService.cpp 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617
  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. #pragma warning (disable : 4786)
  14. #include "build-config.h"
  15. #ifdef _USE_OPENLDAP
  16. #include "ldapsecurity.ipp"
  17. #endif
  18. #include "ws_smcService.hpp"
  19. #include "wshelpers.hpp"
  20. #include "dalienv.hpp"
  21. #include "dasds.hpp"
  22. #include "WUWrapper.hpp"
  23. #include "dfuwu.hpp"
  24. #include "exception_util.hpp"
  25. #include "roxiecontrol.hpp"
  26. #include "workunit.hpp"
  27. #define STATUS_SERVER_THOR "ThorMaster"
  28. #define STATUS_SERVER_HTHOR "HThorServer"
  29. #define STATUS_SERVER_ROXIE "RoxieServer"
  30. #define STATUS_SERVER_DFUSERVER "DFUserver"
  31. #define STATUS_SERVER_ECLSERVER "ECLserver"
  32. #define STATUS_SERVER_ECLCCSERVER "ECLCCserver"
  33. #define STATUS_SERVER_ECLAGENT "ECLagent"
  34. #define CLUSTER_TYPE_THOR "Thor"
  35. #define CLUSTER_TYPE_HTHOR "HThor"
  36. #define CLUSTER_TYPE_ROXIE "Roxie"
  37. static const char* FEATURE_URL = "SmcAccess";
  38. const char* THORQUEUE_FEATURE = "ThorQueueAccess";
  39. static const char* ROXIE_CONTROL_URL = "RoxieControlAccess";
  40. static const char* OWN_WU_ACCESS = "OwnWorkunitsAccess";
  41. static const char* OTHERS_WU_ACCESS = "OthersWorkunitsAccess";
  42. static const char* SMC_ACCESS_DENIED = "Access Denied";
  43. static const char* QUEUE_ACCESS_DENIED = "Failed to access the queue functions. Permission denied.";
  44. const char* PERMISSIONS_FILENAME = "espsmc_permissions.xml";
  45. const unsigned DEFAULTACTIVITYINFOCACHETIMEOUTSECOND = 10;
  46. void AccessSuccess(IEspContext& context, char const * msg,...) __attribute__((format(printf, 2, 3)));
  47. void AccessSuccess(IEspContext& context, char const * msg,...)
  48. {
  49. StringBuffer buf;
  50. buf.appendf("User %s: ",context.queryUserId());
  51. va_list args;
  52. va_start(args, msg);
  53. buf.valist_appendf(msg, args);
  54. va_end(args);
  55. AUDIT(AUDIT_TYPE_ACCESS_SUCCESS,buf.str());
  56. }
  57. void AccessFailure(IEspContext& context, char const * msg,...) __attribute__((format(printf, 2, 3)));
  58. void AccessFailure(IEspContext& context, char const * msg,...)
  59. {
  60. StringBuffer buf;
  61. buf.appendf("User %s: ",context.queryUserId());
  62. va_list args;
  63. va_start(args, msg);
  64. buf.valist_appendf(msg, args);
  65. va_end(args);
  66. AUDIT(AUDIT_TYPE_ACCESS_FAILURE,buf.str());
  67. }
  68. struct QueueLock
  69. {
  70. QueueLock(IJobQueue* q): queue(q) { queue->lock(); }
  71. ~QueueLock()
  72. {
  73. queue->unlock();
  74. }
  75. Linked<IJobQueue> queue;
  76. };
  77. static int sortTargetClustersByNameDescending(IInterface * const *L, IInterface * const *R)
  78. {
  79. IEspTargetCluster *left = (IEspTargetCluster *) *L;
  80. IEspTargetCluster *right = (IEspTargetCluster *) *R;
  81. return strcmp(right->getClusterName(), left->getClusterName());
  82. }
  83. static int sortTargetClustersByNameAscending(IInterface * const *L, IInterface * const *R)
  84. {
  85. IEspTargetCluster *left = (IEspTargetCluster *) *L;
  86. IEspTargetCluster *right = (IEspTargetCluster *) *R;
  87. return strcmp(left->getClusterName(), right->getClusterName());
  88. }
  89. static int sortTargetClustersBySizeDescending(IInterface * const *L, IInterface * const *R)
  90. {
  91. IEspTargetCluster *left = (IEspTargetCluster *) *L;
  92. IEspTargetCluster *right = (IEspTargetCluster *) *R;
  93. return right->getClusterSize() - left->getClusterSize();
  94. }
  95. static int sortTargetClustersBySizeAscending(IInterface * const *L, IInterface * const *R)
  96. {
  97. IEspTargetCluster *left = (IEspTargetCluster *) *L;
  98. IEspTargetCluster *right = (IEspTargetCluster *) *R;
  99. return left->getClusterSize() - right->getClusterSize();
  100. }
  101. void CWsSMCEx::init(IPropertyTree *cfg, const char *process, const char *service)
  102. {
  103. if (!daliClientActive())
  104. {
  105. ERRLOG("No Dali Connection Active.");
  106. throw MakeStringException(-1, "No Dali Connection Active. Please Specify a Dali to connect to in you configuration file");
  107. }
  108. m_BannerAction = 0;
  109. m_EnableChatURL = false;
  110. m_BannerSize = "4";
  111. m_BannerColor = "red";
  112. m_BannerScroll = "2";
  113. StringBuffer xpath;
  114. xpath.appendf("Software/EspProcess[@name='%s']/@portalurl", process);
  115. const char* portalURL = cfg->queryProp(xpath.str());
  116. if (portalURL && *portalURL)
  117. m_PortalURL.append(portalURL);
  118. xpath.setf("Software/EspProcess[@name=\"%s\"]/EspService[@name=\"%s\"]/ActivityInfoCacheSeconds", process, service);
  119. activityInfoCacheSeconds = cfg->getPropInt(xpath.str(), DEFAULTACTIVITYINFOCACHETIMEOUTSECOND);
  120. xpath.setf("Software/EspProcess[@name=\"%s\"]/EspService[@name=\"%s\"]/LogDaliConnection", process, service);
  121. if (cfg->getPropBool(xpath.str()))
  122. querySDS().setConfigOpt("Client/@LogConnection", "true");
  123. }
  124. struct CActiveWorkunitWrapper: public CActiveWorkunit
  125. {
  126. CActiveWorkunitWrapper(IEspContext &context, const char* wuid,const char* location = NULL,unsigned index=0): CActiveWorkunit("","")
  127. {
  128. CWUWrapper wu(wuid, context);
  129. setActiveWorkunit(wu, wuid, location, index, context.getClientVersion(), false);
  130. }
  131. CActiveWorkunitWrapper(const char* wuid, const char* location = NULL, unsigned index=0): CActiveWorkunit("","")
  132. {
  133. CWUWrapper wu(wuid);
  134. setActiveWorkunit(wu, wuid, location, index, 0.0, true);
  135. }
  136. CActiveWorkunitWrapper(const char* wuid,const char* owner, const char* jobname, const char* state, const char* priority): CActiveWorkunit("","")
  137. {
  138. setWuid(wuid);
  139. setState(state);
  140. setOwner(owner);
  141. setJobname(jobname);
  142. setPriority(priority);
  143. }
  144. void setActiveWorkunit(CWUWrapper& wu, const char* wuid, const char* location, unsigned index, double version, bool notCheckVersion)
  145. {
  146. SCMStringBuffer stateEx;
  147. setWuid(wuid);
  148. const char *state = wu->queryStateDesc();
  149. setStateID(wu->getState());
  150. if (wu->getState() == WUStateBlocked)
  151. {
  152. wu->getStateEx(stateEx);
  153. if (notCheckVersion || (version > 1.00))
  154. setExtra(stateEx.str());
  155. }
  156. buildAndSetState(state, stateEx.str(), location, index);
  157. if ((notCheckVersion || (version > 1.09)) && (wu->getState() == WUStateFailed))
  158. setWarning("The job will ultimately not complete. Please check ECLAgent.");
  159. setOwner(wu->queryUser());
  160. setJobname(wu->queryJobName());
  161. setPriorityStr(wu->getPriority());
  162. if ((notCheckVersion || (version > 1.08)) && wu->isPausing())
  163. {
  164. setIsPausing(true);
  165. }
  166. if (notCheckVersion || (version > 1.14))
  167. {
  168. setClusterName(wu->queryClusterName());
  169. }
  170. }
  171. void buildAndSetState(const char* state, const char* stateEx, const char* location, unsigned index)
  172. {
  173. if (!state || !*state)
  174. return;
  175. StringBuffer stateStr;
  176. if(index && location && *location)
  177. stateStr.setf("queued(%d) [%s on %s]", index, state, location);
  178. else if(index)
  179. stateStr.setf("queued(%d) [%s]", index, state);
  180. else if(location && *location)
  181. stateStr.setf("%s [%s]", state, location);
  182. else
  183. stateStr.set(state);
  184. if (stateEx && *stateEx)
  185. stateStr.appendf(" %s", stateEx);
  186. setState(stateStr.str());
  187. }
  188. void setPriorityStr(unsigned priorityType)
  189. {
  190. switch(priorityType)
  191. {
  192. case PriorityClassHigh: setPriority("high"); break;
  193. default:
  194. case PriorityClassNormal: setPriority("normal"); break;
  195. case PriorityClassLow: setPriority("low"); break;
  196. }
  197. return;
  198. }
  199. };
  200. bool CActivityInfo::isCachedActivityInfoValid(unsigned timeOutSeconds)
  201. {
  202. CDateTime timeNow;
  203. timeNow.setNow();
  204. return timeNow.getSimple() <= timeCached.getSimple() + timeOutSeconds;;
  205. }
  206. void CActivityInfo::createActivityInfo(IEspContext& context)
  207. {
  208. Owned<IEnvironmentFactory> factory = getEnvironmentFactory(true);
  209. Owned<IConstEnvironment> env = factory->openEnvironment();
  210. CConstWUClusterInfoArray clusters;
  211. Owned<IPropertyTree> envRoot= &env->getPTree();
  212. getEnvironmentClusterInfo(envRoot, clusters);
  213. try
  214. {
  215. jobQueueSnapshot.setown(createJQSnapshot());
  216. }
  217. catch(IException* e)
  218. {
  219. EXCLOG(e, "CActivityInfo::createActivityInfo");
  220. e->Release();
  221. }
  222. Owned<IRemoteConnection> connStatusServers = querySDS().connect("/Status/Servers",myProcessSession(),RTM_LOCK_READ,30000);
  223. if (!connStatusServers)
  224. throw MakeStringException(ECLWATCH_CANNOT_GET_STATUS_INFO, "Failed to get status server information.");
  225. IPropertyTree* serverStatusRoot = connStatusServers->queryRoot();
  226. readTargetClusterInfo(clusters, serverStatusRoot);
  227. readActiveWUsAndQueuedWUs(context, envRoot, serverStatusRoot);
  228. timeCached.setNow();
  229. }
  230. void CActivityInfo::readTargetClusterInfo(CConstWUClusterInfoArray& clusters, IPropertyTree* serverStatusRoot)
  231. {
  232. ForEachItemIn(c, clusters)
  233. {
  234. IConstWUClusterInfo &cluster = clusters.item(c);
  235. Owned<CWsSMCTargetCluster> targetCluster = new CWsSMCTargetCluster();
  236. readTargetClusterInfo(cluster, serverStatusRoot, targetCluster);
  237. if (cluster.getPlatform() == ThorLCRCluster)
  238. thorTargetClusters.append(*targetCluster.getClear());
  239. else if (cluster.getPlatform() == RoxieCluster)
  240. roxieTargetClusters.append(*targetCluster.getClear());
  241. else
  242. hthorTargetClusters.append(*targetCluster.getClear());
  243. }
  244. }
  245. void CActivityInfo::readTargetClusterInfo(IConstWUClusterInfo& cluster, IPropertyTree* serverStatusRoot, CWsSMCTargetCluster* targetCluster)
  246. {
  247. SCMStringBuffer clusterName;
  248. cluster.getName(clusterName);
  249. targetCluster->clusterName.set(clusterName.str());
  250. targetCluster->clusterType = cluster.getPlatform();
  251. targetCluster->clusterSize = cluster.getSize();
  252. cluster.getServerQueue(targetCluster->serverQueue.queueName);
  253. cluster.getAgentQueue(targetCluster->agentQueue.queueName);
  254. StringBuffer statusServerName;
  255. CWsSMCQueue* smcQueue = NULL;
  256. if (targetCluster->clusterType == ThorLCRCluster)
  257. {
  258. statusServerName.set(getStatusServerTypeName(WsSMCSSTThorLCRCluster));
  259. smcQueue = &targetCluster->clusterQueue;
  260. cluster.getThorQueue(smcQueue->queueName);
  261. }
  262. else if (targetCluster->clusterType == RoxieCluster)
  263. {
  264. statusServerName.set(getStatusServerTypeName(WsSMCSSTRoxieCluster));
  265. smcQueue = &targetCluster->agentQueue;
  266. }
  267. else
  268. {
  269. statusServerName.set(getStatusServerTypeName(WsSMCSSTHThorCluster));
  270. smcQueue = &targetCluster->agentQueue;
  271. }
  272. targetCluster->statusServerName.set(statusServerName.str());
  273. targetCluster->queueName.set(smcQueue->queueName.str());
  274. bool validQueue = readJobQueue(smcQueue->queueName.str(), targetCluster->queuedWUIDs, smcQueue->queueState, smcQueue->queueStateDetails);
  275. if (!validQueue)
  276. smcQueue->notFoundInJobQueues = true;
  277. if (validQueue && smcQueue->queueState.length())
  278. targetCluster->queueStatus.set(smcQueue->queueState.str());
  279. if (serverStatusRoot)
  280. {
  281. smcQueue->foundQueueInStatusServer = findQueueInStatusServer(serverStatusRoot, statusServerName.str(), targetCluster->queueName.get());
  282. if (!smcQueue->foundQueueInStatusServer)
  283. targetCluster->clusterStatusDetails.appendf("Cluster %s not listening for workunits; ", clusterName.str());
  284. }
  285. targetCluster->serverQueue.notFoundInJobQueues = !readJobQueue(targetCluster->serverQueue.queueName.str(), targetCluster->wuidsOnServerQueue, targetCluster->serverQueue.queueState, targetCluster->serverQueue.queueStateDetails);
  286. }
  287. bool CActivityInfo::readJobQueue(const char* queueName, StringArray& wuids, StringBuffer& state, StringBuffer& stateDetails)
  288. {
  289. if (!queueName || !*queueName)
  290. {
  291. state.set("Unknown");
  292. stateDetails.set("Empty queue name");
  293. return false;
  294. }
  295. if (!jobQueueSnapshot)
  296. {
  297. state.set("Unknown");
  298. stateDetails.set("jobQueueSnapshot not found");
  299. WARNLOG("CActivityInfo::readJobQueue: jobQueueSnapshot not found.");
  300. return false;
  301. }
  302. Owned<IJobQueueConst> jobQueue;
  303. try
  304. {
  305. jobQueue.setown(jobQueueSnapshot->getJobQueue(queueName));
  306. if (!jobQueue)
  307. {
  308. WARNLOG("CActivityInfo::readJobQueue: failed to get info for job queue %s", queueName);
  309. return false;
  310. }
  311. }
  312. catch(IException* e)
  313. {
  314. state.set("Unknown");
  315. e->errorMessage(stateDetails);
  316. e->Release();
  317. return false;
  318. }
  319. CJobQueueContents queuedJobs;
  320. jobQueue->copyItemsAndState(queuedJobs, state, stateDetails);
  321. Owned<IJobQueueIterator> iter = queuedJobs.getIterator();
  322. ForEach(*iter)
  323. {
  324. const char* wuid = iter->query().queryWUID();
  325. if (wuid && *wuid)
  326. wuids.append(wuid);
  327. }
  328. return true;
  329. }
  330. const char *CActivityInfo::getStatusServerTypeName(WsSMCStatusServerType type)
  331. {
  332. return (type < WsSMCSSTterm) ? WsSMCStatusServerTypeNames[type] : NULL;
  333. }
  334. bool CActivityInfo::findQueueInStatusServer(IPropertyTree* serverStatusRoot, const char* serverName, const char* queueName)
  335. {
  336. VStringBuffer path("Server[@name=\"%s\"]", serverName);
  337. Owned<IPropertyTreeIterator> it(serverStatusRoot->getElements(path.str()));
  338. ForEach(*it)
  339. {
  340. IPropertyTree& serverStatusNode = it->query();
  341. const char* queue = serverStatusNode.queryProp("@queue");
  342. if (!queue || !*queue)
  343. continue;
  344. StringArray qlist;
  345. qlist.appendListUniq(queue, ",");
  346. ForEachItemIn(q, qlist)
  347. {
  348. if (strieq(qlist.item(q), queueName))
  349. return true;
  350. }
  351. }
  352. return false;
  353. }
  354. void CActivityInfo::readActiveWUsAndQueuedWUs(IEspContext& context, IPropertyTree* envRoot, IPropertyTree* serverStatusRoot)
  355. {
  356. readRunningWUsOnStatusServer(context, serverStatusRoot, WsSMCSSTThorLCRCluster);
  357. readWUsInTargetClusterJobQueues(context, thorTargetClusters);
  358. readRunningWUsOnStatusServer(context, serverStatusRoot, WsSMCSSTRoxieCluster);
  359. readWUsInTargetClusterJobQueues(context, roxieTargetClusters);
  360. readRunningWUsOnStatusServer(context, serverStatusRoot, WsSMCSSTHThorCluster);
  361. readWUsInTargetClusterJobQueues(context, hthorTargetClusters);
  362. readRunningWUsOnStatusServer(context, serverStatusRoot, WsSMCSSTECLagent);
  363. readRunningWUsAndJobQueueforOtherStatusServers(context, serverStatusRoot);
  364. //TODO: add queued WUs for ECLCCServer/ECLServer here. Right now, they are under target clusters.
  365. getDFUServersAndWUs(context, envRoot, serverStatusRoot);
  366. getDFURecoveryJobs();
  367. }
  368. void CActivityInfo::readRunningWUsOnStatusServer(IEspContext& context, IPropertyTree* serverStatusRoot, WsSMCStatusServerType statusServerType)
  369. {
  370. const char* serverName = getStatusServerTypeName(statusServerType);
  371. if (!serverName || !*serverName)
  372. return;
  373. bool isECLAgent = (statusServerType == WsSMCSSTECLagent);
  374. VStringBuffer path("Server[@name=\"%s\"]", serverName);
  375. Owned<IPropertyTreeIterator> itrStatusServer(serverStatusRoot->getElements(path.str()));
  376. ForEach(*itrStatusServer)
  377. {
  378. IPropertyTree& serverStatusNode = itrStatusServer->query();
  379. StringBuffer serverInstance;
  380. if ((statusServerType == WsSMCSSTThorLCRCluster) || (statusServerType == WsSMCSSTRoxieCluster))
  381. serverStatusNode.getProp("@cluster", serverInstance);
  382. else
  383. serverInstance.appendf("%s on %s", serverName, serverStatusNode.queryProp("@node"));
  384. Owned<IPropertyTreeIterator> wuids(serverStatusNode.getElements("WorkUnit"));
  385. ForEach(*wuids)
  386. {
  387. const char* wuid=wuids->query().queryProp(NULL);
  388. if (!wuid || !*wuid || checkSetUniqueECLWUID(wuid))
  389. continue;
  390. CWsSMCTargetCluster* targetCluster;
  391. if (statusServerType == WsSMCSSTRoxieCluster)
  392. targetCluster = findWUClusterInfo(wuid, isECLAgent, roxieTargetClusters, thorTargetClusters, hthorTargetClusters);
  393. else if (statusServerType == WsSMCSSTHThorCluster)
  394. targetCluster = findWUClusterInfo(wuid, isECLAgent, hthorTargetClusters, thorTargetClusters, roxieTargetClusters);
  395. else
  396. targetCluster = findWUClusterInfo(wuid, isECLAgent, thorTargetClusters, roxieTargetClusters, hthorTargetClusters);
  397. if (!targetCluster)
  398. continue;
  399. const char* targetClusterName = targetCluster->clusterName.get();
  400. CWsSMCQueue* jobQueue;
  401. if (statusServerType == WsSMCSSTThorLCRCluster)
  402. jobQueue = &targetCluster->clusterQueue;
  403. else
  404. jobQueue = &targetCluster->agentQueue;
  405. Owned<IEspActiveWorkunit> wu;
  406. if (!isECLAgent)
  407. {
  408. const char *cluster = serverStatusNode.queryProp("Cluster");
  409. StringBuffer queueName;
  410. if (cluster) // backward compat check.
  411. getClusterThorQueueName(queueName, cluster);
  412. else
  413. queueName.append(targetCluster->queueName.get());
  414. createActiveWorkUnit(context, wu, wuid, !strieq(targetClusterName, serverInstance.str()) ? serverInstance.str() : NULL, 0, serverName,
  415. queueName, serverInstance.str(), targetClusterName, false);
  416. if (wu->getStateID() == WUStateRunning) //'aborting' may be another possible status
  417. {
  418. int sgDuration = serverStatusNode.getPropInt("@sg_duration", -1);
  419. int subgraph = serverStatusNode.getPropInt("@subgraph", -1);
  420. if (subgraph > -1 && sgDuration > -1)
  421. {
  422. const char* graph = serverStatusNode.queryProp("@graph");
  423. VStringBuffer durationStr("%d min", sgDuration);
  424. VStringBuffer subgraphStr("%d", subgraph);
  425. wu->setGraphName(graph);
  426. wu->setDuration(durationStr.str());
  427. wu->setGID(subgraphStr.str());
  428. }
  429. if (serverStatusNode.getPropInt("@memoryBlocked ", 0) != 0)
  430. wu->setMemoryBlocked(1);
  431. }
  432. }
  433. else
  434. {
  435. createActiveWorkUnit(context, wu, wuid, serverInstance.str(), 0, serverName, serverName, serverInstance.str(), targetClusterName, false);
  436. if (targetCluster->clusterType == ThorLCRCluster)
  437. wu->setClusterType(CLUSTER_TYPE_THOR);
  438. else if (targetCluster->clusterType == RoxieCluster)
  439. wu->setClusterType(CLUSTER_TYPE_ROXIE);
  440. else
  441. wu->setClusterType(CLUSTER_TYPE_HTHOR);
  442. wu->setClusterQueueName(targetCluster->queueName.get());
  443. if (wu->getStateID() != WUStateRunning)
  444. {
  445. const char *extra = wu->getExtra();
  446. if (wu->getStateID() != WUStateBlocked || !extra || !*extra) // Blocked on persist treated as running here
  447. {
  448. aws.append(*wu.getClear());
  449. jobQueue->countQueuedJobs++;
  450. continue;
  451. }
  452. }
  453. //Should this be set only if wu->getStateID() == WUStateRunning?
  454. if (serverStatusNode.getPropInt("@memoryBlocked ", 0) != 0)
  455. wu->setMemoryBlocked(1);
  456. }
  457. aws.append(*wu.getClear());
  458. jobQueue->countRunningJobs++;
  459. }
  460. }
  461. }
  462. bool CActivityInfo::checkSetUniqueECLWUID(const char* wuid)
  463. {
  464. bool* idFound = uniqueECLWUIDs.getValue(wuid);
  465. if (!idFound || !*idFound)
  466. uniqueECLWUIDs.setValue(wuid, true);
  467. return idFound && *idFound;
  468. }
  469. CWsSMCTargetCluster* CActivityInfo::findWUClusterInfo(const char* wuid, bool isOnECLAgent, CIArrayOf<CWsSMCTargetCluster>& targetClusters,
  470. CIArrayOf<CWsSMCTargetCluster>& targetClusters1, CIArrayOf<CWsSMCTargetCluster>& targetClusters2)
  471. {
  472. StringAttr clusterName;
  473. try
  474. {
  475. Owned<IWorkUnitFactory> factory = getWorkUnitFactory();
  476. Owned<IConstWorkUnit> cw = factory->openWorkUnit(wuid);
  477. if (!cw)
  478. return NULL;
  479. clusterName.set(cw->queryClusterName());
  480. if (!clusterName.length())
  481. return NULL;
  482. }
  483. catch (IException *e)
  484. {//Exception may be thrown when the openWorkUnit() is called inside the CWUWrapper
  485. StringBuffer msg;
  486. WARNLOG("Failed to open workunit %s: %s", wuid, e->errorMessage(msg).str());
  487. e->Release();
  488. return NULL;
  489. }
  490. const char* cluster = clusterName.str();
  491. CWsSMCTargetCluster* targetCluster = findTargetCluster(cluster, targetClusters);
  492. if (targetCluster || !isOnECLAgent)
  493. return targetCluster;
  494. targetCluster = findTargetCluster(cluster, targetClusters1);
  495. if (targetCluster)
  496. return targetCluster;
  497. return findTargetCluster(cluster, targetClusters2);
  498. }
  499. CWsSMCTargetCluster* CActivityInfo::findTargetCluster(const char* clusterName, CIArrayOf<CWsSMCTargetCluster>& targetClusters)
  500. {
  501. ForEachItemIn(i, targetClusters)
  502. {
  503. CWsSMCTargetCluster& targetCluster = targetClusters.item(i);
  504. if (strieq(targetCluster.clusterName.get(), clusterName))
  505. return &targetCluster;
  506. }
  507. return NULL;
  508. }
  509. void CActivityInfo::createActiveWorkUnit(IEspContext& context, Owned<IEspActiveWorkunit>& ownedWU, const char* wuid, const char* location,
  510. unsigned index, const char* serverName, const char* queueName, const char* instanceName, const char* targetClusterName, bool useContext)
  511. {
  512. try
  513. {
  514. if (useContext)
  515. ownedWU.setown(new CActiveWorkunitWrapper(context, wuid, location, index));
  516. else
  517. ownedWU.setown(new CActiveWorkunitWrapper(wuid, location, index));
  518. }
  519. catch (IException *e)
  520. { //if the wu cannot be opened for some reason, the openWorkUnit() inside the CActiveWorkunitWrapper() may throw an exception.
  521. //We do not want the exception stops this process of retrieving/showing all active WUs. And that WU should still be displayed
  522. //with the exception.
  523. StringBuffer msg;
  524. ownedWU.setown(new CActiveWorkunitWrapper(wuid, "", "", e->errorMessage(msg).str(), "normal"));
  525. ownedWU->setStateID(WUStateUnknown);
  526. e->Release();
  527. }
  528. ownedWU->setServer(serverName);
  529. ownedWU->setQueueName(queueName);
  530. if (instanceName && *instanceName)
  531. ownedWU->setInstance(instanceName); // JCSMORE In thor case at least, if queued it is unknown which instance it will run on..
  532. if (targetClusterName && *targetClusterName)
  533. ownedWU->setTargetClusterName(targetClusterName);
  534. }
  535. void CActivityInfo::readWUsInTargetClusterJobQueues(IEspContext& context, CIArrayOf<CWsSMCTargetCluster>& targetClusters)
  536. {
  537. ForEachItemIn(i, targetClusters)
  538. {
  539. CWsSMCTargetCluster& targetCluster = targetClusters.item(i);
  540. if (targetCluster.clusterType == ThorLCRCluster)
  541. readWUsInTargetClusterJobQueue(context, targetCluster, targetCluster.clusterQueue, targetCluster.clusterName.get());
  542. if (targetCluster.agentQueue.queueName.length())
  543. readWUsInTargetClusterJobQueue(context, targetCluster, targetCluster.agentQueue, targetCluster.agentQueue.queueName.str());
  544. if (targetCluster.serverQueue.queueName.length()) //TODO: queued WUs for ECLCCServer/ECLServer should not be here.
  545. readWUsInTargetClusterJobQueue(context, targetCluster, targetCluster.serverQueue, targetCluster.serverQueue.queueName.str());
  546. }
  547. }
  548. void CActivityInfo::readWUsInTargetClusterJobQueue(IEspContext& context, CWsSMCTargetCluster& targetCluster, CWsSMCQueue& jobQueue, const char* queueName)
  549. {
  550. ForEachItemIn(i, targetCluster.queuedWUIDs)
  551. {
  552. const char* wuid = targetCluster.queuedWUIDs.item(i);
  553. if (!wuid || !*wuid || checkSetUniqueECLWUID(wuid))
  554. continue;
  555. Owned<IEspActiveWorkunit> wu;
  556. createActiveWorkUnit(context, wu, wuid, jobQueue.queueName.str(), ++jobQueue.countQueuedJobs, targetCluster.statusServerName.str(),
  557. queueName, NULL, targetCluster.clusterName.get(), false);
  558. aws.append(*wu.getClear());
  559. }
  560. }
  561. void CActivityInfo::addQueuedServerQueueJob(IEspContext& context, const char* serverName, const char* queueName, const char* instanceName, CIArrayOf<CWsSMCTargetCluster>& targetClusters)
  562. {
  563. ForEachItemIn(i, targetClusters)
  564. {
  565. CWsSMCTargetCluster& targetCluster = targetClusters.item(i);
  566. if (!targetCluster.wuidsOnServerQueue.length() || !strieq(queueName, targetCluster.serverQueue.queueName.str()))
  567. continue;
  568. ForEachItemIn(i1, targetCluster.wuidsOnServerQueue)
  569. {
  570. const char* wuid = targetCluster.wuidsOnServerQueue.item(i1);
  571. if (!wuid || !*wuid) //Multiple servers may monitor one queue. The WU may be shown under the multiple servers.
  572. continue;
  573. Owned<IEspActiveWorkunit> wu;
  574. createActiveWorkUnit(context, wu, wuid, NULL, 0, serverName, queueName, instanceName, NULL, false);
  575. aws.append(*wu.getClear());
  576. }
  577. }
  578. }
  579. void CActivityInfo::readRunningWUsAndJobQueueforOtherStatusServers(IEspContext& context, IPropertyTree* serverStatusRoot)
  580. {
  581. BoolHash uniqueServers;
  582. Owned<IPropertyTreeIterator> it(serverStatusRoot->getElements("Server"));
  583. ForEach(*it)
  584. {
  585. IPropertyTree& serverNode = it->query();
  586. const char* serverName = serverNode.queryProp("@name");
  587. const char* node = serverNode.queryProp("@node");
  588. const char* queueName = serverNode.queryProp("@queue");
  589. unsigned port = serverNode.getPropInt("@mpport", 0);
  590. if (!serverName || !*serverName || !node || !*node || strieq(serverName, STATUS_SERVER_DFUSERVER)
  591. || strieq(serverName, getStatusServerTypeName(WsSMCSSTThorLCRCluster)) || strieq(serverName, getStatusServerTypeName(WsSMCSSTRoxieCluster))
  592. || strieq(serverName, getStatusServerTypeName(WsSMCSSTHThorCluster)) || strieq(serverName, getStatusServerTypeName(WsSMCSSTECLagent)))
  593. continue; //target clusters, ECLAgent, DFUServer already handled separately
  594. VStringBuffer instanceName("%s_on_%s:%d", serverName, node, port); //where to get a better instance name?
  595. Owned<IPropertyTreeIterator> wuids(serverNode.getElements("WorkUnit"));
  596. ForEach(*wuids)
  597. {
  598. const char* wuid=wuids->query().queryProp(NULL);
  599. if (!wuid || !*wuid || checkSetUniqueECLWUID(wuid))
  600. continue;
  601. Owned<IEspActiveWorkunit> wu;
  602. createActiveWorkUnit(context, wu, wuid, NULL, 0, serverName, queueName, instanceName.str(), NULL, false);
  603. aws.append(*wu.getClear());
  604. }
  605. bool* found = uniqueServers.getValue(instanceName);
  606. if (!found || !*found)
  607. {
  608. uniqueServers.setValue(instanceName, true);
  609. getServerJobQueue(context, queueName, instanceName, serverName, node, port);
  610. //Now, we found a new server. we need to add queued jobs from the queues the server is monitoring.
  611. StringArray qList;
  612. qList.appendListUniq(queueName, ",");
  613. ForEachItemIn(q, qList)
  614. {
  615. addQueuedServerQueueJob(context, serverName, qList.item(q), instanceName.str(), thorTargetClusters);
  616. addQueuedServerQueueJob(context, serverName, qList.item(q), instanceName.str(), roxieTargetClusters);
  617. addQueuedServerQueueJob(context, serverName, qList.item(q), instanceName.str(), hthorTargetClusters);
  618. }
  619. }
  620. }
  621. return;
  622. }
  623. void CActivityInfo::getDFUServersAndWUs(IEspContext& context, IPropertyTree* envRoot, IPropertyTree* serverStatusRoot)
  624. {
  625. if (!envRoot)
  626. return;
  627. VStringBuffer path("Software/%s", eqDfu);
  628. Owned<IPropertyTreeIterator> services = envRoot->getElements(path);
  629. ForEach(*services)
  630. {
  631. IPropertyTree &serviceTree = services->query();
  632. const char *qname = serviceTree.queryProp("@queue");
  633. if (!qname || !*qname)
  634. continue;
  635. StringArray queues;
  636. queues.appendListUniq(qname, ",");
  637. const char *serverName = serviceTree.queryProp("@name");
  638. ForEachItemIn(q, queues)
  639. {
  640. StringArray wuidList;
  641. const char *queueName = queues.item(q);
  642. readDFUWUDetails(queueName, serverName, wuidList, readDFUWUIDs(serverStatusRoot, queueName, wuidList));
  643. getServerJobQueue(context, queueName, serverName, STATUS_SERVER_DFUSERVER, NULL, 0);
  644. }
  645. }
  646. }
  647. unsigned CActivityInfo::readDFUWUIDs(IPropertyTree* serverStatusRoot, const char* queueName, StringArray& wuidList)
  648. {
  649. if (!queueName || !*queueName)
  650. {
  651. WARNLOG("CActivityInfo::readDFUWUIDs: queue name not specified");
  652. return 0;
  653. }
  654. unsigned runningWUCount = 0;
  655. VStringBuffer path("Server[@name=\"DFUserver\"]/Queue[@name=\"%s\"]",queueName);
  656. Owned<IPropertyTreeIterator> iter = serverStatusRoot->getElements(path.str());
  657. ForEach(*iter)
  658. {
  659. Owned<IPropertyTreeIterator> iterj = iter->query().getElements("Job");
  660. ForEach(*iterj)
  661. {
  662. const char *wuid = iterj->query().queryProp("@wuid");
  663. if (wuid && *wuid && (*wuid!='!')) // filter escapes -- see queuedJobs() in dfuwu.cpp
  664. {
  665. wuidList.append(wuid);
  666. runningWUCount++;
  667. }
  668. }
  669. }
  670. if (!jobQueueSnapshot)
  671. return runningWUCount;
  672. //Read queued jobs
  673. Owned<IJobQueueConst> jobQueue = jobQueueSnapshot->getJobQueue(queueName);
  674. if (!jobQueue)
  675. {
  676. WARNLOG("CActivityInfo::readDFUWUIDs: failed to get info for job queue %s.", queueName);
  677. return runningWUCount;
  678. }
  679. CJobQueueContents jobList;
  680. jobQueue->copyItems(jobList);
  681. Owned<IJobQueueIterator> iterq = jobList.getIterator();
  682. ForEach(*iterq)
  683. {
  684. const char* wuid = iterq->query().queryWUID();
  685. if (wuid && *wuid)
  686. wuidList.append(wuid);
  687. }
  688. return runningWUCount;
  689. }
  690. void CActivityInfo::readDFUWUDetails(const char* queueName, const char* serverName, StringArray& wuidList, unsigned runningWUCount)
  691. {
  692. Owned<IDFUWorkUnitFactory> factory = getDFUWorkUnitFactory();
  693. ForEachItemIn(i, wuidList)
  694. {
  695. StringBuffer jname, uname, state, error;
  696. const char *wuid = wuidList.item(i);
  697. if (i<runningWUCount)
  698. state.set("running");
  699. else
  700. state.set("queued");
  701. try
  702. {
  703. Owned<IConstDFUWorkUnit> dfuwu = factory->openWorkUnit(wuid, false);
  704. dfuwu->getUser(uname);
  705. dfuwu->getJobName(jname);
  706. }
  707. catch (IException *e)
  708. {
  709. e->errorMessage(error);
  710. state.appendf(" (%s)", error.str());
  711. e->Release();
  712. }
  713. Owned<IEspActiveWorkunit> wu(new CActiveWorkunitWrapper(wuid, uname.str(), jname.str(), state.str(), "normal"));
  714. wu->setServer(STATUS_SERVER_DFUSERVER);
  715. wu->setInstance(serverName);
  716. wu->setQueueName(queueName);
  717. aws.append(*wu.getClear());
  718. }
  719. }
  720. void CActivityInfo::getDFURecoveryJobs()
  721. {
  722. Owned<IRemoteConnection> connDFURecovery = querySDS().connect("DFU/RECOVERY",myProcessSession(), RTM_LOCK_READ, 30000);
  723. if (!connDFURecovery)
  724. return;
  725. Owned<IPropertyTreeIterator> it(connDFURecovery->queryRoot()->getElements("job"));
  726. ForEach(*it)
  727. {
  728. IPropertyTree &jb=it->query();
  729. if (!jb.getPropBool("Running",false))
  730. continue;
  731. unsigned done = 0, total = 0;
  732. Owned<IPropertyTreeIterator> it = jb.getElements("DFT/progress");
  733. ForEach(*it)
  734. {
  735. IPropertyTree &p=it->query();
  736. if (p.getPropInt("@done",0))
  737. done++;
  738. total++;
  739. }
  740. StringBuffer cmd;
  741. cmd.append(jb.queryProp("@command")).append(" ").append(jb.queryProp("@command_parameters"));
  742. Owned<IEspDFUJob> job = new CDFUJob("","");
  743. job->setTimeStarted(jb.queryProp("@time_started"));
  744. job->setDone(done);
  745. job->setTotal(total);
  746. job->setCommand(cmd.str());
  747. DFURecoveryJobs.append(*job.getClear());
  748. }
  749. }
  750. void CActivityInfo::getServerJobQueue(IEspContext &context, const char* queueName, const char* serverName,
  751. const char* serverType, const char* networkAddress, unsigned port)
  752. {
  753. if (!queueName || !*queueName || !serverName || !*serverName || !serverType || !*serverType)
  754. return;
  755. double version = context.getClientVersion();
  756. Owned<IEspServerJobQueue> jobQueue = createServerJobQueue("", "");
  757. jobQueue->setServerName(serverName);
  758. jobQueue->setServerType(serverType);
  759. if (networkAddress && *networkAddress)
  760. {
  761. jobQueue->setNetworkAddress(networkAddress);
  762. jobQueue->setPort(port);
  763. }
  764. readServerJobQueueStatus(context, queueName, jobQueue);
  765. serverJobQueues.append(*jobQueue.getClear());
  766. }
  767. void CActivityInfo::readServerJobQueueStatus(IEspContext &context, const char* queueName, IEspServerJobQueue* jobQueue)
  768. {
  769. if (!jobQueueSnapshot)
  770. {
  771. WARNLOG("CActivityInfo::readServerJobQueueStatus: jobQueueSnapshot not found.");
  772. return;
  773. }
  774. StringBuffer queueStateDetails;
  775. bool hasStopped = false, hasPaused = false;
  776. StringArray queueNames;
  777. queueNames.appendListUniq(queueName, ",");
  778. IArrayOf<IEspServerJobQueue> jobQueues;
  779. ForEachItemIn(i, queueNames)
  780. readServerJobQueueDetails(context, queueNames.item(i), hasStopped, hasPaused, queueStateDetails, jobQueues);
  781. double version = context.getClientVersion();
  782. if (version < 1.20)
  783. jobQueue->setQueueName(queueName);
  784. else if (version < 1.21)
  785. jobQueue->setQueueNames(queueNames);
  786. else
  787. jobQueue->setQueues(jobQueues);
  788. //The hasStopped, hasPaused, and queueStateDetails should be set inside readServerJobQueueDetails().
  789. if (hasStopped)
  790. jobQueue->setQueueStatus("stopped"); //Some of its job queues is stopped. So, return a warning here.
  791. else if (hasPaused)
  792. jobQueue->setQueueStatus("paused"); //Some of its job queues is paused. So, return a warning here.
  793. else
  794. jobQueue->setQueueStatus("running");
  795. jobQueue->setStatusDetails(queueStateDetails.str());
  796. }
  797. void CActivityInfo::readServerJobQueueDetails(IEspContext &context, const char* queueName, bool& hasStopped,
  798. bool& hasPaused, StringBuffer& queueStateDetails, IArrayOf<IEspServerJobQueue>& jobQueues)
  799. {
  800. double version = context.getClientVersion();
  801. StringBuffer status, details, stateDetailsString;
  802. Owned<IJobQueueConst> queue = jobQueueSnapshot->getJobQueue(queueName);
  803. if (queue)
  804. queue->getState(status, details);
  805. if (status.isEmpty())
  806. {
  807. if (version < 1.21)
  808. {
  809. if (!queue)
  810. queueStateDetails.appendf("%s not found in Status Server list; ", queueName);
  811. else
  812. queueStateDetails.appendf("No status set in Status Server list for %s; ", queueName);
  813. }
  814. else
  815. {
  816. Owned<IEspServerJobQueue> jobQueue = createServerJobQueue();
  817. jobQueue->setQueueName(queueName);
  818. if (!queue)
  819. stateDetailsString.setf("%s not found in Status Server list", queueName);
  820. else
  821. stateDetailsString.setf("No status set in Status Server list for %s", queueName);
  822. queueStateDetails.appendf("%s;", stateDetailsString.str());
  823. jobQueue->setStatusDetails(stateDetailsString.str());
  824. jobQueues.append(*jobQueue.getClear());
  825. }
  826. return;
  827. }
  828. if (version < 1.21)
  829. {
  830. if (strieq(status.str(), "paused"))
  831. hasPaused = true;
  832. else if (strieq(status.str(), "stopped"))
  833. hasStopped = true;
  834. if (details && *details)
  835. queueStateDetails.appendf("%s: queue %s; %s;", queueName, status.str(), details.str());
  836. else
  837. queueStateDetails.appendf("%s: queue %s;", queueName, status.str());
  838. }
  839. else
  840. {
  841. Owned<IEspServerJobQueue> jobQueue = createServerJobQueue();
  842. jobQueue->setQueueName(queueName);
  843. if (strieq(status.str(), "paused"))
  844. {
  845. hasPaused = true;
  846. jobQueue->setQueueStatus("paused");
  847. }
  848. else if (strieq(status.str(), "stopped"))
  849. {
  850. hasStopped = true;
  851. jobQueue->setQueueStatus("stopped");
  852. }
  853. else
  854. {
  855. jobQueue->setQueueStatus("running");
  856. }
  857. if (details && *details)
  858. {
  859. queueStateDetails.appendf("%s: queue %s; %s;", queueName, status.str(), details.str());
  860. stateDetailsString.setf("%s: queue %s; %s;", queueName, status.str(), details.str());
  861. }
  862. else
  863. {
  864. queueStateDetails.appendf("%s: queue %s;", queueName, status.str());
  865. stateDetailsString.setf("%s: queue %s;", queueName, status.str());
  866. }
  867. jobQueue->setStatusDetails(stateDetailsString.str());
  868. jobQueues.append(*jobQueue.getClear());
  869. }
  870. }
  871. bool CWsSMCEx::onIndex(IEspContext &context, IEspSMCIndexRequest &req, IEspSMCIndexResponse &resp)
  872. {
  873. resp.setRedirectUrl("/");
  874. return true;
  875. }
  876. void CWsSMCEx::readBannerAndChatRequest(IEspContext& context, IEspActivityRequest &req, IEspActivityResponse& resp)
  877. {
  878. StringBuffer chatURLStr, bannerStr;
  879. const char* chatURL = req.getChatURL();
  880. const char* banner = req.getBannerContent();
  881. //Filter out invalid chars
  882. if (chatURL && *chatURL)
  883. {
  884. const char* pStr = chatURL;
  885. unsigned len = strlen(chatURL);
  886. for (unsigned i = 0; i < len; i++)
  887. {
  888. if (isprint(*pStr))
  889. chatURLStr.append(*pStr);
  890. pStr++;
  891. }
  892. }
  893. if (banner && *banner)
  894. {
  895. const char* pStr = banner;
  896. unsigned len = strlen(banner);
  897. for (unsigned i = 0; i < len; i++)
  898. {
  899. bannerStr.append(isprint(*pStr) ? *pStr : '.');
  900. pStr++;
  901. }
  902. }
  903. chatURLStr.trim();
  904. bannerStr.trim();
  905. if (!req.getBannerAction_isNull() && req.getBannerAction() && (bannerStr.length() < 1))
  906. throw MakeStringException(ECLWATCH_MISSING_BANNER_CONTENT, "If a Banner is enabled, the Banner content must be specified.");
  907. if (!req.getEnableChatURL_isNull() && req.getEnableChatURL() && (chatURLStr.length() < 1))
  908. throw MakeStringException(ECLWATCH_MISSING_CHAT_URL, "If a Chat is enabled, the Chat URL must be specified.");
  909. //Now, store the strings since they are valid.
  910. m_ChatURL = chatURLStr;
  911. m_Banner = bannerStr;
  912. const char* bannerSize = req.getBannerSize();
  913. if (bannerSize && *bannerSize)
  914. m_BannerSize.set(bannerSize);
  915. const char* bannerColor = req.getBannerColor();
  916. if (bannerColor && *bannerColor)
  917. m_BannerColor.set(bannerColor);
  918. const char* bannerScroll = req.getBannerScroll();
  919. if (bannerScroll && *bannerScroll)
  920. m_BannerScroll.set(bannerScroll);
  921. m_BannerAction = req.getBannerAction();
  922. if(!req.getEnableChatURL_isNull())
  923. m_EnableChatURL = req.getEnableChatURL();
  924. }
  925. void CWsSMCEx::setBannerAndChatData(double version, IEspActivityResponse& resp)
  926. {
  927. resp.setShowBanner(m_BannerAction);
  928. resp.setShowChatURL(m_EnableChatURL);
  929. resp.setBannerContent(m_Banner.str());
  930. resp.setBannerSize(m_BannerSize.str());
  931. resp.setBannerColor(m_BannerColor.str());
  932. resp.setChatURL(m_ChatURL.str());
  933. if (version >= 1.08)
  934. resp.setBannerScroll(m_BannerScroll.str());
  935. }
  936. void CWsSMCEx::sortTargetClusters(IArrayOf<IEspTargetCluster>& clusters, const char* sortBy, bool descending)
  937. {
  938. if (!sortBy || !*sortBy || strieq(sortBy, "name"))
  939. clusters.sort(descending ? sortTargetClustersByNameDescending : sortTargetClustersByNameAscending);
  940. else
  941. clusters.sort(descending ? sortTargetClustersBySizeDescending : sortTargetClustersBySizeAscending);
  942. }
  943. void CWsSMCEx::getClusterQueueStatus(const CWsSMCTargetCluster& targetCluster, ClusterStatusType& queueStatusType, StringBuffer& queueStatusDetails)
  944. {
  945. const CWsSMCQueue* jobQueue = &targetCluster.clusterQueue;
  946. if (targetCluster.clusterType != ThorLCRCluster)
  947. jobQueue = &targetCluster.agentQueue;
  948. if (!jobQueue->queueName.length())
  949. return;
  950. bool queuePausedOrStopped = false;
  951. //get queueStatusDetails
  952. if (targetCluster.clusterStatusDetails.length())
  953. queueStatusDetails.set(targetCluster.clusterStatusDetails.str());
  954. if (jobQueue->queueState.length())
  955. {
  956. const char* queueState = jobQueue->queueState.str();
  957. queueStatusDetails.appendf("%s: queue %s; ", jobQueue->queueName.str(), queueState);
  958. if (jobQueue->queueStateDetails.length())
  959. queueStatusDetails.appendf(" %s;", jobQueue->queueStateDetails.str());
  960. if (strieq(queueState,"stopped") || strieq(queueState,"paused"))
  961. queuePausedOrStopped = true;
  962. }
  963. //get queueStatusType
  964. if (!jobQueue->foundQueueInStatusServer)
  965. {
  966. if (queuePausedOrStopped)
  967. queueStatusType = QueuePausedOrStoppedNotFound;
  968. else
  969. queueStatusType = QueueRunningNotFound;
  970. }
  971. else if (jobQueue->notFoundInJobQueues)
  972. queueStatusType = QueueNotFound;
  973. else if (!queuePausedOrStopped)
  974. queueStatusType = RunningNormal;
  975. else if (jobQueue->countRunningJobs > 0)
  976. queueStatusType = QueuePausedOrStoppedWithJobs;
  977. else
  978. queueStatusType = QueuePausedOrStoppedWithNoJob;
  979. return;
  980. }
  981. void CWsSMCEx::setClusterStatus(IEspContext& context, const CWsSMCTargetCluster& targetCluster, IEspTargetCluster* returnCluster)
  982. {
  983. ClusterStatusType queueStatusType = RunningNormal;
  984. StringBuffer queueStatusDetails;
  985. getClusterQueueStatus(targetCluster, queueStatusType, queueStatusDetails);
  986. returnCluster->setClusterStatus(queueStatusType);
  987. //Set 'Warning' which may be displayed beside cluster name
  988. if (queueStatusType == QueueRunningNotFound)
  989. returnCluster->setWarning("Cluster not listening for workunits");
  990. else if (queueStatusType == QueuePausedOrStoppedNotFound)
  991. returnCluster->setWarning("Queue paused or stopped - Cluster not listening for workunits");
  992. else if (queueStatusType == QueueNotFound)
  993. returnCluster->setWarning("Queue not found");
  994. else if (queueStatusType != RunningNormal)
  995. returnCluster->setWarning("Queue paused or stopped");
  996. //Set 'StatusDetails' which may be displayed when a mouse is moved over cluster icon
  997. if (queueStatusDetails.length())
  998. returnCluster->setStatusDetails(queueStatusDetails.str());
  999. }
  1000. // This method reads job information from both /Status/Servers and IJobQueue.
  1001. //
  1002. // Each server component (a thor cluster, a dfuserver, or an eclagent) is one 'Server' branch under
  1003. // /Status/Servers. A 'Server' branch has a @queue which indicates the queue name of the server.
  1004. // A 'Server' branch also contains the information about running WUs on that 'Server'. This
  1005. // method reads the information. Those WUs are displays under that server (identified by its queue name)
  1006. // on Activity page.
  1007. //
  1008. // For the WUs list inside /Status/Servers/Server[@name=ECLagent] but not list under other 'Server', the
  1009. // existing code has to find out WUID and @clusterName of the WU. Then, uses @clusterName to find out the
  1010. // queue name in IConstWUClusterInfo. Those WUs list under that server (identified by its queue name) with
  1011. // a note 'on ECLagent'. TBD: the logic here will be simpler if the /Status/Servers/Server is named the
  1012. // instance and/or cluster.
  1013. //
  1014. // In order to get information about queued WUs, this method gets queue names from both IConstWUClusterInfo
  1015. // and other environment functions. Each of those queue names is linked to one IJobQueues. From the
  1016. // IJobQueues, this method reads queued jobs for each server component and list them under the server
  1017. // component (identified by its queue name).
  1018. bool CWsSMCEx::onActivity(IEspContext &context, IEspActivityRequest &req, IEspActivityResponse& resp)
  1019. {
  1020. try
  1021. {
  1022. context.ensureFeatureAccess(FEATURE_URL, SecAccess_Read, ECLWATCH_SMC_ACCESS_DENIED, SMC_ACCESS_DENIED);
  1023. const char* build_ver = getBuildVersion();
  1024. resp.setBuild(build_ver);
  1025. double version = context.getClientVersion();
  1026. bool isSuperUser = true;
  1027. #ifdef _USE_OPENLDAP
  1028. CLdapSecManager* secmgr = dynamic_cast<CLdapSecManager*>(context.querySecManager());
  1029. if(secmgr && !secmgr->isSuperUser(context.queryUser()))
  1030. isSuperUser = false;
  1031. #endif
  1032. if(isSuperUser && req.getFromSubmitBtn())
  1033. readBannerAndChatRequest(context, req, resp);
  1034. if (version >= 1.12)
  1035. resp.setSuperUser(isSuperUser);
  1036. if (version >= 1.06)
  1037. setBannerAndChatData(version, resp);
  1038. Owned<CActivityInfo> activityInfo = getActivityInfo(context);
  1039. setActivityResponse(context, activityInfo, req, resp);
  1040. }
  1041. catch(IException* e)
  1042. {
  1043. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1044. }
  1045. return true;
  1046. }
  1047. void CWsSMCEx::clearActivityInfoCache()
  1048. {
  1049. CriticalBlock b(getActivityCrit);
  1050. activityInfoCache.clear();
  1051. }
  1052. CActivityInfo* CWsSMCEx::getActivityInfo(IEspContext &context)
  1053. {
  1054. CriticalBlock b(getActivityCrit);
  1055. if (activityInfoCache && activityInfoCache->isCachedActivityInfoValid(activityInfoCacheSeconds))
  1056. return activityInfoCache.getLink();
  1057. DBGLOG("CWsSMCEx::getActivityInfo - rebuild cached information");
  1058. {
  1059. EspTimeSection timer("createActivityInfo");
  1060. activityInfoCache.setown(new CActivityInfo());
  1061. activityInfoCache->createActivityInfo(context);
  1062. }
  1063. return activityInfoCache.getLink();
  1064. }
  1065. void CWsSMCEx::addWUsToResponse(IEspContext &context, const IArrayOf<IEspActiveWorkunit>& aws, IEspActivityResponse& resp)
  1066. {
  1067. const char* user = context.queryUserId();
  1068. IArrayOf<IEspActiveWorkunit> awsReturned;
  1069. ForEachItemIn(i, aws)
  1070. {
  1071. IEspActiveWorkunit& wu = aws.item(i);
  1072. const char* wuid = wu.getWuid();
  1073. if (wuid[0] == 'D')//DFU WU
  1074. {
  1075. awsReturned.append(*LINK(&wu));
  1076. continue;
  1077. }
  1078. try
  1079. {
  1080. //if no access, throw an exception and go to the 'catch' section.
  1081. const char* owner = wu.getOwner();
  1082. context.validateFeatureAccess((!owner || !*owner || (user && streq(user, owner))) ? OWN_WU_ACCESS : OTHERS_WU_ACCESS, SecAccess_Read, true);
  1083. awsReturned.append(*LINK(&wu));
  1084. continue;
  1085. }
  1086. catch (IException *e)
  1087. { //if the wu cannot be opened for some reason, the openWorkUnit() inside the CActiveWorkunitWrapper() may throw an exception.
  1088. //We do not want the exception stops this process of retrieving/showing all active WUs. And that WU should still be displayed
  1089. //with the exception.
  1090. StringBuffer msg;
  1091. Owned<IEspActiveWorkunit> cw = new CActiveWorkunitWrapper(wuid, "", "", e->errorMessage(msg).str(), "normal");
  1092. cw->setStateID(WUStateUnknown);
  1093. cw->setServer(wu.getServer());
  1094. cw->setQueueName(wu.getQueueName());
  1095. const char* instanceName = wu.getInstance();
  1096. const char* targetClusterName = wu.getTargetClusterName();
  1097. if (instanceName && *instanceName)
  1098. cw->setInstance(instanceName); // JCSMORE In thor case at least, if queued it is unknown which instance it will run on..
  1099. if (targetClusterName && *targetClusterName)
  1100. cw->setTargetClusterName(targetClusterName);
  1101. awsReturned.append(*cw.getClear());
  1102. e->Release();
  1103. }
  1104. }
  1105. resp.setRunning(awsReturned);
  1106. return;
  1107. }
  1108. void CWsSMCEx::setActivityResponse(IEspContext &context, CActivityInfo* activityInfo, IEspActivityRequest &req, IEspActivityResponse& resp)
  1109. {
  1110. double version = context.getClientVersion();
  1111. const char* sortBy = req.getSortBy();
  1112. bool descending = req.getDescending();
  1113. if (version >= 1.16)
  1114. {
  1115. IArrayOf<IEspTargetCluster> thorClusters;
  1116. IArrayOf<IEspTargetCluster> hthorClusters;
  1117. IArrayOf<IEspTargetCluster> roxieClusters;
  1118. setESPTargetClusters(context, activityInfo->queryThorTargetClusters(), thorClusters);
  1119. setESPTargetClusters(context, activityInfo->queryRoxieTargetClusters(), roxieClusters);
  1120. setESPTargetClusters(context, activityInfo->queryHThorTargetClusters(), hthorClusters);
  1121. sortTargetClusters(thorClusters, sortBy, descending);
  1122. sortTargetClusters(roxieClusters, sortBy, descending);
  1123. SecAccessFlags access;
  1124. if (context.authorizeFeature(THORQUEUE_FEATURE, access) && access>=SecAccess_Full)
  1125. resp.setAccessRight("Access_Full");
  1126. resp.setSortBy(sortBy);
  1127. resp.setDescending(descending);
  1128. resp.setThorClusterList(thorClusters);
  1129. resp.setRoxieClusterList(roxieClusters);
  1130. resp.setHThorClusterList(hthorClusters);
  1131. resp.setServerJobQueues(activityInfo->queryServerJobQueues());
  1132. }
  1133. else
  1134. {//for backward compatible
  1135. IArrayOf<IEspThorCluster> thorClusters;
  1136. CIArrayOf<CWsSMCTargetCluster>& thorTargetClusters = activityInfo->queryThorTargetClusters();
  1137. ForEachItemIn(i, thorTargetClusters)
  1138. {
  1139. CWsSMCTargetCluster& targetCluster = thorTargetClusters.item(i);
  1140. Owned<IEspThorCluster> respThorCluster = new CThorCluster("", "");
  1141. respThorCluster->setClusterName(targetCluster.clusterName.get());
  1142. respThorCluster->setQueueStatus(targetCluster.queueStatus.get());
  1143. if (version >= 1.03)
  1144. respThorCluster->setQueueName(targetCluster.queueName.get());
  1145. if (version >= 1.11)
  1146. respThorCluster->setClusterSize(targetCluster.clusterSize);
  1147. thorClusters.append(*respThorCluster.getClear());
  1148. }
  1149. resp.setThorClusters(thorClusters);
  1150. if (version > 1.06)
  1151. {
  1152. IArrayOf<IEspRoxieCluster> roxieClusters;
  1153. CIArrayOf<CWsSMCTargetCluster>& roxieTargetClusters = activityInfo->queryRoxieTargetClusters();
  1154. ForEachItemIn(i, roxieTargetClusters)
  1155. {
  1156. CWsSMCTargetCluster& targetCluster = roxieTargetClusters.item(i);
  1157. Owned<IEspRoxieCluster> respRoxieCluster = new CRoxieCluster("", "");
  1158. respRoxieCluster->setClusterName(targetCluster.clusterName.get());
  1159. respRoxieCluster->setQueueStatus(targetCluster.queueStatus.get());
  1160. respRoxieCluster->setQueueName(targetCluster.queueName.get());
  1161. if (version >= 1.11)
  1162. respRoxieCluster->setClusterSize(targetCluster.clusterSize);
  1163. roxieClusters.append(*respRoxieCluster.getClear());
  1164. }
  1165. resp.setRoxieClusters(roxieClusters);
  1166. }
  1167. if (version > 1.10)
  1168. {
  1169. resp.setSortBy(sortBy);
  1170. resp.setDescending(req.getDescending());
  1171. }
  1172. if (version > 1.11)
  1173. {
  1174. IArrayOf<IEspHThorCluster> hThorClusters;
  1175. CIArrayOf<CWsSMCTargetCluster>& hthorTargetClusters = activityInfo->queryHThorTargetClusters();
  1176. ForEachItemIn(i, hthorTargetClusters)
  1177. {
  1178. CWsSMCTargetCluster& targetCluster = hthorTargetClusters.item(i);
  1179. Owned<IEspHThorCluster> respHThorCluster = new CHThorCluster("", "");
  1180. respHThorCluster->setClusterName(targetCluster.clusterName.get());
  1181. respHThorCluster->setQueueStatus(targetCluster.queueStatus.get());
  1182. respHThorCluster->setQueueName(targetCluster.queueName.get());
  1183. respHThorCluster->setClusterSize(targetCluster.clusterSize);
  1184. hThorClusters.append(*respHThorCluster.getClear());
  1185. }
  1186. resp.setHThorClusters(hThorClusters);
  1187. SecAccessFlags access;
  1188. if (context.authorizeFeature(THORQUEUE_FEATURE, access) && access>=SecAccess_Full)
  1189. resp.setAccessRight("Access_Full");
  1190. }
  1191. if (version > 1.03)
  1192. resp.setServerJobQueues(activityInfo->queryServerJobQueues());
  1193. }
  1194. resp.setDFUJobs(activityInfo->queryDFURecoveryJobs());
  1195. addWUsToResponse(context, activityInfo->queryActiveWUs(), resp);
  1196. return;
  1197. }
  1198. void CWsSMCEx::setESPTargetClusters(IEspContext& context, const CIArrayOf<CWsSMCTargetCluster>& targetClusters, IArrayOf<IEspTargetCluster>& respTargetClusters)
  1199. {
  1200. ForEachItemIn(i, targetClusters)
  1201. {
  1202. Owned<IEspTargetCluster> respTargetCluster = new CTargetCluster("", "");
  1203. setESPTargetCluster(context, targetClusters.item(i), respTargetCluster);
  1204. respTargetClusters.append(*respTargetCluster.getClear());
  1205. }
  1206. }
  1207. void CWsSMCEx::addCapabilities(IPropertyTree* pFeatureNode, const char* access,
  1208. IArrayOf<IEspCapability>& capabilities)
  1209. {
  1210. StringBuffer xpath(access);
  1211. xpath.append("/Capability");
  1212. Owned<IPropertyTreeIterator> it = pFeatureNode->getElements(xpath.str());
  1213. ForEach(*it)
  1214. {
  1215. IPropertyTree* pCapabilityNode = &it->query();
  1216. IEspCapability* pCapability = new CCapability("ws_smc");
  1217. pCapability->setName( pCapabilityNode->queryProp("@name") );
  1218. pCapability->setDescription( pCapabilityNode->queryProp("@description") );
  1219. capabilities.append(*pCapability);
  1220. }
  1221. }
  1222. bool CWsSMCEx::onMoveJobDown(IEspContext &context, IEspSMCJobRequest &req, IEspSMCJobResponse &resp)
  1223. {
  1224. try
  1225. {
  1226. context.ensureFeatureAccess(THORQUEUE_FEATURE, SecAccess_Full, ECLWATCH_THOR_QUEUE_ACCESS_DENIED, QUEUE_ACCESS_DENIED);
  1227. {
  1228. Owned<IJobQueue> queue = createJobQueue(req.getQueueName());
  1229. QueueLock lock(queue);
  1230. unsigned index=queue->findRank(req.getWuid());
  1231. if(index<queue->ordinality())
  1232. {
  1233. Owned<IJobQueueItem> item0 = queue->getItem(index);
  1234. Owned<IJobQueueItem> item = queue->getItem(index+1);
  1235. if(item && item0 && (item0->getPriority() == item->getPriority()))
  1236. queue->moveAfter(req.getWuid(),item->queryWUID());
  1237. }
  1238. }
  1239. AccessSuccess(context, "Changed job priority %s",req.getWuid());
  1240. clearActivityInfoCache();
  1241. resp.setRedirectUrl("/WsSMC/");
  1242. }
  1243. catch(IException* e)
  1244. {
  1245. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1246. }
  1247. return true;
  1248. }
  1249. bool CWsSMCEx::onMoveJobUp(IEspContext &context, IEspSMCJobRequest &req, IEspSMCJobResponse &resp)
  1250. {
  1251. try
  1252. {
  1253. context.ensureFeatureAccess(THORQUEUE_FEATURE, SecAccess_Full, ECLWATCH_THOR_QUEUE_ACCESS_DENIED, QUEUE_ACCESS_DENIED);
  1254. {
  1255. Owned<IJobQueue> queue = createJobQueue(req.getQueueName());
  1256. QueueLock lock(queue);
  1257. unsigned index=queue->findRank(req.getWuid());
  1258. if(index>0 && index<queue->ordinality())
  1259. {
  1260. Owned<IJobQueueItem> item0 = queue->getItem(index);
  1261. Owned<IJobQueueItem> item = queue->getItem(index-1);
  1262. if(item && item0 && (item0->getPriority() == item->getPriority()))
  1263. queue->moveBefore(req.getWuid(),item->queryWUID());
  1264. }
  1265. }
  1266. AccessSuccess(context, "Changed job priority %s",req.getWuid());
  1267. clearActivityInfoCache();
  1268. resp.setRedirectUrl("/WsSMC/");
  1269. }
  1270. catch(IException* e)
  1271. {
  1272. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1273. }
  1274. return true;
  1275. }
  1276. bool CWsSMCEx::onMoveJobBack(IEspContext &context, IEspSMCJobRequest &req, IEspSMCJobResponse &resp)
  1277. {
  1278. try
  1279. {
  1280. context.ensureFeatureAccess(THORQUEUE_FEATURE, SecAccess_Full, ECLWATCH_THOR_QUEUE_ACCESS_DENIED, QUEUE_ACCESS_DENIED);
  1281. {
  1282. Owned<IJobQueue> queue = createJobQueue(req.getQueueName());
  1283. QueueLock lock(queue);
  1284. unsigned index=queue->findRank(req.getWuid());
  1285. if(index<queue->ordinality())
  1286. {
  1287. Owned<IJobQueueItem> item = queue->getItem(index);
  1288. int priority0 = item->getPriority();
  1289. unsigned biggestIndoxInSamePriority = index;
  1290. unsigned nextIndex = biggestIndoxInSamePriority + 1;
  1291. while (nextIndex<queue->ordinality())
  1292. {
  1293. item.setown(queue->getItem(nextIndex));
  1294. if (priority0 != item->getPriority())
  1295. {
  1296. break;
  1297. }
  1298. biggestIndoxInSamePriority = nextIndex;
  1299. nextIndex++;
  1300. }
  1301. if (biggestIndoxInSamePriority != index)
  1302. {
  1303. item.setown(queue->getItem(biggestIndoxInSamePriority));
  1304. queue->moveAfter(req.getWuid(), item->queryWUID());
  1305. }
  1306. }
  1307. }
  1308. AccessSuccess(context, "Changed job priority %s",req.getWuid());
  1309. clearActivityInfoCache();
  1310. resp.setRedirectUrl("/WsSMC/");
  1311. }
  1312. catch(IException* e)
  1313. {
  1314. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1315. }
  1316. return true;
  1317. }
  1318. bool CWsSMCEx::onMoveJobFront(IEspContext &context, IEspSMCJobRequest &req, IEspSMCJobResponse &resp)
  1319. {
  1320. try
  1321. {
  1322. context.ensureFeatureAccess(THORQUEUE_FEATURE, SecAccess_Full, ECLWATCH_THOR_QUEUE_ACCESS_DENIED, QUEUE_ACCESS_DENIED);
  1323. {
  1324. Owned<IJobQueue> queue=createJobQueue(req.getQueueName());
  1325. QueueLock lock(queue);
  1326. unsigned index=queue->findRank(req.getWuid());
  1327. if (index>0 && index<queue->ordinality())
  1328. {
  1329. Owned<IJobQueueItem> item = queue->getItem(index);
  1330. int priority0 = item->getPriority();
  1331. unsigned smallestIndoxInSamePriority = index;
  1332. int nextIndex = smallestIndoxInSamePriority - 1;
  1333. while (nextIndex >= 0)
  1334. {
  1335. item.setown(queue->getItem(nextIndex));
  1336. if (priority0 != item->getPriority())
  1337. {
  1338. break;
  1339. }
  1340. smallestIndoxInSamePriority = nextIndex;
  1341. nextIndex--;
  1342. }
  1343. if (smallestIndoxInSamePriority != index)
  1344. {
  1345. item.setown(queue->getItem(smallestIndoxInSamePriority));
  1346. queue->moveBefore(req.getWuid(), item->queryWUID());
  1347. }
  1348. }
  1349. }
  1350. AccessSuccess(context, "Changed job priority %s",req.getWuid());
  1351. clearActivityInfoCache();
  1352. resp.setRedirectUrl("/WsSMC/");
  1353. }
  1354. catch(IException* e)
  1355. {
  1356. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1357. }
  1358. return true;
  1359. }
  1360. bool CWsSMCEx::onRemoveJob(IEspContext &context, IEspSMCJobRequest &req, IEspSMCJobResponse &resp)
  1361. {
  1362. try
  1363. {
  1364. context.ensureFeatureAccess(THORQUEUE_FEATURE, SecAccess_Full, ECLWATCH_THOR_QUEUE_ACCESS_DENIED, QUEUE_ACCESS_DENIED);
  1365. abortWorkUnit(req.getWuid(), context.querySecManager(), context.queryUser());
  1366. {
  1367. Owned<IJobQueue> queue = createJobQueue(req.getQueueName());
  1368. QueueLock lock(queue);
  1369. unsigned index=queue->findRank(req.getWuid());
  1370. if(index<queue->ordinality())
  1371. {
  1372. if(!queue->cancelInitiateConversation(req.getWuid()))
  1373. throw MakeStringException(ECLWATCH_CANNOT_DELETE_WORKUNIT,"Failed to remove the workunit %s",req.getWuid());
  1374. }
  1375. }
  1376. AccessSuccess(context, "Removed job %s",req.getWuid());
  1377. clearActivityInfoCache();
  1378. resp.setRedirectUrl("/WsSMC/");
  1379. }
  1380. catch(IException* e)
  1381. {
  1382. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1383. }
  1384. return true;
  1385. }
  1386. bool CWsSMCEx::onStopQueue(IEspContext &context, IEspSMCQueueRequest &req, IEspSMCQueueResponse &resp)
  1387. {
  1388. try
  1389. {
  1390. context.ensureFeatureAccess(THORQUEUE_FEATURE, SecAccess_Full, ECLWATCH_THOR_QUEUE_ACCESS_DENIED, QUEUE_ACCESS_DENIED);
  1391. {
  1392. Owned<IJobQueue> queue = createJobQueue(req.getQueueName());
  1393. StringBuffer info;
  1394. queue->stop(createQueueActionInfo(context, "stopped", req, info));
  1395. }
  1396. AccessSuccess(context, "Stopped queue %s", req.getCluster());
  1397. clearActivityInfoCache();
  1398. double version = context.getClientVersion();
  1399. if (version >= 1.19)
  1400. getStatusServerInfo(context, req.getServerType(), req.getCluster(), req.getNetworkAddress(), req.getPort(), resp.updateStatusServerInfo());
  1401. resp.setRedirectUrl("/WsSMC/");
  1402. }
  1403. catch(IException* e)
  1404. {
  1405. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1406. }
  1407. return true;
  1408. }
  1409. bool CWsSMCEx::onResumeQueue(IEspContext &context, IEspSMCQueueRequest &req, IEspSMCQueueResponse &resp)
  1410. {
  1411. try
  1412. {
  1413. context.ensureFeatureAccess(THORQUEUE_FEATURE, SecAccess_Full, ECLWATCH_THOR_QUEUE_ACCESS_DENIED, QUEUE_ACCESS_DENIED);
  1414. {
  1415. Owned<IJobQueue> queue = createJobQueue(req.getQueueName());
  1416. StringBuffer info;
  1417. queue->resume(createQueueActionInfo(context, "resumed", req, info));
  1418. }
  1419. AccessSuccess(context, "Resumed queue %s", req.getCluster());
  1420. clearActivityInfoCache();
  1421. double version = context.getClientVersion();
  1422. if (version >= 1.19)
  1423. getStatusServerInfo(context, req.getServerType(), req.getCluster(), req.getNetworkAddress(), req.getPort(), resp.updateStatusServerInfo());
  1424. resp.setRedirectUrl("/WsSMC/");
  1425. }
  1426. catch(IException* e)
  1427. {
  1428. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1429. }
  1430. return true;
  1431. }
  1432. const char* CWsSMCEx::createQueueActionInfo(IEspContext &context, const char* state, IEspSMCQueueRequest &req, StringBuffer& info)
  1433. {
  1434. StringBuffer peer, currentTime;
  1435. context.getPeer(peer);
  1436. const char* userId = context.queryUserId();
  1437. if (!userId || !*userId)
  1438. userId = "Unknown user";
  1439. CDateTime now;
  1440. now.setNow();
  1441. now.getString(currentTime);
  1442. info.appendf("%s by <%s> at <%s> from <%s>", state, userId, currentTime.str(), peer.str());
  1443. const char* comment = req.getComment();
  1444. if (comment && *comment)
  1445. info.append(": ' ").append(comment).append("'");
  1446. return info.str();
  1447. }
  1448. bool CWsSMCEx::onPauseQueue(IEspContext &context, IEspSMCQueueRequest &req, IEspSMCQueueResponse &resp)
  1449. {
  1450. try
  1451. {
  1452. context.ensureFeatureAccess(THORQUEUE_FEATURE, SecAccess_Full, ECLWATCH_THOR_QUEUE_ACCESS_DENIED, QUEUE_ACCESS_DENIED);
  1453. {
  1454. Owned<IJobQueue> queue = createJobQueue(req.getQueueName());
  1455. StringBuffer info;
  1456. queue->pause(createQueueActionInfo(context, "paused", req, info));
  1457. }
  1458. AccessSuccess(context, "Paused queue %s", req.getCluster());
  1459. clearActivityInfoCache();
  1460. double version = context.getClientVersion();
  1461. if (version >= 1.19)
  1462. getStatusServerInfo(context, req.getServerType(), req.getCluster(), req.getNetworkAddress(), req.getPort(), resp.updateStatusServerInfo());
  1463. resp.setRedirectUrl("/WsSMC/");
  1464. }
  1465. catch(IException* e)
  1466. {
  1467. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1468. }
  1469. return true;
  1470. }
  1471. bool CWsSMCEx::onClearQueue(IEspContext &context, IEspSMCQueueRequest &req, IEspSMCQueueResponse &resp)
  1472. {
  1473. try
  1474. {
  1475. context.ensureFeatureAccess(THORQUEUE_FEATURE, SecAccess_Full, ECLWATCH_THOR_QUEUE_ACCESS_DENIED, QUEUE_ACCESS_DENIED);
  1476. {
  1477. Owned<IJobQueue> queue = createJobQueue(req.getQueueName());
  1478. QueueLock lock(queue);
  1479. for(unsigned i=0;i<queue->ordinality();i++)
  1480. {
  1481. Owned<IJobQueueItem> item = queue->getItem(i);
  1482. abortWorkUnit(item->queryWUID(), context.querySecManager(), context.queryUser());
  1483. }
  1484. queue->clear();
  1485. }
  1486. AccessSuccess(context, "Cleared queue %s",req.getCluster());
  1487. clearActivityInfoCache();
  1488. double version = context.getClientVersion();
  1489. if (version >= 1.19)
  1490. getStatusServerInfo(context, req.getServerType(), req.getCluster(), req.getNetworkAddress(), req.getPort(), resp.updateStatusServerInfo());
  1491. resp.setRedirectUrl("/WsSMC/");
  1492. }
  1493. catch(IException* e)
  1494. {
  1495. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1496. }
  1497. return true;
  1498. }
  1499. void CWsSMCEx::setJobPriority(IEspContext &context, IWorkUnitFactory* factory, const char* wuid, const char* queueName, WUPriorityClass& priority)
  1500. {
  1501. if (!wuid || !*wuid)
  1502. throw MakeStringException(ECLWATCH_INVALID_INPUT, "Workunit ID not specified.");
  1503. if (!queueName || !*queueName)
  1504. throw MakeStringException(ECLWATCH_INVALID_INPUT, "queue not specified.");
  1505. Owned<IWorkUnit> lw = factory->updateWorkUnit(wuid, context.querySecManager(), context.queryUser());
  1506. if (!lw)
  1507. throw MakeStringException(ECLWATCH_CANNOT_UPDATE_WORKUNIT, "Cannot update Workunit %s", wuid);
  1508. lw->setPriority(priority);
  1509. // set job priority to queue
  1510. int priorityValue = lw->getPriorityValue();
  1511. {
  1512. CriticalBlock b(crit);
  1513. Owned<IJobQueue> queue = createJobQueue(queueName);
  1514. QueueLock lock(queue);
  1515. queue->changePriority(wuid,priorityValue);
  1516. }
  1517. return;
  1518. }
  1519. bool CWsSMCEx::onSetJobPriority(IEspContext &context, IEspSMCPriorityRequest &req, IEspSMCPriorityResponse &resp)
  1520. {
  1521. try
  1522. {
  1523. context.ensureFeatureAccess(THORQUEUE_FEATURE, SecAccess_Full, ECLWATCH_THOR_QUEUE_ACCESS_DENIED, QUEUE_ACCESS_DENIED);
  1524. WUPriorityClass priority = PriorityClassNormal;
  1525. if(strieq(req.getPriority(),"high"))
  1526. priority = PriorityClassHigh;
  1527. else if(strieq(req.getPriority(),"low"))
  1528. priority = PriorityClassLow;
  1529. {
  1530. Owned<IWorkUnitFactory> factory = getWorkUnitFactory();
  1531. IArrayOf<IConstSMCJob>& jobs = req.getSMCJobs();
  1532. if (!jobs.length())
  1533. setJobPriority(context, factory, req.getWuid(), req.getQueueName(), priority);
  1534. else
  1535. {
  1536. ForEachItemIn(i, jobs)
  1537. {
  1538. IConstSMCJob &item = jobs.item(i);
  1539. const char *wuid = item.getWuid();
  1540. const char *queueName = item.getQueueName();
  1541. if (wuid && *wuid && queueName && *queueName)
  1542. setJobPriority(context, factory, wuid, queueName, priority);
  1543. }
  1544. }
  1545. }
  1546. clearActivityInfoCache();
  1547. resp.setRedirectUrl("/WsSMC/");
  1548. }
  1549. catch(IException* e)
  1550. {
  1551. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1552. }
  1553. return true;
  1554. }
  1555. bool CWsSMCEx::onGetThorQueueAvailability(IEspContext &context, IEspGetThorQueueAvailabilityRequest &req, IEspGetThorQueueAvailabilityResponse& resp)
  1556. {
  1557. try
  1558. {
  1559. context.ensureFeatureAccess(FEATURE_URL, SecAccess_Read, ECLWATCH_THOR_QUEUE_ACCESS_DENIED, QUEUE_ACCESS_DENIED);
  1560. StringArray thorNames, groupNames, targetNames, queueNames;
  1561. getEnvironmentThorClusterNames(thorNames, groupNames, targetNames, queueNames);
  1562. IArrayOf<IEspThorCluster> ThorClusters;
  1563. ForEachItemIn(x, thorNames)
  1564. {
  1565. const char* targetName = targetNames.item(x);
  1566. const char* queueName = queueNames.item(x);
  1567. IEspThorCluster* returnCluster = new CThorCluster("","");
  1568. returnCluster->setClusterName(targetName);
  1569. returnCluster->setQueueName(queueName);
  1570. StringBuffer info;
  1571. Owned<IJobQueue> queue = createJobQueue(queueName);
  1572. if(queue->stopped(info))
  1573. returnCluster->setQueueStatus("stopped");
  1574. else if (queue->paused(info))
  1575. returnCluster->setQueueStatus("paused");
  1576. else
  1577. returnCluster->setQueueStatus("running");
  1578. unsigned enqueued=0;
  1579. unsigned connected=0;
  1580. unsigned waiting=0;
  1581. queue->getStats(connected,waiting,enqueued);
  1582. returnCluster->setQueueAvailable(waiting);
  1583. returnCluster->setJobsRunning(connected - waiting);
  1584. returnCluster->setJobsInQueue(enqueued);
  1585. ThorClusters.append(*returnCluster);
  1586. }
  1587. resp.setThorClusters(ThorClusters);
  1588. }
  1589. catch(IException* e)
  1590. {
  1591. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1592. }
  1593. return true;
  1594. }
  1595. bool CWsSMCEx::onSetBanner(IEspContext &context, IEspSetBannerRequest &req, IEspSetBannerResponse& resp)
  1596. {
  1597. try
  1598. {
  1599. #ifdef _USE_OPENLDAP
  1600. CLdapSecManager* secmgr = dynamic_cast<CLdapSecManager*>(context.querySecManager());
  1601. if(!secmgr || !secmgr->isSuperUser(context.queryUser()))
  1602. {
  1603. context.setAuthStatus(AUTH_STATUS_NOACCESS);
  1604. throw MakeStringException(ECLWATCH_SUPER_USER_ACCESS_DENIED, "access denied, administrators only.");
  1605. }
  1606. #endif
  1607. StringBuffer chatURLStr, bannerStr;
  1608. const char* chatURL = req.getChatURL();
  1609. const char* banner = req.getBannerContent();
  1610. //Only display valid strings
  1611. if (chatURL)
  1612. {
  1613. const char* pStr = chatURL;
  1614. for (unsigned i = 0; i < strlen(chatURL); i++)
  1615. {
  1616. if ((pStr[0] > 31) && (pStr[0] < 127))
  1617. chatURLStr.append(pStr[0]);
  1618. pStr++;
  1619. }
  1620. }
  1621. if (banner)
  1622. {
  1623. const char* pStr = banner;
  1624. for (unsigned i = 0; i < strlen(banner); i++)
  1625. {
  1626. if ((pStr[0] > 31) && (pStr[0] < 127))
  1627. bannerStr.append(pStr[0]);
  1628. pStr++;
  1629. }
  1630. }
  1631. chatURLStr.trim();
  1632. bannerStr.trim();
  1633. if (!req.getBannerAction_isNull() && req.getBannerAction() && (bannerStr.length() < 1))
  1634. {
  1635. throw MakeStringException(ECLWATCH_MISSING_BANNER_CONTENT, "If a Banner is enabled, the Banner content must be specified.");
  1636. }
  1637. if (!req.getEnableChatURL_isNull() && req.getEnableChatURL() && (!req.getChatURL() || !*req.getChatURL()))
  1638. {
  1639. throw MakeStringException(ECLWATCH_MISSING_CHAT_URL, "If a Chat is enabled, the Chat URL must be specified.");
  1640. }
  1641. m_ChatURL = chatURLStr;
  1642. m_Banner = bannerStr;
  1643. const char* bannerSize = req.getBannerSize();
  1644. if (bannerSize && *bannerSize)
  1645. m_BannerSize.clear().append(bannerSize);
  1646. const char* bannerColor = req.getBannerColor();
  1647. if (bannerColor && *bannerColor)
  1648. m_BannerColor.clear().append(bannerColor);
  1649. const char* bannerScroll = req.getBannerScroll();
  1650. if (bannerScroll && *bannerScroll)
  1651. m_BannerScroll.clear().append(bannerScroll);
  1652. m_BannerAction = 0;
  1653. if(!req.getBannerAction_isNull())
  1654. m_BannerAction = req.getBannerAction();
  1655. m_EnableChatURL = 0;
  1656. if(!req.getEnableChatURL_isNull())
  1657. m_EnableChatURL = req.getEnableChatURL();
  1658. resp.setRedirectUrl("/WsSMC/Activity");
  1659. }
  1660. catch(IException* e)
  1661. {
  1662. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1663. }
  1664. return true;
  1665. }
  1666. bool CWsSMCEx::onNotInCommunityEdition(IEspContext &context, IEspNotInCommunityEditionRequest &req, IEspNotInCommunityEditionResponse &resp)
  1667. {
  1668. return true;
  1669. }
  1670. bool CWsSMCEx::onBrowseResources(IEspContext &context, IEspBrowseResourcesRequest & req, IEspBrowseResourcesResponse & resp)
  1671. {
  1672. try
  1673. {
  1674. context.ensureFeatureAccess(FEATURE_URL, SecAccess_Read, ECLWATCH_SMC_ACCESS_DENIED, SMC_ACCESS_DENIED);
  1675. double version = context.getClientVersion();
  1676. Owned<IEnvironmentFactory> factory = getEnvironmentFactory(true);
  1677. Owned<IConstEnvironment> constEnv = factory->openEnvironment();
  1678. //The resource files will be downloaded from the same box of ESP (not dali)
  1679. StringBuffer ipStr;
  1680. IpAddress ipaddr = queryHostIP();
  1681. ipaddr.getIpText(ipStr);
  1682. if (ipStr.length() > 0)
  1683. {
  1684. resp.setNetAddress(ipStr.str());
  1685. Owned<IConstMachineInfo> machine = constEnv->getMachineByAddress(ipStr.str());
  1686. if (machine)
  1687. {
  1688. int os = machine->getOS();
  1689. resp.setOS(os);
  1690. }
  1691. }
  1692. if (m_PortalURL.length() > 0)
  1693. resp.setPortalURL(m_PortalURL.str());
  1694. #ifndef USE_RESOURCE
  1695. if (version > 1.12)
  1696. resp.setUseResource(false);
  1697. #else
  1698. if (version > 1.12)
  1699. resp.setUseResource(true);
  1700. //Now, get a list of resources stored inside the ESP box
  1701. IArrayOf<IEspHPCCResourceRepository> resourceRepositories;
  1702. Owned<IPropertyTree> pEnvRoot = &constEnv->getPTree();
  1703. const char* ossInstall = pEnvRoot->queryProp("EnvSettings/path");
  1704. if (!ossInstall || !*ossInstall)
  1705. {
  1706. WARNLOG("Failed to get EnvSettings/Path in environment settings.");
  1707. return true;
  1708. }
  1709. StringBuffer path;
  1710. path.appendf("%s/componentfiles/files/downloads", ossInstall);
  1711. Owned<IFile> f = createIFile(path.str());
  1712. if(!f->exists() || !f->isDirectory())
  1713. {
  1714. WARNLOG("Invalid resource folder");
  1715. return true;
  1716. }
  1717. Owned<IDirectoryIterator> di = f->directoryFiles(NULL, false, true);
  1718. if(di.get() == NULL)
  1719. {
  1720. WARNLOG("Resource folder is empty.");
  1721. return true;
  1722. }
  1723. ForEach(*di)
  1724. {
  1725. if (!di->isDir())
  1726. continue;
  1727. StringBuffer folder, path0, tmpBuf;
  1728. di->getName(folder);
  1729. if (folder.length() == 0)
  1730. continue;
  1731. path0.appendf("%s/%s/description.xml", path.str(), folder.str());
  1732. Owned<IFile> f0 = createIFile(path0.str());
  1733. if(!f0->exists())
  1734. {
  1735. WARNLOG("Description file not found for %s", folder.str());
  1736. continue;
  1737. }
  1738. OwnedIFileIO rIO = f0->openShared(IFOread,IFSHfull);
  1739. if(!rIO)
  1740. {
  1741. WARNLOG("Failed to open the description file for %s", folder.str());
  1742. continue;
  1743. }
  1744. offset_t fileSize = f0->size();
  1745. tmpBuf.ensureCapacity((unsigned)fileSize);
  1746. tmpBuf.setLength((unsigned)fileSize);
  1747. size32_t nRead = rIO->read(0, (size32_t) fileSize, (char*)tmpBuf.str());
  1748. if (nRead != fileSize)
  1749. {
  1750. WARNLOG("Failed to read the description file for %s", folder.str());
  1751. continue;
  1752. }
  1753. Owned<IPropertyTree> desc = createPTreeFromXMLString(tmpBuf.str());
  1754. if (!desc)
  1755. {
  1756. WARNLOG("Invalid description file for %s", folder.str());
  1757. continue;
  1758. }
  1759. Owned<IPropertyTreeIterator> fileIterator = desc->getElements("file");
  1760. if (!fileIterator->first())
  1761. {
  1762. WARNLOG("Invalid description file for %s", folder.str());
  1763. continue;
  1764. }
  1765. IArrayOf<IEspHPCCResource> resourcs;
  1766. do {
  1767. IPropertyTree &fileItem = fileIterator->query();
  1768. const char* filename = fileItem.queryProp("filename");
  1769. if (!filename || !*filename)
  1770. continue;
  1771. const char* name0 = fileItem.queryProp("name");
  1772. const char* description0 = fileItem.queryProp("description");
  1773. const char* version0 = fileItem.queryProp("version");
  1774. Owned<IEspHPCCResource> onefile = createHPCCResource();
  1775. onefile->setFileName(filename);
  1776. if (name0 && *name0)
  1777. onefile->setName(name0);
  1778. if (description0 && *description0)
  1779. onefile->setDescription(description0);
  1780. if (version0 && *version0)
  1781. onefile->setVersion(version0);
  1782. resourcs.append(*onefile.getLink());
  1783. } while (fileIterator->next());
  1784. if (resourcs.ordinality())
  1785. {
  1786. StringBuffer path1;
  1787. path1.appendf("%s/%s", path.str(), folder.str());
  1788. Owned<IEspHPCCResourceRepository> oneRepository = createHPCCResourceRepository();
  1789. oneRepository->setName(folder.str());
  1790. oneRepository->setPath(path1.str());
  1791. oneRepository->setHPCCResources(resourcs);
  1792. resourceRepositories.append(*oneRepository.getLink());
  1793. }
  1794. }
  1795. if (resourceRepositories.ordinality())
  1796. resp.setHPCCResourceRepositories(resourceRepositories);
  1797. #endif
  1798. }
  1799. catch(IException* e)
  1800. {
  1801. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1802. }
  1803. return true;
  1804. }
  1805. int CWsSMCSoapBindingEx::onHttpEcho(CHttpRequest* request, CHttpResponse* response)
  1806. {
  1807. StringBuffer xml;
  1808. xml.append(
  1809. "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
  1810. "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
  1811. "<soap:Body>"
  1812. "<HttpEchoResponse xmlns='urn:hpccsystems:ws:httpecho'>");
  1813. appendXMLTag(xml, "Method", request->queryMethod());
  1814. appendXMLTag(xml, "UrlPath", request->queryPath());
  1815. appendXMLTag(xml, "UrlParameters", request->queryParamStr());
  1816. appendXMLOpenTag(xml, "Headers");
  1817. StringArray &headers = request->queryHeaders();
  1818. headers.sortAscii(false);
  1819. ForEachItemIn(i, headers)
  1820. {
  1821. const char *h = headers.item(i);
  1822. if (strnicmp(h, "Authorization", 13))
  1823. appendXMLTag(xml, "Header", h);
  1824. }
  1825. appendXMLCloseTag(xml, "Headers");
  1826. const char *content = request->queryContent();
  1827. if (content && *content)
  1828. appendXMLTag(xml, "Content", content);
  1829. xml.append("</HttpEchoResponse></soap:Body></soap:Envelope>");
  1830. response->setContent(xml);
  1831. response->setContentType("text/xml");
  1832. response->send();
  1833. return 0;
  1834. }
  1835. int CWsSMCSoapBindingEx::onGet(CHttpRequest* request, CHttpResponse* response)
  1836. {
  1837. const char *operation = request->queryServiceMethod();
  1838. if (!operation || !strieq(operation, "HttpEcho"))
  1839. return CWsSMCSoapBinding::onGet(request, response);
  1840. return onHttpEcho(request, response);
  1841. }
  1842. void CWsSMCSoapBindingEx::handleHttpPost(CHttpRequest *request, CHttpResponse *response)
  1843. {
  1844. sub_service sstype;
  1845. StringBuffer operation;
  1846. request->getEspPathInfo(sstype, NULL, NULL, &operation, false);
  1847. if (!operation || !strieq(operation, "HttpEcho"))
  1848. CWsSMCSoapBinding::handleHttpPost(request, response);
  1849. else
  1850. onHttpEcho(request, response);
  1851. }
  1852. int CWsSMCSoapBindingEx::onGetForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method)
  1853. {
  1854. try
  1855. {
  1856. if(stricmp(method,"NotInCommunityEdition")==0)
  1857. {
  1858. StringBuffer page, url, link;
  1859. request->getParameter("EEPortal", url);
  1860. if (url.length() > 0)
  1861. link.appendf("Further information can be found at <a href=\"%s\" target=\"_blank\">%s</a>.", url.str(), url.str());
  1862. page.append(
  1863. "<html>"
  1864. "<head>"
  1865. "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
  1866. "<link rel=\"stylesheet\" type=\"text/css\" href=\"/esp/files/default.css\"/>"
  1867. "<link rel=\"stylesheet\" type=\"text/css\" href=\"/esp/files/yui/build/fonts/fonts-min.css\" />"
  1868. "<title>Advanced feature in Enterprise Edition</title>"
  1869. "</head>"
  1870. "<body>"
  1871. "<h3 style=\"text-align:centre;\">Advanced feature in the Enterprise Edition</h4>"
  1872. "<p style=\"text-align:centre;\">Support for this feature is coming soon. ");
  1873. if (link.length() > 0)
  1874. page.append(link.str());
  1875. page.append("</p></body>"
  1876. "</html>");
  1877. response->setContent(page.str());
  1878. response->setContentType("text/html");
  1879. response->send();
  1880. return 0;
  1881. }
  1882. else if(stricmp(method,"DisabledInThisVersion")==0)
  1883. {
  1884. StringBuffer page;
  1885. page.append(
  1886. "<html>"
  1887. "<head>"
  1888. "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
  1889. "<link rel=\"stylesheet\" type=\"text/css\" href=\"/esp/files/default.css\"/>"
  1890. "<link rel=\"stylesheet\" type=\"text/css\" href=\"/esp/files/yui/build/fonts/fonts-min.css\" />"
  1891. "<title>Disabled Feature in This Version</title>"
  1892. "</head>"
  1893. "<body>"
  1894. "<h3 style=\"text-align:centre;\">Disabled Feature in This Version</h4>"
  1895. "<p style=\"text-align:centre;\">This feature is disabled in this version. ");
  1896. page.append("</p></body>"
  1897. "</html>");
  1898. response->setContent(page.str());
  1899. response->setContentType("text/html");
  1900. response->send();
  1901. return 0;
  1902. }
  1903. }
  1904. catch(IException* e)
  1905. {
  1906. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  1907. }
  1908. return onGetForm(context, request, response, service, method);
  1909. }
  1910. inline const char *controlCmdMessage(int cmd)
  1911. {
  1912. switch (cmd)
  1913. {
  1914. case CRoxieControlCmdType_ATTACH:
  1915. return "<control:unlockDali/>";
  1916. case CRoxieControlCmdType_DETACH:
  1917. return "<control:lockDali/>";
  1918. case CRoxieControlCmdType_RELOAD:
  1919. return "<control:reload/>";
  1920. case CRoxieControlCmdType_RELOAD_RETRY:
  1921. return "<control:reload forceRetry='1' />";
  1922. case CRoxieControlCmdType_STATE:
  1923. return "<control:state/>";
  1924. default:
  1925. throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Unknown Roxie Control Command.");
  1926. }
  1927. return NULL;
  1928. }
  1929. bool CWsSMCEx::onRoxieControlCmd(IEspContext &context, IEspRoxieControlCmdRequest &req, IEspRoxieControlCmdResponse &resp)
  1930. {
  1931. context.ensureFeatureAccess(ROXIE_CONTROL_URL, SecAccess_Full, ECLWATCH_SMC_ACCESS_DENIED, SMC_ACCESS_DENIED);
  1932. const char *process = req.getProcessCluster();
  1933. if (!process || !*process)
  1934. throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Process cluster not specified.");
  1935. const char *controlReq = controlCmdMessage(req.getCommand());
  1936. SocketEndpointArray addrs;
  1937. getRoxieProcessServers(process, addrs);
  1938. if (!addrs.length())
  1939. throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Process cluster not found.");
  1940. Owned<IPropertyTree> controlResp = sendRoxieControlAllNodes(addrs.item(0), controlReq, true, req.getWait());
  1941. if (!controlResp)
  1942. throw MakeStringException(ECLWATCH_INTERNAL_ERROR, "Failed to get control response from roxie.");
  1943. IArrayOf<IEspRoxieControlEndpointInfo> respEndpoints;
  1944. Owned<IPropertyTreeIterator> roxieEndpoints = controlResp->getElements("Endpoint");
  1945. ForEach(*roxieEndpoints)
  1946. {
  1947. IPropertyTree &roxieEndpoint = roxieEndpoints->query();
  1948. Owned<IEspRoxieControlEndpointInfo> respEndpoint = createRoxieControlEndpointInfo();
  1949. respEndpoint->setAddress(roxieEndpoint.queryProp("@ep"));
  1950. respEndpoint->setStatus(roxieEndpoint.queryProp("Status"));
  1951. if (roxieEndpoint.hasProp("Dali/@connected"))
  1952. respEndpoint->setAttached(roxieEndpoint.getPropBool("Dali/@connected"));
  1953. if (roxieEndpoint.hasProp("State/@hash"))
  1954. respEndpoint->setStateHash(roxieEndpoint.queryProp("State/@hash"));
  1955. respEndpoints.append(*respEndpoint.getClear());
  1956. }
  1957. resp.setEndpoints(respEndpoints);
  1958. return true;
  1959. }
  1960. bool CWsSMCEx::onGetStatusServerInfo(IEspContext &context, IEspGetStatusServerInfoRequest &req, IEspGetStatusServerInfoResponse &resp)
  1961. {
  1962. context.ensureFeatureAccess(FEATURE_URL, SecAccess_Read, ECLWATCH_SMC_ACCESS_DENIED, SMC_ACCESS_DENIED);
  1963. getStatusServerInfo(context, req.getServerType(), req.getServerName(), req.getNetworkAddress(), req.getPort(), resp.updateStatusServerInfo());
  1964. return true;
  1965. }
  1966. void CWsSMCEx::getStatusServerInfo(IEspContext &context, const char *serverType, const char *server, const char *networkAddress, unsigned port,
  1967. IEspStatusServerInfo& statusServerInfo)
  1968. {
  1969. if (!serverType || !*serverType)
  1970. throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Server type not specified.");
  1971. Owned<CActivityInfo> activityInfo = getActivityInfo(context);
  1972. if (!activityInfo)
  1973. throw MakeStringException(ECLWATCH_INTERNAL_ERROR, "Failed to get Activity Info cache.");
  1974. if (strieq(serverType,STATUS_SERVER_THOR))
  1975. {
  1976. setTargetClusterInfo(context, serverType, server, activityInfo->queryThorTargetClusters(), activityInfo->queryActiveWUs(), statusServerInfo);
  1977. }
  1978. else if (strieq(serverType,STATUS_SERVER_ROXIE))
  1979. {
  1980. setTargetClusterInfo(context, serverType, server, activityInfo->queryRoxieTargetClusters(), activityInfo->queryActiveWUs(), statusServerInfo);
  1981. }
  1982. else if (strieq(serverType,STATUS_SERVER_HTHOR))
  1983. {
  1984. setTargetClusterInfo(context, serverType, server, activityInfo->queryHThorTargetClusters(), activityInfo->queryActiveWUs(), statusServerInfo);
  1985. }
  1986. else if (strieq(serverType,STATUS_SERVER_DFUSERVER))
  1987. {
  1988. setServerQueueInfo(context, serverType, server, activityInfo->queryServerJobQueues(), activityInfo->queryActiveWUs(), statusServerInfo);
  1989. }
  1990. else
  1991. {
  1992. setServerQueueInfo(context, serverType, networkAddress, port, activityInfo->queryServerJobQueues(), activityInfo->queryActiveWUs(), statusServerInfo);
  1993. }
  1994. }
  1995. void CWsSMCEx::setTargetClusterInfo(IEspContext &context, const char *serverType, const char *clusterName, const CIArrayOf<CWsSMCTargetCluster>& targetClusters,
  1996. const IArrayOf<IEspActiveWorkunit>& aws, IEspStatusServerInfo& statusServerInfo)
  1997. {
  1998. if (!clusterName || !*clusterName)
  1999. throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Cluster name not specified.");
  2000. IEspTargetCluster& clusterInfo = statusServerInfo.updateTargetClusterInfo();
  2001. ForEachItemIn(i, targetClusters)
  2002. {
  2003. CWsSMCTargetCluster& targetCluster = targetClusters.item(i);
  2004. const char* name = targetCluster.clusterName.get();
  2005. if (name && strieq(name, clusterName))
  2006. {
  2007. setESPTargetCluster(context, targetCluster, &clusterInfo);
  2008. break;
  2009. }
  2010. }
  2011. setActiveWUs(context, serverType, clusterName, clusterInfo.getQueueName(), aws, statusServerInfo);
  2012. }
  2013. void CWsSMCEx::setServerQueueInfo(IEspContext &context, const char *serverType, const char *serverName, const IArrayOf<IEspServerJobQueue>& serverJobQueues,
  2014. const IArrayOf<IEspActiveWorkunit>& aws, IEspStatusServerInfo& statusServerInfo)
  2015. {
  2016. if (!serverName || !*serverName)
  2017. throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Server name not specified.");
  2018. ForEachItemIn(i, serverJobQueues)
  2019. {
  2020. IEspServerJobQueue& serverJobQueue = serverJobQueues.item(i);
  2021. const char* name = serverJobQueue.getServerName();
  2022. if (name && strieq(name, serverName))
  2023. {
  2024. IEspServerJobQueue& serverQueue = statusServerInfo.updateServerInfo();
  2025. serverQueue.copy(serverJobQueue);
  2026. break;
  2027. }
  2028. }
  2029. setActiveWUs(context, serverType, serverName, aws, statusServerInfo);
  2030. }
  2031. void CWsSMCEx::setServerQueueInfo(IEspContext &context, const char *serverType, const char *networkAddress, unsigned port, const IArrayOf<IEspServerJobQueue>& serverJobQueues,
  2032. const IArrayOf<IEspActiveWorkunit>& aws, IEspStatusServerInfo& statusServerInfo)
  2033. {
  2034. if (!networkAddress || !*networkAddress)
  2035. throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Network address not specified.");
  2036. ForEachItemIn(i, serverJobQueues)
  2037. {
  2038. IEspServerJobQueue& serverJobQueue = serverJobQueues.item(i);
  2039. const char* ipAddress = serverJobQueue.getNetworkAddress();
  2040. unsigned thePort = serverJobQueue.getPort();
  2041. if (ipAddress && strieq(ipAddress, networkAddress) && (thePort == port))
  2042. {
  2043. IEspServerJobQueue& serverQueue = statusServerInfo.updateServerInfo();
  2044. serverQueue.copy(serverJobQueue);
  2045. break;
  2046. }
  2047. }
  2048. VStringBuffer instance("%s_on_%s:%d", serverType, networkAddress, port);
  2049. setActiveWUs(context, serverType, instance.str(), aws, statusServerInfo);
  2050. }
  2051. void CWsSMCEx::setESPTargetCluster(IEspContext &context, const CWsSMCTargetCluster& targetCluster, IEspTargetCluster* espTargetCluster)
  2052. {
  2053. espTargetCluster->setClusterName(targetCluster.clusterName.get());
  2054. espTargetCluster->setClusterSize(targetCluster.clusterSize);
  2055. espTargetCluster->setClusterType(targetCluster.clusterType);
  2056. espTargetCluster->setQueueName(targetCluster.queueName.get());
  2057. espTargetCluster->setQueueStatus(targetCluster.queueStatus.get());
  2058. setClusterStatus(context, targetCluster, espTargetCluster);
  2059. }
  2060. void CWsSMCEx::setActiveWUs(IEspContext &context, const char *serverType, const char *clusterName, const char *queueName, const IArrayOf<IEspActiveWorkunit>& aws, IEspStatusServerInfo& statusServerInfo)
  2061. {
  2062. const char* clusterType = CLUSTER_TYPE_THOR;
  2063. if (strieq(serverType,STATUS_SERVER_ROXIE))
  2064. clusterType = CLUSTER_TYPE_ROXIE;
  2065. else if (strieq(serverType,STATUS_SERVER_HTHOR))
  2066. clusterType = CLUSTER_TYPE_HTHOR;
  2067. IArrayOf<IEspActiveWorkunit> awsOnThisQueue;
  2068. ForEachItemIn(i, aws)
  2069. {
  2070. IEspActiveWorkunit& wu = aws.item(i);
  2071. const char* wuid = wu.getWuid();
  2072. if (!wuid || !*wuid)
  2073. continue;
  2074. const char* wuServerType = wu.getServer();
  2075. const char* wuClusterName = wu.getTargetClusterName();
  2076. if (!wuServerType || !wuClusterName || !strieq(serverType, wuServerType) || !strieq(clusterName, wuClusterName))
  2077. {
  2078. const char* wuClusterType = wu.getClusterType();
  2079. const char* wuClusterQueueName = wu.getClusterQueueName();
  2080. if (!wuClusterType || !wuClusterQueueName || !strieq(clusterType, wuClusterType) || !strieq(queueName, wuClusterQueueName))
  2081. continue;
  2082. }
  2083. Owned<IEspActiveWorkunit> wuOnThisQueue = new CActiveWorkunitWrapper(wuid, "", "", "", "");
  2084. setActiveWUs(context, wu, wuOnThisQueue);
  2085. awsOnThisQueue.append(*wuOnThisQueue.getClear());
  2086. }
  2087. statusServerInfo.setWorkunits(awsOnThisQueue);
  2088. }
  2089. void CWsSMCEx::setActiveWUs(IEspContext &context, const char *serverType, const char *instance, const IArrayOf<IEspActiveWorkunit>& aws, IEspStatusServerInfo& statusServerInfo)
  2090. {
  2091. IArrayOf<IEspActiveWorkunit> awsOnThisQueue;
  2092. ForEachItemIn(i, aws)
  2093. {
  2094. IEspActiveWorkunit& wu = aws.item(i);
  2095. const char* wuid = wu.getWuid();
  2096. if (!wuid || !*wuid)
  2097. continue;
  2098. const char* wuInstance = wu.getInstance();
  2099. if (!wuInstance || !strieq(wuInstance, instance))
  2100. continue;
  2101. Owned<IEspActiveWorkunit> wuOnThisQueue = new CActiveWorkunitWrapper(wuid, "", "", "", "");
  2102. setActiveWUs(context, wu, wuOnThisQueue);
  2103. awsOnThisQueue.append(*wuOnThisQueue.getClear());
  2104. }
  2105. statusServerInfo.setWorkunits(awsOnThisQueue);
  2106. }
  2107. void CWsSMCEx::setActiveWUs(IEspContext &context, IEspActiveWorkunit& wu, IEspActiveWorkunit* wuToSet)
  2108. {
  2109. try
  2110. {
  2111. const char* user = context.queryUserId();
  2112. const char* owner = wu.getOwner();
  2113. //if no access, throw an exception and go to the 'catch' section.
  2114. context.validateFeatureAccess((!owner || !*owner || (user && streq(user, owner))) ? OWN_WU_ACCESS : OTHERS_WU_ACCESS, SecAccess_Read, true);
  2115. wuToSet->copy(wu);
  2116. }
  2117. catch (IException *e)
  2118. { //if the wu cannot be opened for some reason, the openWorkUnit() inside the CActiveWorkunitWrapper() may throw an exception.
  2119. //We do not want the exception stops this process of retrieving/showing all active WUs. And that WU should still be displayed
  2120. //with the exception.
  2121. wuToSet->setStateID(WUStateUnknown);
  2122. wuToSet->setServer(wu.getServer());
  2123. wuToSet->setQueueName(wu.getQueueName());
  2124. const char* instanceName = wu.getInstance();
  2125. const char* targetClusterName = wu.getTargetClusterName();
  2126. if (instanceName && *instanceName)
  2127. wuToSet->setInstance(instanceName); // JCSMORE In thor case at least, if queued it is unknown which instance it will run on..
  2128. if (targetClusterName && *targetClusterName)
  2129. wuToSet->setTargetClusterName(targetClusterName);
  2130. e->Release();
  2131. }
  2132. }
  2133. static const char *LockModeNames[] = { "ALL", "READ", "WRITE", "HOLD", "SUB" };
  2134. void CWsSMCEx::addLockInfo(CLockMetaData& lD, const char* xPath, const char* lfn, unsigned msNow, time_t ttNow, IArrayOf<IEspLock>& locks)
  2135. {
  2136. Owned<IEspLock> lock = createLock();
  2137. if (xPath && *xPath)
  2138. lock->setXPath(xPath);
  2139. else if (lfn && *lfn)
  2140. lock->setLogicalFile(lfn);
  2141. else
  2142. return; //Should not happen
  2143. lock->setEPIP(lD.queryEp());
  2144. lock->setSessionID(lD.sessId);
  2145. unsigned duration = msNow-lD.timeLockObtained;
  2146. lock->setDurationMS(duration);
  2147. CDateTime timeLocked;
  2148. StringBuffer timeStr;
  2149. time_t ttLocked = ttNow - duration/1000;
  2150. timeLocked.set(ttLocked);
  2151. timeLocked.getString(timeStr);
  2152. lock->setTimeLocked(timeStr.str());
  2153. unsigned mode = lD.mode;
  2154. VStringBuffer modeStr("%x", mode);
  2155. lock->setModes(modeStr.str());
  2156. StringArray modes;
  2157. if (RTM_MODE(mode, RTM_LOCK_READ))
  2158. modes.append(LockModeNames[CLockModes_READ]);
  2159. if (RTM_MODE(mode, RTM_LOCK_WRITE))
  2160. modes.append(LockModeNames[CLockModes_WRITE]);
  2161. if (RTM_MODE(mode, RTM_LOCK_HOLD)) // long-term lock
  2162. modes.append(LockModeNames[CLockModes_HOLD]);
  2163. if (RTM_MODE(mode, RTM_LOCK_SUB)) // locks all descendants as well as self
  2164. modes.append(LockModeNames[CLockModes_SUB]);
  2165. lock->setModeNames(modes);
  2166. locks.append(*lock.getClear());
  2167. }
  2168. bool CWsSMCEx::onLockQuery(IEspContext &context, IEspLockQueryRequest &req, IEspLockQueryResponse &resp)
  2169. {
  2170. class CLockPostFilter
  2171. {
  2172. CLockModes mode;
  2173. time_t ttLTLow, ttLTHigh;
  2174. bool checkLTLow, checkLTHigh;
  2175. int durationLow, durationHigh;
  2176. bool checkMode(unsigned lockMode)
  2177. {
  2178. unsigned modeReq;
  2179. switch (mode)
  2180. {
  2181. case CLockModes_READ:
  2182. modeReq = RTM_LOCK_READ;
  2183. break;
  2184. case CLockModes_WRITE:
  2185. modeReq = RTM_LOCK_WRITE;
  2186. break;
  2187. case CLockModes_HOLD:
  2188. modeReq = RTM_LOCK_HOLD;
  2189. break;
  2190. case CLockModes_SUB:
  2191. modeReq = RTM_LOCK_SUB;
  2192. break;
  2193. default:
  2194. return true;
  2195. }
  2196. if (lockMode & modeReq)
  2197. return true;
  2198. return false;
  2199. }
  2200. public:
  2201. CLockPostFilter(IEspLockQueryRequest& req)
  2202. {
  2203. ttLTLow = 0;
  2204. ttLTHigh = 0;
  2205. mode = req.getMode();
  2206. if (mode == LockModes_Undefined)
  2207. throw MakeStringException(ECLWATCH_INVALID_INPUT, "Invalid Lock Mode");
  2208. if (req.getDurationMSLow_isNull())
  2209. durationLow = -1;
  2210. else
  2211. durationLow = req.getDurationMSLow();
  2212. if (req.getDurationMSHigh_isNull())
  2213. durationHigh = -1;
  2214. else
  2215. durationHigh = req.getDurationMSHigh();
  2216. const char* timeLow = req.getTimeLockedLow();
  2217. if (!timeLow || !*timeLow)
  2218. checkLTLow = false;
  2219. else
  2220. {
  2221. CDateTime dtLow;
  2222. dtLow.setString(timeLow, NULL, false);
  2223. ttLTLow = dtLow.getSimple();
  2224. checkLTLow = true;
  2225. }
  2226. const char* timeHigh = req.getTimeLockedHigh();
  2227. if (!timeHigh || !*timeHigh)
  2228. checkLTHigh = false;
  2229. else
  2230. {
  2231. CDateTime dtHigh;
  2232. dtHigh.setString(timeHigh, NULL, false);
  2233. ttLTHigh = dtHigh.getSimple();
  2234. checkLTHigh = true;
  2235. }
  2236. }
  2237. bool check(CLockMetaData& lD, unsigned msNow, time_t ttNow)
  2238. {
  2239. if (!checkMode(lD.mode))
  2240. return false;
  2241. int duration = msNow-lD.timeLockObtained;
  2242. if (durationLow > duration)
  2243. return false;
  2244. if ((durationHigh >= 0) && (durationHigh < duration))
  2245. return false;
  2246. if (checkLTLow && (ttNow - duration/1000 < ttLTLow))
  2247. return false;
  2248. if (checkLTHigh && (ttNow - duration/1000 > ttLTHigh))
  2249. return false;
  2250. return true;
  2251. }
  2252. };
  2253. try
  2254. {
  2255. context.ensureFeatureAccess(FEATURE_URL, SecAccess_Read, ECLWATCH_SMC_ACCESS_DENIED, SMC_ACCESS_DENIED);
  2256. CLockPostFilter postFilter(req);
  2257. StringBuffer xPath;
  2258. if (req.getAllFileLocks())
  2259. xPath.appendf("/%s/*", querySdsFilesRoot());
  2260. else
  2261. xPath = req.getXPath();
  2262. Owned<ILockInfoCollection> lockInfoCollection = querySDS().getLocks(req.getEPIP(), xPath.str());
  2263. IArrayOf<IEspLock> locks;
  2264. CDateTime time;
  2265. time.setNow();
  2266. time_t ttNow = time.getSimple();
  2267. unsigned msNow = msTick();
  2268. for (unsigned l=0; l<lockInfoCollection->queryLocks(); l++)
  2269. {
  2270. ILockInfo& lockInfo = lockInfoCollection->queryLock(l);
  2271. CDfsLogicalFileName dlfn;
  2272. const char* lfn = NULL;
  2273. const char* xPath = NULL;
  2274. if (dlfn.setFromXPath(lockInfo.queryXPath()))
  2275. lfn = dlfn.get();
  2276. else
  2277. xPath = lockInfo.queryXPath();
  2278. for (unsigned i=0; i<lockInfo.queryConnections(); i++)
  2279. {
  2280. CLockMetaData& lMD = lockInfo.queryLockData(i);
  2281. if (postFilter.check(lMD, msNow, ttNow))
  2282. addLockInfo(lMD, xPath, lfn, msNow, ttNow, locks);
  2283. }
  2284. }
  2285. unsigned numLocks = locks.length();
  2286. if (numLocks)
  2287. resp.setLocks(locks);
  2288. resp.setNumLocks(numLocks);
  2289. }
  2290. catch(IException* e)
  2291. {
  2292. FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
  2293. }
  2294. return true;
  2295. }