wizardInputs.cpp 46 KB

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