TpWrapper.cpp 68 KB

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