wizardInputs.cpp 44 KB

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