wizardInputs.cpp 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  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. /////////////////////////////////////////////////////////////////////////////
  14. //
  15. // WizardInputs.cpp : implementation file
  16. //
  17. /////////////////////////////////////////////////////////////////////////////
  18. #include "wizardInputs.hpp"
  19. #include "XMLTags.h"
  20. #include "jencrypt.hpp"
  21. #include "buildset.hpp"
  22. #include "confighelper.hpp"
  23. CInstDetails::CInstDetails(const char * compName, const StringArray &ipAssigned) : m_compName(compName)
  24. {
  25. m_ipAssigned.clear();
  26. for (unsigned i = 0; i < ipAssigned.ordinality(); i++)
  27. {
  28. m_ipAssigned.append(ipAssigned.item(i));
  29. }
  30. }
  31. //---------------------------------------------------------------------------
  32. // CWizardInputs
  33. //---------------------------------------------------------------------------
  34. CWizardInputs::CWizardInputs(const char* xmlArg,const char *service,
  35. IPropertyTree * cfg,
  36. MapStringTo<StringAttr, const char *>* dirMap,
  37. StringArray &arrBuildSetsWithAssignedIPs,
  38. StringArray &arrAssignedIPs): m_service(service),
  39. m_cfg(cfg), m_overrideDirs(dirMap), m_roxieOnDemand(true),
  40. m_supportNodes(0), m_arrBuildSetsWithAssignedIPs(arrBuildSetsWithAssignedIPs), m_arrAssignedIPs(arrAssignedIPs)
  41. {
  42. m_pXml.setown(createPTreeFromXMLString(xmlArg && *xmlArg ? xmlArg : "<XmlArgs/>"));
  43. }
  44. //----------------------------------------------------------------------
  45. CWizardInputs::~CWizardInputs()
  46. {
  47. m_pXml.clear();
  48. HashIterator info(m_invalidServerCombo);
  49. for(info.first();info.isValid();info.next())
  50. {
  51. StringArray *a = *m_invalidServerCombo.mapToValue(&info.query());
  52. delete a;
  53. }
  54. HashIterator iter(m_compIpMap);
  55. ForEach(iter)
  56. {
  57. IMapping &cur = iter.query();
  58. CInstDetails* pInfo = m_compIpMap.mapToValue(&cur);
  59. pInfo->Release();
  60. }
  61. HashIterator sIter(m_compForTopology);
  62. for(sIter.first();sIter.isValid();sIter.next())
  63. {
  64. StringArray* a = *m_compForTopology.mapToValue(&sIter.query());
  65. delete a;
  66. }
  67. }
  68. //-----------------------------------------------------------------------
  69. // SetEnvironment
  70. //-----------------------------------------------------------------------
  71. void CWizardInputs::setEnvironment()
  72. {
  73. StringBuffer xpath;
  74. if(m_pXml->hasProp("@ipList"))
  75. formIPList(m_pXml->queryProp("@ipList"), m_ipaddress);
  76. if(m_pXml->hasProp("@roxieNodes"))
  77. m_roxieNodes = atoi(m_pXml->queryProp("@roxieNodes"));
  78. if(m_pXml->hasProp("@thorNodes"))
  79. m_thorNodes = atoi(m_pXml->queryProp("@thorNodes"));
  80. m_espNodes = 1;
  81. if(m_pXml->hasProp("@espNodes"))
  82. m_espNodes = atoi(m_pXml->queryProp("@espNodes"));
  83. if(m_pXml->hasProp("@supportNodes"))
  84. {
  85. m_supportNodes = atoi(m_pXml->queryProp("@supportNodes"));
  86. if (m_supportNodes)
  87. {
  88. if (m_ipaddress.length() > 0 &&
  89. ((m_ipaddress.length() > m_supportNodes) ||
  90. ((m_ipaddress.length() == m_supportNodes) &&
  91. (m_roxieNodes == 0) && (m_thorNodes == 0) && (m_espNodes == 0))))
  92. {
  93. for(unsigned i = 0; i < m_supportNodes; i++)
  94. m_ipaddressSupport.append(m_ipaddress.item(i));
  95. m_ipaddress.removen(0, m_supportNodes);
  96. }
  97. else
  98. m_supportNodes = 0;
  99. }
  100. }
  101. if(m_pXml->hasProp("@dbuser"))
  102. m_dbuser = m_pXml->queryProp("@dbuser");
  103. if(m_pXml->hasProp("@dbpassword"))
  104. m_dbpassword = m_pXml->queryProp("@dbpassword");
  105. m_thorSlavesPerNode = 1;
  106. if(m_pXml->hasProp("@slavesPerNode"))
  107. m_thorSlavesPerNode = atoi( m_pXml->queryProp("@slavesPerNode"));
  108. if (m_thorSlavesPerNode < 1)
  109. m_thorSlavesPerNode = 1;
  110. m_thorChannelsPerSlave = 1;
  111. if(m_pXml->hasProp("@thorChannelsPerSlave"))
  112. m_thorChannelsPerSlave = atoi( m_pXml->queryProp("@thorChannelsPerSlave"));
  113. if (m_thorChannelsPerSlave < 1)
  114. m_thorChannelsPerSlave = 1;
  115. m_roxieChannelsPerSlave = 1;
  116. if(m_pXml->hasProp("@roxieChannelsPerSlave"))
  117. m_roxieChannelsPerSlave = atoi( m_pXml->queryProp("@roxieChannelsPerSlave"));
  118. if (m_roxieChannelsPerSlave < 1)
  119. m_roxieChannelsPerSlave = 1;
  120. m_roxieOnDemand = m_pXml->getPropBool("@roxieOnDemand", true);
  121. xpath.clear().appendf("Software/EspProcess/EspService[@name='%s']/LocalConfFile", m_service.str());
  122. const char* pConfFile = m_cfg->queryProp(xpath.str());
  123. xpath.clear().appendf("Software/EspProcess/EspService[@name='%s']/LocalEnvConfFile", m_service.str());
  124. const char* pEnvConfFile = m_cfg->queryProp(xpath.str());
  125. if (pConfFile && *pConfFile && pEnvConfFile && *pEnvConfFile)
  126. {
  127. Owned<IProperties> pParams = createProperties(pConfFile);
  128. Owned<IProperties> pEnvParams = createProperties(pEnvConfFile);
  129. StringBuffer sb, fileName;
  130. CConfigHelper *pConfigHelper = CConfigHelper::getInstance(m_cfg, m_service.str());
  131. if (pConfigHelper == NULL)
  132. {
  133. throw MakeStringException( -1 , "Error loading buildset from configuration");
  134. }
  135. IPropertyTree* pBuildSet = pConfigHelper->getBuildSetTree();
  136. if (strlen(pConfigHelper->getBuildSetFileName()) == 0 || pBuildSet == NULL)
  137. {
  138. throw MakeStringException( -1 , "The buildset file %s/%s does not exist", pConfigHelper->getBuildSetFilePath(), pConfigHelper->getBuildSetFileName());
  139. }
  140. m_buildSetTree.setown(pBuildSet);
  141. fileName.clear().append((pEnvParams->queryProp("configs") != NULL ? (sb.clear().append(pEnvParams->queryProp("configs")).append("/")): hpccBuildInfo.configDir));
  142. fileName.append((pParams->queryProp("wizardalgorithm") != NULL ? (sb.clear().append(pParams->queryProp("wizardalgorithm"))) : STANDARD_CONFIG_ALGORITHMFILE));
  143. if(fileName.length() && checkFileExists(fileName.str()))
  144. m_algProp.setown(createProperties(fileName.str()));
  145. else
  146. throw MakeStringException( -1 , "The algorithm file %s does not exists", fileName.str());
  147. }
  148. setWizardRules();
  149. setTopologyParam();
  150. }
  151. void CWizardInputs::setWizardRules()
  152. {
  153. const char* roxieRedTypes[] = {"Full", "Circular", "None", "Overloaded"};
  154. m_roxieAgentRedType.clear().append("Circular");
  155. m_roxieAgentRedChannels = 2;
  156. m_roxieAgentRedOffset = 1;
  157. if(m_algProp)
  158. {
  159. CConfigHelper::getInstance()->addPluginsToGenEnvRules(m_algProp.get());
  160. Owned<IPropertyIterator> iter = m_algProp->getIterator();
  161. StringBuffer prop;
  162. ForEach(*iter)
  163. {
  164. m_algProp->getProp(iter->getPropKey(), prop.clear());
  165. if(prop.length() && prop.charAt(prop.length()-1) == ',')
  166. prop.setCharAt((prop.length()-1),' ');
  167. if(!strcmp(iter->getPropKey(), "max_comps_per_node"))
  168. {
  169. m_maxCompOnNode = atoi(prop.str());
  170. }
  171. else if(!strcmp(iter->getPropKey(), "avoid_combo"))
  172. {
  173. StringArray pairValue;
  174. pairValue.appendList(prop.str(), ",");
  175. if( pairValue.ordinality() > 0)
  176. {
  177. for( unsigned i = 0; i < pairValue.ordinality() ; i++)
  178. {
  179. StringArray eachpair;
  180. eachpair.appendList(pairValue.item(i), "-");
  181. if(eachpair.ordinality() == 2 )
  182. {
  183. StringArray* serverCompArr = 0;
  184. ForEachItemIn(x, eachpair)
  185. {
  186. StringArrayPtr* pairServerArr = m_invalidServerCombo.getValue(eachpair.item(x));
  187. if(pairServerArr)
  188. {
  189. serverCompArr = (*pairServerArr);
  190. serverCompArr->append(x == 0 ? eachpair.item(1): eachpair.item(0));
  191. }
  192. else
  193. {
  194. serverCompArr = new StringArray();
  195. serverCompArr->append(x == 0 ? eachpair.item(1): eachpair.item(0));
  196. m_invalidServerCombo.setValue(eachpair.item(x),serverCompArr);
  197. }
  198. }
  199. }
  200. }
  201. }
  202. }
  203. else if(!strcmp (iter->getPropKey(),"do_not_generate"))
  204. m_doNotGenComp.appendList(prop.str(), ",");
  205. else if(!strcmp (iter->getPropKey(),"comps_on_all_nodes"))
  206. m_compOnAllNodes.appendList(prop.str(), ",");
  207. else if(!strcmp(iter->getPropKey(), "topology_for_comps"))
  208. m_clusterForTopology.appendList(prop.str(), ",");
  209. else if (!strcmp(iter->getPropKey(), "roxie_agent_redundancy"))
  210. {
  211. StringArray sbarr;
  212. sbarr.appendList(prop.str(), ",");
  213. if (sbarr.length() > 1)
  214. {
  215. int type = atoi(sbarr.item(0));
  216. if (type == 0)
  217. continue;
  218. if (type > 0 && type < 5)
  219. m_roxieAgentRedType.clear().append(roxieRedTypes[type-1]);
  220. else
  221. continue;
  222. m_roxieAgentRedChannels = atoi(sbarr.item(1));
  223. if (m_roxieAgentRedChannels <= 0)
  224. m_roxieAgentRedChannels = 1;
  225. if (sbarr.length() > 2)
  226. {
  227. m_roxieAgentRedOffset = atoi(sbarr.item(2));
  228. if (m_roxieAgentRedOffset <= 0)
  229. m_roxieAgentRedOffset = 1;
  230. }
  231. else
  232. m_roxieAgentRedOffset = 0;
  233. }
  234. }
  235. }
  236. }
  237. }
  238. CInstDetails* CWizardInputs::getServerIPMap(const char* compName, const char* buildSetName,const IPropertyTree* pEnvTree, unsigned numOfNodes)
  239. {
  240. if (numOfNodes == 0)
  241. return NULL;
  242. StringBuffer xPath;
  243. xPath.appendf("./Programs/Build/BuildSet[@name=\"%s\"]",buildSetName);
  244. IPropertyTree* pBuildSet = pEnvTree->queryPropTree(xPath.str());
  245. CInstDetails* instDetails = NULL;
  246. if(pBuildSet)
  247. {
  248. if(m_doNotGenComp.find(buildSetName) != NotFound)
  249. return instDetails;
  250. if(m_compOnAllNodes.find(buildSetName) != NotFound)
  251. return instDetails;
  252. if (m_arrBuildSetsWithAssignedIPs.find(buildSetName) != NotFound)
  253. instDetails = new CInstDetails(compName, getIpAddrMap(buildSetName));
  254. if (m_ipaddress.ordinality() + m_supportNodes == 1 && instDetails == NULL && strcmp(buildSetName, "backupnode"))
  255. {
  256. if (m_ipaddress.ordinality() > 0)
  257. instDetails = new CInstDetails(compName, m_ipaddress.item(0));
  258. else if (m_ipaddressSupport.ordinality() > 0)
  259. instDetails = new CInstDetails(compName, m_ipaddressSupport.item(0));
  260. else
  261. return instDetails;
  262. m_compIpMap.setValue(buildSetName,instDetails);
  263. return instDetails;
  264. }
  265. else if (m_supportNodes == 1 && strcmp(buildSetName, "roxie") && strcmp(buildSetName, "thor" )
  266. && strcmp(buildSetName, "backupnode") && instDetails == NULL)
  267. {
  268. instDetails = new CInstDetails(compName, m_ipaddressSupport.item(0));
  269. m_compIpMap.setValue(buildSetName,instDetails);
  270. return instDetails;
  271. }
  272. else
  273. {
  274. if (!strcmp(buildSetName, "backupnode") && m_arrBuildSetsWithAssignedIPs.find(buildSetName) == NotFound)
  275. return NULL;
  276. unsigned x = 0;
  277. unsigned origNumOfNodes(numOfNodes);
  278. for(; x < numOfNodes ; x++)
  279. {
  280. StringArray* pIpAddrMap = NULL;
  281. if (m_arrBuildSetsWithAssignedIPs.find(buildSetName) != NotFound || !(x == 0 && m_supportNodes > 0 && !strcmp(buildSetName, "thor")))
  282. pIpAddrMap = &getIpAddrMap(buildSetName);
  283. else
  284. pIpAddrMap = &m_ipaddressSupport;
  285. unsigned numOfIPSAlreadyTaken = m_arrBuildSetsWithAssignedIPs.find(buildSetName) == NotFound ? getCntForAlreadyAssignedIPS(buildSetName) : x;
  286. if( numOfIPSAlreadyTaken < pIpAddrMap->ordinality())
  287. addToCompIPMap(buildSetName, pIpAddrMap->item(numOfIPSAlreadyTaken), compName);
  288. else if (!applyOverlappingRules(compName, buildSetName, numOfIPSAlreadyTaken, pIpAddrMap))
  289. break;
  290. }
  291. if(m_compIpMap.find(buildSetName) != NULL)
  292. {
  293. delete instDetails; // Possibly previously NEW'ed, delete to avoid override
  294. instDetails = m_compIpMap.getValue(buildSetName);
  295. if( (instDetails->getIpAssigned()).ordinality() != numOfNodes)
  296. {
  297. StringBuffer sb("support");
  298. StringBuffer sbBuildSet(buildSetName);
  299. unsigned ips = m_ipaddressSupport.length();
  300. unsigned ipns = m_ipaddress.length();
  301. if (!strcmp(buildSetName, "thor") && m_supportNodes > 0)
  302. {
  303. if (x == 0)
  304. {
  305. sb.clear().append(m_supportNodes == 0?"non-support":"support");
  306. sbBuildSet.clear().append("Thor Master");
  307. numOfNodes = 1;
  308. }
  309. else
  310. {
  311. sb.clear().append("non-support");
  312. sbBuildSet.clear().append("Thor Slaves");
  313. numOfNodes--;
  314. }
  315. }
  316. else if (!strcmp(buildSetName, "roxie") || !strcmp(buildSetName, "backupnode"))
  317. sb.clear().append("non-support ");
  318. if (m_arrBuildSetsWithAssignedIPs.find(buildSetName) == NotFound)
  319. throw MakeStringException(-1, \
  320. "Total nodes: %d (%d Support Nodes + %d Non-support Nodes)\nError: Cannot assign %d number of nodes for %s due to insufficient %s nodes available. Please enter different values", \
  321. ips + ipns, ips, ipns, numOfNodes, sbBuildSet.str(), sb.str());
  322. else
  323. throw MakeStringException(-1, "Total nodes required: %d\nError: Unable to assign %d nodes, no more assigned ip nodes available for %s", origNumOfNodes, origNumOfNodes - getCntForAlreadyAssignedIPS(buildSetName), buildSetName);
  324. }
  325. else{
  326. return m_compIpMap.getValue(buildSetName);
  327. }
  328. }
  329. }
  330. return instDetails;
  331. }
  332. return NULL;
  333. }
  334. bool CWizardInputs::applyOverlappingRules(const char* compName,const char* buildSetName, unsigned startpos, StringArray* pIpAddrMap)
  335. {
  336. StringArray dontAssign , ignoredForOverlap;
  337. bool assignedIP = false;
  338. CInstDetails* compPtr = NULL;
  339. if(m_invalidServerCombo.find(buildSetName) != NULL)
  340. {
  341. StringArray* serverCompArr = 0;
  342. StringArrayPtr* pairServerArr = m_invalidServerCombo.getValue(buildSetName);
  343. if(pairServerArr)
  344. serverCompArr = (*pairServerArr);
  345. for(unsigned i = 0 ; i < serverCompArr->ordinality() ; i++)
  346. {
  347. compPtr = m_compIpMap.getValue(serverCompArr->item(i));
  348. if(compPtr)
  349. {
  350. StringArray& ipArr = compPtr->getIpAssigned();
  351. ForEachItemIn(i, ipArr)
  352. dontAssign.append(ipArr.item(i));
  353. }
  354. }
  355. }
  356. //Since Roxie and thor might already have some ips asssigned we need to ignore those too.
  357. if(m_compIpMap.find(buildSetName) != NULL)
  358. {
  359. compPtr = m_compIpMap.getValue(buildSetName);
  360. StringArray& ipArr = compPtr->getIpAssigned();
  361. ForEachItemIn(i, ipArr)
  362. dontAssign.append(ipArr.item(i));
  363. }
  364. unsigned pos = startpos % pIpAddrMap->ordinality();
  365. for (unsigned j=pos; j < pos + pIpAddrMap->ordinality(); j++)
  366. {
  367. unsigned ii = (j >= pIpAddrMap->ordinality()) ? 0 : j;
  368. count_t ipAssignedCount = getNumOfInstForIP(pIpAddrMap->item(ii));
  369. if(dontAssign.ordinality() > 0)
  370. {
  371. if( dontAssign.find(pIpAddrMap->item(ii)) == NotFound)
  372. {
  373. if(ipAssignedCount >= m_maxCompOnNode )
  374. {
  375. ignoredForOverlap.append(pIpAddrMap->item(ii));
  376. }
  377. else
  378. {
  379. assignedIP = true;
  380. addToCompIPMap(buildSetName, pIpAddrMap->item(ii), compName);
  381. break;
  382. }
  383. }
  384. }
  385. else
  386. {
  387. if(ipAssignedCount >= m_maxCompOnNode )
  388. {
  389. ignoredForOverlap.append(pIpAddrMap->item(ii));
  390. }
  391. else
  392. {
  393. assignedIP = true;
  394. addToCompIPMap(buildSetName, pIpAddrMap->item(ii), compName);
  395. break;
  396. }
  397. }
  398. }
  399. if(!assignedIP && ignoredForOverlap.ordinality() > 0)
  400. {
  401. addToCompIPMap(buildSetName, ignoredForOverlap.item(0), compName);
  402. assignedIP = true;
  403. }
  404. return assignedIP;
  405. }
  406. count_t CWizardInputs::getNumOfInstForIP(const char * ip)
  407. {
  408. count_t cnt = 0;
  409. HashIterator ips(m_compIpMap);
  410. ForEach(ips)
  411. {
  412. CInstDetails* comp = m_compIpMap.mapToValue(&ips.query());
  413. StringArray& ipArray = comp->getIpAssigned();
  414. if(ipArray.find(ip) != NotFound)
  415. cnt++;
  416. }
  417. return cnt;
  418. }
  419. bool CWizardInputs::generateEnvironment(StringBuffer& envXml)
  420. {
  421. if(m_algProp)
  422. {
  423. Owned<IPropertyTree> pEnvTree = createEnvironment();
  424. if(pEnvTree)
  425. {
  426. toXML(pEnvTree,envXml, 0, XML_SortTags | XML_Format);
  427. }
  428. }
  429. else
  430. {
  431. DBGLOG("not yet decided");//use default algorithm
  432. }
  433. return true;
  434. }
  435. IPropertyTree* CWizardInputs::createEnvironment()
  436. {
  437. StringBuffer xpath, sbTemp, name ;
  438. sbTemp.clear().appendf("<%s><%s></%s>", XML_HEADER, XML_TAG_ENVIRONMENT, XML_TAG_ENVIRONMENT);
  439. IPropertyTree* pNewEnvTree = createPTreeFromXMLString(sbTemp.str());
  440. IPropertyTree* pSettings = pNewEnvTree->addPropTree(XML_TAG_ENVSETTINGS, createPTree());
  441. xpath.clear().appendf("%s/%s/%s[%s='%s']/LocalEnvFile", XML_TAG_SOFTWARE, XML_TAG_ESPPROCESS, XML_TAG_ESPSERVICE, XML_ATTR_NAME, m_service.str());
  442. const char* pConfFile = m_cfg->queryProp(xpath.str());
  443. xpath.clear().appendf("%s/%s/%s[%s='%s']/LocalEnvConfFile", XML_TAG_SOFTWARE, XML_TAG_ESPPROCESS, XML_TAG_ESPSERVICE, XML_ATTR_NAME, m_service.str());
  444. const char* tmp = m_cfg->queryProp(xpath.str());
  445. if (tmp && *tmp)
  446. {
  447. Owned<IProperties> pParams = createProperties(tmp);
  448. Owned<IPropertyIterator> iter = pParams->getIterator();
  449. ForEach(*iter)
  450. {
  451. StringBuffer prop;
  452. pParams->getProp(iter->getPropKey(), prop);
  453. pSettings->addProp(iter->getPropKey(), prop.length() ? prop.str():"");
  454. }
  455. }
  456. Owned<IPropertyTree> pProgramTree = createPTreeFromIPT(m_buildSetTree);
  457. pNewEnvTree->addPropTree(XML_TAG_PROGRAMS, createPTreeFromIPT(pProgramTree->queryPropTree("./" XML_TAG_PROGRAMS)));
  458. Owned<IPropertyTree> pCompTree = createPTree(XML_TAG_HARDWARE);
  459. generateHardwareHeaders(pNewEnvTree, sbTemp, false, pCompTree);
  460. pCompTree->removeProp(XML_TAG_COMPUTER);
  461. xpath.clear().appendf("./%s/%s", XML_TAG_COMPUTERTYPE, XML_ATTR_MEMORY);
  462. pCompTree->removeProp(xpath.str());
  463. xpath.clear().appendf("./%s/%s", XML_TAG_COMPUTERTYPE, XML_ATTR_NICSPEED);
  464. pCompTree->removeProp(xpath.str());
  465. xpath.clear().append(XML_TAG_SWITCH).append("/").append(XML_ATTR_NAME);
  466. pCompTree->setProp(xpath.str(), "Switch") ;
  467. xpath.clear().append(XML_TAG_DOMAIN).append("/").append(XML_ATTR_NAME);
  468. pCompTree->setProp(xpath.str(), "localdomain");
  469. xpath.clear().append(XML_TAG_DOMAIN).append("/").append(XML_ATTR_PASSWORD);
  470. pCompTree->setProp(xpath.str(), m_pXml->queryProp("@password"));
  471. xpath.clear().append(XML_TAG_DOMAIN).append("/").append(XML_ATTR_USERNAME);
  472. pCompTree->setProp(xpath.str(), m_pXml->queryProp("@username"));
  473. xpath.clear().appendf("./%s/@snmpSecurityString", XML_TAG_DOMAIN);
  474. pCompTree->removeProp(xpath.str());
  475. xpath.clear().append(XML_TAG_COMPUTERTYPE).append("/").append(XML_ATTR_COMPUTERTYPE);
  476. pCompTree->setProp(xpath.str(), "linuxmachine");
  477. xpath.clear().append(XML_TAG_COMPUTERTYPE).append("/").append(XML_ATTR_MANUFACTURER);
  478. pCompTree->setProp(xpath.str(), "unknown");
  479. xpath.clear().append(XML_TAG_COMPUTERTYPE).append("/").append(XML_ATTR_NAME);
  480. pCompTree->setProp(xpath.str(), "linuxmachine");
  481. xpath.clear().append(XML_TAG_COMPUTERTYPE).append("/").append(XML_ATTR_OPSYS);
  482. pCompTree->setProp(xpath.str(), "linux");
  483. xpath.clear().append(XML_TAG_COMPUTERTYPE).append("/").append(XML_ATTR_NICSPEED);
  484. pCompTree->setProp(xpath.str(), "1000");
  485. unsigned x;
  486. IpAddress ipaddr;
  487. for(unsigned i = 0; i < m_ipaddressSupport.ordinality(); i++)
  488. {
  489. IPropertyTree* pComputer = pCompTree->addPropTree(XML_TAG_COMPUTER,createPTree());
  490. ipaddr.ipset(m_ipaddressSupport.item(i));
  491. ipaddr.getNetAddress(sizeof(x),&x);
  492. name.clear().appendf("node%03d%03d", (x >> 16) & 0xFF, (x >> 24) & 0xFF);
  493. getUniqueName(pCompTree, name, XML_TAG_COMPUTER, "");
  494. pComputer->addProp(XML_ATTR_COMPUTERTYPE, "linuxmachine");
  495. pComputer->addProp(XML_ATTR_DOMAIN, "localdomain");
  496. pComputer->addProp(XML_ATTR_NAME, name.str());
  497. pComputer->addProp(XML_ATTR_NETADDRESS, m_ipaddressSupport.item(i));
  498. }
  499. for(unsigned i = 0; i < m_ipaddress.ordinality(); i++)
  500. {
  501. IPropertyTree* pComputer = pCompTree->addPropTree(XML_TAG_COMPUTER,createPTree());
  502. ipaddr.ipset(m_ipaddress.item(i));
  503. ipaddr.getNetAddress(sizeof(x),&x);
  504. name.clear().appendf("node%03d%03d", (x >> 16) & 0xFF, (x >> 24) & 0xFF);
  505. getUniqueName(pCompTree, name, XML_TAG_COMPUTER, "");
  506. pComputer->addProp(XML_ATTR_COMPUTERTYPE, "linuxmachine");
  507. pComputer->addProp(XML_ATTR_DOMAIN, "localdomain");
  508. pComputer->addProp(XML_ATTR_NAME, name.str());
  509. pComputer->addProp(XML_ATTR_NETADDRESS, m_ipaddress.item(i));
  510. }
  511. for(unsigned i = 0; i < m_arrBuildSetsWithAssignedIPs.ordinality(); i++)
  512. {
  513. const StringArray &strIPs = getIpAddrMap(m_arrBuildSetsWithAssignedIPs.item(i));
  514. for (unsigned i2 = 0; i2 < strIPs.ordinality(); i2++)
  515. {
  516. VStringBuffer strXPath("./%s/[%s=\"%s\"]", XML_TAG_COMPUTER, XML_ATTR_NETADDRESS, strIPs.item(i2));
  517. if (pCompTree->hasProp(strXPath.str()))
  518. continue;
  519. IPropertyTree* pComputer = pCompTree->addPropTree(XML_TAG_COMPUTER,createPTree());
  520. ipaddr.ipset(strIPs.item(i2));
  521. ipaddr.getNetAddress(sizeof(x),&x);
  522. name.setf("node%03d%03d", (x >> 16) & 0xFF, (x >> 24) & 0xFF);
  523. getUniqueName(pCompTree, name, XML_TAG_COMPUTER, "");
  524. pComputer->addProp(XML_ATTR_COMPUTERTYPE, "linuxmachine");
  525. pComputer->addProp(XML_ATTR_DOMAIN, "localdomain");
  526. pComputer->addProp(XML_ATTR_NAME, name.str());
  527. pComputer->addProp(XML_ATTR_NETADDRESS, strIPs.item(i2));
  528. }
  529. }
  530. pNewEnvTree->addPropTree(XML_TAG_HARDWARE, createPTreeFromIPT(pCompTree));
  531. //Before we generate software tree check for dependencies of component for do_not_generate ,roxie, thor
  532. checkForDependencies();
  533. generateSoftwareTree(pNewEnvTree);
  534. return pNewEnvTree;
  535. }
  536. void CWizardInputs::generateSoftwareTree(IPropertyTree* pNewEnvTree)
  537. {
  538. StringBuffer xpath;
  539. if(m_buildSetTree)
  540. {
  541. bool ovrLog = true, ovrRun = true;
  542. if (m_overrideDirs && m_overrideDirs->count() > 0)
  543. {
  544. HashIterator iter(*m_overrideDirs);
  545. ForEach(iter)
  546. {
  547. IMapping &cur = iter.query();
  548. StringAttr* dirvalue = m_overrideDirs->mapToValue(&cur);
  549. const char * key = (const char*)cur.getKey();
  550. xpath.clear().appendf(XML_TAG_SOFTWARE"/Directories/Category[@name='%s']", key);
  551. if (!strcmp(key, "log"))
  552. ovrLog = false;
  553. else if (!strcmp(key, "run"))
  554. ovrRun = false;
  555. IPropertyTree* pDir = m_buildSetTree->queryPropTree(xpath.str());
  556. if (pDir)
  557. pDir->setProp("@dir", dirvalue->str());
  558. else
  559. {
  560. pDir = m_buildSetTree->queryPropTree(XML_TAG_SOFTWARE"/Directories/")->addPropTree("Category", createPTree());
  561. pDir->setProp(XML_ATTR_NAME, (const char*)cur.getKey());
  562. pDir->setProp("@dir", dirvalue->str());
  563. }
  564. }
  565. }
  566. pNewEnvTree->addPropTree(XML_TAG_SOFTWARE,createPTreeFromIPT(m_buildSetTree->queryPropTree("./" XML_TAG_SOFTWARE)));
  567. xpath.clear().appendf("%s/%s/%s[%s='%s']/LocalEnvConfFile", XML_TAG_SOFTWARE, XML_TAG_ESPPROCESS, XML_TAG_ESPSERVICE, XML_ATTR_NAME, m_service.str());
  568. const char* tmp = m_cfg->queryProp(xpath.str());
  569. if (tmp && *tmp)
  570. {
  571. Owned<IProperties> pParams = createProperties(tmp);
  572. updateDirsWithConfSettings(pNewEnvTree, pParams, ovrLog, ovrRun);
  573. }
  574. const char* firstComp = "esp";
  575. xpath.clear().appendf("./%s/%s/%s/[@name=\"%s\"]", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET, firstComp);
  576. IPropertyTree* pEspBuildSet = m_buildSetTree->queryPropTree(xpath.str());
  577. if (pEspBuildSet)
  578. addComponentToSoftware(pNewEnvTree, pEspBuildSet);
  579. xpath.clear().appendf("./%s/%s/%s", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET);
  580. Owned<IPropertyTreeIterator> buildSetInsts = m_buildSetTree->getElements(xpath.str());
  581. ForEach(*buildSetInsts)
  582. {
  583. IPropertyTree* pBuildSet = &buildSetInsts->query();
  584. const char* buildSetName = pBuildSet->queryProp(XML_ATTR_NAME);
  585. if (strcmp(firstComp, buildSetName))
  586. addComponentToSoftware(pNewEnvTree, &buildSetInsts->query());
  587. }
  588. getEspBindingInformation(pNewEnvTree);
  589. addTopology(pNewEnvTree);
  590. getDefaultsForWizard(pNewEnvTree);
  591. }
  592. }
  593. void CWizardInputs::addInstanceToTree(IPropertyTree* pNewEnvTree, const char * attrName, const char* processName, const char* buildSetName, const char* instName)
  594. {
  595. StringBuffer sb, sbl, compName, xpath, nodeName;
  596. xpath.clear().appendf("./%s/%s[%s=\"%s\"]", XML_TAG_HARDWARE, XML_TAG_COMPUTER, XML_ATTR_NETADDRESS, attrName);
  597. IPropertyTree* pHardTemp = pNewEnvTree->queryPropTree(xpath.str());
  598. if(pHardTemp)
  599. nodeName.clear().append(pHardTemp->queryProp("./" XML_ATTR_NAME));//NodeName
  600. xpath.clear().appendf("./%s/%s[%s=\"%s\"]", XML_TAG_SOFTWARE, processName, XML_ATTR_BUILDSET, buildSetName);
  601. IPropertyTree* pComp = pNewEnvTree->queryPropTree(xpath.str());
  602. compName.clear().append(pComp->queryProp(XML_ATTR_NAME));//compName
  603. sb.clear().appendf("<Instance buildSet=\"%s\" compName=\"%s\" ><Instance name=\"%s\" /></Instance>", buildSetName, compName.str(), nodeName.str());
  604. Owned<IPropertyTree> pInstance = createPTreeFromXMLString(sb.str());
  605. if(pInstance)
  606. addInstanceToCompTree(pNewEnvTree, pInstance, sbl.clear(), sb.clear(),NULL);
  607. xpath.clear().appendf("./%s/%s[%s=\"%s\"]/%s[%s=\"%s\"]", XML_TAG_SOFTWARE, processName, XML_ATTR_NAME, compName.str(), XML_TAG_INSTANCE, XML_ATTR_COMPUTER, nodeName.str());
  608. IPropertyTree* pInst = pNewEnvTree->queryPropTree(xpath.str());
  609. if(pInst)
  610. {
  611. pInst->addProp(XML_ATTR_NAME, instName);
  612. }
  613. }
  614. void CWizardInputs::getDefaultsForWizard(IPropertyTree* pNewEnvTree)
  615. {
  616. StringBuffer xpath, tempName, value;
  617. Owned<IPropertyTree> pBuildTree = createPTreeFromIPT(pNewEnvTree->queryPropTree("./" XML_TAG_PROGRAMS));
  618. xpath.clear().appendf("./%s/%s/", XML_TAG_BUILD, XML_TAG_BUILDSET);
  619. Owned<IPropertyTreeIterator> buildSetInsts = pBuildTree->getElements(xpath.str());
  620. ForEach(*buildSetInsts)
  621. {
  622. IPropertyTree* pBuildSet = &buildSetInsts->query();
  623. StringBuffer buildSetPath, compName;
  624. const char* buildSetName = pBuildSet->queryProp(XML_ATTR_NAME);
  625. const char* xsdFileName = pBuildSet->queryProp(XML_ATTR_SCHEMA);
  626. const char* processName = pBuildSet->queryProp(XML_ATTR_PROCESS_NAME);
  627. if(processName && *processName && buildSetName && * buildSetName && xsdFileName && *xsdFileName)
  628. {
  629. Owned<IPropertyTree> pSchema = loadSchema(pBuildTree->queryPropTree("./" XML_TAG_BUILD "[1]"), pBuildSet, buildSetPath, NULL);
  630. Owned<IPropertyTree> pCompTree = generateTreeFromXsd(pNewEnvTree, pSchema, processName, buildSetName, m_cfg, m_service.str(), true, true, this);
  631. xpath.clear().appendf("./%s/%s/[%s=\"%s\"]", XML_TAG_SOFTWARE, processName, XML_ATTR_BUILDSET, buildSetName);
  632. IPropertyTree* pSWCompTree = pNewEnvTree->queryPropTree(xpath.str());
  633. if(pSWCompTree && pCompTree)
  634. {
  635. Owned<IAttributeIterator> iAttr = pCompTree->getAttributes();
  636. ForEach(*iAttr)
  637. {
  638. if( pSWCompTree->hasProp(iAttr->queryName()) && strcmp(iAttr->queryName(), "@buildSet") != 0)
  639. {
  640. if (!strcmp(iAttr->queryName(), XML_ATTR_NAME))
  641. {
  642. StringBuffer sbxpath, sbnew, sbMsg;
  643. sbnew.clear().append(iAttr->queryValue());
  644. sbxpath.clear().append(processName);
  645. getUniqueName(pNewEnvTree, sbnew, sbxpath.str(), XML_TAG_SOFTWARE);
  646. bool ret = checkComponentReferences(pNewEnvTree, pSWCompTree, pSWCompTree->queryProp(iAttr->queryName()), sbMsg, sbnew.str());
  647. if (ret)
  648. pSWCompTree->setProp(iAttr->queryName(), iAttr->queryValue());
  649. }
  650. else
  651. pSWCompTree->setProp(iAttr->queryName(), iAttr->queryValue());
  652. }
  653. }
  654. //Now adding elements
  655. Owned<IPropertyTreeIterator> iterElems = pCompTree->getElements("*");
  656. ForEach (*iterElems)
  657. {
  658. IPropertyTree* pElem = &iterElems->query();
  659. Owned<IAttributeIterator> iAttr = pElem->getAttributes();
  660. ForEach(*iAttr)
  661. {
  662. IPropertyTree* pNewSubElem = pSWCompTree->queryPropTree(pElem->queryName());
  663. if (!pNewSubElem)
  664. {
  665. pNewSubElem = pSWCompTree->addPropTree(pElem->queryName(), createPTreeFromIPT(pElem));
  666. break;
  667. }
  668. else
  669. {
  670. Owned<IPropertyTreeIterator> srcElems = pSWCompTree->getElements(pElem->queryName());
  671. IPropertyTree* pSrcElem = NULL;
  672. ForEach(*srcElems)
  673. {
  674. pSrcElem = &srcElems->query();
  675. Owned<IAttributeIterator> iAttrElem = pElem->getAttributes();
  676. ForEach(*iAttrElem)
  677. {
  678. const char* attrName = iAttrElem->queryName();
  679. if (pSrcElem->hasProp(attrName))
  680. pSrcElem->setProp(attrName, iAttrElem->queryValue());
  681. Owned<IPropertyTreeIterator> iterSubElems = pElem->getElements("*");
  682. ForEach (*iterSubElems)
  683. {
  684. IPropertyTree* pSubElem = &iterSubElems->query();
  685. Owned<IPropertyTreeIterator> srcSubElems = pSWCompTree->getElements(pSubElem->queryName());
  686. IPropertyTree* pSrcSubElem = NULL;
  687. ForEach(*srcSubElems)
  688. {
  689. pSrcSubElem = &srcSubElems->query();
  690. Owned<IAttributeIterator> iAttrElem = pSubElem->getAttributes();
  691. ForEach(*iAttrElem)
  692. {
  693. const char* attrName = iAttrElem->queryName();
  694. if (pSrcSubElem->hasProp(attrName))
  695. pSrcSubElem->setProp(attrName, iAttrElem->queryValue());
  696. }
  697. }
  698. }
  699. }
  700. }
  701. }
  702. }
  703. }
  704. }
  705. }
  706. }
  707. }
  708. void CWizardInputs::addToCompIPMap(const char* buildSetName, const char* value, const char* compName)
  709. {
  710. CInstDetails* pInst = NULL;
  711. if(m_compIpMap.find(buildSetName) != NULL)
  712. {
  713. pInst = m_compIpMap.getValue(buildSetName);
  714. (pInst->getIpAssigned()).append(value);
  715. }
  716. else
  717. {
  718. pInst = new CInstDetails();
  719. pInst->setParams(compName, value);
  720. m_compIpMap.setValue(buildSetName, pInst);
  721. }
  722. }
  723. unsigned CWizardInputs::getCntForAlreadyAssignedIPS(const char* buildSetName)
  724. {
  725. unsigned cnt = 0;
  726. CInstDetails* pInstRoxie = NULL, *pInstThor = NULL;
  727. if (!strcmp(buildSetName, "roxie") || !strcmp(buildSetName, "thor" ))
  728. {
  729. if (m_compIpMap.find("roxie") != NULL)
  730. {
  731. CInstDetails* pInst = m_compIpMap.getValue("roxie");
  732. cnt += pInst->getIpAssigned().length();
  733. }
  734. if (m_compIpMap.find("thor") != NULL)
  735. {
  736. CInstDetails* pInst = m_compIpMap.getValue("thor");
  737. cnt += pInst->getIpAssigned().length();
  738. }
  739. return cnt;
  740. }
  741. else
  742. {
  743. if (m_compIpMap.find("roxie") != NULL)
  744. pInstRoxie = m_compIpMap.getValue("roxie");
  745. if (m_compIpMap.find("thor") != NULL)
  746. pInstThor = m_compIpMap.getValue("thor");
  747. }
  748. HashIterator ips(m_compIpMap);
  749. ForEach(ips)
  750. {
  751. CInstDetails* comp = m_compIpMap.mapToValue(&ips.query());
  752. if (pInstRoxie == comp || pInstThor == comp)
  753. continue;
  754. StringArray& ipArray = comp->getIpAssigned();
  755. cnt += ipArray.length();
  756. }
  757. return cnt;
  758. }
  759. void CWizardInputs::addRoxieThorClusterToEnv(IPropertyTree* pNewEnvTree, CInstDetails* pInstDetails, const char* buildSetName, bool genRoxieOnDemand)
  760. {
  761. StringBuffer xmlForRoxiePorts, xmlForRoxieServers, xpath, compName, computerName, msg;
  762. if(!strcmp(buildSetName, "roxie"))
  763. {
  764. //Before proceeding remove the roxieserver already added to env via xsd.
  765. xpath.clear().appendf("./%s/%s/%s", XML_TAG_SOFTWARE, XML_TAG_ROXIECLUSTER, XML_ATTR_NAME);
  766. compName.clear().append(pNewEnvTree->queryProp(xpath.str()));
  767. xmlForRoxiePorts.clear().appendf("<RoxieData type=\"RoxieFarm\" parentName=\"\" roxieName=\"%s\" ", compName.str());
  768. if (genRoxieOnDemand)
  769. xmlForRoxiePorts.append("port=\"0\" >");
  770. else
  771. xmlForRoxiePorts.append(">");
  772. if (m_roxieNodes >= 1)
  773. xmlForRoxieServers.clear().appendf("<RoxieData type=\"None\" roxieName=\"%s\" >", compName.str());
  774. if(pInstDetails)
  775. {
  776. StringArray& ipAssignedToComp = pInstDetails->getIpAssigned();
  777. xmlForRoxieServers.append("<Instances>");
  778. ForEachItemIn(i, ipAssignedToComp)
  779. {
  780. xpath.clear().appendf("./%s/%s/[%s=\"%s\"]", XML_TAG_HARDWARE, XML_TAG_COMPUTER, XML_ATTR_NETADDRESS, ipAssignedToComp.item(i));
  781. IPropertyTree* pHardTemp = pNewEnvTree->queryPropTree(xpath.str());
  782. if(pHardTemp){
  783. xmlForRoxiePorts.appendf("<Component name=\"%s\" />", pHardTemp->queryProp("./@name"));
  784. xmlForRoxieServers.appendf("<Instance name=\"%s\"/>", pHardTemp->queryProp("./@name"));
  785. }
  786. }
  787. xmlForRoxieServers.append("</Instances>");
  788. xmlForRoxiePorts.append("</RoxieData>");
  789. xmlForRoxieServers.append("</RoxieData>");
  790. handleRoxieOperation(pNewEnvTree, "AddRoxieFarm", xmlForRoxiePorts.str());
  791. if (!genRoxieOnDemand)
  792. handleRoxieOperation(pNewEnvTree, "RoxieSlaveConfig" ,xmlForRoxieServers.str());
  793. }
  794. xpath.clear().appendf("./%s/%s[%s=\"%s\"]/%s[%s=\"\"]", XML_TAG_SOFTWARE, XML_TAG_ROXIECLUSTER, XML_ATTR_NAME, compName.str(), XML_TAG_ROXIE_SERVER, XML_ATTR_NETADDRESS);
  795. pNewEnvTree->removeProp(xpath.str());
  796. xpath.clear().appendf("./%s/%s[%s=\"%s\"]", XML_TAG_SOFTWARE, XML_TAG_ROXIECLUSTER, XML_ATTR_NAME, compName.str());
  797. IPropertyTree* pRoxieCluster = pNewEnvTree->queryPropTree(xpath.str());
  798. if (pRoxieCluster) {
  799. pRoxieCluster->setPropInt("@channelsPerSlave", m_roxieChannelsPerSlave);
  800. }
  801. }
  802. else if(!strcmp(buildSetName, "thor"))
  803. {
  804. //We need only one master
  805. StringBuffer masterIP, xml;
  806. xpath.clear().appendf("./%s/%s/%s", XML_TAG_SOFTWARE, XML_TAG_THORCLUSTER, XML_ATTR_NAME);
  807. compName.clear().append(pNewEnvTree->queryProp(xpath.str()));
  808. if(pInstDetails)
  809. {
  810. StringArray& ipAssignedToComp = pInstDetails->getIpAssigned();
  811. if(!ipAssignedToComp.empty())
  812. masterIP.clear().append(ipAssignedToComp.item(0));
  813. xpath.clear().appendf("./%s/%s[%s=\"%s\"]", XML_TAG_HARDWARE, XML_TAG_COMPUTER, XML_ATTR_NETADDRESS, masterIP.str());
  814. IPropertyTree* pHardTemp = pNewEnvTree->queryPropTree(xpath.str());
  815. if(pHardTemp)
  816. xml.clear().appendf("<ThorData type=\"Master\" name=\"%s\" validateComputers=\"false\" skipExisting=\"false\" > <Computer name=\"%s\" /></ThorData>", compName.str(), pHardTemp->queryProp("./@name"));
  817. handleThorTopologyOp(pNewEnvTree, "Add", xml.str(), msg);
  818. //Now add Slave
  819. xml.clear().appendf("<ThorData type=\"Slave\" name=\"%s\" validateComputers=\"false\" slavesPerNode=\"%d\" channelsPerSlave=\"%d\" skipExisting=\"false\" >", compName.str(), m_thorSlavesPerNode, m_thorChannelsPerSlave);
  820. unsigned numOfNodes = ipAssignedToComp.ordinality() == 1 ? 0 : 1;
  821. for( ; numOfNodes < ipAssignedToComp.ordinality() ; numOfNodes++)
  822. {
  823. xpath.clear().appendf("./%s/%s[%s=\"%s\"]", XML_TAG_HARDWARE, XML_TAG_COMPUTER, XML_ATTR_NETADDRESS, ipAssignedToComp.item(numOfNodes));
  824. IPropertyTree* pHardTemp = pNewEnvTree->queryPropTree(xpath.str());
  825. if(pHardTemp)
  826. xml.appendf("<Computer name=\"%s\" />", pHardTemp->queryProp("./@name"));
  827. }
  828. xml.append("</ThorData>");
  829. handleThorTopologyOp(pNewEnvTree, "Add" , xml.str(), msg);
  830. }
  831. }
  832. }
  833. void CWizardInputs::getEspBindingInformation(IPropertyTree* pNewEnvTree)
  834. {
  835. StringBuffer xpath, sbDefn, xmlArg, compName, sbNewName;
  836. Owned<IPropertyTreeIterator> espProcessIter = pNewEnvTree->getElements("./" XML_TAG_SOFTWARE "/" XML_TAG_ESPPROCESS);
  837. ForEach(*espProcessIter)
  838. {
  839. IPropertyTree* pEspProcess = &espProcessIter->query();
  840. compName.clear().append(pEspProcess->queryProp(XML_ATTR_NAME));
  841. xpath.clear().appendf("./%s/%s/%s[@processName=\"%s\"]", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET, XML_TAG_ESPSERVICE);
  842. Owned<IPropertyTreeIterator> espServiceIter = pNewEnvTree->getElements(xpath.str());
  843. ForEach (*espServiceIter)
  844. {
  845. IPropertyTree* pEspService = &espServiceIter->query();
  846. if(pEspService)
  847. {
  848. StringBuffer espServiceName;
  849. espServiceName.appendf("my%s", pEspService->queryProp("@name"));
  850. xpath.clear().appendf("./%s/%s[%s=\"%s\"]", XML_TAG_SOFTWARE, XML_TAG_ESPSERVICE, XML_ATTR_NAME, espServiceName.str());
  851. IPropertyTree* pEspServiceInSWTree = pNewEnvTree->queryPropTree(xpath.str());
  852. if(pEspServiceInSWTree)
  853. {
  854. xpath.clear().append("./Properties/@defaultPort");
  855. const char* port = pEspService->queryProp(xpath.str());
  856. xpath.clear().append("./Properties/@defaultResourcesBasedn");
  857. const char* resourceBasedn = pEspService->queryProp(xpath.str());
  858. const char* buildSetName = pEspService->queryProp(XML_ATTR_NAME);
  859. const char* processName = pEspService->queryProp(XML_ATTR_PROCESS_NAME);
  860. StringBuffer buildSetPath;
  861. Owned<IPropertyTree> pSchema = loadSchema(pNewEnvTree->queryPropTree("./Programs/Build[1]"), pEspService, buildSetPath, NULL);
  862. xmlArg.clear().appendf("<EspServiceBindings type=\"EspBinding\" compName=\"%s\" > <Item name=\"%s\" params=\"pcType=EspProcess::pcName=%s::subType=EspBinding::subTypeKey=%s \"/></EspServiceBindings>", compName.str(), espServiceName.str(), compName.str(), espServiceName.str());
  863. addEspBindingInformation(xmlArg, pNewEnvTree, sbNewName, NULL, m_cfg, m_service.str());
  864. xpath.clear().appendf("./%s/%s/%s/[%s=\"\"]", XML_TAG_SOFTWARE, XML_TAG_ESPPROCESS, XML_TAG_ESPBINDING, XML_ATTR_SERVICE);
  865. IPropertyTree* pEspBindingInfo = pNewEnvTree->queryPropTree(xpath.str());
  866. pEspBindingInfo->setProp(XML_ATTR_NAME,(espServiceName.toLowerCase()).str());
  867. pEspBindingInfo->setProp(XML_ATTR_SERVICE,(espServiceName.toLowerCase()).str());
  868. pEspBindingInfo->setProp(XML_ATTR_PORT, port );
  869. pEspBindingInfo->setProp("@resourcesBasedn",resourceBasedn);
  870. xpath.clear().appendf("%s/%s[%s=\"%s\"]/Properties", XML_TAG_SOFTWARE, XML_TAG_ESPSERVICE, XML_ATTR_NAME, (espServiceName.toLowerCase()).str());
  871. IPropertyTree* pSvcProps = pNewEnvTree->queryPropTree(xpath.str());
  872. Owned<IPropertyTree> pCompTree = generateTreeFromXsd(pNewEnvTree, pSchema, processName, buildSetName, m_cfg, m_service.str(), true, false, 0);
  873. Owned<IPropertyTreeIterator> i = pSvcProps->getElements("Authenticate");
  874. ForEach(*i)
  875. {
  876. IPropertyTree* pAuthCopy = createPTreeFromIPT(&i->query());
  877. mergeAttributes(pAuthCopy, pCompTree->queryPropTree("Authenticate"));
  878. IPropertyTree* pNewNode = pEspBindingInfo->addPropTree("Authenticate", pAuthCopy);
  879. }
  880. i.setown( pSvcProps->getElements("AuthenticateFeature") );
  881. ForEach(*i)
  882. {
  883. IPropertyTree* pAuthCopy = createPTreeFromIPT(&i->query());
  884. //Adding authentication to true for espbinding.
  885. pAuthCopy->addProp("@authenticate","Yes");
  886. mergeAttributes(pAuthCopy, pCompTree->queryPropTree("AuthenticateFeature"));
  887. IPropertyTree* pNewNode = pEspBindingInfo->addPropTree("AuthenticateFeature", pAuthCopy);
  888. }
  889. i.setown( pSvcProps->getElements("AuthenticateSetting") );
  890. ForEach(*i)
  891. {
  892. IPropertyTree* pAuthCopy = createPTreeFromIPT(&i->query());
  893. pAuthCopy->addProp("@include", "Yes");
  894. mergeAttributes(pAuthCopy, pCompTree->queryPropTree("AuthenticateSetting"));
  895. IPropertyTree* pNewNode = pEspBindingInfo->addPropTree("AuthenticateSetting", pAuthCopy);
  896. }
  897. }
  898. }
  899. }
  900. }
  901. }
  902. void CWizardInputs::addTopology(IPropertyTree* pNewEnvTree)
  903. {
  904. StringBuffer xpath;
  905. if(!pNewEnvTree->hasProp("./" XML_TAG_SOFTWARE "/" XML_TAG_TOPOLOGY))
  906. pNewEnvTree->addPropTree("./" XML_TAG_SOFTWARE "/" XML_TAG_TOPOLOGY, createPTree());
  907. HashIterator sIter(m_compForTopology);
  908. for(sIter.first();sIter.isValid();sIter.next())
  909. {
  910. IMapping &cur = sIter.query();
  911. IPropertyTree* pCluster = createTopologyForComp(pNewEnvTree,(const char *) cur.getKey());
  912. if(pCluster)
  913. pNewEnvTree->addPropTree("./" XML_TAG_SOFTWARE "/" XML_TAG_TOPOLOGY "/Cluster", pCluster);
  914. }
  915. }
  916. IPropertyTree* CWizardInputs::createTopologyForComp(IPropertyTree* pNewEnvTree, const char* component)
  917. {
  918. StringBuffer xmlTag, xpath , compName, clusterStr;
  919. if(!strcmp(component, "roxie"))
  920. xmlTag.clear().append(XML_TAG_ROXIECLUSTER);
  921. else if(!strcmp(component, "thor"))
  922. xmlTag.clear().append(XML_TAG_THORCLUSTER);
  923. else if(!strcmp(component, "hthor"))
  924. xmlTag.clear().append("hthor");
  925. xpath.clear().appendf("./%s/%s[1]/%s", XML_TAG_SOFTWARE, xmlTag.str(), XML_ATTR_NAME);
  926. clusterStr.clear().appendf("<Cluster name=\"%s\" prefix=\"%s\" alias=\"\"></Cluster>", component, component);
  927. IPropertyTree* pCluster = createPTreeFromXMLString(clusterStr.str());
  928. if(pCluster)
  929. {
  930. if(pNewEnvTree->hasProp(xpath.str()))
  931. {
  932. IPropertyTree* pComponent = pCluster->addPropTree(xmlTag.str(), createPTree());
  933. pComponent->addProp(XML_ATTR_PROCESS, pNewEnvTree->queryProp(xpath.str()));
  934. }
  935. if(m_compForTopology.find(component) != NULL)
  936. {
  937. StringArray* clusterCompEle = 0;
  938. StringArrayPtr* clusterPair = m_compForTopology.getValue(component);
  939. if(clusterPair)
  940. {
  941. clusterCompEle = (*clusterPair);
  942. for(unsigned i = 0 ; i < clusterCompEle->ordinality() ; i++)
  943. {
  944. const char* eachClusterElem = clusterCompEle->item(i);
  945. xpath.clear().appendf("./%s/%s/%s[%s=\"%s\"]", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET, XML_ATTR_NAME, eachClusterElem);
  946. IPropertyTree* pBuildset = pNewEnvTree->queryPropTree(xpath.str());
  947. if(pBuildset)
  948. {
  949. const char* processName = pBuildset->queryProp(XML_ATTR_PROCESS_NAME);
  950. if(processName && *processName)
  951. {
  952. IPropertyTree* pElement = pCluster->addPropTree(processName,createPTree());
  953. xpath.clear().appendf("./%s/%s[1]/%s", XML_TAG_SOFTWARE, processName, XML_ATTR_NAME);
  954. if(pElement && pNewEnvTree->hasProp(xpath.str()))
  955. pElement->addProp(XML_ATTR_PROCESS, pNewEnvTree->queryProp(xpath.str()));
  956. }
  957. }
  958. }
  959. }
  960. clusterCompEle->kill();
  961. }
  962. return pCluster;
  963. }
  964. else
  965. return NULL;
  966. }
  967. void CWizardInputs::checkForDependencies()
  968. {
  969. StringBuffer xpath;
  970. if(m_buildSetTree)
  971. {
  972. xpath.clear().appendf("./%s/%s/%s", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET);
  973. Owned<IPropertyTreeIterator> buildSetInsts = m_buildSetTree->getElements(xpath.str());
  974. ForEach(*buildSetInsts)
  975. {
  976. IPropertyTree* pBuildSet = &buildSetInsts->query();
  977. const char* buildSetName = pBuildSet->queryProp(XML_ATTR_NAME);
  978. unsigned numOfNodesNeeded = 1;
  979. if((!strcmp(buildSetName,"roxie") && m_roxieNodes == 0 )|| (!strcmp(buildSetName,"thor")&& m_thorNodes == 0)){
  980. numOfNodesNeeded = 0;
  981. m_doNotGenComp.append(buildSetName);
  982. m_compForTopology.remove("thor_roxie");
  983. if (!strcmp(buildSetName,"thor"))
  984. m_compForTopology.remove("thor");
  985. }
  986. if(numOfNodesNeeded == 0 || (m_doNotGenComp.find(buildSetName) != NotFound))
  987. {
  988. if(m_compForTopology.find(buildSetName) != NULL )
  989. m_compForTopology.remove(buildSetName);
  990. checkAndAddDependComponent(buildSetName);
  991. }
  992. }
  993. }
  994. }
  995. void CWizardInputs::checkAndAddDependComponent(const char* key)
  996. {
  997. StringBuffer paramEntry(key);
  998. paramEntry.append("_dependencies");
  999. if(m_algProp)
  1000. {
  1001. if(m_algProp->hasProp(paramEntry.str()))
  1002. {
  1003. StringArray sArray;
  1004. sArray.appendList(m_algProp->queryProp(paramEntry.str()), ";");
  1005. ForEachItemIn(x, sArray)
  1006. {
  1007. if(m_doNotGenComp.find(sArray.item(x)) == NotFound)
  1008. {
  1009. m_doNotGenComp.append(sArray.item(x));
  1010. checkAndAddDependComponent(sArray.item(x));
  1011. }
  1012. }
  1013. }
  1014. }
  1015. }
  1016. unsigned CWizardInputs::getNumOfNodes(const char* compName)
  1017. {
  1018. if(m_compIpMap.find(compName) != NULL)
  1019. {
  1020. CInstDetails* pInst = NULL;
  1021. pInst = m_compIpMap.getValue(compName);
  1022. StringArray& ipArr = pInst->getIpAssigned();
  1023. return ipArr.ordinality();
  1024. }
  1025. return 0;
  1026. }
  1027. void CWizardInputs::setTopologyParam()
  1028. {
  1029. if(m_clusterForTopology.ordinality() > 0)
  1030. {
  1031. StringBuffer topologySec;
  1032. ForEachItemIn(x, m_clusterForTopology)
  1033. {
  1034. topologySec.clear().appendf("%s_topology",m_clusterForTopology.item(x));
  1035. const char * elemForCluster = m_algProp->queryProp(topologySec.str());
  1036. if(elemForCluster && *elemForCluster)
  1037. {
  1038. StringArray* compClusterArr = new StringArray();
  1039. StringArray clusterElemArr;
  1040. clusterElemArr.appendList(elemForCluster, ",");
  1041. ForEachItemIn(y, clusterElemArr)
  1042. compClusterArr->append(clusterElemArr.item(y));
  1043. m_compForTopology.setValue(m_clusterForTopology.item(x),compClusterArr);
  1044. }
  1045. }
  1046. }
  1047. }
  1048. void CWizardInputs::addComponentToSoftware(IPropertyTree* pNewEnvTree, IPropertyTree* pBuildSet)
  1049. {
  1050. if (!pBuildSet)
  1051. return;
  1052. StringBuffer xpath, sbNewName;
  1053. StringBuffer buildSetPath, compName, assignedIP, sbl;
  1054. const char* buildSetName = pBuildSet->queryProp(XML_ATTR_NAME);
  1055. const char* xsdFileName = pBuildSet->queryProp(XML_ATTR_SCHEMA);
  1056. const char* processName = pBuildSet->queryProp(XML_ATTR_PROCESS_NAME);
  1057. StringBuffer deployable(pBuildSet->queryProp("@" TAG_DEPLOYABLE));
  1058. unsigned numOfIpNeeded = 1;
  1059. if (!hasBaseInstantRequested())
  1060. numOfIpNeeded = 0;
  1061. if (m_doNotGenComp.find(buildSetName) != NotFound )
  1062. return;
  1063. if (processName && *processName && buildSetName && * buildSetName && xsdFileName && *xsdFileName)
  1064. {
  1065. Owned<IPropertyTree> pSchema = loadSchema(m_buildSetTree->queryPropTree("./" XML_TAG_PROGRAMS "/" XML_TAG_BUILD "[1]"), pBuildSet, buildSetPath, NULL);
  1066. IPropertyTree* pCompTree = generateTreeFromXsd(pNewEnvTree, pSchema, processName, buildSetName, m_cfg, m_service.str(), false);
  1067. sbNewName.clear();
  1068. if (strstr(buildSetName ,"my") == NULL && (strcmp(buildSetName, "topology") != 0))
  1069. sbNewName.append("my");
  1070. addComponentToEnv(pNewEnvTree, buildSetName, sbNewName, pCompTree);
  1071. if (!strcmp(processName, XML_TAG_ESPSERVICE) || !strcmp(processName, XML_TAG_PLUGINPROCESS))
  1072. processName = buildSetName;
  1073. if (strcmp(deployable,"no") != 0)
  1074. {
  1075. if (m_compOnAllNodes.find(buildSetName) != NotFound)
  1076. {
  1077. for (unsigned i = 0; i < m_ipaddressSupport.ordinality(); i++)
  1078. {
  1079. sbl.clear().appendf("s").append(i+1);
  1080. assignedIP.clear().append(m_ipaddressSupport.item(i));
  1081. addInstanceToTree(pNewEnvTree, assignedIP, processName, buildSetName,sbl.str());
  1082. }
  1083. for (unsigned i = 0; i < m_ipaddress.ordinality(); i++)
  1084. {
  1085. sbl.clear().appendf("s").append(m_ipaddressSupport.ordinality() + i+1);
  1086. assignedIP.clear().append(m_ipaddress.item(i));
  1087. addInstanceToTree(pNewEnvTree, assignedIP, processName, buildSetName,sbl.str());
  1088. }
  1089. int nCount = 1;
  1090. for (unsigned i = 0; i < m_arrBuildSetsWithAssignedIPs.ordinality(); i++)
  1091. {
  1092. const StringArray &strIPList = getIpAddrMap(m_arrBuildSetsWithAssignedIPs.item(i));
  1093. for (unsigned i2 = 0; i2 < strIPList.ordinality(); i2++)
  1094. {
  1095. sbl.set("s").append(m_ipaddress.ordinality() + m_ipaddressSupport.ordinality() + nCount++);
  1096. assignedIP.set(strIPList.item(i2));
  1097. addInstanceToTree(pNewEnvTree, assignedIP, processName, buildSetName,sbl.str());
  1098. }
  1099. }
  1100. }
  1101. else if (numOfIpNeeded > 0)
  1102. {
  1103. if (!strcmp(buildSetName, "roxie"))
  1104. numOfIpNeeded = m_roxieNodes;
  1105. else if (!strcmp(buildSetName, "thor"))
  1106. numOfIpNeeded = m_thorNodes + 1;
  1107. else if (!strcmp(buildSetName, "esp"))
  1108. numOfIpNeeded = m_espNodes;
  1109. CInstDetails* pInstDetail = getServerIPMap(sbNewName.str(), buildSetName, pNewEnvTree, numOfIpNeeded);
  1110. if (pInstDetail)
  1111. {
  1112. if (!strcmp(buildSetName, "roxie") || !strcmp(buildSetName, "thor" ))
  1113. {
  1114. addRoxieThorClusterToEnv(pNewEnvTree, pInstDetail, buildSetName);
  1115. if (!strcmp(buildSetName, "roxie") && m_roxieOnDemand)
  1116. addRoxieThorClusterToEnv(pNewEnvTree, pInstDetail, buildSetName, true);
  1117. }
  1118. else
  1119. {
  1120. StringArray& ipArr = pInstDetail->getIpAssigned();
  1121. ForEachItemIn(x, ipArr)
  1122. {
  1123. assignedIP.clear().append(ipArr.item(x));
  1124. if (!strcmp(buildSetName, "esp"))
  1125. {
  1126. StringBuffer s1("s_1");
  1127. const char *pName = getUniqueName2(pNewEnvTree, s1, XML_TAG_ESPPROCESS, "");
  1128. addInstanceToTree(pNewEnvTree, assignedIP, processName, buildSetName, pName);
  1129. }
  1130. else
  1131. addInstanceToTree(pNewEnvTree, assignedIP, processName, buildSetName, "s1");
  1132. }
  1133. }
  1134. }
  1135. }
  1136. }
  1137. }
  1138. }
  1139. StringArray& CWizardInputs::getIpAddrMap(const char* buildSetName)
  1140. {
  1141. if (buildSetName && *buildSetName)
  1142. {
  1143. for (unsigned i = 0; i < m_arrBuildSetsWithAssignedIPs.ordinality(); i++)
  1144. {
  1145. if (stricmp(buildSetName, m_arrBuildSetsWithAssignedIPs.item(i)) == 0)
  1146. {
  1147. m_sipaddress.clear();
  1148. formIPList(m_arrAssignedIPs.item(i), m_sipaddress);
  1149. return m_sipaddress;
  1150. }
  1151. }
  1152. }
  1153. if (m_supportNodes == 0)
  1154. return m_ipaddress;
  1155. else
  1156. {
  1157. if (!strcmp(buildSetName, "roxie") || !strcmp(buildSetName, "thor" ))
  1158. return m_ipaddress;
  1159. }
  1160. return m_ipaddressSupport;
  1161. }
  1162. bool CWizardInputs::hasBaseInstantRequested()
  1163. {
  1164. return (m_supportNodes > 0) || (m_espNodes > 0) || (m_roxieNodes > 0) || (m_thorNodes > 0);
  1165. }