TpWrapper.cpp 79 KB

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