ws_smcService.cpp 99 KB

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