TpWrapper.cpp 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133
  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. // TpWrapper.cpp: implementation of the CTpWrapper class.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "TpWrapper.hpp"
  18. #include <stdio.h>
  19. #include "securesocket.hpp"
  20. #include "workunit.hpp"
  21. #include "exception_util.hpp"
  22. #include "portlist.h"
  23. #include "daqueue.hpp"
  24. #include "dautils.hpp"
  25. #include "dameta.hpp"
  26. #ifdef _CONTAINERIZED
  27. #error "Should not be compiled in the container build"
  28. #endif
  29. const char* MSG_FAILED_GET_ENVIRONMENT_INFO = "Failed to get environment information.";
  30. //////////////////////////////////////////////////////////////////////
  31. // Construction/Destruction
  32. //////////////////////////////////////////////////////////////////////
  33. IPropertyTree* CTpWrapper::getEnvironment(const char* xpath)
  34. {
  35. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
  36. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  37. Owned<IPropertyTree> root = &constEnv->getPTree();
  38. if (!xpath || !*xpath)
  39. return LINK(root);
  40. IPropertyTree* pSubTree = root->queryPropTree( xpath );
  41. if (pSubTree)
  42. return LINK(pSubTree);
  43. return NULL;
  44. }
  45. void CTpWrapper::getClusterMachineList(double clientVersion,
  46. const char* ClusterType,
  47. const char* ClusterPath,
  48. const char* ClusterDirectory,
  49. IArrayOf<IEspTpMachine> &MachineList,
  50. bool& hasThorSpareProcess,
  51. const char* ClusterName)
  52. {
  53. try
  54. {
  55. StringBuffer returnStr,path;
  56. getAttPath(ClusterPath,path);
  57. set<string> machineNames; //used for checking duplicates
  58. if (strcmp(eqTHORMACHINES,ClusterType) == 0)
  59. {
  60. bool multiSlaves = false;
  61. getMachineList(clientVersion, eqThorMasterProcess, path.str(), "", ClusterDirectory, MachineList);
  62. getThorSlaveMachineList(clientVersion, ClusterName, ClusterDirectory, MachineList);
  63. unsigned count = MachineList.length();
  64. getThorSpareMachineList(clientVersion, ClusterName, ClusterDirectory, MachineList);
  65. //The checkMultiSlavesFlag is for legacy multiSlaves environment, not for new environments.
  66. //count < MachineList.length(): There is some node for eqThorSpareProcess being added to the MachineList.
  67. if (!checkMultiSlavesFlag(ClusterName) &&(count < MachineList.length()))
  68. hasThorSpareProcess = true;
  69. }
  70. else if (strcmp(eqHOLEMACHINES,ClusterType) == 0)
  71. {
  72. getMachineList(clientVersion, eqHoleSocketProcess, path.str(), "", ClusterDirectory, MachineList);
  73. getMachineList(clientVersion, eqHoleProcessorProcess, path.str(), "", ClusterDirectory, MachineList);
  74. getMachineList(clientVersion, eqHoleControlProcess, path.str(), "", ClusterDirectory, MachineList);
  75. getMachineList(clientVersion, eqHoleCollatorProcess, path.str(), "", ClusterDirectory, MachineList);
  76. getMachineList(clientVersion, eqHoleStandbyProcess, path.str(), "", ClusterDirectory, MachineList);
  77. }
  78. else if (strcmp(eqROXIEMACHINES,ClusterType) == 0)
  79. {
  80. getMachineList(clientVersion, "RoxieServerProcess", path.str(), "", ClusterDirectory, MachineList, &machineNames);
  81. }
  82. else if (strcmp(eqMACHINES,ClusterType) == 0)
  83. {
  84. //load a list of available machines.......
  85. getMachineList(clientVersion, "Computer", "/Environment/Hardware", "", ClusterDirectory, MachineList);
  86. }
  87. else if (strcmp("AVAILABLEMACHINES",ClusterType) == 0)
  88. {
  89. getMachineList(clientVersion, "Computer", "/Environment/Hardware", eqMachineAvailablability, ClusterDirectory, MachineList);
  90. }
  91. else if (strcmp("DROPZONE",ClusterType) == 0)
  92. {
  93. getDropZoneMachineList(clientVersion, false, MachineList);
  94. }
  95. else if (strcmp("STANDBYNNODE",ClusterType) == 0)
  96. {
  97. getThorSpareMachineList(clientVersion, ClusterName, ClusterDirectory, MachineList);
  98. getMachineList(clientVersion, eqHoleStandbyProcess, path.str(), "", ClusterDirectory, MachineList);
  99. }
  100. else if (strcmp("THORSPARENODES",ClusterType) == 0)
  101. {
  102. getThorSpareMachineList(clientVersion, ClusterName, ClusterDirectory, MachineList);
  103. }
  104. else if (strcmp("HOLESTANDBYNODES",ClusterType) == 0)
  105. {
  106. getMachineList(clientVersion, eqHoleStandbyProcess, path.str(), "", ClusterDirectory, MachineList);
  107. }
  108. }
  109. catch(IException* e){
  110. StringBuffer msg;
  111. e->errorMessage(msg);
  112. IWARNLOG("%s", msg.str());
  113. e->Release();
  114. }
  115. catch(...){
  116. IWARNLOG("Unknown Exception caught within CTpWrapper::getClusterMachineList");
  117. }
  118. }
  119. void CTpWrapper::fetchInstances(const char* ServiceType, IPropertyTree& service,
  120. IArrayOf<IEspTpMachine>& tpMachines)
  121. {
  122. Owned<IPropertyTreeIterator> instances = service.getElements("Instance");
  123. if (instances->first()) {
  124. do {
  125. IPropertyTree& instanceNode = instances->query();
  126. IEspTpMachine* machine = createTpMachine("", "");
  127. getMachineInfo(*machine, instanceNode, "/Environment/Software", ServiceType, "@computer");
  128. machine->setPort( instanceNode.getPropInt("@port") );
  129. const char* directory = instanceNode.queryProp("@directory");
  130. if (directory && *directory)
  131. machine->setDirectory( directory );
  132. tpMachines.append(*machine);
  133. } while (instances->next());
  134. }
  135. }
  136. void CTpWrapper::getTpDaliServers(double clientVersion, IArrayOf<IConstTpDali>& list)
  137. {
  138. Owned<IPropertyTree> root = getEnvironment("Software");
  139. if (!root)
  140. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  141. Owned<IPropertyTreeIterator> services= root->getElements(eqDali);
  142. ForEach(*services)
  143. {
  144. IPropertyTree& serviceTree = services->query();
  145. Owned<IEspTpDali> pService = createTpDali("","");
  146. const char* name = serviceTree.queryProp("@name");
  147. pService->setName(name);
  148. pService->setDescription(serviceTree.queryProp("@description"));
  149. pService->setBackupComputer(serviceTree.queryProp("@backupCoputer"));
  150. pService->setBackupDirectory(serviceTree.queryProp("@backupDirectory"));
  151. pService->setBuild(serviceTree.queryProp("@build"));
  152. pService->setType(eqDali);
  153. StringBuffer tmpDir, tmpAuditDir;
  154. if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "dali", name, tmpDir))
  155. {
  156. const char* pStr = tmpDir.str();
  157. if (pStr)
  158. {
  159. if (strchr(pStr, '/'))
  160. tmpDir.append("/");
  161. else
  162. tmpDir.append("\\");
  163. tmpAuditDir.set(tmpDir.str());
  164. tmpDir.append("server");
  165. pService->setLogDirectory(tmpDir.str());
  166. if (clientVersion >= 1.27)
  167. {
  168. tmpAuditDir.append("audit");
  169. pService->setAuditLogDirectory(tmpAuditDir.str());
  170. }
  171. }
  172. }
  173. else
  174. {
  175. pService->setLogDirectory(serviceTree.queryProp("@LogDir")); // backward compatible
  176. }
  177. IArrayOf<IEspTpMachine> tpMachines;
  178. fetchInstances(eqDali, serviceTree, tpMachines);
  179. pService->setTpMachines(tpMachines);
  180. list.append(*pService.getLink());
  181. }
  182. }
  183. void CTpWrapper::getTpEclServers(IArrayOf<IConstTpEclServer>& list, const char* serverName)
  184. {
  185. Owned<IPropertyTree> root = getEnvironment("Software");
  186. if (!root)
  187. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  188. Owned<IPropertyTreeIterator> services= root->getElements(eqEclServer);
  189. ForEach(*services)
  190. {
  191. IPropertyTree& serviceTree = services->query();
  192. Owned<IEspTpEclServer> pService = createTpEclServer("","");
  193. const char* name = serviceTree.queryProp("@name");
  194. if (serverName && stricmp(name, serverName))
  195. continue;
  196. pService->setName(name);
  197. pService->setDescription(serviceTree.queryProp("@description"));
  198. pService->setBuild(serviceTree.queryProp("@build"));
  199. StringBuffer tmpDir;
  200. if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "eclserver", name, tmpDir))
  201. {
  202. pService->setLogDirectory( tmpDir.str() );
  203. }
  204. else
  205. {
  206. pService->setLogDirectory(serviceTree.queryProp("@eclLogDir"));
  207. }
  208. pService->setType(eqEclServer);
  209. IArrayOf<IEspTpMachine> tpMachines;
  210. fetchInstances(eqEclServer, serviceTree, tpMachines);
  211. pService->setTpMachines(tpMachines);
  212. list.append(*pService.getLink());
  213. }
  214. }
  215. void CTpWrapper::getTpEclCCServers(IArrayOf<IConstTpEclServer>& list, const char* serverName)
  216. {
  217. Owned<IPropertyTree> root = getEnvironment("Software");
  218. if (!root)
  219. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  220. getTpEclCCServers(root, list, serverName);
  221. return;
  222. }
  223. void CTpWrapper::getTpEclCCServers(IPropertyTree* environmentSoftware, IArrayOf<IConstTpEclServer>& list, const char* serverName)
  224. {
  225. if (!environmentSoftware)
  226. return;
  227. Owned<IPropertyTreeIterator> services= environmentSoftware->getElements(eqEclCCServer);
  228. ForEach(*services)
  229. {
  230. IPropertyTree& serviceTree = services->query();
  231. const char* name = serviceTree.queryProp("@name");
  232. const char* logDir = serviceTree.queryProp("@logDir");
  233. if (serverName && stricmp(name, serverName))
  234. continue;
  235. Owned<IEspTpEclServer> pService = createTpEclServer("","");
  236. pService->setName(name);
  237. pService->setDescription(serviceTree.queryProp("@description"));
  238. pService->setBuild(serviceTree.queryProp("@build"));
  239. StringBuffer tmpDir;
  240. if (getConfigurationDirectory(environmentSoftware->queryPropTree("Directories"), "log", "eclccserver", name, tmpDir))
  241. {
  242. pService->setLogDirectory( tmpDir.str() );
  243. }
  244. else
  245. {
  246. pService->setLogDirectory(logDir);
  247. }
  248. pService->setType(eqEclCCServer);
  249. IArrayOf<IEspTpMachine> tpMachines;
  250. fetchInstances(eqEclCCServer, serviceTree, tpMachines);
  251. pService->setTpMachines(tpMachines);
  252. list.append(*pService.getLink());
  253. }
  254. }
  255. void CTpWrapper::getTpEclAgents(IArrayOf<IConstTpEclAgent>& list, const char* agentName)
  256. {
  257. Owned<IPropertyTree> root = getEnvironment("Software");
  258. if (!root)
  259. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  260. Owned<IPropertyTreeIterator> services= root->getElements(eqEclAgent);
  261. ForEach(*services)
  262. {
  263. IPropertyTree& serviceTree = services->query();
  264. const char* name = serviceTree.queryProp("@name");
  265. if (agentName && stricmp(name, agentName))
  266. continue;
  267. const char* daliServers = serviceTree.queryProp("@daliServers");
  268. const char* logDir = serviceTree.queryProp("@logDir");
  269. Owned<IEspTpEclAgent> pService = createTpEclAgent("","");
  270. pService->setDaliServer(daliServers);
  271. StringBuffer tmpDir;
  272. if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "eclagent", name, tmpDir))
  273. {
  274. pService->setLogDir( tmpDir.str() );
  275. }
  276. else
  277. {
  278. pService->setLogDir(logDir);
  279. }
  280. pService->setName(name);
  281. pService->setDescription(serviceTree.queryProp("@description"));
  282. pService->setBuild(serviceTree.queryProp("@build"));
  283. pService->setType(eqEclAgent);
  284. IArrayOf<IEspTpMachine> tpMachines;
  285. fetchInstances(eqEclAgent, serviceTree, tpMachines);
  286. pService->setTpMachines(tpMachines);
  287. list.append(*pService.getLink());
  288. }
  289. }
  290. void CTpWrapper::getTpEclSchedulers(IArrayOf<IConstTpEclScheduler>& list, const char* serverName)
  291. {
  292. Owned<IPropertyTree> root = getEnvironment("Software");
  293. if (!root)
  294. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  295. Owned<IPropertyTreeIterator> services= root->getElements(eqEclScheduler);
  296. ForEach(*services)
  297. {
  298. IPropertyTree& serviceTree = services->query();
  299. const char* name = serviceTree.queryProp("@name");
  300. const char* logDir = serviceTree.queryProp("@logDir");
  301. if (serverName && stricmp(name, serverName))
  302. continue;
  303. Owned<IEspTpEclScheduler> pService = createTpEclScheduler("","");
  304. pService->setName(name);
  305. pService->setDescription(serviceTree.queryProp("@description"));
  306. pService->setBuild(serviceTree.queryProp("@build"));
  307. StringBuffer tmpDir;
  308. if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "eclscheduler", name, tmpDir))
  309. {
  310. pService->setLogDirectory( tmpDir.str() );
  311. }
  312. else
  313. {
  314. pService->setLogDirectory(logDir);
  315. }
  316. pService->setType(eqEclScheduler);
  317. IArrayOf<IEspTpMachine> tpMachines;
  318. fetchInstances(eqEclScheduler, serviceTree, tpMachines);
  319. pService->setTpMachines(tpMachines);
  320. list.append(*pService.getLink());
  321. }
  322. }
  323. void CTpWrapper::getTpEspServers(IArrayOf<IConstTpEspServer>& list)
  324. {
  325. Owned<IPropertyTree> root = getEnvironment("Software");
  326. if (!root)
  327. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  328. Owned<IPropertyTreeIterator> services= root->getElements(eqEsp);
  329. ForEach(*services)
  330. {
  331. IPropertyTree& serviceTree = services->query();
  332. Owned<IEspTpEspServer> pService = createTpEspServer("","");
  333. const char* name = serviceTree.queryProp("@name");
  334. pService->setName(name);
  335. pService->setDescription(serviceTree.queryProp("@description"));
  336. pService->setBuild(serviceTree.queryProp("@build"));
  337. pService->setType(eqEsp);
  338. StringBuffer tmpDir;
  339. if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "esp", name, tmpDir))
  340. {
  341. pService->setLogDirectory( tmpDir.str() );
  342. }
  343. else
  344. {
  345. const char* logDir = serviceTree.queryProp("@logDir");
  346. if (logDir && *logDir)
  347. pService->setLogDirectory(logDir);
  348. }
  349. IArrayOf<IEspTpMachine> tpMachines;
  350. fetchInstances(eqEsp, serviceTree, tpMachines);
  351. pService->setTpMachines(tpMachines);
  352. Owned<IPropertyTreeIterator> iBinding = serviceTree.getElements("EspBinding");
  353. IArrayOf<IEspTpBinding> tpBindings;
  354. ForEach(*iBinding)
  355. {
  356. IPropertyTree& binding = iBinding->query();
  357. const char* service = binding.queryProp("@service");
  358. if (service && *service)
  359. {
  360. Owned<IEspTpBinding> pTpBinding = createTpBinding("", "");
  361. pTpBinding->setName (binding.queryProp("@name"));
  362. pTpBinding->setService(service);
  363. pTpBinding->setProtocol (binding.queryProp("@protocol"));
  364. pTpBinding->setPort (binding.queryProp("@port"));
  365. StringBuffer xpath;
  366. xpath.appendf("EspService[@name='%s']", service);
  367. IPropertyTree* pServiceNode = root->queryPropTree(xpath.str());
  368. if (pServiceNode)
  369. {
  370. const char* serviceType = pServiceNode->queryProp("Properties/@type");
  371. if (serviceType && *serviceType)
  372. pTpBinding->setServiceType(serviceType);
  373. const char* bindingType = pServiceNode->queryProp("Properties/@bindingType");
  374. if (bindingType && *bindingType)
  375. pTpBinding->setBindingType(bindingType);
  376. const char* buildSet = pServiceNode->queryProp("@buildSet");
  377. if (buildSet && *buildSet)
  378. pTpBinding->setServiceBuildSet(buildSet);
  379. }
  380. tpBindings.append(*pTpBinding.getLink());
  381. }
  382. }
  383. pService->setTpBindings( tpBindings);
  384. list.append(*pService.getLink());
  385. }
  386. }
  387. void CTpWrapper::getTpDfuServers(IArrayOf<IConstTpDfuServer>& list)
  388. {
  389. Owned<IPropertyTree> root = getEnvironment("Software");
  390. if (!root)
  391. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  392. Owned<IPropertyTreeIterator> services= root->getElements(eqDfu);
  393. ForEach(*services)
  394. {
  395. IPropertyTree& serviceTree = services->query();
  396. Owned<IEspTpDfuServer> pService = createTpDfuServer("","");
  397. const char* name = serviceTree.queryProp("@name");
  398. pService->setName(name);
  399. pService->setDescription(serviceTree.queryProp("@description"));
  400. pService->setBuild(serviceTree.queryProp("@build"));
  401. pService->setQueue(serviceTree.queryProp("@queue"));
  402. pService->setType(eqDfu);
  403. StringBuffer tmpDir;
  404. if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "dfuserver", name, tmpDir))
  405. {
  406. pService->setLogDirectory( tmpDir.str() );
  407. }
  408. else
  409. {
  410. pService->setLogDirectory(serviceTree.queryProp("@dfuLogDir"));
  411. }
  412. IArrayOf<IEspTpMachine> tpMachines;
  413. fetchInstances(eqDfu, serviceTree, tpMachines);
  414. pService->setTpMachines(tpMachines);
  415. list.append(*pService.getClear());
  416. }
  417. }
  418. void CTpWrapper::getTpSashaServers(IArrayOf<IConstTpSashaServer>& list)
  419. {
  420. Owned<IPropertyTree> root = getEnvironment("Software");
  421. if (!root)
  422. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  423. Owned<IPropertyTreeIterator> services= root->getElements(eqSashaServer);
  424. ForEach(*services)
  425. {
  426. IPropertyTree& serviceTree = services->query();
  427. Owned<IEspTpSashaServer> pService = createTpSashaServer("","");
  428. const char* name = serviceTree.queryProp("@name");
  429. pService->setName(name);
  430. pService->setDescription(serviceTree.queryProp("@description"));
  431. pService->setBuild(serviceTree.queryProp("@build"));
  432. StringBuffer tmpDir;
  433. if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "sasha", name, tmpDir))
  434. {
  435. pService->setLogDirectory( tmpDir.str() );
  436. }
  437. else
  438. {
  439. pService->setLogDirectory(serviceTree.queryProp("@logDir"));
  440. }
  441. IArrayOf<IEspTpMachine> tpMachines;
  442. fetchInstances(eqSashaServer, serviceTree, tpMachines);
  443. pService->setTpMachines(tpMachines);
  444. list.append(*pService.getLink());
  445. }
  446. }
  447. void CTpWrapper::getTpLdapServers(IArrayOf<IConstTpLdapServer>& list)
  448. {
  449. Owned<IPropertyTree> root = getEnvironment("Software");
  450. if (!root)
  451. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  452. Owned<IPropertyTreeIterator> services= root->getElements(eqLdapServer);
  453. ForEach(*services)
  454. {
  455. IPropertyTree& serviceTree = services->query();
  456. Owned<IEspTpLdapServer> pService = createTpLdapServer("","");
  457. pService->setName(serviceTree.queryProp("@name"));
  458. pService->setDescription(serviceTree.queryProp("@description"));
  459. pService->setBuild(serviceTree.queryProp("@build"));
  460. IArrayOf<IEspTpMachine> tpMachines;
  461. fetchInstances(eqLdapServer, serviceTree, tpMachines);
  462. int port = serviceTree.getPropInt("@ldapPort", 0);
  463. if (tpMachines.length() == 0)
  464. {
  465. const char* computer = serviceTree.queryProp("@computer");
  466. if (computer && *computer)
  467. {
  468. Owned<IEspTpMachine> machine = createTpMachine("", "");
  469. setMachineInfo(computer, "LDAPServerProcess", *machine);
  470. StringBuffer tmpPath;
  471. StringBuffer ppath("/Environment/Software");
  472. setAttPath(ppath, "Instance", "name", computer, tmpPath);
  473. machine->setPath(tmpPath.str());
  474. if (port)
  475. machine->setPort( port );
  476. tpMachines.append(*machine.getLink());
  477. }
  478. }
  479. else
  480. {
  481. const int nMachines = tpMachines.length();
  482. for (int i=0; i<nMachines; i++)
  483. tpMachines.item(i).setPort(port);
  484. }
  485. pService->setTpMachines(tpMachines);
  486. list.append(*pService.getLink());
  487. }
  488. }
  489. void CTpWrapper::getTpFTSlaves(IArrayOf<IConstTpFTSlave>& list)
  490. {
  491. Owned<IPropertyTree> root = getEnvironment("Software");
  492. if (!root)
  493. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  494. Owned<IPropertyTreeIterator> services= root->getElements(eqFTSlave);
  495. ForEach(*services)
  496. {
  497. IPropertyTree& serviceTree = services->query();
  498. Owned<IEspTpFTSlave> pService = createTpFTSlave("","");
  499. pService->setName(serviceTree.queryProp("@name"));
  500. pService->setDescription(serviceTree.queryProp("@description"));
  501. pService->setBuild(serviceTree.queryProp("@build"));
  502. IArrayOf<IEspTpMachine> tpMachines;
  503. fetchInstances(eqFTSlave, serviceTree, tpMachines);
  504. pService->setTpMachines(tpMachines);
  505. list.append(*pService.getLink());
  506. }
  507. }
  508. void CTpWrapper::getTpGenesisServers(IArrayOf<IConstTpGenesisServer>& list)
  509. {
  510. Owned<IPropertyTree> root = getEnvironment("Software");
  511. if (!root)
  512. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  513. Owned<IPropertyTreeIterator> services= root->getElements(eqGenesisServer);
  514. ForEach(*services)
  515. {
  516. IPropertyTree& serviceTree = services->query();
  517. Owned<IEspTpGenesisServer> pService = createTpGenesisServer("","");
  518. pService->setName(serviceTree.queryProp("@name"));
  519. pService->setDescription(serviceTree.queryProp("@description"));
  520. pService->setBuild(serviceTree.queryProp("@build"));
  521. IArrayOf<IEspTpMachine> tpMachines;
  522. fetchInstances(eqGenesisServer, serviceTree, tpMachines);
  523. pService->setTpMachines(tpMachines);
  524. list.append(*pService.getLink());
  525. }
  526. }
  527. void CTpWrapper::getTargetClusterList(IArrayOf<IEspTpLogicalCluster>& clusters, const char* clusterType, const char* clusterName)
  528. {
  529. Owned<IPropertyTree> root = getEnvironment("Software");
  530. if (!root)
  531. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  532. Owned<IPropertyTreeIterator> clusterIterator = root->getElements("Topology/Cluster");
  533. if (clusterIterator->first())
  534. {
  535. do {
  536. IPropertyTree &cluster0 = clusterIterator->query();
  537. StringBuffer processName;
  538. const char* clusterName0 = cluster0.queryProp("@name");
  539. if (!clusterName0 || !*clusterName0)
  540. continue;
  541. bool bAdd = false;
  542. if (!clusterType || !*clusterType)
  543. {
  544. bAdd = true;
  545. }
  546. else
  547. {
  548. Owned<IPropertyTreeIterator> clusters0= cluster0.getElements(clusterType);
  549. if (clusters0->first())
  550. {
  551. if (!clusterName || !*clusterName)
  552. {
  553. IPropertyTree &cluster = clusters0->query();
  554. const char* name = cluster.queryProp("@process");
  555. if (name && *name)
  556. processName.append(name);
  557. bAdd = true;
  558. }
  559. else
  560. {
  561. do {
  562. IPropertyTree &cluster = clusters0->query();
  563. const char* name = cluster.queryProp("@process");
  564. if (!name||!*name)
  565. continue;
  566. if (!stricmp(name, clusterName))
  567. {
  568. bAdd = true;
  569. break;
  570. }
  571. } while (clusters0->next());
  572. }
  573. }
  574. }
  575. if (!bAdd)
  576. continue;
  577. IEspTpLogicalCluster* pService = createTpLogicalCluster("","");
  578. pService->setName(clusterName0);
  579. if (processName.length() > 0)
  580. pService->setProcess(processName);
  581. pService->setLanguageVersion("3.0.0");
  582. clusters.append(*pService);
  583. } while (clusterIterator->next());
  584. }
  585. }
  586. void CTpWrapper::queryTargetClusterProcess(double version, const char* processName, const char* clusterType, IArrayOf<IConstTpCluster>& clusterList)
  587. {
  588. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
  589. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  590. Owned<IPropertyTree> root = &constEnv->getPTree();
  591. StringBuffer xpath;
  592. xpath.appendf("Software/%s[@name='%s']", clusterType, processName);
  593. IPropertyTree* pClusterTree = root->queryPropTree(xpath.str());
  594. if (!pClusterTree)
  595. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  596. const char* queueName = NULL;
  597. if (processName&&(stricmp(clusterType,eqThorCluster)==0))
  598. {
  599. // only for multi-thor
  600. // only list first thor cluster on queue
  601. queueName = pClusterTree->queryProp("@queueName");
  602. if (!queueName||!*queueName)
  603. queueName = processName;
  604. }
  605. IEspTpCluster* clusterInfo = createTpCluster("","");
  606. clusterInfo->setName(processName);
  607. if (queueName && *queueName)
  608. clusterInfo->setQueueName(queueName);
  609. else
  610. clusterInfo->setQueueName(processName);
  611. clusterInfo->setDesc(processName);
  612. clusterInfo->setBuild( pClusterTree->queryProp("@build") );
  613. clusterInfo->setType(clusterType);
  614. StringBuffer tmpPath;
  615. StringBuffer path("/Environment/Software");
  616. setAttPath(path, clusterType, "name", processName, tmpPath);
  617. clusterInfo->setPath(tmpPath.str());
  618. StringBuffer dirStr;
  619. if (!getConfigurationDirectory(root->queryPropTree("Software/Directories"), "run", clusterType, processName, dirStr))
  620. {
  621. dirStr.clear().append(pClusterTree->queryProp("@directory"));
  622. }
  623. clusterInfo->setDirectory(dirStr.str());
  624. StringBuffer tmpDir;
  625. if (getConfigurationDirectory(root->queryPropTree("Software/Directories"), "log", clusterType, processName, tmpDir))
  626. {
  627. clusterInfo->setLogDirectory( tmpDir.str() );
  628. }
  629. else
  630. {
  631. const char* logDir = pClusterTree->queryProp("@logDir");
  632. if (logDir)
  633. clusterInfo->setLogDirectory( logDir );
  634. }
  635. clusterInfo->setPrefix("");
  636. if(pClusterTree->hasProp("@dataBuild"))
  637. clusterInfo->setDataModel(pClusterTree->queryProp("@dataBuild"));
  638. clusterList.append(*clusterInfo);
  639. //find out OS
  640. OS_TYPE os = OS_WINDOWS;
  641. unsigned int clusterTypeLen = strlen(clusterType);
  642. const char* childType = NULL;
  643. const char* clusterType0 = NULL;
  644. if (clusterTypeLen > 4)
  645. {
  646. if (!strnicmp(clusterType, "roxie", 4))
  647. {
  648. childType = "RoxieServerProcess[1]";
  649. clusterType0 = eqROXIEMACHINES;
  650. }
  651. else if (!strnicmp(clusterType, "thor", 4))
  652. {
  653. childType = "ThorMasterProcess";
  654. clusterType0 = eqTHORMACHINES;
  655. }
  656. else
  657. {
  658. childType = "HoleControlProcess";
  659. clusterType0 = eqHOLEMACHINES;
  660. }
  661. }
  662. if (childType)
  663. {
  664. IPropertyTree* pChild = pClusterTree->queryPropTree(childType);
  665. if (pChild)
  666. {
  667. const char* computer = pChild->queryProp("@computer");
  668. IPropertyTree* pHardware = root->queryPropTree("Hardware");
  669. if (computer && *computer && pHardware)
  670. {
  671. StringBuffer xpath;
  672. xpath.appendf("Computer[@name='%s']/@computerType", computer);
  673. const char* computerType = pHardware->queryProp( xpath.str() );
  674. if (computerType && *computerType)
  675. {
  676. xpath.clear().appendf("ComputerType[@name='%s']/@opSys", computerType);
  677. const char* opSys = pHardware->queryProp( xpath.str() );
  678. if (!stricmp(opSys, "linux") || !stricmp( opSys, "solaris"))
  679. os = OS_LINUX;
  680. }
  681. }
  682. }
  683. }
  684. clusterInfo->setOS(os);
  685. if (clusterType0 && *clusterType0)
  686. {
  687. bool hasThorSpareProcess = false;
  688. IArrayOf<IEspTpMachine> machineList;
  689. getClusterMachineList(version, clusterType0, tmpPath.str(), dirStr.str(), machineList, hasThorSpareProcess, processName);
  690. if (machineList.length() > 0)
  691. clusterInfo->setTpMachines(machineList);
  692. if (version > 1.14)
  693. clusterInfo->setHasThorSpareProcess(hasThorSpareProcess);
  694. }
  695. return;
  696. }
  697. void CTpWrapper::queryTargetClusters(double version, const char* clusterType, const char* clusterName, IArrayOf<IEspTpTargetCluster>& targetClusterList)
  698. {
  699. try
  700. {
  701. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
  702. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  703. Owned<IPropertyTree> root = &constEnv->getPTree();
  704. Owned<IPropertyTreeIterator> clusters= root->getElements("Software/Topology/Cluster");
  705. if (!clusters->first())
  706. return;
  707. do {
  708. IPropertyTree &cluster = clusters->query();
  709. const char* name = cluster.queryProp("@name");
  710. if (!name||!*name)
  711. continue;
  712. if (clusterName && *clusterName && strcmp(clusterName, name))
  713. continue;
  714. const char* prefix = cluster.queryProp("@prefix");
  715. Owned<IPropertyTreeIterator> thorClusters= cluster.getElements(eqThorCluster);
  716. Owned<IPropertyTreeIterator> roxieClusters= cluster.getElements(eqRoxieCluster);
  717. Owned<IPropertyTreeIterator> eclCCServerProcesses= cluster.getElements(eqEclCCServer);
  718. Owned<IPropertyTreeIterator> eclServerProcesses= cluster.getElements(eqEclServer);
  719. Owned<IPropertyTreeIterator> eclSchedulerProcesses= cluster.getElements(eqEclScheduler);
  720. Owned<IPropertyTreeIterator> eclAgentProcesses= cluster.getElements(eqEclAgent);
  721. if (clusterType && !stricmp(clusterType, eqThorCluster) && !thorClusters->first())
  722. continue;
  723. if (clusterType && !stricmp(clusterType, eqRoxieCluster) && !roxieClusters->first())
  724. continue;
  725. if (clusterType && !stricmp(clusterType, eqHoleCluster) && (roxieClusters->first() || thorClusters->first()))
  726. continue;
  727. IEspTpTargetCluster* clusterInfo = createTpTargetCluster("","");
  728. clusterInfo->setName(name);
  729. if (prefix && *prefix)
  730. clusterInfo->setPrefix(prefix);
  731. //Read Cluster process
  732. clusterInfo->setType(eqHoleCluster);
  733. IArrayOf<IConstTpCluster>& clusterList = clusterInfo->getTpClusters();
  734. if (thorClusters->first())
  735. {
  736. clusterInfo->setType(eqThorCluster);
  737. do {
  738. IPropertyTree &thorCluster = thorClusters->query();
  739. const char* process = thorCluster.queryProp("@process");
  740. if (process && *process)
  741. {
  742. queryTargetClusterProcess(version, process, eqThorCluster, clusterList);
  743. }
  744. } while (thorClusters->next());
  745. }
  746. if (roxieClusters->first())
  747. {
  748. clusterInfo->setType(eqRoxieCluster);
  749. do {
  750. IPropertyTree &roxieCluster = roxieClusters->query();
  751. const char* process = roxieCluster.queryProp("@process");
  752. if (process && *process)
  753. {
  754. queryTargetClusterProcess(version, process, eqRoxieCluster, clusterList);
  755. }
  756. } while (roxieClusters->next());
  757. }
  758. //Read eclCCServer process
  759. IArrayOf<IConstTpEclServer>& eclCCServerList = clusterInfo->getTpEclCCServers();
  760. if (eclCCServerProcesses->first())
  761. {
  762. IPropertyTree &eclCCServerProcess = eclCCServerProcesses->query();
  763. const char* process = eclCCServerProcess.queryProp("@process");
  764. if (process && *process)
  765. {
  766. getTpEclCCServers(eclCCServerList, process);
  767. }
  768. }
  769. //Read eclServer process
  770. if ((version >= 1.19) && eclServerProcesses->first())
  771. {
  772. IArrayOf<IConstTpEclServer>& eclServerList = clusterInfo->getTpEclServers();
  773. IPropertyTree &eclServerProcess = eclServerProcesses->query();
  774. const char* process = eclServerProcess.queryProp("@process");
  775. if (process && *process)
  776. {
  777. getTpEclServers(eclServerList, process);
  778. }
  779. }
  780. //Read eclAgent process
  781. IArrayOf<IConstTpEclAgent>& eclAgentList = clusterInfo->getTpEclAgents();
  782. if (eclAgentProcesses->first())
  783. {
  784. IPropertyTree &eclAgentProcess = eclAgentProcesses->query();
  785. const char* process = eclAgentProcess.queryProp("@process");
  786. if (process && *process)
  787. {
  788. getTpEclAgents(eclAgentList, process);
  789. }
  790. }
  791. //Read eclScheduler process
  792. IArrayOf<IConstTpEclScheduler>& eclSchedulerList = clusterInfo->getTpEclSchedulers();
  793. if (eclSchedulerProcesses->first())
  794. {
  795. IPropertyTree &eclSchedulerProcess = eclSchedulerProcesses->query();
  796. const char* process = eclSchedulerProcess.queryProp("@process");
  797. if (process && *process)
  798. {
  799. getTpEclSchedulers(eclSchedulerList, process);
  800. }
  801. }
  802. targetClusterList.append(*clusterInfo);
  803. } while (clusters->next());
  804. }
  805. catch(IException* e){
  806. StringBuffer msg;
  807. e->errorMessage(msg);
  808. IWARNLOG("%s", msg.str());
  809. e->Release();
  810. }
  811. catch(...){
  812. IWARNLOG("Unknown Exception caught within CTpWrapper::getClusterList");
  813. }
  814. }
  815. void CTpWrapper::getClusterProcessList(const char* ClusterType, IArrayOf<IEspTpCluster>& clusterList, bool ignoreduplicatqueues, bool ignoreduplicategroups)
  816. {
  817. try
  818. {
  819. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
  820. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  821. Owned<IPropertyTree> root = &constEnv->getPTree();
  822. IPropertyTree* pSoftware = root->queryPropTree("Software");
  823. if (!pSoftware)
  824. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  825. StringArray queuesdone;
  826. StringArray groupsdone;
  827. Owned<IPropertyTreeIterator> clusters= pSoftware->getElements(ClusterType);
  828. if (clusters->first()) {
  829. do {
  830. IPropertyTree &cluster = clusters->query();
  831. const char* name = cluster.queryProp("@name");
  832. if (!name||!*name)
  833. continue;
  834. const char* queueName = NULL;
  835. const char* groupName = NULL;
  836. if (name&&(stricmp(ClusterType,eqThorCluster)==0))
  837. {
  838. // only for multi-thor
  839. // only list first thor cluster on queue
  840. queueName = cluster.queryProp("@queueName");
  841. if (!queueName||!*queueName)
  842. queueName = name;
  843. if (ignoreduplicatqueues)
  844. {
  845. bool done=false;
  846. ForEachItemIn(i,queuesdone)
  847. {
  848. if (strcmp(queuesdone.item(i),queueName)==0)
  849. {
  850. done = true;
  851. break;
  852. }
  853. }
  854. if (done)
  855. continue;
  856. queuesdone.append(queueName);
  857. }
  858. groupName = cluster.queryProp("@nodeGroup");
  859. if (!groupName||!*groupName)
  860. groupName = name;
  861. if (ignoreduplicategroups)
  862. {
  863. bool done=false;
  864. ForEachItemIn(i,groupsdone)
  865. {
  866. if (strcmp(groupsdone.item(i),groupName)==0)
  867. {
  868. done = true;
  869. break;
  870. }
  871. }
  872. if (done)
  873. continue;
  874. groupsdone.append(groupName);
  875. }
  876. }
  877. IEspTpCluster* clusterInfo = createTpCluster("","");
  878. clusterInfo->setName(name);
  879. if (queueName && *queueName)
  880. clusterInfo->setQueueName(queueName);
  881. else
  882. clusterInfo->setQueueName(name);
  883. clusterInfo->setDesc(name);
  884. clusterInfo->setBuild( cluster.queryProp("@build") );
  885. StringBuffer path("/Environment/Software");
  886. StringBuffer tmpPath;
  887. setAttPath(path, ClusterType, "name", name, tmpPath);
  888. clusterInfo->setType(ClusterType);
  889. StringBuffer tmpDir;
  890. if (getConfigurationDirectory(root->queryPropTree("Software/Directories"), "run", ClusterType, name, tmpDir))
  891. {
  892. clusterInfo->setDirectory(tmpDir.str());
  893. }
  894. else
  895. {
  896. clusterInfo->setDirectory(cluster.queryProp("@directory"));
  897. }
  898. tmpDir.clear();
  899. if (getConfigurationDirectory(root->queryPropTree("Software/Directories"), "log", ClusterType, name, tmpDir))
  900. {
  901. clusterInfo->setLogDirectory( tmpDir.str() );
  902. }
  903. else
  904. {
  905. const char* logDir = cluster.queryProp("@logDir");
  906. if (logDir)
  907. clusterInfo->setLogDirectory( logDir );
  908. }
  909. clusterInfo->setPath(tmpPath.str());
  910. clusterInfo->setPrefix("");
  911. if(cluster.hasProp("@dataBuild"))
  912. clusterInfo->setDataModel(cluster.queryProp("@dataBuild"));
  913. clusterList.append(*clusterInfo);
  914. //find out OS
  915. OS_TYPE os = OS_WINDOWS;
  916. unsigned int clusterTypeLen = strlen(ClusterType);
  917. const char* childType = NULL;
  918. if (clusterTypeLen > 4)
  919. {
  920. if (!strnicmp(ClusterType, "roxie", 4))
  921. childType = "RoxieServerProcess[1]";
  922. else if (!strnicmp(ClusterType, "thor", 4))
  923. childType = "ThorMasterProcess";
  924. else
  925. childType = "HoleControlProcess";
  926. }
  927. if (childType)
  928. {
  929. IPropertyTree* pChild = cluster.queryPropTree(childType);
  930. if (pChild)
  931. {
  932. const char* computer = pChild->queryProp("@computer");
  933. IPropertyTree* pHardware = root->queryPropTree("Hardware");
  934. if (computer && *computer && pHardware)
  935. {
  936. StringBuffer xpath;
  937. xpath.appendf("Computer[@name='%s']/@computerType", computer);
  938. const char* computerType = pHardware->queryProp( xpath.str() );
  939. if (computerType && *computerType)
  940. {
  941. xpath.clear().appendf("ComputerType[@name='%s']/@opSys", computerType);
  942. const char* opSys = pHardware->queryProp( xpath.str() );
  943. if (!stricmp(opSys, "linux") || !stricmp( opSys, "solaris"))
  944. os = OS_LINUX;
  945. }
  946. }
  947. }
  948. }
  949. clusterInfo->setOS(os);
  950. } while (clusters->next());
  951. }
  952. }
  953. catch(IException* e){
  954. StringBuffer msg;
  955. e->errorMessage(msg);
  956. IWARNLOG("%s", msg.str());
  957. e->Release();
  958. }
  959. catch(...){
  960. IWARNLOG("Unknown Exception caught within CTpWrapper::getClusterList");
  961. }
  962. }
  963. void CTpWrapper::getHthorClusterList(IArrayOf<IEspTpCluster>& clusterList)
  964. {
  965. try
  966. {
  967. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
  968. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  969. Owned<IPropertyTree> root = &constEnv->getPTree();
  970. IPropertyTree* pSoftware = root->queryPropTree("Software");
  971. const char * ClusterType = "EclAgentProcess";
  972. Owned<IPropertyTreeIterator> clusters(pSoftware->getElements(ClusterType));
  973. ForEach(*clusters)
  974. {
  975. IPropertyTree &cluster = clusters->query();
  976. const char* name = cluster.queryProp("@name");
  977. if (!name||!*name)
  978. continue;
  979. unsigned ins = 0;
  980. Owned<IPropertyTreeIterator> insts = clusters->query().getElements("Instance");
  981. ForEach(*insts)
  982. {
  983. const char *na = insts->query().queryProp("@netAddress");
  984. if (na&&*na)
  985. {
  986. SocketEndpoint ep(na);
  987. if (!ep.isNull())
  988. {
  989. ins++;
  990. StringBuffer gname("hthor__");
  991. gname.append(name);
  992. if (ins>1)
  993. gname.append('_').append(ins);
  994. IEspTpCluster* clusterInfo = createTpCluster("","");
  995. clusterInfo->setName(gname.str());
  996. clusterInfo->setQueueName(name);
  997. clusterInfo->setDesc(cluster.queryProp("@build"));
  998. clusterInfo->setBuild( cluster.queryProp("@description") );
  999. StringBuffer path("/Environment/Software");
  1000. StringBuffer tmpPath;
  1001. setAttPath(path, ClusterType, "name", name, tmpPath);
  1002. clusterInfo->setType(ClusterType);
  1003. clusterInfo->setDirectory(insts->query().queryProp("@directory"));
  1004. StringBuffer tmpDir;
  1005. if (getConfigurationDirectory(root->queryPropTree("Software/Directories"), "run", ClusterType, name, tmpDir))
  1006. {
  1007. clusterInfo->setDirectory(tmpDir.str());
  1008. }
  1009. else
  1010. {
  1011. clusterInfo->setDirectory(insts->query().queryProp("@directory"));
  1012. }
  1013. clusterInfo->setPath(tmpPath.str());
  1014. clusterList.append(*clusterInfo);
  1015. //find out OS
  1016. OS_TYPE os = OS_WINDOWS;
  1017. const char* computer = insts->query().queryProp("@computer");
  1018. IPropertyTree* pHardware = root->queryPropTree("Hardware");
  1019. if (computer && *computer && pHardware)
  1020. {
  1021. StringBuffer xpath;
  1022. xpath.appendf("Computer[@name='%s']/@computerType", computer);
  1023. const char* computerType = pHardware->queryProp( xpath.str() );
  1024. if (computerType && *computerType)
  1025. {
  1026. xpath.clear().appendf("ComputerType[@name='%s']/@opSys", computerType);
  1027. const char* opSys = pHardware->queryProp( xpath.str() );
  1028. if (!stricmp(opSys, "linux") || !stricmp( opSys, "solaris"))
  1029. os = OS_LINUX;
  1030. }
  1031. }
  1032. clusterInfo->setOS(os);
  1033. }
  1034. }
  1035. }
  1036. }
  1037. }
  1038. catch(IException* e){
  1039. StringBuffer msg;
  1040. e->errorMessage(msg);
  1041. IWARNLOG("%s", msg.str());
  1042. e->Release();
  1043. }
  1044. catch(...){
  1045. IWARNLOG("Unknown Exception caught within CTpWrapper::getHthorClusterList");
  1046. }
  1047. }
  1048. void CTpWrapper::getGroupList(double espVersion, const char* kindReq, IArrayOf<IEspTpGroup> &GroupList)
  1049. {
  1050. try
  1051. {
  1052. Owned<IRemoteConnection> conn = querySDS().connect("/Groups", myProcessSession(), RTM_LOCK_READ, SDS_LOCK_TIMEOUT);
  1053. Owned<IPropertyTreeIterator> groups= conn->queryRoot()->getElements("Group");
  1054. if (groups->first())
  1055. {
  1056. do
  1057. {
  1058. IPropertyTree &group = groups->query();
  1059. const char* kind = group.queryProp("@kind");
  1060. if (kindReq && *kindReq && !strieq(kindReq, kind))
  1061. continue;
  1062. IEspTpGroup* pGroup = createTpGroup("","");
  1063. const char* name = group.queryProp("@name");
  1064. pGroup->setName(name);
  1065. if (kind && *kind && (espVersion >= 1.21))
  1066. {
  1067. pGroup->setKind(kind);
  1068. pGroup->setReplicateOutputs(checkGroupReplicateOutputs(name, kind));
  1069. }
  1070. GroupList.append(*pGroup);
  1071. } while (groups->next());
  1072. }
  1073. }
  1074. catch(IException* e)
  1075. {
  1076. StringBuffer msg;
  1077. e->errorMessage(msg);
  1078. IWARNLOG("%s", msg.str());
  1079. e->Release();
  1080. }
  1081. catch(...)
  1082. {
  1083. IWARNLOG("Unknown Exception caught within CTpWrapper::getGroupList");
  1084. }
  1085. }
  1086. bool CTpWrapper::checkGroupReplicateOutputs(const char* groupName, const char* kind)
  1087. {
  1088. if (strieq(kind, "Roxie") || strieq(kind, "hthor"))
  1089. return false;
  1090. Owned<IEnvironmentFactory> factory = getEnvironmentFactory(true);
  1091. Owned<IConstEnvironment> environment = factory->openEnvironment();
  1092. Owned<IPropertyTree> root = &environment->getPTree();
  1093. Owned<IPropertyTreeIterator> it= root->getElements("Software/ThorCluster");
  1094. ForEach(*it)
  1095. {
  1096. StringBuffer thorClusterGroupName;
  1097. IPropertyTree& cluster = it->query();
  1098. getClusterGroupName(cluster, thorClusterGroupName);
  1099. if (thorClusterGroupName.length() && strieq(thorClusterGroupName.str(), groupName))
  1100. return cluster.getPropBool("@replicateOutputs", false);
  1101. }
  1102. return false;
  1103. }
  1104. void CTpWrapper::getMachineInfo(double clientVersion, const char* name, const char* netAddress, IEspTpMachine& machineInfo)
  1105. {
  1106. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
  1107. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  1108. Owned<IConstMachineInfo> pMachineInfo;
  1109. if (name && *name)
  1110. pMachineInfo.setown(constEnv->getMachine(name));
  1111. else if (netAddress && *netAddress)
  1112. pMachineInfo.setown(constEnv->getMachineByAddress(netAddress));
  1113. else
  1114. throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Machine not specified");
  1115. if (!pMachineInfo)
  1116. throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Machine Not Found for %s '%s'",
  1117. (name && *name)? "Name" : "Net Address", (name && *name)? name : netAddress);
  1118. setTpMachine(pMachineInfo, machineInfo);
  1119. }
  1120. void CTpWrapper::setTpMachine(IConstMachineInfo* machine, IEspTpMachine& tpMachine)
  1121. {
  1122. if (!machine)
  1123. return;
  1124. SCMStringBuffer machineName, netAddress;
  1125. machine->getName(machineName);
  1126. machine->getNetAddress(netAddress);
  1127. tpMachine.setName(machineName.str());
  1128. tpMachine.setNetaddress(netAddress.str());
  1129. tpMachine.setOS(machine->getOS());
  1130. switch(machine->getState())
  1131. {
  1132. case MachineStateAvailable:
  1133. tpMachine.setAvailable("Available");
  1134. break;
  1135. case MachineStateUnavailable:
  1136. tpMachine.setAvailable("Unavailable");
  1137. break;
  1138. case MachineStateUnknown:
  1139. tpMachine.setAvailable("Unknown");
  1140. break;
  1141. }
  1142. Owned<IConstDomainInfo> pDomain = machine->getDomain();
  1143. if (pDomain != 0)
  1144. {
  1145. SCMStringBuffer sName;
  1146. tpMachine.setDomain(pDomain->getName(sName).str());
  1147. }
  1148. }
  1149. void CTpWrapper::getMachineInfo(IEspTpMachine& machineInfo,IPropertyTree& machine,const char* ParentPath,const char* MachineType,const char* nodenametag)
  1150. {
  1151. const char* name = machine.queryProp(nodenametag);
  1152. setMachineInfo(name,MachineType,machineInfo);
  1153. StringBuffer tmpPath;
  1154. StringBuffer ppath(ParentPath);
  1155. setAttPath(ppath,machine.queryName(),"name",name,tmpPath);
  1156. machineInfo.setPath(tmpPath.str());
  1157. }
  1158. bool CTpWrapper::checkMultiSlavesFlag(const char* clusterName)
  1159. {
  1160. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
  1161. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  1162. Owned<IPropertyTree> root = &constEnv->getPTree();
  1163. VStringBuffer path("Software/ThorCluster[@name=\"%s\"]", clusterName);
  1164. Owned<IPropertyTree> cluster= root->getPropTree(path.str());
  1165. if (!cluster)
  1166. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  1167. //set this flag for legacy multi slave clusters because SwapNode made little sense in the old scheme
  1168. //This is no longer an option in new environments, but is kept for backward compatibility with old
  1169. //multi slave environments that used to list multiple slaves per node manually.
  1170. return cluster->getPropBool("@multiSlaves");
  1171. }
  1172. void CTpWrapper::appendThorMachineList(double clientVersion, IConstEnvironment* constEnv, INode& node, const char* clusterName,
  1173. const char* machineType, unsigned& processNumber, unsigned channels, const char* directory, IArrayOf<IEspTpMachine>& machineList)
  1174. {
  1175. StringBuffer netAddress;
  1176. node.endpoint().getIpText(netAddress);
  1177. if (netAddress.length() == 0)
  1178. {
  1179. OWARNLOG("Net address not found for a node of %s", clusterName);
  1180. return;
  1181. }
  1182. processNumber++;
  1183. Owned<IEspTpMachine> machineInfo = createTpMachine("","");
  1184. machineInfo->setType(machineType);
  1185. machineInfo->setNetaddress(netAddress.str());
  1186. if (!isEmptyString(directory))
  1187. machineInfo->setDirectory(directory);
  1188. Owned<IConstMachineInfo> pMachineInfo = constEnv->getMachineByAddress(netAddress.str());
  1189. if (pMachineInfo.get())
  1190. {
  1191. setTpMachine(pMachineInfo, *machineInfo);
  1192. if (clientVersion > 1.17)
  1193. {
  1194. machineInfo->setProcessNumber(processNumber);
  1195. }
  1196. }
  1197. else
  1198. {
  1199. machineInfo->setName("external");
  1200. machineInfo->setOS(MachineOsUnknown);
  1201. }
  1202. if (clientVersion >= 1.30)
  1203. machineInfo->setChannels(channels);
  1204. machineList.append(*machineInfo.getLink());
  1205. }
  1206. void CTpWrapper::getThorSlaveMachineList(double clientVersion, const char* clusterName, const char* directory, IArrayOf<IEspTpMachine>& machineList)
  1207. {
  1208. try
  1209. {
  1210. getThorMachineList(clientVersion, clusterName, directory, true, machineList);
  1211. }
  1212. catch(IException* e)
  1213. {
  1214. StringBuffer msg;
  1215. e->errorMessage(msg);
  1216. IWARNLOG("%s", msg.str());
  1217. e->Release();
  1218. }
  1219. catch(...)
  1220. {
  1221. IWARNLOG("Unknown Exception caught within CTpWrapper::getMachineList");
  1222. }
  1223. return;
  1224. }
  1225. void CTpWrapper::getThorSpareMachineList(double clientVersion, const char* clusterName, const char* directory, IArrayOf<IEspTpMachine>& machineList)
  1226. {
  1227. try
  1228. {
  1229. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
  1230. getThorMachineList(clientVersion, clusterName, directory, false, machineList);
  1231. }
  1232. catch(IException* e)
  1233. {
  1234. StringBuffer msg;
  1235. e->errorMessage(msg);
  1236. IWARNLOG("%s", msg.str());
  1237. e->Release();
  1238. }
  1239. catch(...)
  1240. {
  1241. IWARNLOG("Unknown Exception caught within CTpWrapper::getMachineList");
  1242. }
  1243. return;
  1244. }
  1245. void CTpWrapper::getThorMachineList(double clientVersion, const char* clusterName, const char* directory,
  1246. bool slaveNode, IArrayOf<IEspTpMachine>& machineList)
  1247. {
  1248. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
  1249. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  1250. Owned<IPropertyTree> root = &constEnv->getPTree();
  1251. VStringBuffer path("Software/%s[@name=\"%s\"]", eqThorCluster, clusterName);
  1252. Owned<IPropertyTree> cluster= root->getPropTree(path.str());
  1253. if (!cluster)
  1254. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  1255. Owned<IGroup> nodeGroup;
  1256. if (slaveNode)
  1257. {
  1258. nodeGroup.setown(getClusterProcessNodeGroup(clusterName, eqThorCluster));
  1259. }
  1260. else
  1261. {
  1262. StringBuffer groupName;
  1263. getClusterSpareGroupName(*cluster, groupName);
  1264. if (groupName.length() < 1)
  1265. return;
  1266. nodeGroup.setown(queryNamedGroupStore().lookup(groupName.str()));
  1267. }
  1268. if (!nodeGroup || (nodeGroup->ordinality() == 0))
  1269. return;
  1270. unsigned processNumber = 0;
  1271. unsigned channels = cluster->getPropInt("@channelsPerSlave", 1);
  1272. Owned<INodeIterator> gi = nodeGroup->getIterator();
  1273. ForEach(*gi)
  1274. appendThorMachineList(clientVersion, constEnv, gi->query(), clusterName,
  1275. slaveNode? eqThorSlaveProcess : eqThorSpareProcess, processNumber, channels, directory, machineList);
  1276. }
  1277. void CTpWrapper::getMachineList(double clientVersion, const char* MachineType, const char* ParentPath,
  1278. const char* Status, const char* Directory, IArrayOf<IEspTpMachine>& MachineList, set<string>* pMachineNames/*=NULL*/)
  1279. {
  1280. try
  1281. {
  1282. //ParentPath=Path to parent node... normally a cluster
  1283. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
  1284. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  1285. Owned<IPropertyTree> root0 = &constEnv->getPTree();
  1286. char* xpath = (char*)ParentPath;
  1287. if (!strnicmp(xpath, "/Environment/", 13))
  1288. xpath += 13;
  1289. IPropertyTree* root = root0->queryPropTree( xpath );
  1290. if (!root)
  1291. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  1292. bool hasPropChannelsPerNode = root->hasProp("@channelsPerNode");
  1293. int channels = root->getPropInt("@channelsPerNode");
  1294. Owned<IPropertyTreeIterator> machines= root->getElements(MachineType);
  1295. const char* nodenametag = getNodeNameTag(MachineType);
  1296. if (machines->first()) {
  1297. do {
  1298. IPropertyTree &machine = machines->query();
  1299. if (pMachineNames)//caller wishes us to avoid inserting duplicate entries for machines
  1300. {
  1301. const char* machineName = machine.queryProp(nodenametag);
  1302. if (pMachineNames->find(machineName) != pMachineNames->end())
  1303. continue;
  1304. pMachineNames->insert(machineName);
  1305. }
  1306. //load up the machines of which we do not care what status is set or we have a matching status
  1307. const char* state = machine.queryProp("@state");
  1308. if ((Status==NULL || *Status=='\0') ||
  1309. (state && strcmp(Status, state)==0))
  1310. {
  1311. IEspTpMachine & machineInfo = *(createTpMachine("",""));
  1312. getMachineInfo(machineInfo,machine,ParentPath,MachineType,nodenametag);
  1313. if (Directory && *Directory)
  1314. machineInfo.setDirectory(Directory);
  1315. if (hasPropChannelsPerNode && (clientVersion >= 1.30))
  1316. machineInfo.setChannels(channels);
  1317. MachineList.append(machineInfo);
  1318. }
  1319. } while (machines->next());
  1320. }
  1321. }
  1322. catch(IException* e){
  1323. StringBuffer msg;
  1324. e->errorMessage(msg);
  1325. IWARNLOG("%s", msg.str());
  1326. e->Release();
  1327. }
  1328. catch(...){
  1329. IWARNLOG("Unknown Exception caught within CTpWrapper::getMachineList");
  1330. }
  1331. }
  1332. const char* CTpWrapper::getNodeNameTag(const char* MachineType)
  1333. {
  1334. if (strcmp(MachineType,"Computer")==0)
  1335. return "@name";
  1336. else
  1337. return "@computer";
  1338. }
  1339. void CTpWrapper::getDropZoneMachineList(double clientVersion, bool ECLWatchVisibleOnly, IArrayOf<IEspTpMachine> &MachineList)
  1340. {
  1341. try
  1342. {
  1343. IArrayOf<IConstTpDropZone> list;
  1344. getTpDropZones(clientVersion, nullptr, ECLWatchVisibleOnly, list);
  1345. ForEachItemIn(i, list)
  1346. {
  1347. IConstTpDropZone& dropZone = list.item(i);
  1348. IArrayOf<IConstTpMachine>& tpMachines = dropZone.getTpMachines();
  1349. ForEachItemIn(ii, tpMachines)
  1350. {
  1351. IConstTpMachine& tpMachine = tpMachines.item(ii);
  1352. Owned<IEspTpMachine> machine = createTpMachine();
  1353. machine->copy(tpMachine);
  1354. MachineList.append(*machine.getLink());
  1355. }
  1356. }
  1357. }
  1358. catch(IException* e)
  1359. {
  1360. EXCLOG(e);
  1361. e->Release();
  1362. }
  1363. catch(...)
  1364. {
  1365. IWARNLOG("Unknown Exception caught within CTpWrapper::getDropZoneMachineList");
  1366. }
  1367. }
  1368. //For a given dropzone or every dropzones (check ECLWatchVisible if needed), read: "@name",
  1369. // "@description", "@build", "@directory", "@ECLWatchVisible" into an IEspTpDropZone object.
  1370. //For each ServerList, read "@name" and "@server" (hostname or IP) into an IEspTpMachine object.
  1371. //Add the IEspTpMachine object into the IEspTpDropZone.
  1372. void CTpWrapper::getTpDropZones(double clientVersion, const char* name, bool ECLWatchVisibleOnly, IArrayOf<IConstTpDropZone>& list)
  1373. {
  1374. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
  1375. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  1376. if (!isEmptyString(name))
  1377. {
  1378. Owned<IConstDropZoneInfo> pDropZoneInfo = constEnv->getDropZone(name);
  1379. if (pDropZoneInfo && (!ECLWatchVisibleOnly || pDropZoneInfo->isECLWatchVisible()))
  1380. appendTpDropZone(clientVersion, constEnv, *pDropZoneInfo, list);
  1381. }
  1382. else
  1383. {
  1384. Owned<IConstDropZoneInfoIterator> it = constEnv->getDropZoneIterator();
  1385. ForEach(*it)
  1386. {
  1387. IConstDropZoneInfo& dropZoneInfo = it->query();
  1388. if (!ECLWatchVisibleOnly || dropZoneInfo.isECLWatchVisible())
  1389. appendTpDropZone(clientVersion, constEnv, dropZoneInfo, list);
  1390. }
  1391. }
  1392. }
  1393. void CTpWrapper::appendTpDropZone(double clientVersion, IConstEnvironment* constEnv, IConstDropZoneInfo& dropZoneInfo, IArrayOf<IConstTpDropZone>& list)
  1394. {
  1395. SCMStringBuffer dropZoneName, description, directory, umask, build, computer;
  1396. dropZoneInfo.getName(dropZoneName);
  1397. dropZoneInfo.getDescription(description);
  1398. dropZoneInfo.getDirectory(directory);
  1399. dropZoneInfo.getUMask(umask);
  1400. dropZoneInfo.getComputerName(computer);
  1401. Owned<IEspTpDropZone> dropZone = createTpDropZone();
  1402. if (dropZoneName.length() > 0)
  1403. dropZone->setName(dropZoneName.str());
  1404. if (description.length() > 0)
  1405. dropZone->setDescription(description.str());
  1406. if (directory.length() > 0)
  1407. dropZone->setPath(directory.str());
  1408. if (build.length() > 0)
  1409. dropZone->setBuild(build.str());
  1410. dropZone->setECLWatchVisible(dropZoneInfo.isECLWatchVisible());
  1411. IArrayOf<IEspTpMachine> tpMachines;
  1412. Owned<IConstDropZoneServerInfoIterator> itr = dropZoneInfo.getServers();
  1413. ForEach(*itr)
  1414. {
  1415. IConstDropZoneServerInfo& dropZoneServer = itr->query();
  1416. StringBuffer name, server, networkAddress;
  1417. dropZoneServer.getName(name);
  1418. dropZoneServer.getServer(server);
  1419. if (name.isEmpty() && server.isEmpty())
  1420. continue;
  1421. Owned<IEspTpMachine> machine = createTpMachine();
  1422. if (!name.isEmpty())
  1423. machine->setName(name.str());
  1424. if (!server.isEmpty())
  1425. {
  1426. machine->setNetaddress(server);
  1427. machine->setConfigNetaddress(server); //May be used by legacy ECLWatch. Leave it for now.
  1428. }
  1429. if (directory.length() > 0)
  1430. {
  1431. machine->setDirectory(directory.str());
  1432. machine->setOS(getPathSepChar(directory.str()) == '/' ? MachineOsLinux : MachineOsW2K);
  1433. }
  1434. tpMachines.append(*machine.getLink());
  1435. }
  1436. dropZone->setTpMachines(tpMachines);
  1437. list.append(*dropZone.getLink());
  1438. }
  1439. void CTpWrapper::getTpSparkThors(double clientVersion, const char* name, IArrayOf<IConstTpSparkThor>& list)
  1440. {
  1441. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory(true);
  1442. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  1443. if (!isEmptyString(name))
  1444. {
  1445. Owned<IConstSparkThorInfo> sparkThorInfo = constEnv->getSparkThor(name);
  1446. if (sparkThorInfo)
  1447. appendTpSparkThor(clientVersion, constEnv, *sparkThorInfo, list);
  1448. }
  1449. else
  1450. {
  1451. Owned<IConstSparkThorInfoIterator> it = constEnv->getSparkThorIterator();
  1452. ForEach(*it)
  1453. appendTpSparkThor(clientVersion, constEnv, it->query(), list);
  1454. }
  1455. }
  1456. void CTpWrapper::appendTpSparkThor(double clientVersion, IConstEnvironment* constEnv, IConstSparkThorInfo& sparkThorInfo, IArrayOf<IConstTpSparkThor>& list)
  1457. {
  1458. SCMStringBuffer name, build, thorClusterName;
  1459. sparkThorInfo.getName(name);
  1460. sparkThorInfo.getBuild(build);
  1461. sparkThorInfo.getThorClusterName(thorClusterName);
  1462. Owned<IEspTpSparkThor> sparkThor = createTpSparkThor();
  1463. if (name.length() > 0)
  1464. sparkThor->setName(name.str());
  1465. if (build.length() > 0)
  1466. sparkThor->setBuild(build.str());
  1467. if (thorClusterName.length() > 0)
  1468. sparkThor->setThorClusterName(thorClusterName.str());
  1469. sparkThor->setSparkExecutorCores(sparkThorInfo.getSparkExecutorCores());
  1470. sparkThor->setSparkExecutorMemory(sparkThorInfo.getSparkExecutorMemory());
  1471. sparkThor->setSparkMasterPort(sparkThorInfo.getSparkMasterPort());
  1472. sparkThor->setSparkMasterWebUIPort(sparkThorInfo.getSparkMasterWebUIPort());
  1473. sparkThor->setSparkWorkerCores(sparkThorInfo.getSparkWorkerCores());
  1474. sparkThor->setSparkWorkerMemory(sparkThorInfo.getSparkWorkerMemory());
  1475. sparkThor->setSparkWorkerPort(sparkThorInfo.getSparkWorkerPort());
  1476. //Create the Path used by the thor cluster.
  1477. StringBuffer tmpPath;
  1478. StringBuffer path("/Environment/Software");
  1479. setAttPath(path, eqThorCluster, "name", thorClusterName.str(), tmpPath);
  1480. sparkThor->setThorPath(tmpPath.str());
  1481. StringBuffer dirBuf;
  1482. Owned<IPropertyTree> root = &constEnv->getPTree();
  1483. if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "sparkthor", name.str(), dirBuf))
  1484. sparkThor->setLogDirectory(dirBuf.str());
  1485. IArrayOf<IConstTpMachine> machines;
  1486. Owned<IConstInstanceInfoIterator> instanceInfoItr = sparkThorInfo.getInstanceIterator();
  1487. ForEach(*instanceInfoItr)
  1488. appendTpMachine(clientVersion, constEnv, instanceInfoItr->query(), machines);
  1489. sparkThor->setTpMachines(machines);
  1490. list.append(*sparkThor.getLink());
  1491. }
  1492. IEspTpMachine* CTpWrapper::createTpMachineEx(const char* name, const char* type, IConstMachineInfo* machineInfo)
  1493. {
  1494. if (!machineInfo)
  1495. return nullptr;
  1496. Owned<IEspTpMachine> machine = createTpMachine();
  1497. machine->setName(name);
  1498. machine->setType(type);
  1499. machine->setOS(machineInfo->getOS());
  1500. Owned<IConstDomainInfo> domain = machineInfo->getDomain();
  1501. if (domain)
  1502. {
  1503. SCMStringBuffer sName;
  1504. machine->setDomain(domain->getName(sName).str());
  1505. }
  1506. SCMStringBuffer netAddr;
  1507. machineInfo->getNetAddress(netAddr);
  1508. if (netAddr.length() > 0)
  1509. {
  1510. StringBuffer networkAddress;
  1511. IpAddress ipAddr;
  1512. ipAddr.ipset(netAddr.str());
  1513. ipAddr.getIpText(networkAddress);
  1514. machine->setNetaddress(networkAddress.str());
  1515. }
  1516. switch(machineInfo->getState())
  1517. {
  1518. case MachineStateAvailable:
  1519. machine->setAvailable("Available");
  1520. break;
  1521. case MachineStateUnavailable:
  1522. machine->setAvailable("Unavailable");
  1523. break;
  1524. default:
  1525. machine->setAvailable("Unknown");
  1526. break;
  1527. }
  1528. return machine.getClear();
  1529. }
  1530. void CTpWrapper::setMachineInfo(const char* name,const char* type,IEspTpMachine& machine)
  1531. {
  1532. try{
  1533. Owned<IEnvironmentFactory> factory = getEnvironmentFactory(true);
  1534. Owned<IConstEnvironment> constEnv = factory->openEnvironment();
  1535. Owned<IConstMachineInfo> pMachineInfo = constEnv->getMachine(name);
  1536. if (pMachineInfo.get())
  1537. {
  1538. SCMStringBuffer ep;
  1539. pMachineInfo->getNetAddress(ep);
  1540. machine.setNetaddress(ep.str());
  1541. machine.setConfigNetaddress(ep.str());
  1542. machine.setOS(pMachineInfo->getOS());
  1543. switch(pMachineInfo->getState())
  1544. {
  1545. case MachineStateAvailable:
  1546. machine.setAvailable("Available");
  1547. break;
  1548. case MachineStateUnavailable:
  1549. machine.setAvailable("Unavailable");
  1550. break;
  1551. case MachineStateUnknown:
  1552. machine.setAvailable("Unknown");
  1553. break;
  1554. }
  1555. Owned<IConstDomainInfo> pDomain = pMachineInfo->getDomain();
  1556. if (pDomain != 0)
  1557. {
  1558. SCMStringBuffer sName;
  1559. machine.setDomain(pDomain->getName(sName).str());
  1560. }
  1561. }
  1562. machine.setName(name);
  1563. machine.setType(type);
  1564. }
  1565. catch(IException* e){
  1566. StringBuffer msg;
  1567. e->errorMessage(msg);
  1568. IWARNLOG("%s", msg.str());
  1569. e->Release();
  1570. }
  1571. catch(...){
  1572. IWARNLOG("Unknown Exception caught within CTpWrapper::getDropZoneList");
  1573. }
  1574. }
  1575. void CTpWrapper::setAttPath(StringBuffer& Path,const char* PathToAppend,const char* AttName,const char* AttValue,StringBuffer& returnStr)
  1576. {
  1577. Path.append("/");
  1578. Path.append(PathToAppend);
  1579. Path.append("[@");
  1580. Path.append(AttName);
  1581. Path.append("=\"");
  1582. Path.append(AttValue);
  1583. Path.append("\"]");
  1584. StringBuffer rawPath;
  1585. const void* buff = (void*)Path.str();
  1586. JBASE64_Encode(buff,Path.length(),rawPath, false);
  1587. returnStr.append(rawPath.str());
  1588. }
  1589. void CTpWrapper::getAttPath(const char* Path,StringBuffer& returnStr)
  1590. {
  1591. StringBuffer decodedStr;
  1592. JBASE64_Decode(Path, returnStr);
  1593. }
  1594. void CTpWrapper::getServices(double version, const char* serviceType, const char* serviceName, IArrayOf<IConstHPCCService>& services)
  1595. {
  1596. Owned<IPropertyTreeIterator> itr = getGlobalConfigSP()->getElements("services");
  1597. ForEach(*itr)
  1598. {
  1599. IPropertyTree& service = itr->query();
  1600. //Only show the public services for now
  1601. if (!service.getPropBool("@public"))
  1602. continue;
  1603. const char* type = service.queryProp("@type");
  1604. if (isEmptyString(type) || (!isEmptyString(serviceType) && !strieq(serviceType, type)))
  1605. continue;
  1606. const char* name = service.queryProp("@name");
  1607. if (isEmptyString(name) || (!isEmptyString(serviceName) && !strieq(serviceName, name)))
  1608. continue;
  1609. Owned<IEspHPCCService> svc = createHPCCService();
  1610. svc->setName(name);
  1611. svc->setType(type);
  1612. svc->setPort(service.getPropInt("@port"));
  1613. if (service.getPropBool("@tls"))
  1614. svc->setTLSSecure(true);
  1615. services.append(*svc.getLink());
  1616. if (!isEmptyString(serviceName))
  1617. break;
  1618. }
  1619. }
  1620. class CContainerWUClusterInfo : public CSimpleInterfaceOf<IConstWUClusterInfo>
  1621. {
  1622. StringAttr name;
  1623. StringAttr serverQueue;
  1624. StringAttr agentQueue;
  1625. StringAttr thorQueue;
  1626. ClusterType platform;
  1627. unsigned clusterWidth;
  1628. StringArray thorProcesses;
  1629. public:
  1630. CContainerWUClusterInfo(const char* _name, const char* type, unsigned _clusterWidth)
  1631. : name(_name), clusterWidth(_clusterWidth)
  1632. {
  1633. StringBuffer queue;
  1634. if (strieq(type, "thor"))
  1635. {
  1636. thorQueue.set(getClusterThorQueueName(queue.clear(), name));
  1637. platform = ThorLCRCluster;
  1638. thorProcesses.append(name);
  1639. }
  1640. else if (strieq(type, "roxie"))
  1641. {
  1642. agentQueue.set(getClusterEclAgentQueueName(queue.clear(), name));
  1643. platform = RoxieCluster;
  1644. }
  1645. else
  1646. {
  1647. agentQueue.set(getClusterEclAgentQueueName(queue.clear(), name));
  1648. platform = HThorCluster;
  1649. }
  1650. serverQueue.set(getClusterEclCCServerQueueName(queue.clear(), name));
  1651. }
  1652. virtual IStringVal& getName(IStringVal& str) const override
  1653. {
  1654. str.set(name.get());
  1655. return str;
  1656. }
  1657. virtual IStringVal& getAgentQueue(IStringVal& str) const override
  1658. {
  1659. str.set(agentQueue);
  1660. return str;
  1661. }
  1662. virtual IStringVal& getServerQueue(IStringVal& str) const override
  1663. {
  1664. str.set(serverQueue);
  1665. return str;
  1666. }
  1667. virtual IStringVal& getThorQueue(IStringVal& str) const override
  1668. {
  1669. str.set(thorQueue);
  1670. return str;
  1671. }
  1672. virtual ClusterType getPlatform() const override
  1673. {
  1674. return platform;
  1675. }
  1676. virtual unsigned getSize() const override
  1677. {
  1678. return clusterWidth;
  1679. }
  1680. virtual bool isLegacyEclServer() const override
  1681. {
  1682. return false;
  1683. }
  1684. virtual IStringVal& getScope(IStringVal& str) const override
  1685. {
  1686. UNIMPLEMENTED;
  1687. }
  1688. virtual unsigned getNumberOfSlaveLogs() const override
  1689. {
  1690. UNIMPLEMENTED;
  1691. }
  1692. virtual IStringVal & getAgentName(IStringVal & str) const override
  1693. {
  1694. UNIMPLEMENTED;
  1695. }
  1696. virtual IStringVal & getECLSchedulerName(IStringVal & str) const override
  1697. {
  1698. UNIMPLEMENTED;
  1699. }
  1700. virtual const StringArray & getECLServerNames() const override
  1701. {
  1702. UNIMPLEMENTED;
  1703. }
  1704. virtual IStringVal & getRoxieProcess(IStringVal & str) const override
  1705. {
  1706. str.set(name.get());
  1707. return str;
  1708. }
  1709. virtual const StringArray & getThorProcesses() const override
  1710. {
  1711. return thorProcesses;
  1712. }
  1713. virtual const StringArray & getPrimaryThorProcesses() const override
  1714. {
  1715. UNIMPLEMENTED;
  1716. }
  1717. virtual const SocketEndpointArray & getRoxieServers() const override
  1718. {
  1719. UNIMPLEMENTED;
  1720. }
  1721. virtual const char *getLdapUser() const override
  1722. {
  1723. UNIMPLEMENTED;
  1724. }
  1725. virtual const char *getLdapPassword() const override
  1726. {
  1727. UNIMPLEMENTED;
  1728. }
  1729. virtual unsigned getRoxieRedundancy() const override
  1730. {
  1731. return 1;
  1732. }
  1733. virtual unsigned getChannelsPerNode() const override
  1734. {
  1735. return 1;
  1736. }
  1737. virtual int getRoxieReplicateOffset() const override
  1738. {
  1739. return 0;
  1740. }
  1741. virtual const char *getAlias() const override
  1742. {
  1743. UNIMPLEMENTED;
  1744. }
  1745. };
  1746. extern TPWRAPPER_API unsigned getContainerWUClusterInfo(CConstWUClusterInfoArray& clusters)
  1747. {
  1748. Owned<IPropertyTreeIterator> queues = getComponentConfigSP()->getElements("queues");
  1749. ForEach(*queues)
  1750. {
  1751. IPropertyTree& queue = queues->query();
  1752. Owned<IConstWUClusterInfo> cluster = new CContainerWUClusterInfo(queue.queryProp("@name"),
  1753. queue.queryProp("@type"), (unsigned) queue.getPropInt("@width", 1));
  1754. clusters.append(*cluster.getClear());
  1755. }
  1756. return clusters.ordinality();
  1757. }
  1758. extern TPWRAPPER_API unsigned getWUClusterInfo(CConstWUClusterInfoArray& clusters)
  1759. {
  1760. return getEnvironmentClusterInfo(clusters);
  1761. }
  1762. static IPropertyTree * getContainerClusterConfig(const char * clusterName)
  1763. {
  1764. VStringBuffer xpath("queues[@name='%s']", clusterName);
  1765. return getComponentConfigSP()->getPropTree(xpath);
  1766. }
  1767. extern TPWRAPPER_API IConstWUClusterInfo* getWUClusterInfoByName(const char* clusterName)
  1768. {
  1769. return getTargetClusterInfo(clusterName);
  1770. }
  1771. extern TPWRAPPER_API void initContainerRoxieTargets(MapStringToMyClass<ISmartSocketFactory>& connMap)
  1772. {
  1773. Owned<IPropertyTreeIterator> services = getGlobalConfigSP()->getElements("services[@type='roxie']");
  1774. ForEach(*services)
  1775. {
  1776. IPropertyTree& service = services->query();
  1777. const char* target = service.queryProp("@target");
  1778. if (isEmptyString(target) || isEmptyString(service.queryProp("@name"))) //bad config?
  1779. continue;
  1780. bool tls = service.getPropBool("@tls", false);
  1781. Owned<ISmartSocketFactory> sf = tls ? createSecureSmartSocketFactory(service) : createSmartSocketFactory(service);
  1782. connMap.setValue(target, sf.get());
  1783. }
  1784. }
  1785. extern TPWRAPPER_API unsigned getThorClusterNames(StringArray& targetNames, StringArray& queueNames)
  1786. {
  1787. StringArray thorNames, groupNames;
  1788. getEnvironmentThorClusterNames(thorNames, groupNames, targetNames, queueNames);
  1789. return targetNames.ordinality();
  1790. }
  1791. static std::set<std::string> validTargets;
  1792. static CriticalSection validTargetSect;
  1793. // called within validTargetSect lock
  1794. static void refreshValidTargets()
  1795. {
  1796. validTargets.clear();
  1797. Owned<IStringIterator> it = getTargetClusters(nullptr, nullptr);
  1798. ForEach(*it)
  1799. {
  1800. SCMStringBuffer s;
  1801. IStringVal& val = it->str(s);
  1802. if (validTargets.find(val.str()) == validTargets.end())
  1803. {
  1804. validTargets.insert(val.str());
  1805. PROGLOG("adding valid target: %s", val.str());
  1806. }
  1807. }
  1808. }
  1809. extern TPWRAPPER_API void validateTargetName(const char* target)
  1810. {
  1811. if (isEmptyString(target))
  1812. throw makeStringException(ECLWATCH_INVALID_CLUSTER_NAME, "Empty target name.");
  1813. CriticalBlock block(validTargetSect);
  1814. if (validTargets.find(target) == validTargets.end())
  1815. {
  1816. // bare metal rechecks in case env. changed since target list built
  1817. if (!validateTargetClusterName(target))
  1818. throw makeStringExceptionV(ECLWATCH_INVALID_CLUSTER_NAME, "Invalid target name: %s", target);
  1819. refreshValidTargets();
  1820. }
  1821. }
  1822. extern TPWRAPPER_API bool validateDataPlaneName(const char * remoteDali, const char * name)
  1823. {
  1824. return isProcessCluster(remoteDali, name);
  1825. }
  1826. bool getSashaService(StringBuffer &serviceAddress, const char *serviceName, bool failIfNotFound)
  1827. {
  1828. if (!isEmptyString(serviceName))
  1829. {
  1830. // all services are on same sasha on bare-metal as far as esp services are concerned
  1831. StringBuffer sashaAddress;
  1832. IArrayOf<IConstTpSashaServer> sashaservers;
  1833. CTpWrapper dummy;
  1834. dummy.getTpSashaServers(sashaservers);
  1835. if (0 != sashaservers.ordinality())
  1836. {
  1837. // NB: this code (in bare-matal) doesn't handle >1 Sasha.
  1838. // Prior to this change, it would have failed to [try to] contact any Sasha.
  1839. IConstTpSashaServer& sashaserver = sashaservers.item(0);
  1840. IArrayOf<IConstTpMachine> &sashaservermachine = sashaserver.getTpMachines();
  1841. sashaAddress.append(sashaservermachine.item(0).getNetaddress());
  1842. if (!sashaAddress.isEmpty())
  1843. {
  1844. serviceAddress.append(sashaAddress).append(':').append(DEFAULT_SASHA_PORT);
  1845. return true;
  1846. }
  1847. }
  1848. }
  1849. if (failIfNotFound)
  1850. throw makeStringExceptionV(ECLWATCH_ARCHIVE_SERVER_NOT_FOUND, "Sasha '%s' server not found", serviceName);
  1851. return false;
  1852. }
  1853. bool getSashaServiceEP(SocketEndpoint &serviceEndpoint, const char *service, bool failIfNotFound)
  1854. {
  1855. StringBuffer serviceAddress;
  1856. if (!getSashaService(serviceAddress, service, failIfNotFound))
  1857. return false;
  1858. serviceEndpoint.set(serviceAddress);
  1859. return true;
  1860. }
  1861. StringBuffer & getRoxieDefaultPlane(StringBuffer & plane, const char * roxieName)
  1862. {
  1863. Owned <IConstWUClusterInfo> clusterInfo(getTargetClusterInfo(roxieName));
  1864. StringBufferAdaptor process(plane);
  1865. if (clusterInfo && clusterInfo->getPlatform()==RoxieCluster)
  1866. clusterInfo->getRoxieProcess(process);
  1867. return plane;
  1868. }
  1869. StringArray & getRoxieDirectAccessPlanes(StringArray & planes, StringBuffer &defaultPlane, const char * roxieName, bool includeDefaultPlane)
  1870. {
  1871. getRoxieDefaultPlane(defaultPlane, roxieName);
  1872. if (defaultPlane.length() && includeDefaultPlane)
  1873. planes.append(defaultPlane);
  1874. return planes;
  1875. }