TpWrapper.cpp 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811
  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. const char* MSG_FAILED_GET_ENVIRONMENT_INFO = "Failed to get environment information.";
  22. //////////////////////////////////////////////////////////////////////
  23. // Construction/Destruction
  24. //////////////////////////////////////////////////////////////////////
  25. IPropertyTree* CTpWrapper::getEnvironment(const char* xpath)
  26. {
  27. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory();
  28. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  29. Owned<IPropertyTree> root = &constEnv->getPTree();
  30. if (root)
  31. {
  32. if (!xpath || !*xpath)
  33. {
  34. return LINK(root);
  35. }
  36. else
  37. {
  38. IPropertyTree* pSubTree = root->queryPropTree( xpath );
  39. if (pSubTree)
  40. return LINK(pSubTree);
  41. }
  42. }
  43. return NULL;
  44. }
  45. bool CTpWrapper::getClusterLCR(const char* clusterType, const char* clusterName)
  46. {
  47. bool bLCR = false;
  48. if (!clusterType || !*clusterType || !clusterName || !*clusterName)
  49. return bLCR;
  50. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory();
  51. if (!envFactory)
  52. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  53. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  54. if (!constEnv)
  55. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  56. Owned<IPropertyTree> root = &constEnv->getPTree();
  57. if (!root)
  58. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  59. StringBuffer xpath;
  60. xpath.appendf("Software/%s[@name='%s']", clusterType, clusterName);
  61. IPropertyTree* pCluster = root->queryPropTree( xpath.str() );
  62. if (!pCluster)
  63. throw MakeStringException(ECLWATCH_CLUSTER_NOT_IN_ENV_INFO, "'%s %s' is not defined.", clusterType, clusterName);
  64. bLCR = !pCluster->getPropBool("@Legacy");
  65. return bLCR;
  66. }
  67. void CTpWrapper::getClusterMachineList(double clientVersion,
  68. const char* ClusterType,
  69. const char* ClusterPath,
  70. const char* ClusterDirectory,
  71. IArrayOf<IEspTpMachine> &MachineList,
  72. bool& hasThorSpareProcess,
  73. const char* ClusterName)
  74. {
  75. try
  76. {
  77. StringBuffer returnStr,path;
  78. getAttPath(ClusterPath,path);
  79. set<string> machineNames; //used for checking duplicates
  80. if (strcmp(eqTHORMACHINES,ClusterType) == 0)
  81. {
  82. bool multiSlaves = false;
  83. getMachineList(eqThorMasterProcess,path.str(),"", ClusterDirectory, MachineList);
  84. getMachineList(clientVersion, ClusterName, eqThorSlaveProcess,path.str(),"", ClusterDirectory, multiSlaves, MachineList);
  85. unsigned count = MachineList.length();
  86. getMachineList(clientVersion, ClusterName, eqThorSpareProcess,path.str(),"", ClusterDirectory, multiSlaves, MachineList);
  87. //The multiSlaves is for legacy multiSlaves environment.
  88. //count < MachineList.length(): There is some node for eqThorSpareProcess being added to the MachineList.
  89. if (!multiSlaves &&(count < MachineList.length()))
  90. hasThorSpareProcess = true;
  91. }
  92. else if (strcmp(eqHOLEMACHINES,ClusterType) == 0)
  93. {
  94. getMachineList(eqHoleSocketProcess,path.str(),"", ClusterDirectory, MachineList);
  95. getMachineList(eqHoleProcessorProcess,path.str(),"", ClusterDirectory, MachineList);
  96. getMachineList(eqHoleControlProcess,path.str(),"", ClusterDirectory, MachineList);
  97. getMachineList(eqHoleCollatorProcess,path.str(),"", ClusterDirectory, MachineList);
  98. getMachineList(eqHoleStandbyProcess,path.str(),"", ClusterDirectory, MachineList);
  99. }
  100. else if (strcmp(eqROXIEMACHINES,ClusterType) == 0)
  101. {
  102. getMachineList("RoxieServerProcess",path.str(),"", ClusterDirectory, MachineList, &machineNames);
  103. }
  104. else if (strcmp(eqMACHINES,ClusterType) == 0)
  105. {
  106. //load a list of available machines.......
  107. getMachineList("Computer","/Environment/Hardware","", ClusterDirectory, MachineList);
  108. }
  109. else if (strcmp("AVAILABLEMACHINES",ClusterType) == 0)
  110. {
  111. getMachineList("Computer","/Environment/Hardware",eqMachineAvailablability, ClusterDirectory, MachineList);
  112. }
  113. else if (strcmp("DROPZONE",ClusterType) == 0)
  114. {
  115. getDropZoneList(eqDropZone,"/Environment/Software", ClusterDirectory, MachineList);
  116. }
  117. else if (strcmp("STANDBYNNODE",ClusterType) == 0)
  118. {
  119. bool multiSlaves = false;
  120. getMachineList(clientVersion, ClusterName,eqThorSpareProcess,path.str(),"", ClusterDirectory, multiSlaves, MachineList);
  121. getMachineList(eqHoleStandbyProcess,path.str(),"", ClusterDirectory, MachineList);
  122. }
  123. else if (strcmp("THORSPARENODES",ClusterType) == 0)
  124. {
  125. bool multiSlaves = false;
  126. getMachineList(clientVersion, ClusterName, eqThorSpareProcess,path.str(),"", ClusterDirectory, multiSlaves, MachineList);
  127. }
  128. else if (strcmp("HOLESTANDBYNODES",ClusterType) == 0)
  129. {
  130. getMachineList(eqHoleStandbyProcess,path.str(),"", ClusterDirectory, MachineList);
  131. }
  132. }
  133. catch(IException* e){
  134. StringBuffer msg;
  135. e->errorMessage(msg);
  136. WARNLOG("%s", msg.str());
  137. e->Release();
  138. }
  139. catch(...){
  140. WARNLOG("Unknown Exception caught within CTpWrapper::getClusterMachineList");
  141. }
  142. }
  143. void CTpWrapper::fetchInstances(const char* ServiceType, IPropertyTree& service,
  144. IArrayOf<IEspTpMachine>& tpMachines)
  145. {
  146. Owned<IPropertyTreeIterator> instances = service.getElements("Instance");
  147. if (instances->first()) {
  148. do {
  149. IPropertyTree& instanceNode = instances->query();
  150. IEspTpMachine* machine = createTpMachine("", "");
  151. getMachineInfo(*machine, instanceNode, "/Environment/Software", ServiceType, "@computer");
  152. machine->setPort( instanceNode.getPropInt("@port") );
  153. const char* directory = instanceNode.queryProp("@directory");
  154. if (directory && *directory)
  155. machine->setDirectory( directory );
  156. tpMachines.append(*machine);
  157. } while (instances->next());
  158. }
  159. }
  160. void CTpWrapper::getTpDaliServers(IArrayOf<IConstTpDali>& list)
  161. {
  162. Owned<IPropertyTree> root = getEnvironment("Software");
  163. if (!root)
  164. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  165. Owned<IPropertyTreeIterator> services= root->getElements(eqDali);
  166. ForEach(*services)
  167. {
  168. IPropertyTree& serviceTree = services->query();
  169. Owned<IEspTpDali> pService = createTpDali("","");
  170. const char* name = serviceTree.queryProp("@name");
  171. pService->setName(name);
  172. pService->setDescription(serviceTree.queryProp("@description"));
  173. pService->setBackupComputer(serviceTree.queryProp("@backupCoputer"));
  174. pService->setBackupDirectory(serviceTree.queryProp("@backupDirectory"));
  175. pService->setBuild(serviceTree.queryProp("@build"));
  176. pService->setType(eqDali);
  177. StringBuffer tmpDir;
  178. if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "dali", name, tmpDir))
  179. {
  180. const char* pStr = tmpDir.str();
  181. if (pStr)
  182. {
  183. if (strchr(pStr, '/'))
  184. tmpDir.append("/server");
  185. else
  186. tmpDir.append("\\server");
  187. pService->setLogDirectory( tmpDir.str() );
  188. }
  189. }
  190. else
  191. {
  192. pService->setLogDirectory(serviceTree.queryProp("@LogDir")); // backward compatible
  193. }
  194. IArrayOf<IEspTpMachine> tpMachines;
  195. fetchInstances(eqDali, serviceTree, tpMachines);
  196. pService->setTpMachines(tpMachines);
  197. list.append(*pService.getLink());
  198. }
  199. }
  200. void CTpWrapper::getTpEclServers(IArrayOf<IConstTpEclServer>& list, const char* serverName)
  201. {
  202. Owned<IPropertyTree> root = getEnvironment("Software");
  203. if (!root)
  204. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  205. Owned<IPropertyTreeIterator> services= root->getElements(eqEclServer);
  206. ForEach(*services)
  207. {
  208. IPropertyTree& serviceTree = services->query();
  209. Owned<IEspTpEclServer> pService = createTpEclServer("","");
  210. const char* name = serviceTree.queryProp("@name");
  211. if (serverName && stricmp(name, serverName))
  212. continue;
  213. pService->setName(name);
  214. pService->setDescription(serviceTree.queryProp("@description"));
  215. pService->setBuild(serviceTree.queryProp("@build"));
  216. StringBuffer tmpDir;
  217. if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "eclserver", name, tmpDir))
  218. {
  219. pService->setLogDirectory( tmpDir.str() );
  220. }
  221. else
  222. {
  223. pService->setLogDirectory(serviceTree.queryProp("@eclLogDir"));
  224. }
  225. pService->setType(eqEclServer);
  226. IArrayOf<IEspTpMachine> tpMachines;
  227. fetchInstances(eqEclServer, serviceTree, tpMachines);
  228. pService->setTpMachines(tpMachines);
  229. list.append(*pService.getLink());
  230. }
  231. }
  232. void CTpWrapper::getTpEclCCServers(IArrayOf<IConstTpEclServer>& list, const char* serverName)
  233. {
  234. Owned<IPropertyTree> root = getEnvironment("Software");
  235. if (!root)
  236. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  237. getTpEclCCServers(root, list, serverName);
  238. return;
  239. }
  240. void CTpWrapper::getTpEclCCServers(IPropertyTree* environmentSoftware, IArrayOf<IConstTpEclServer>& list, const char* serverName)
  241. {
  242. if (!environmentSoftware)
  243. return;
  244. Owned<IPropertyTreeIterator> services= environmentSoftware->getElements(eqEclCCServer);
  245. ForEach(*services)
  246. {
  247. IPropertyTree& serviceTree = services->query();
  248. const char* name = serviceTree.queryProp("@name");
  249. const char* logDir = serviceTree.queryProp("@logDir");
  250. if (serverName && stricmp(name, serverName))
  251. continue;
  252. Owned<IEspTpEclServer> pService = createTpEclServer("","");
  253. pService->setName(name);
  254. pService->setDescription(serviceTree.queryProp("@description"));
  255. pService->setBuild(serviceTree.queryProp("@build"));
  256. StringBuffer tmpDir;
  257. if (getConfigurationDirectory(environmentSoftware->queryPropTree("Directories"), "log", "eclccserver", name, tmpDir))
  258. {
  259. pService->setLogDirectory( tmpDir.str() );
  260. }
  261. else
  262. {
  263. pService->setLogDirectory(logDir);
  264. }
  265. pService->setType(eqEclCCServer);
  266. IArrayOf<IEspTpMachine> tpMachines;
  267. fetchInstances(eqEclCCServer, serviceTree, tpMachines);
  268. pService->setTpMachines(tpMachines);
  269. list.append(*pService.getLink());
  270. }
  271. }
  272. void CTpWrapper::getTpEclAgents(IArrayOf<IConstTpEclAgent>& list, const char* agentName)
  273. {
  274. Owned<IPropertyTree> root = getEnvironment("Software");
  275. if (!root)
  276. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  277. Owned<IPropertyTreeIterator> services= root->getElements(eqEclAgent);
  278. ForEach(*services)
  279. {
  280. IPropertyTree& serviceTree = services->query();
  281. const char* name = serviceTree.queryProp("@name");
  282. if (agentName && stricmp(name, agentName))
  283. continue;
  284. const char* daliServers = serviceTree.queryProp("@daliServers");
  285. const char* logDir = serviceTree.queryProp("@logDir");
  286. Owned<IEspTpEclAgent> pService = createTpEclAgent("","");
  287. pService->setDaliServer(daliServers);
  288. StringBuffer tmpDir;
  289. if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "eclagent", name, tmpDir))
  290. {
  291. pService->setLogDir( tmpDir.str() );
  292. }
  293. else
  294. {
  295. pService->setLogDir(logDir);
  296. }
  297. pService->setName(name);
  298. pService->setDescription(serviceTree.queryProp("@description"));
  299. pService->setBuild(serviceTree.queryProp("@build"));
  300. pService->setType(eqEclAgent);
  301. IArrayOf<IEspTpMachine> tpMachines;
  302. fetchInstances(eqEclAgent, serviceTree, tpMachines);
  303. pService->setTpMachines(tpMachines);
  304. list.append(*pService.getLink());
  305. }
  306. }
  307. void CTpWrapper::getTpEclSchedulers(IArrayOf<IConstTpEclScheduler>& list, const char* serverName)
  308. {
  309. Owned<IPropertyTree> root = getEnvironment("Software");
  310. if (!root)
  311. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  312. Owned<IPropertyTreeIterator> services= root->getElements(eqEclScheduler);
  313. ForEach(*services)
  314. {
  315. IPropertyTree& serviceTree = services->query();
  316. const char* name = serviceTree.queryProp("@name");
  317. const char* logDir = serviceTree.queryProp("@logDir");
  318. if (serverName && stricmp(name, serverName))
  319. continue;
  320. Owned<IEspTpEclScheduler> pService = createTpEclScheduler("","");
  321. pService->setName(name);
  322. pService->setDescription(serviceTree.queryProp("@description"));
  323. pService->setBuild(serviceTree.queryProp("@build"));
  324. StringBuffer tmpDir;
  325. if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "eclscheduler", name, tmpDir))
  326. {
  327. pService->setLogDirectory( tmpDir.str() );
  328. }
  329. else
  330. {
  331. pService->setLogDirectory(logDir);
  332. }
  333. pService->setType(eqEclScheduler);
  334. IArrayOf<IEspTpMachine> tpMachines;
  335. fetchInstances(eqEclScheduler, serviceTree, tpMachines);
  336. pService->setTpMachines(tpMachines);
  337. list.append(*pService.getLink());
  338. }
  339. }
  340. void CTpWrapper::getTpEspServers(IArrayOf<IConstTpEspServer>& list)
  341. {
  342. Owned<IPropertyTree> root = getEnvironment("Software");
  343. if (!root)
  344. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  345. Owned<IPropertyTreeIterator> services= root->getElements(eqEsp);
  346. ForEach(*services)
  347. {
  348. IPropertyTree& serviceTree = services->query();
  349. Owned<IEspTpEspServer> pService = createTpEspServer("","");
  350. const char* name = serviceTree.queryProp("@name");
  351. pService->setName(name);
  352. pService->setDescription(serviceTree.queryProp("@description"));
  353. pService->setBuild(serviceTree.queryProp("@build"));
  354. pService->setType(eqEsp);
  355. StringBuffer tmpDir;
  356. if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "esp", name, tmpDir))
  357. {
  358. pService->setLogDirectory( tmpDir.str() );
  359. }
  360. else
  361. {
  362. const char* logDir = serviceTree.queryProp("@logDir");
  363. if (logDir && *logDir)
  364. pService->setLogDirectory(logDir);
  365. }
  366. IArrayOf<IEspTpMachine> tpMachines;
  367. fetchInstances(eqEsp, serviceTree, tpMachines);
  368. pService->setTpMachines(tpMachines);
  369. Owned<IPropertyTreeIterator> iBinding = serviceTree.getElements("EspBinding");
  370. IArrayOf<IEspTpBinding> tpBindings;
  371. ForEach(*iBinding)
  372. {
  373. IPropertyTree& binding = iBinding->query();
  374. const char* service = binding.queryProp("@service");
  375. if (service && *service)
  376. {
  377. Owned<IEspTpBinding> pTpBinding = createTpBinding("", "");
  378. pTpBinding->setName (binding.queryProp("@name"));
  379. pTpBinding->setService(service);
  380. pTpBinding->setProtocol (binding.queryProp("@protocol"));
  381. pTpBinding->setPort (binding.queryProp("@port"));
  382. StringBuffer xpath;
  383. xpath.appendf("EspService[@name='%s']", service);
  384. IPropertyTree* pServiceNode = root->queryPropTree(xpath.str());
  385. if (pServiceNode)
  386. {
  387. const char* serviceType = pServiceNode->queryProp("Properties/@type");
  388. if (serviceType && *serviceType)
  389. pTpBinding->setServiceType(serviceType);
  390. const char* bindingType = pServiceNode->queryProp("Properties/@bindingType");
  391. if (bindingType && *bindingType)
  392. pTpBinding->setBindingType(bindingType);
  393. const char* buildSet = pServiceNode->queryProp("@buildSet");
  394. if (buildSet && *buildSet)
  395. pTpBinding->setServiceBuildSet(buildSet);
  396. }
  397. tpBindings.append(*pTpBinding.getLink());
  398. }
  399. }
  400. pService->setTpBindings( tpBindings);
  401. list.append(*pService.getLink());
  402. }
  403. }
  404. void CTpWrapper::getTpDfuServers(IArrayOf<IConstTpDfuServer>& list)
  405. {
  406. Owned<IPropertyTree> root = getEnvironment("Software");
  407. if (!root)
  408. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  409. Owned<IPropertyTreeIterator> services= root->getElements(eqDfu);
  410. ForEach(*services)
  411. {
  412. IPropertyTree& serviceTree = services->query();
  413. Owned<IEspTpDfuServer> pService = createTpDfuServer("","");
  414. const char* name = serviceTree.queryProp("@name");
  415. pService->setName(name);
  416. pService->setDescription(serviceTree.queryProp("@description"));
  417. pService->setBuild(serviceTree.queryProp("@build"));
  418. pService->setQueue(serviceTree.queryProp("@queue"));
  419. pService->setType(eqDfu);
  420. StringBuffer tmpDir;
  421. if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "dfuserver", name, tmpDir))
  422. {
  423. pService->setLogDirectory( tmpDir.str() );
  424. }
  425. else
  426. {
  427. pService->setLogDirectory(serviceTree.queryProp("@dfuLogDir"));
  428. }
  429. IArrayOf<IEspTpMachine> tpMachines;
  430. fetchInstances(eqDfu, serviceTree, tpMachines);
  431. pService->setTpMachines(tpMachines);
  432. list.append(*pService.getLink());
  433. }
  434. }
  435. void CTpWrapper::getTpSashaServers(IArrayOf<IConstTpSashaServer>& list)
  436. {
  437. Owned<IPropertyTree> root = getEnvironment("Software");
  438. if (!root)
  439. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  440. Owned<IPropertyTreeIterator> services= root->getElements(eqSashaServer);
  441. ForEach(*services)
  442. {
  443. IPropertyTree& serviceTree = services->query();
  444. Owned<IEspTpSashaServer> pService = createTpSashaServer("","");
  445. const char* name = serviceTree.queryProp("@name");
  446. pService->setName(name);
  447. pService->setDescription(serviceTree.queryProp("@description"));
  448. pService->setBuild(serviceTree.queryProp("@build"));
  449. StringBuffer tmpDir;
  450. if (getConfigurationDirectory(root->queryPropTree("Directories"), "log", "sasha", name, tmpDir))
  451. {
  452. pService->setLogDirectory( tmpDir.str() );
  453. }
  454. else
  455. {
  456. pService->setLogDirectory(serviceTree.queryProp("@logDir"));
  457. }
  458. IArrayOf<IEspTpMachine> tpMachines;
  459. fetchInstances(eqSashaServer, serviceTree, tpMachines);
  460. pService->setTpMachines(tpMachines);
  461. list.append(*pService.getLink());
  462. }
  463. }
  464. void CTpWrapper::getTpLdapServers(IArrayOf<IConstTpLdapServer>& list)
  465. {
  466. Owned<IPropertyTree> root = getEnvironment("Software");
  467. if (!root)
  468. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  469. Owned<IPropertyTreeIterator> services= root->getElements(eqLdapServer);
  470. ForEach(*services)
  471. {
  472. IPropertyTree& serviceTree = services->query();
  473. Owned<IEspTpLdapServer> pService = createTpLdapServer("","");
  474. pService->setName(serviceTree.queryProp("@name"));
  475. pService->setDescription(serviceTree.queryProp("@description"));
  476. pService->setBuild(serviceTree.queryProp("@build"));
  477. IArrayOf<IEspTpMachine> tpMachines;
  478. fetchInstances(eqLdapServer, serviceTree, tpMachines);
  479. int port = serviceTree.getPropInt("@ldapPort", 0);
  480. if (tpMachines.length() == 0)
  481. {
  482. const char* computer = serviceTree.queryProp("@computer");
  483. if (computer && *computer)
  484. {
  485. Owned<IEspTpMachine> machine = createTpMachine("", "");
  486. setMachineInfo(computer, "LDAPServerProcess", *machine);
  487. StringBuffer tmpPath;
  488. StringBuffer ppath("/Environment/Software");
  489. setAttPath(ppath, "Instance", "name", computer, tmpPath);
  490. machine->setPath(tmpPath.str());
  491. if (port)
  492. machine->setPort( port );
  493. tpMachines.append(*machine.getLink());
  494. }
  495. }
  496. else
  497. {
  498. const int nMachines = tpMachines.length();
  499. for (int i=0; i<nMachines; i++)
  500. tpMachines.item(i).setPort(port);
  501. }
  502. pService->setTpMachines(tpMachines);
  503. list.append(*pService.getLink());
  504. }
  505. }
  506. void CTpWrapper::getTpDropZones(IArrayOf<IConstTpDropZone>& list)
  507. {
  508. Owned<IPropertyTree> root = getEnvironment("Software");
  509. if (!root)
  510. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  511. Owned<IEnvironmentFactory> factory = getEnvironmentFactory();
  512. Owned<IConstEnvironment> m_pConstEnvironment = factory->openEnvironment();
  513. Owned<IPropertyTreeIterator> services= root->getElements(eqDropZone);
  514. ForEach(*services)
  515. {
  516. IPropertyTree& serviceTree = services->query();
  517. if (!serviceTree.getPropBool("@ECLWatchVisible", true))
  518. continue;
  519. Owned<IEspTpDropZone> pService = createTpDropZone("","");
  520. pService->setName(serviceTree.queryProp("@name"));
  521. pService->setDescription(serviceTree.queryProp("@description"));
  522. pService->setBuild(serviceTree.queryProp("@build"));
  523. const char* directory = serviceTree.queryProp("@directory");
  524. IArrayOf<IEspTpMachine> tpMachines;
  525. const char* computer = serviceTree.queryProp("@computer");
  526. if (computer && *computer)
  527. {
  528. StringBuffer computerName;
  529. if (strcmp(computer, "."))
  530. computerName.append(computer);
  531. else
  532. computerName.append("localhost");
  533. Owned<IEspTpMachine> machine = createTpMachine("", "");
  534. setMachineInfo(computerName, "DropZone", *machine);
  535. StringBuffer tmpPath;
  536. StringBuffer ppath("/Environment/Software");
  537. setAttPath(ppath, "", "name", computerName, tmpPath);
  538. machine->setPath(tmpPath.str());
  539. if (directory && *directory)
  540. machine->setDirectory(directory);
  541. Owned<IConstMachineInfo> pMachineInfo = m_pConstEnvironment->getMachine(computerName.str());
  542. machine->setOS(pMachineInfo->getOS());
  543. tpMachines.append(*machine.getLink());
  544. }
  545. pService->setTpMachines(tpMachines);
  546. list.append(*pService.getLink());
  547. }
  548. }
  549. void CTpWrapper::getTpFTSlaves(IArrayOf<IConstTpFTSlave>& list)
  550. {
  551. Owned<IPropertyTree> root = getEnvironment("Software");
  552. if (!root)
  553. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  554. Owned<IPropertyTreeIterator> services= root->getElements(eqFTSlave);
  555. ForEach(*services)
  556. {
  557. IPropertyTree& serviceTree = services->query();
  558. Owned<IEspTpFTSlave> pService = createTpFTSlave("","");
  559. pService->setName(serviceTree.queryProp("@name"));
  560. pService->setDescription(serviceTree.queryProp("@description"));
  561. pService->setBuild(serviceTree.queryProp("@build"));
  562. IArrayOf<IEspTpMachine> tpMachines;
  563. fetchInstances(eqFTSlave, serviceTree, tpMachines);
  564. pService->setTpMachines(tpMachines);
  565. list.append(*pService.getLink());
  566. }
  567. }
  568. void CTpWrapper::getTpDkcSlaves(IArrayOf<IConstTpDkcSlave>& list)
  569. {
  570. Owned<IPropertyTree> root = getEnvironment("Software");
  571. if (!root)
  572. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  573. Owned<IPropertyTreeIterator> services= root->getElements(eqDkcSlave);
  574. ForEach(*services)
  575. {
  576. IPropertyTree& serviceTree = services->query();
  577. Owned<IEspTpDkcSlave> pService =createTpDkcSlave("","");
  578. pService->setName(serviceTree.queryProp("@name"));
  579. pService->setDescription(serviceTree.queryProp("@description"));
  580. pService->setBuild(serviceTree.queryProp("@build"));
  581. IArrayOf<IEspTpMachine> tpMachines;
  582. fetchInstances(eqDkcSlave, serviceTree, tpMachines);
  583. pService->setTpMachines(tpMachines);
  584. list.append(*pService.getLink());
  585. }
  586. }
  587. void CTpWrapper::getTpGenesisServers(IArrayOf<IConstTpGenesisServer>& list)
  588. {
  589. Owned<IPropertyTree> root = getEnvironment("Software");
  590. if (!root)
  591. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  592. Owned<IPropertyTreeIterator> services= root->getElements(eqGenesisServer);
  593. ForEach(*services)
  594. {
  595. IPropertyTree& serviceTree = services->query();
  596. Owned<IEspTpGenesisServer> pService = createTpGenesisServer("","");
  597. pService->setName(serviceTree.queryProp("@name"));
  598. pService->setDescription(serviceTree.queryProp("@description"));
  599. pService->setBuild(serviceTree.queryProp("@build"));
  600. IArrayOf<IEspTpMachine> tpMachines;
  601. fetchInstances(eqGenesisServer, serviceTree, tpMachines);
  602. pService->setTpMachines(tpMachines);
  603. list.append(*pService.getLink());
  604. }
  605. }
  606. void CTpWrapper::getTargetClusterList(IArrayOf<IEspTpLogicalCluster>& clusters, const char* clusterType, const char* clusterName)
  607. {
  608. Owned<IPropertyTree> root = getEnvironment("Software");
  609. if (!root)
  610. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  611. Owned<IPropertyTreeIterator> clusterIterator = root->getElements("Topology/Cluster");
  612. if (clusterIterator->first())
  613. {
  614. do {
  615. IPropertyTree &cluster0 = clusterIterator->query();
  616. StringBuffer processName;
  617. const char* clusterName0 = cluster0.queryProp("@name");
  618. if (!clusterName0 || !*clusterName0)
  619. continue;
  620. bool bAdd = false;
  621. if (!clusterType || !*clusterType)
  622. {
  623. bAdd = true;
  624. }
  625. else
  626. {
  627. Owned<IPropertyTreeIterator> clusters0= cluster0.getElements(clusterType);
  628. if (clusters0->first())
  629. {
  630. if (!clusterName || !*clusterName)
  631. {
  632. IPropertyTree &cluster = clusters0->query();
  633. const char* name = cluster.queryProp("@process");
  634. if (name && *name)
  635. processName.append(name);
  636. bAdd = true;
  637. }
  638. else
  639. {
  640. do {
  641. IPropertyTree &cluster = clusters0->query();
  642. const char* name = cluster.queryProp("@process");
  643. if (!name||!*name)
  644. continue;
  645. if (!stricmp(name, clusterName))
  646. {
  647. bAdd = true;
  648. break;
  649. }
  650. } while (clusters0->next());
  651. }
  652. }
  653. }
  654. if (!bAdd)
  655. continue;
  656. IEspTpLogicalCluster* pService = createTpLogicalCluster("","");
  657. pService->setName(clusterName0);
  658. if (processName.length() > 0)
  659. pService->setProcess(processName);
  660. pService->setLanguageVersion("3.0.0");
  661. clusters.append(*pService);
  662. } while (clusterIterator->next());
  663. }
  664. }
  665. void CTpWrapper::queryTargetClusterProcess(double version, const char* processName, const char* clusterType, IArrayOf<IConstTpCluster>& clusterList)
  666. {
  667. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory();
  668. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  669. Owned<IPropertyTree> root = &constEnv->getPTree();
  670. if (!root)
  671. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  672. StringBuffer xpath;
  673. xpath.appendf("Software/%s[@name='%s']", clusterType, processName);
  674. IPropertyTree* pClusterTree = root->queryPropTree(xpath.str());
  675. if (!pClusterTree)
  676. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  677. const char* queueName = NULL;
  678. if (processName&&(stricmp(clusterType,eqThorCluster)==0))
  679. {
  680. // only for multi-thor
  681. // only list first thor cluster on queue
  682. queueName = pClusterTree->queryProp("@queueName");
  683. if (!queueName||!*queueName)
  684. queueName = processName;
  685. }
  686. IEspTpCluster* clusterInfo = createTpCluster("","");
  687. clusterInfo->setName(processName);
  688. if (queueName && *queueName)
  689. clusterInfo->setQueueName(queueName);
  690. else
  691. clusterInfo->setQueueName(processName);
  692. clusterInfo->setDesc(processName);
  693. clusterInfo->setBuild( pClusterTree->queryProp("@build") );
  694. clusterInfo->setType(clusterType);
  695. StringBuffer tmpPath;
  696. StringBuffer path("/Environment/Software");
  697. setAttPath(path, clusterType, "name", processName, tmpPath);
  698. clusterInfo->setPath(tmpPath.str());
  699. StringBuffer dirStr;
  700. if (!getConfigurationDirectory(root->queryPropTree("Software/Directories"), "run", clusterType, processName, dirStr))
  701. {
  702. dirStr.clear().append(pClusterTree->queryProp("@directory"));
  703. }
  704. clusterInfo->setDirectory(dirStr.str());
  705. StringBuffer tmpDir;
  706. if (getConfigurationDirectory(root->queryPropTree("Software/Directories"), "log", clusterType, processName, tmpDir))
  707. {
  708. clusterInfo->setLogDirectory( tmpDir.str() );
  709. }
  710. else
  711. {
  712. const char* logDir = pClusterTree->queryProp("@logDir");
  713. if (logDir)
  714. clusterInfo->setLogDirectory( logDir );
  715. }
  716. clusterInfo->setPrefix("");
  717. if(pClusterTree->hasProp("@dataBuild"))
  718. clusterInfo->setDataModel(pClusterTree->queryProp("@dataBuild"));
  719. clusterList.append(*clusterInfo);
  720. //find out OS
  721. OS_TYPE os = OS_WINDOWS;
  722. unsigned int clusterTypeLen = strlen(clusterType);
  723. const char* childType = NULL;
  724. const char* clusterType0 = NULL;
  725. if (clusterTypeLen > 4)
  726. {
  727. if (!strnicmp(clusterType, "roxie", 4))
  728. {
  729. childType = "RoxieServerProcess[1]";
  730. clusterType0 = eqROXIEMACHINES;
  731. }
  732. else if (!strnicmp(clusterType, "thor", 4))
  733. {
  734. childType = "ThorMasterProcess";
  735. clusterType0 = eqTHORMACHINES;
  736. }
  737. else
  738. {
  739. childType = "HoleControlProcess";
  740. clusterType0 = eqHOLEMACHINES;
  741. }
  742. }
  743. if (childType)
  744. {
  745. IPropertyTree* pChild = pClusterTree->queryPropTree(childType);
  746. if (pChild)
  747. {
  748. const char* computer = pChild->queryProp("@computer");
  749. IPropertyTree* pHardware = root->queryPropTree("Hardware");
  750. if (computer && *computer && pHardware)
  751. {
  752. StringBuffer xpath;
  753. xpath.appendf("Computer[@name='%s']/@computerType", computer);
  754. const char* computerType = pHardware->queryProp( xpath.str() );
  755. if (computerType && *computerType)
  756. {
  757. xpath.clear().appendf("ComputerType[@name='%s']/@opSys", computerType);
  758. const char* opSys = pHardware->queryProp( xpath.str() );
  759. if (!stricmp(opSys, "linux") || !stricmp( opSys, "solaris"))
  760. os = OS_LINUX;
  761. }
  762. }
  763. }
  764. }
  765. clusterInfo->setOS(os);
  766. if (clusterType0 && *clusterType0)
  767. {
  768. bool hasThorSpareProcess = false;
  769. IArrayOf<IEspTpMachine> machineList;
  770. getClusterMachineList(version, clusterType0, tmpPath.str(), dirStr.str(), machineList, hasThorSpareProcess, processName);
  771. if (machineList.length() > 0)
  772. clusterInfo->setTpMachines(machineList);
  773. if (version > 1.14)
  774. clusterInfo->setHasThorSpareProcess(hasThorSpareProcess);
  775. }
  776. return;
  777. }
  778. void CTpWrapper::queryTargetClusters(double version, const char* clusterType, const char* clusterName, IArrayOf<IEspTpTargetCluster>& targetClusterList)
  779. {
  780. try
  781. {
  782. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory();
  783. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  784. Owned<IPropertyTree> root = &constEnv->getPTree();
  785. if (!root)
  786. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  787. Owned<IPropertyTreeIterator> clusters= root->getElements("Software/Topology/Cluster");
  788. if (!clusters->first())
  789. return;
  790. do {
  791. IPropertyTree &cluster = clusters->query();
  792. const char* name = cluster.queryProp("@name");
  793. if (!name||!*name)
  794. continue;
  795. if (clusterName && *clusterName && strcmp(clusterName, name))
  796. continue;
  797. const char* prefix = cluster.queryProp("@prefix");
  798. Owned<IPropertyTreeIterator> thorClusters= cluster.getElements(eqThorCluster);
  799. Owned<IPropertyTreeIterator> roxieClusters= cluster.getElements(eqRoxieCluster);
  800. Owned<IPropertyTreeIterator> eclCCServerProcesses= cluster.getElements(eqEclCCServer);
  801. Owned<IPropertyTreeIterator> eclServerProcesses= cluster.getElements(eqEclServer);
  802. Owned<IPropertyTreeIterator> eclSchedulerProcesses= cluster.getElements(eqEclScheduler);
  803. Owned<IPropertyTreeIterator> eclAgentProcesses= cluster.getElements(eqEclAgent);
  804. if (clusterType && !stricmp(clusterType, eqThorCluster) && !thorClusters->first())
  805. continue;
  806. if (clusterType && !stricmp(clusterType, eqRoxieCluster) && !roxieClusters->first())
  807. continue;
  808. if (clusterType && !stricmp(clusterType, eqHoleCluster) && (roxieClusters->first() || thorClusters->first()))
  809. continue;
  810. IEspTpTargetCluster* clusterInfo = createTpTargetCluster("","");
  811. clusterInfo->setName(name);
  812. if (prefix && *prefix)
  813. clusterInfo->setPrefix(prefix);
  814. //Read Cluster process
  815. clusterInfo->setType(eqHoleCluster);
  816. IArrayOf<IConstTpCluster>& clusterList = clusterInfo->getTpClusters();
  817. if (thorClusters->first())
  818. {
  819. clusterInfo->setType(eqThorCluster);
  820. do {
  821. IPropertyTree &thorCluster = thorClusters->query();
  822. const char* process = thorCluster.queryProp("@process");
  823. if (process && *process)
  824. {
  825. queryTargetClusterProcess(version, process, eqThorCluster, clusterList);
  826. }
  827. } while (thorClusters->next());
  828. }
  829. if (roxieClusters->first())
  830. {
  831. clusterInfo->setType(eqRoxieCluster);
  832. do {
  833. IPropertyTree &roxieCluster = roxieClusters->query();
  834. const char* process = roxieCluster.queryProp("@process");
  835. if (process && *process)
  836. {
  837. queryTargetClusterProcess(version, process, eqRoxieCluster, clusterList);
  838. }
  839. } while (roxieClusters->next());
  840. }
  841. //Read eclCCServer process
  842. IArrayOf<IConstTpEclServer>& eclCCServerList = clusterInfo->getTpEclCCServers();
  843. if (eclCCServerProcesses->first())
  844. {
  845. IPropertyTree &eclCCServerProcess = eclCCServerProcesses->query();
  846. const char* process = eclCCServerProcess.queryProp("@process");
  847. if (process && *process)
  848. {
  849. getTpEclCCServers(eclCCServerList, process);
  850. }
  851. }
  852. //Read eclServer process
  853. if ((version >= 1.19) && eclServerProcesses->first())
  854. {
  855. IArrayOf<IConstTpEclServer>& eclServerList = clusterInfo->getTpEclServers();
  856. IPropertyTree &eclServerProcess = eclServerProcesses->query();
  857. const char* process = eclServerProcess.queryProp("@process");
  858. if (process && *process)
  859. {
  860. getTpEclServers(eclServerList, process);
  861. }
  862. }
  863. //Read eclAgent process
  864. IArrayOf<IConstTpEclAgent>& eclAgentList = clusterInfo->getTpEclAgents();
  865. if (eclAgentProcesses->first())
  866. {
  867. IPropertyTree &eclAgentProcess = eclAgentProcesses->query();
  868. const char* process = eclAgentProcess.queryProp("@process");
  869. if (process && *process)
  870. {
  871. getTpEclAgents(eclAgentList, process);
  872. }
  873. }
  874. //Read eclScheduler process
  875. IArrayOf<IConstTpEclScheduler>& eclSchedulerList = clusterInfo->getTpEclSchedulers();
  876. if (eclSchedulerProcesses->first())
  877. {
  878. IPropertyTree &eclSchedulerProcess = eclSchedulerProcesses->query();
  879. const char* process = eclSchedulerProcess.queryProp("@process");
  880. if (process && *process)
  881. {
  882. getTpEclSchedulers(eclSchedulerList, process);
  883. }
  884. }
  885. targetClusterList.append(*clusterInfo);
  886. } while (clusters->next());
  887. }
  888. catch(IException* e){
  889. StringBuffer msg;
  890. e->errorMessage(msg);
  891. WARNLOG("%s", msg.str());
  892. e->Release();
  893. }
  894. catch(...){
  895. WARNLOG("Unknown Exception caught within CTpWrapper::getClusterList");
  896. }
  897. }
  898. void CTpWrapper::getClusterProcessList(const char* ClusterType, IArrayOf<IEspTpCluster>& clusterList, bool ignoreduplicatqueues, bool ignoreduplicategroups)
  899. {
  900. try
  901. {
  902. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory();
  903. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  904. Owned<IPropertyTree> root = &constEnv->getPTree();
  905. if (root)
  906. {
  907. IPropertyTree* pSoftware = root->queryPropTree("Software");
  908. if (!pSoftware)
  909. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  910. StringArray queuesdone;
  911. StringArray groupsdone;
  912. Owned<IPropertyTreeIterator> clusters= pSoftware->getElements(ClusterType);
  913. if (clusters->first()) {
  914. do {
  915. IPropertyTree &cluster = clusters->query();
  916. const char* name = cluster.queryProp("@name");
  917. if (!name||!*name)
  918. continue;
  919. const char* queueName = NULL;
  920. const char* groupName = NULL;
  921. if (name&&(stricmp(ClusterType,eqThorCluster)==0))
  922. {
  923. // only for multi-thor
  924. // only list first thor cluster on queue
  925. queueName = cluster.queryProp("@queueName");
  926. if (!queueName||!*queueName)
  927. queueName = name;
  928. if (ignoreduplicatqueues)
  929. {
  930. bool done=false;
  931. ForEachItemIn(i,queuesdone)
  932. {
  933. if (strcmp(queuesdone.item(i),queueName)==0)
  934. {
  935. done = true;
  936. break;
  937. }
  938. }
  939. if (done)
  940. continue;
  941. queuesdone.append(queueName);
  942. }
  943. groupName = cluster.queryProp("@nodeGroup");
  944. if (!groupName||!*groupName)
  945. groupName = name;
  946. if (ignoreduplicategroups)
  947. {
  948. bool done=false;
  949. ForEachItemIn(i,groupsdone)
  950. {
  951. if (strcmp(groupsdone.item(i),groupName)==0)
  952. {
  953. done = true;
  954. break;
  955. }
  956. }
  957. if (done)
  958. continue;
  959. groupsdone.append(groupName);
  960. }
  961. }
  962. IEspTpCluster* clusterInfo = createTpCluster("","");
  963. clusterInfo->setName(name);
  964. if (queueName && *queueName)
  965. clusterInfo->setQueueName(queueName);
  966. else
  967. clusterInfo->setQueueName(name);
  968. clusterInfo->setDesc(name);
  969. clusterInfo->setBuild( cluster.queryProp("@build") );
  970. StringBuffer path("/Environment/Software");
  971. StringBuffer tmpPath;
  972. setAttPath(path, ClusterType, "name", name, tmpPath);
  973. clusterInfo->setType(ClusterType);
  974. StringBuffer tmpDir;
  975. if (getConfigurationDirectory(root->queryPropTree("Software/Directories"), "run", ClusterType, name, tmpDir))
  976. {
  977. clusterInfo->setDirectory(tmpDir.str());
  978. }
  979. else
  980. {
  981. clusterInfo->setDirectory(cluster.queryProp("@directory"));
  982. }
  983. tmpDir.clear();
  984. if (getConfigurationDirectory(root->queryPropTree("Software/Directories"), "log", ClusterType, name, tmpDir))
  985. {
  986. clusterInfo->setLogDirectory( tmpDir.str() );
  987. }
  988. else
  989. {
  990. const char* logDir = cluster.queryProp("@logDir");
  991. if (logDir)
  992. clusterInfo->setLogDirectory( logDir );
  993. }
  994. clusterInfo->setPath(tmpPath.str());
  995. clusterInfo->setPrefix("");
  996. if(cluster.hasProp("@dataBuild"))
  997. clusterInfo->setDataModel(cluster.queryProp("@dataBuild"));
  998. clusterList.append(*clusterInfo);
  999. //find out OS
  1000. OS_TYPE os = OS_WINDOWS;
  1001. unsigned int clusterTypeLen = strlen(ClusterType);
  1002. const char* childType = NULL;
  1003. if (clusterTypeLen > 4)
  1004. {
  1005. if (!strnicmp(ClusterType, "roxie", 4))
  1006. childType = "RoxieServerProcess[1]";
  1007. else if (!strnicmp(ClusterType, "thor", 4))
  1008. childType = "ThorMasterProcess";
  1009. else
  1010. childType = "HoleControlProcess";
  1011. }
  1012. if (childType)
  1013. {
  1014. IPropertyTree* pChild = cluster.queryPropTree(childType);
  1015. if (pChild)
  1016. {
  1017. const char* computer = pChild->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. }
  1033. }
  1034. clusterInfo->setOS(os);
  1035. } while (clusters->next());
  1036. }
  1037. }
  1038. }
  1039. catch(IException* e){
  1040. StringBuffer msg;
  1041. e->errorMessage(msg);
  1042. WARNLOG("%s", msg.str());
  1043. e->Release();
  1044. }
  1045. catch(...){
  1046. WARNLOG("Unknown Exception caught within CTpWrapper::getClusterList");
  1047. }
  1048. }
  1049. void CTpWrapper::getHthorClusterList(IArrayOf<IEspTpCluster>& clusterList)
  1050. {
  1051. try
  1052. {
  1053. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory();
  1054. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  1055. Owned<IPropertyTree> root = &constEnv->getPTree();
  1056. if (root)
  1057. {
  1058. IPropertyTree* pSoftware = root->queryPropTree("Software");
  1059. const char * ClusterType = "EclAgentProcess";
  1060. Owned<IPropertyTreeIterator> clusters(pSoftware->getElements(ClusterType));
  1061. ForEach(*clusters)
  1062. {
  1063. IPropertyTree &cluster = clusters->query();
  1064. const char* name = cluster.queryProp("@name");
  1065. if (!name||!*name)
  1066. continue;
  1067. unsigned ins = 0;
  1068. Owned<IPropertyTreeIterator> insts = clusters->query().getElements("Instance");
  1069. ForEach(*insts)
  1070. {
  1071. const char *na = insts->query().queryProp("@netAddress");
  1072. if (na&&*na)
  1073. {
  1074. SocketEndpoint ep(na);
  1075. if (!ep.isNull())
  1076. {
  1077. ins++;
  1078. StringBuffer gname("hthor__");
  1079. gname.append(name);
  1080. if (ins>1)
  1081. gname.append('_').append(ins);
  1082. IEspTpCluster* clusterInfo = createTpCluster("","");
  1083. clusterInfo->setName(gname.str());
  1084. clusterInfo->setQueueName(name);
  1085. clusterInfo->setDesc(cluster.queryProp("@build"));
  1086. clusterInfo->setBuild( cluster.queryProp("@description") );
  1087. StringBuffer path("/Environment/Software");
  1088. StringBuffer tmpPath;
  1089. setAttPath(path, ClusterType, "name", name, tmpPath);
  1090. clusterInfo->setType(ClusterType);
  1091. clusterInfo->setDirectory(insts->query().queryProp("@directory"));
  1092. StringBuffer tmpDir;
  1093. if (getConfigurationDirectory(root->queryPropTree("Software/Directories"), "run", ClusterType, name, tmpDir))
  1094. {
  1095. clusterInfo->setDirectory(tmpDir.str());
  1096. }
  1097. else
  1098. {
  1099. clusterInfo->setDirectory(insts->query().queryProp("@directory"));
  1100. }
  1101. clusterInfo->setPath(tmpPath.str());
  1102. clusterList.append(*clusterInfo);
  1103. //find out OS
  1104. OS_TYPE os = OS_WINDOWS;
  1105. const char* computer = insts->query().queryProp("@computer");
  1106. IPropertyTree* pHardware = root->queryPropTree("Hardware");
  1107. if (computer && *computer && pHardware)
  1108. {
  1109. StringBuffer xpath;
  1110. xpath.appendf("Computer[@name='%s']/@computerType", computer);
  1111. const char* computerType = pHardware->queryProp( xpath.str() );
  1112. if (computerType && *computerType)
  1113. {
  1114. xpath.clear().appendf("ComputerType[@name='%s']/@opSys", computerType);
  1115. const char* opSys = pHardware->queryProp( xpath.str() );
  1116. if (!stricmp(opSys, "linux") || !stricmp( opSys, "solaris"))
  1117. os = OS_LINUX;
  1118. }
  1119. }
  1120. clusterInfo->setOS(os);
  1121. }
  1122. }
  1123. }
  1124. }
  1125. }
  1126. }
  1127. catch(IException* e){
  1128. StringBuffer msg;
  1129. e->errorMessage(msg);
  1130. WARNLOG("%s", msg.str());
  1131. e->Release();
  1132. }
  1133. catch(...){
  1134. WARNLOG("Unknown Exception caught within CTpWrapper::getHthorClusterList");
  1135. }
  1136. }
  1137. void CTpWrapper::getGroupList(double espVersion, const char* kindReq, IArrayOf<IEspTpGroup> &GroupList)
  1138. {
  1139. try
  1140. {
  1141. Owned<IRemoteConnection> conn = querySDS().connect("/Groups", myProcessSession(), RTM_LOCK_READ, SDS_LOCK_TIMEOUT);
  1142. Owned<IPropertyTreeIterator> groups= conn->queryRoot()->getElements("Group");
  1143. if (groups->first())
  1144. {
  1145. do
  1146. {
  1147. IPropertyTree &group = groups->query();
  1148. const char* kind = group.queryProp("@kind");
  1149. if (kindReq && *kindReq && !strieq(kindReq, kind))
  1150. continue;
  1151. IEspTpGroup* pGroup = createTpGroup("","");
  1152. const char* name = group.queryProp("@name");
  1153. pGroup->setName(name);
  1154. if (kind && *kind && (espVersion >= 1.21))
  1155. {
  1156. pGroup->setKind(kind);
  1157. pGroup->setReplicateOutputs(checkGroupReplicateOutputs(name, kind));
  1158. }
  1159. GroupList.append(*pGroup);
  1160. } while (groups->next());
  1161. }
  1162. }
  1163. catch(IException* e)
  1164. {
  1165. StringBuffer msg;
  1166. e->errorMessage(msg);
  1167. WARNLOG("%s", msg.str());
  1168. e->Release();
  1169. }
  1170. catch(...)
  1171. {
  1172. WARNLOG("Unknown Exception caught within CTpWrapper::getGroupList");
  1173. }
  1174. }
  1175. bool CTpWrapper::checkGroupReplicateOutputs(const char* groupName, const char* kind)
  1176. {
  1177. if (strieq(kind, "Roxie") || strieq(kind, "hthor"))
  1178. return false;
  1179. Owned<IEnvironmentFactory> factory = getEnvironmentFactory();
  1180. Owned<IConstEnvironment> environment = factory->openEnvironment();
  1181. if (!environment)
  1182. throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get environment information.");
  1183. Owned<IPropertyTree> root = &environment->getPTree();
  1184. if (!root)
  1185. throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Failed to get environment information.");
  1186. Owned<IPropertyTreeIterator> it= root->getElements("Software/ThorCluster");
  1187. ForEach(*it)
  1188. {
  1189. StringBuffer thorClusterGroupName;
  1190. IPropertyTree& cluster = it->query();
  1191. getClusterGroupName(cluster, thorClusterGroupName);
  1192. if (thorClusterGroupName.length() && strieq(thorClusterGroupName.str(), groupName))
  1193. return cluster.getPropBool("@replicateOutputs", false);
  1194. }
  1195. return false;
  1196. }
  1197. void CTpWrapper::resolveGroupInfo(const char* groupName,StringBuffer& Cluster, StringBuffer& ClusterPrefix)
  1198. {
  1199. if(*groupName == 0)
  1200. {
  1201. DBGLOG("NULL PARAMETER groupName");
  1202. return;
  1203. }
  1204. //There is a big estimate here.... namely that one group can only be associated with one cluster.......
  1205. // if this changes then this code may be invalidated....
  1206. try
  1207. {
  1208. Owned<IPropertyTree> pTopology = getEnvironment("Software/Topology");
  1209. if (!pTopology)
  1210. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  1211. Owned<IPropertyTreeIterator> nodes= pTopology->getElements("//Cluster");
  1212. if (nodes->first())
  1213. {
  1214. do
  1215. {
  1216. IPropertyTree &node = nodes->query();
  1217. if (ContainsProcessDefinition(node,groupName)==true)
  1218. {
  1219. //the prefix info is contained within the parent
  1220. ClusterPrefix.append(node.queryProp("@prefix"));
  1221. Cluster.append(node.queryProp("@name"));
  1222. break;
  1223. }
  1224. } while (nodes->next());
  1225. }
  1226. }
  1227. catch(IException* e){
  1228. StringBuffer msg;
  1229. e->errorMessage(msg);
  1230. WARNLOG("%s", msg.str());
  1231. e->Release();
  1232. }
  1233. catch(...){
  1234. WARNLOG("Unknown Exception caught within CTpWrapper::resolveGroupInfo");
  1235. }
  1236. }
  1237. bool CTpWrapper::ContainsProcessDefinition(IPropertyTree& clusterNode,const char* clusterName)
  1238. {
  1239. Owned<IPropertyTreeIterator> processNodes = clusterNode.getElements("*");
  1240. if (processNodes->first()) {
  1241. do {
  1242. IPropertyTree &node = processNodes->query();
  1243. const char* processName = node.queryProp("@process");
  1244. if (*processName > 0 && (strcmp(processName,clusterName) == 0))
  1245. return true;
  1246. } while (processNodes->next());
  1247. }
  1248. return false;
  1249. }
  1250. void CTpWrapper::getMachineInfo(double clientVersion, const char* name, const char* netAddress, IEspTpMachine& machineInfo)
  1251. {
  1252. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory();
  1253. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  1254. Owned<IConstMachineInfo> pMachineInfo;
  1255. if (name && *name)
  1256. pMachineInfo.setown(constEnv->getMachine(name));
  1257. else if (netAddress && *netAddress)
  1258. pMachineInfo.setown(constEnv->getMachineByAddress(netAddress));
  1259. else
  1260. throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Machine not specified");
  1261. if (!pMachineInfo)
  1262. throw MakeStringException(ECLWATCH_CANNOT_GET_ENV_INFO, "Machine Not Found for %s '%s'",
  1263. (name && *name)? "Name" : "Net Address", (name && *name)? name : netAddress);
  1264. setTpMachine(pMachineInfo, machineInfo);
  1265. }
  1266. void CTpWrapper::setTpMachine(IConstMachineInfo* machine, IEspTpMachine& tpMachine)
  1267. {
  1268. if (!machine)
  1269. return;
  1270. SCMStringBuffer machineName, netAddress;
  1271. machine->getName(machineName);
  1272. machine->getNetAddress(netAddress);
  1273. tpMachine.setName(machineName.str());
  1274. tpMachine.setNetaddress(netAddress.str());
  1275. tpMachine.setOS(machine->getOS());
  1276. switch(machine->getState())
  1277. {
  1278. case MachineStateAvailable:
  1279. tpMachine.setAvailable("Available");
  1280. break;
  1281. case MachineStateUnavailable:
  1282. tpMachine.setAvailable("Unavailable");
  1283. break;
  1284. case MachineStateUnknown:
  1285. tpMachine.setAvailable("Unknown");
  1286. break;
  1287. }
  1288. Owned<IConstDomainInfo> pDomain = machine->getDomain();
  1289. if (pDomain != 0)
  1290. {
  1291. SCMStringBuffer sName;
  1292. tpMachine.setDomain(pDomain->getName(sName).str());
  1293. }
  1294. }
  1295. void CTpWrapper::getMachineInfo(IEspTpMachine& machineInfo,IPropertyTree& machine,const char* ParentPath,const char* MachineType,const char* nodenametag)
  1296. {
  1297. const char* name = machine.queryProp(nodenametag);
  1298. setMachineInfo(name,MachineType,machineInfo);
  1299. StringBuffer tmpPath;
  1300. StringBuffer ppath(ParentPath);
  1301. setAttPath(ppath,machine.queryName(),"name",name,tmpPath);
  1302. machineInfo.setPath(tmpPath.str());
  1303. }
  1304. void CTpWrapper::getMachineList(double clientVersion,
  1305. const char* clusterName,
  1306. const char* MachineType,
  1307. const char* ParentPath,
  1308. const char* Status,
  1309. const char* Directory,
  1310. bool& multiSlaves,
  1311. IArrayOf<IEspTpMachine> &MachineList)
  1312. {
  1313. try
  1314. {
  1315. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory();
  1316. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  1317. Owned<IPropertyTree> root = &constEnv->getPTree();
  1318. if (!root)
  1319. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  1320. StringBuffer path;
  1321. path.appendf("Software/ThorCluster[@name=\"%s\"]", clusterName);
  1322. Owned<IPropertyTree> cluster= root->getPropTree(path.str());
  1323. if (!cluster)
  1324. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  1325. //set this flag for legacy multi slave clusters because SwapNode made little sense in the old scheme
  1326. multiSlaves = cluster->getPropBool("@multiSlaves");
  1327. StringBuffer groupName;
  1328. if (strieq(MachineType, eqThorSlaveProcess))
  1329. getClusterGroupName(*cluster, groupName);
  1330. else if (strieq(MachineType, eqThorSpareProcess))
  1331. getClusterSpareGroupName(*cluster, groupName);
  1332. if (groupName.length() < 1)
  1333. return;
  1334. Owned<IGroup> nodeGroup = queryNamedGroupStore().lookup(groupName.str());
  1335. if (!nodeGroup || (nodeGroup->ordinality() == 0))
  1336. return;
  1337. unsigned processNumber = 0;
  1338. Owned<INodeIterator> gi = nodeGroup->getIterator();
  1339. ForEach(*gi)
  1340. {
  1341. StringBuffer netAddress;
  1342. gi->query().endpoint().getIpText(netAddress);
  1343. if (netAddress.length() == 0)
  1344. {
  1345. WARNLOG("Net address not found for a node in node group %s", groupName.str());
  1346. continue;
  1347. }
  1348. processNumber++;
  1349. IEspTpMachine & machineInfo = *(createTpMachine("",""));
  1350. machineInfo.setType(MachineType);
  1351. machineInfo.setNetaddress(netAddress.str());
  1352. if (Directory && *Directory)
  1353. machineInfo.setDirectory(Directory);
  1354. Owned<IConstMachineInfo> pMachineInfo = constEnv->getMachineByAddress(netAddress.str());
  1355. if (pMachineInfo.get())
  1356. {
  1357. setTpMachine(pMachineInfo, machineInfo);
  1358. if (clientVersion > 1.17)
  1359. {
  1360. machineInfo.setProcessNumber(processNumber);
  1361. }
  1362. }
  1363. else
  1364. {
  1365. machineInfo.setName("external");
  1366. machineInfo.setOS(MachineOsUnknown);
  1367. }
  1368. MachineList.append(machineInfo);
  1369. }
  1370. }
  1371. catch(IException* e){
  1372. StringBuffer msg;
  1373. e->errorMessage(msg);
  1374. WARNLOG("%s", msg.str());
  1375. e->Release();
  1376. }
  1377. catch(...){
  1378. WARNLOG("Unknown Exception caught within CTpWrapper::getMachineList");
  1379. }
  1380. return;
  1381. }
  1382. void CTpWrapper::getMachineList(const char* MachineType,
  1383. const char* ParentPath,
  1384. const char* Status,
  1385. const char* Directory,
  1386. IArrayOf<IEspTpMachine> &MachineList,
  1387. set<string>* pMachineNames/*=NULL*/)
  1388. {
  1389. try
  1390. {
  1391. //ParentPath=Path to parent node... normally a cluster
  1392. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory();
  1393. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  1394. Owned<IPropertyTree> root0 = &constEnv->getPTree();
  1395. if (!root0)
  1396. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  1397. char* xpath = (char*)ParentPath;
  1398. if (!strnicmp(xpath, "/Environment/", 13))
  1399. xpath += 13;
  1400. IPropertyTree* root = root0->queryPropTree( xpath );
  1401. if (!root)
  1402. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  1403. Owned<IPropertyTreeIterator> machines= root->getElements(MachineType);
  1404. const char* nodenametag = getNodeNameTag(MachineType);
  1405. if (machines->first()) {
  1406. do {
  1407. IPropertyTree &machine = machines->query();
  1408. if (pMachineNames)//caller wishes us to avoid inserting duplicate entries for machines
  1409. {
  1410. const char* machineName = machine.queryProp(nodenametag);
  1411. if (pMachineNames->find(machineName) != pMachineNames->end())
  1412. continue;
  1413. pMachineNames->insert(machineName);
  1414. }
  1415. //load up the machines of which we do not care what status is set or we have a matching status
  1416. const char* state = machine.queryProp("@state");
  1417. if ((Status==NULL || *Status=='\0') ||
  1418. (state && strcmp(Status, state)==0))
  1419. {
  1420. IEspTpMachine & machineInfo = *(createTpMachine("",""));
  1421. getMachineInfo(machineInfo,machine,ParentPath,MachineType,nodenametag);
  1422. if (Directory && *Directory)
  1423. machineInfo.setDirectory(Directory);
  1424. MachineList.append(machineInfo);
  1425. }
  1426. } while (machines->next());
  1427. }
  1428. }
  1429. catch(IException* e){
  1430. StringBuffer msg;
  1431. e->errorMessage(msg);
  1432. WARNLOG("%s", msg.str());
  1433. e->Release();
  1434. }
  1435. catch(...){
  1436. WARNLOG("Unknown Exception caught within CTpWrapper::getMachineList");
  1437. }
  1438. }
  1439. const char* CTpWrapper::getNodeNameTag(const char* MachineType)
  1440. {
  1441. if (strcmp(MachineType,"Computer")==0)
  1442. return "@name";
  1443. else
  1444. return "@computer";
  1445. }
  1446. void CTpWrapper::getDropZoneList(const char* MachineType,
  1447. const char* ParentPath,
  1448. const char* Directory,
  1449. IArrayOf<IEspTpMachine> &MachineList)
  1450. {
  1451. try
  1452. {
  1453. Owned<IEnvironmentFactory> envFactory = getEnvironmentFactory();
  1454. Owned<IConstEnvironment> constEnv = envFactory->openEnvironment();
  1455. Owned<IPropertyTree> root0 = &constEnv->getPTree();
  1456. if (!root0)
  1457. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  1458. char* xpath = (char*)ParentPath;
  1459. if (!strnicmp(xpath, "/Environment/", 13))
  1460. xpath += 13;
  1461. IPropertyTree* root = root0->queryPropTree( xpath );
  1462. if (!root)
  1463. throw MakeStringExceptionDirect(ECLWATCH_CANNOT_GET_ENV_INFO, MSG_FAILED_GET_ENVIRONMENT_INFO);
  1464. Owned<IPropertyTreeIterator> nodes= root->getElements(eqDropZone);
  1465. if (nodes->first()) {
  1466. do {
  1467. IPropertyTree &machine = nodes->query();
  1468. IEspTpMachine & machineInfo = *(createTpMachine("",""));
  1469. const char* name = machine.queryProp("@computer");
  1470. StringBuffer ppath(ParentPath);
  1471. StringBuffer tmpPath;
  1472. setAttPath(ppath,machine.queryName(),"name",name,tmpPath);
  1473. machineInfo.setPath(tmpPath.str());
  1474. setMachineInfo(name,MachineType,machineInfo);
  1475. machineInfo.setDirectory(machine.queryProp("@directory"));
  1476. MachineList.append(machineInfo);
  1477. } while (nodes->next());
  1478. }
  1479. }
  1480. catch(IException* e){
  1481. StringBuffer msg;
  1482. e->errorMessage(msg);
  1483. WARNLOG("%s", msg.str());
  1484. e->Release();
  1485. }
  1486. catch(...){
  1487. WARNLOG("Unknown Exception caught within CTpWrapper::getDropZoneList");
  1488. }
  1489. }
  1490. void CTpWrapper::setMachineInfo(const char* name,const char* type,IEspTpMachine& machine)
  1491. {
  1492. try{
  1493. Owned<IEnvironmentFactory> factory = getEnvironmentFactory();
  1494. Owned<IConstEnvironment> m_pConstEnvironment = factory->openEnvironment();
  1495. Owned<IConstMachineInfo> pMachineInfo = m_pConstEnvironment->getMachine(name);
  1496. if (pMachineInfo.get())
  1497. {
  1498. SCMStringBuffer ep;
  1499. pMachineInfo->getNetAddress(ep);
  1500. const char* ip = ep.str();
  1501. if (!ip || stricmp(ip, "."))
  1502. {
  1503. machine.setNetaddress(ep.str());
  1504. machine.setConfigNetaddress(ep.str());
  1505. }
  1506. else
  1507. {
  1508. StringBuffer ipStr;
  1509. IpAddress ipaddr = queryHostIP();
  1510. ipaddr.getIpText(ipStr);
  1511. if (ipStr.length() > 0)
  1512. {
  1513. #ifdef MACHINE_IP
  1514. machine.setNetaddress(MACHINE_IP);
  1515. #else
  1516. machine.setNetaddress(ipStr.str());
  1517. #endif
  1518. machine.setConfigNetaddress(".");
  1519. }
  1520. }
  1521. machine.setOS(pMachineInfo->getOS());
  1522. switch(pMachineInfo->getState())
  1523. {
  1524. case MachineStateAvailable:
  1525. machine.setAvailable("Available");
  1526. break;
  1527. case MachineStateUnavailable:
  1528. machine.setAvailable("Unavailable");
  1529. break;
  1530. case MachineStateUnknown:
  1531. machine.setAvailable("Unknown");
  1532. break;
  1533. }
  1534. Owned<IConstDomainInfo> pDomain = pMachineInfo->getDomain();
  1535. if (pDomain != 0)
  1536. {
  1537. SCMStringBuffer sName;
  1538. machine.setDomain(pDomain->getName(sName).str());
  1539. }
  1540. }
  1541. machine.setName(name);
  1542. machine.setType(type);
  1543. }
  1544. catch(IException* e){
  1545. StringBuffer msg;
  1546. e->errorMessage(msg);
  1547. WARNLOG("%s", msg.str());
  1548. e->Release();
  1549. }
  1550. catch(...){
  1551. WARNLOG("Unknown Exception caught within CTpWrapper::getDropZoneList");
  1552. }
  1553. }
  1554. void CTpWrapper::setAttPath(StringBuffer& Path,const char* PathToAppend,const char* AttName,const char* AttValue,StringBuffer& returnStr)
  1555. {
  1556. Path.append("/");
  1557. Path.append(PathToAppend);
  1558. Path.append("[@");
  1559. Path.append(AttName);
  1560. Path.append("=\"");
  1561. Path.append(AttValue);
  1562. Path.append("\"]");
  1563. StringBuffer rawPath;
  1564. const void* buff = (void*)Path.str();
  1565. JBASE64_Encode(buff,Path.length(),rawPath, false);
  1566. returnStr.append(rawPath.str());
  1567. }
  1568. void CTpWrapper::getAttPath(const char* Path,StringBuffer& returnStr)
  1569. {
  1570. StringBuffer decodedStr;
  1571. JBASE64_Decode(Path, returnStr);
  1572. }