TpWrapper.cpp 70 KB

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