TpWrapper.cpp 71 KB

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