wizardInputs.cpp 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  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. unsigned x;
  411. IpAddress ipaddr;
  412. for(unsigned i = 0; i < m_ipaddressSupport.ordinality(); i++)
  413. {
  414. IPropertyTree* pComputer = pCompTree->addPropTree(XML_TAG_COMPUTER,createPTree());
  415. ipaddr.ipset(m_ipaddressSupport.item(i));
  416. ipaddr.getNetAddress(sizeof(x),&x);
  417. name.clear().appendf("node%03d%03d", (x >> 16) & 0xFF, (x >> 24) & 0xFF);
  418. getUniqueName(pCompTree, name, XML_TAG_COMPUTER, "");
  419. pComputer->addProp(XML_ATTR_COMPUTERTYPE, "linuxmachine");
  420. pComputer->addProp(XML_ATTR_DOMAIN, "localdomain");
  421. pComputer->addProp(XML_ATTR_NAME, name.str());
  422. pComputer->addProp(XML_ATTR_NETADDRESS, m_ipaddressSupport.item(i));
  423. }
  424. for(unsigned i = 0; i < m_ipaddress.ordinality(); i++)
  425. {
  426. IPropertyTree* pComputer = pCompTree->addPropTree(XML_TAG_COMPUTER,createPTree());
  427. ipaddr.ipset(m_ipaddress.item(i));
  428. ipaddr.getNetAddress(sizeof(x),&x);
  429. name.clear().appendf("node%03d%03d", (x >> 16) & 0xFF, (x >> 24) & 0xFF);
  430. getUniqueName(pCompTree, name, XML_TAG_COMPUTER, "");
  431. pComputer->addProp(XML_ATTR_COMPUTERTYPE, "linuxmachine");
  432. pComputer->addProp(XML_ATTR_DOMAIN, "localdomain");
  433. pComputer->addProp(XML_ATTR_NAME, name.str());
  434. pComputer->addProp(XML_ATTR_NETADDRESS, m_ipaddress.item(i));
  435. }
  436. pNewEnvTree->addPropTree(XML_TAG_HARDWARE, createPTreeFromIPT(pCompTree));
  437. //Before we generate software tree check for dependencies of component for do_not_generate ,roxie, thor
  438. checkForDependencies();
  439. generateSoftwareTree(pNewEnvTree);
  440. return pNewEnvTree;
  441. }
  442. void CWizardInputs::generateSoftwareTree(IPropertyTree* pNewEnvTree)
  443. {
  444. StringBuffer xpath;
  445. if(m_buildSetTree)
  446. {
  447. bool ovrLog = true, ovrRun = true;
  448. if (m_overrideDirs && m_overrideDirs->count() > 0)
  449. {
  450. HashIterator iter(*m_overrideDirs);
  451. ForEach(iter)
  452. {
  453. IMapping &cur = iter.query();
  454. StringBuffer* dirvalue = m_overrideDirs->mapToValue(&cur);
  455. const char * key = (const char*)cur.getKey();
  456. xpath.clear().appendf(XML_TAG_SOFTWARE"/Directories/Category[@name='%s']", key);
  457. if (!strcmp(key, "log"))
  458. ovrLog = false;
  459. else if (!strcmp(key, "run"))
  460. ovrRun = false;
  461. IPropertyTree* pDir = m_buildSetTree->queryPropTree(xpath.str());
  462. if (pDir)
  463. pDir->setProp("@dir", dirvalue->str());
  464. else
  465. {
  466. pDir = m_buildSetTree->queryPropTree(XML_TAG_SOFTWARE"/Directories/")->addPropTree("Category", createPTree());
  467. pDir->setProp(XML_ATTR_NAME, (const char*)cur.getKey());
  468. pDir->setProp("@dir", dirvalue->str());
  469. }
  470. }
  471. }
  472. pNewEnvTree->addPropTree(XML_TAG_SOFTWARE,createPTreeFromIPT(m_buildSetTree->queryPropTree("./"XML_TAG_SOFTWARE)));
  473. xpath.clear().appendf("%s/%s/%s[%s='%s']/LocalEnvConfFile", XML_TAG_SOFTWARE, XML_TAG_ESPPROCESS, XML_TAG_ESPSERVICE, XML_ATTR_NAME, m_service.str());
  474. const char* tmp = m_cfg->queryProp(xpath.str());
  475. if (tmp && *tmp)
  476. {
  477. Owned<IProperties> pParams = createProperties(tmp);
  478. updateDirsWithConfSettings(pNewEnvTree, pParams, ovrLog, ovrRun);
  479. }
  480. const char* firstComp = "esp";
  481. xpath.clear().appendf("./%s/%s/%s/[@name=\"%s\"]", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET, firstComp);
  482. IPropertyTree* pEspBuildSet = m_buildSetTree->queryPropTree(xpath.str());
  483. if (pEspBuildSet)
  484. addComponentToSoftware(pNewEnvTree, pEspBuildSet);
  485. xpath.clear().appendf("./%s/%s/%s", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET);
  486. Owned<IPropertyTreeIterator> buildSetInsts = m_buildSetTree->getElements(xpath.str());
  487. ForEach(*buildSetInsts)
  488. {
  489. IPropertyTree* pBuildSet = &buildSetInsts->query();
  490. const char* buildSetName = pBuildSet->queryProp(XML_ATTR_NAME);
  491. if (strcmp(firstComp, buildSetName))
  492. addComponentToSoftware(pNewEnvTree, &buildSetInsts->query());
  493. }
  494. getEspBindingInformation(pNewEnvTree);
  495. addTopology(pNewEnvTree);
  496. getDefaultsForWizard(pNewEnvTree);
  497. }
  498. }
  499. void CWizardInputs::addInstanceToTree(IPropertyTree* pNewEnvTree, StringBuffer attrName, const char* processName, const char* buildSetName, const char* instName)
  500. {
  501. StringBuffer sb, sbl, compName, xpath, nodeName;
  502. xpath.clear().appendf("./%s/%s[%s=\"%s\"]", XML_TAG_HARDWARE, XML_TAG_COMPUTER, XML_ATTR_NETADDRESS, attrName.str());
  503. IPropertyTree* pHardTemp = pNewEnvTree->queryPropTree(xpath.str());
  504. if(pHardTemp)
  505. nodeName.clear().append(pHardTemp->queryProp("./"XML_ATTR_NAME));//NodeName
  506. xpath.clear().appendf("./%s/%s[%s=\"%s\"]", XML_TAG_SOFTWARE, processName, XML_ATTR_BUILDSET, buildSetName);
  507. IPropertyTree* pComp = pNewEnvTree->queryPropTree(xpath.str());
  508. compName.clear().append(pComp->queryProp(XML_ATTR_NAME));//compName
  509. sb.clear().appendf("<Instance buildSet=\"%s\" compName=\"%s\" ><Instance name=\"%s\" /></Instance>", buildSetName, compName.str(), nodeName.str());
  510. Owned<IPropertyTree> pInstance = createPTreeFromXMLString(sb.str());
  511. if(pInstance)
  512. addInstanceToCompTree(pNewEnvTree, pInstance, sbl.clear(), sb.clear(),NULL);
  513. 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());
  514. IPropertyTree* pInst = pNewEnvTree->queryPropTree(xpath.str());
  515. if(pInst)
  516. {
  517. pInst->addProp(XML_ATTR_NAME, instName);
  518. }
  519. }
  520. void CWizardInputs::getDefaultsForWizard(IPropertyTree* pNewEnvTree)
  521. {
  522. StringBuffer xpath, tempName, value;
  523. Owned<IPropertyTree> pBuildTree = createPTreeFromIPT(pNewEnvTree->queryPropTree("./"XML_TAG_PROGRAMS));
  524. xpath.clear().appendf("./%s/%s/", XML_TAG_BUILD, XML_TAG_BUILDSET);
  525. Owned<IPropertyTreeIterator> buildSetInsts = pBuildTree->getElements(xpath.str());
  526. ForEach(*buildSetInsts)
  527. {
  528. IPropertyTree* pBuildSet = &buildSetInsts->query();
  529. StringBuffer buildSetPath, compName;
  530. const char* buildSetName = pBuildSet->queryProp(XML_ATTR_NAME);
  531. const char* xsdFileName = pBuildSet->queryProp(XML_ATTR_SCHEMA);
  532. const char* processName = pBuildSet->queryProp(XML_ATTR_PROCESS_NAME);
  533. if(processName && *processName && buildSetName && * buildSetName && xsdFileName && *xsdFileName)
  534. {
  535. Owned<IPropertyTree> pSchema = loadSchema(pBuildTree->queryPropTree("./"XML_TAG_BUILD"[1]"), pBuildSet, buildSetPath, NULL);
  536. Owned<IPropertyTree> pCompTree = generateTreeFromXsd(pNewEnvTree, pSchema, processName, buildSetName, m_cfg, m_service.str(), true, true, this);
  537. xpath.clear().appendf("./%s/%s/[%s=\"%s\"]", XML_TAG_SOFTWARE, processName, XML_ATTR_BUILDSET, buildSetName);
  538. IPropertyTree* pSWCompTree = pNewEnvTree->queryPropTree(xpath.str());
  539. if(pSWCompTree && pCompTree)
  540. {
  541. Owned<IAttributeIterator> iAttr = pCompTree->getAttributes();
  542. ForEach(*iAttr)
  543. {
  544. if( pSWCompTree->hasProp(iAttr->queryName()) && strcmp(iAttr->queryName(), "@buildSet") != 0)
  545. {
  546. if (!strcmp(iAttr->queryName(), XML_ATTR_NAME))
  547. {
  548. StringBuffer sbxpath, sbnew, sbMsg;
  549. sbnew.clear().append(iAttr->queryValue());
  550. sbxpath.clear().append(processName);
  551. getUniqueName(pNewEnvTree, sbnew, sbxpath.str(), XML_TAG_SOFTWARE);
  552. bool ret = checkComponentReferences(pNewEnvTree, pSWCompTree, pSWCompTree->queryProp(iAttr->queryName()), sbMsg, sbnew.str());
  553. if (ret)
  554. pSWCompTree->setProp(iAttr->queryName(), iAttr->queryValue());
  555. }
  556. else
  557. pSWCompTree->setProp(iAttr->queryName(), iAttr->queryValue());
  558. }
  559. }
  560. //Now adding elements
  561. Owned<IPropertyTreeIterator> iterElems = pCompTree->getElements("*");
  562. ForEach (*iterElems)
  563. {
  564. IPropertyTree* pElem = &iterElems->query();
  565. Owned<IAttributeIterator> iAttr = pElem->getAttributes();
  566. ForEach(*iAttr)
  567. {
  568. IPropertyTree* pNewSubElem = pSWCompTree->queryPropTree(pElem->queryName());
  569. if (!pNewSubElem)
  570. {
  571. pNewSubElem = pSWCompTree->addPropTree(pElem->queryName(), createPTreeFromIPT(pElem));
  572. break;
  573. }
  574. else
  575. {
  576. Owned<IPropertyTreeIterator> srcElems = pSWCompTree->getElements(pElem->queryName());
  577. IPropertyTree* pSrcElem = NULL;
  578. ForEach(*srcElems)
  579. {
  580. pSrcElem = &srcElems->query();
  581. Owned<IAttributeIterator> iAttrElem = pElem->getAttributes();
  582. ForEach(*iAttrElem)
  583. {
  584. const char* attrName = iAttrElem->queryName();
  585. if (pSrcElem->hasProp(attrName))
  586. pSrcElem->setProp(attrName, iAttrElem->queryValue());
  587. Owned<IPropertyTreeIterator> iterSubElems = pElem->getElements("*");
  588. ForEach (*iterSubElems)
  589. {
  590. IPropertyTree* pSubElem = &iterSubElems->query();
  591. Owned<IPropertyTreeIterator> srcSubElems = pSWCompTree->getElements(pSubElem->queryName());
  592. IPropertyTree* pSrcSubElem = NULL;
  593. ForEach(*srcSubElems)
  594. {
  595. pSrcSubElem = &srcSubElems->query();
  596. Owned<IAttributeIterator> iAttrElem = pSubElem->getAttributes();
  597. ForEach(*iAttrElem)
  598. {
  599. const char* attrName = iAttrElem->queryName();
  600. if (pSrcSubElem->hasProp(attrName))
  601. pSrcSubElem->setProp(attrName, iAttrElem->queryValue());
  602. }
  603. }
  604. }
  605. }
  606. }
  607. }
  608. }
  609. }
  610. }
  611. }
  612. }
  613. }
  614. void CWizardInputs::addToCompIPMap(const char* buildSetName, const char* value, const char* compName)
  615. {
  616. CInstDetails* pInst = NULL;
  617. if(m_compIpMap.find(buildSetName) != NULL)
  618. {
  619. pInst = m_compIpMap.getValue(buildSetName);
  620. (pInst->getIpAssigned()).append(value);
  621. }
  622. else
  623. {
  624. pInst = new CInstDetails();
  625. pInst->setParams(compName, value);
  626. m_compIpMap.setValue(buildSetName, pInst);
  627. }
  628. }
  629. unsigned CWizardInputs::getCntForAlreadyAssignedIPS(const char* buildSetName)
  630. {
  631. unsigned cnt = 0;
  632. CInstDetails* pInstRoxie = NULL, *pInstThor = NULL;
  633. if (!strcmp(buildSetName, "roxie") || !strcmp(buildSetName, "thor" ))
  634. {
  635. if (m_compIpMap.find("roxie") != NULL)
  636. {
  637. CInstDetails* pInst = m_compIpMap.getValue("roxie");
  638. cnt += pInst->getIpAssigned().length();
  639. }
  640. if (m_compIpMap.find("thor") != NULL)
  641. {
  642. CInstDetails* pInst = m_compIpMap.getValue("thor");
  643. cnt += pInst->getIpAssigned().length();
  644. }
  645. return cnt;
  646. }
  647. else
  648. {
  649. if (m_compIpMap.find("roxie") != NULL)
  650. pInstRoxie = m_compIpMap.getValue("roxie");
  651. if (m_compIpMap.find("thor") != NULL)
  652. pInstThor = m_compIpMap.getValue("thor");
  653. }
  654. HashIterator ips(m_compIpMap);
  655. ForEach(ips)
  656. {
  657. CInstDetails* comp = m_compIpMap.mapToValue(&ips.query());
  658. if (pInstRoxie == comp || pInstThor == comp)
  659. continue;
  660. StringArray& ipArray = comp->getIpAssigned();
  661. cnt += ipArray.length();
  662. }
  663. return cnt;
  664. }
  665. void CWizardInputs::addRoxieThorClusterToEnv(IPropertyTree* pNewEnvTree, CInstDetails* pInstDetails, const char* buildSetName, bool genRoxieOnDemand)
  666. {
  667. StringBuffer xmlForRoxieServer, xmlForRoxieSlave, xpath, compName, computerName, msg;
  668. if(!strcmp(buildSetName, "roxie"))
  669. {
  670. //Before proceeding remove the roxieserver already added to env via xsd.
  671. xpath.clear().appendf("./%s/%s/%s", XML_TAG_SOFTWARE, XML_TAG_ROXIECLUSTER, XML_ATTR_NAME);
  672. compName.clear().append(pNewEnvTree->queryProp(xpath.str()));
  673. xmlForRoxieServer.clear().appendf("<RoxieData type=\"RoxieFarm\" parentName=\"\" roxieName=\"%s\" ", compName.str());
  674. if (genRoxieOnDemand)
  675. xmlForRoxieServer.append("port=\"0\" >");
  676. else
  677. xmlForRoxieServer.append(">");
  678. if (m_roxieNodes == 1)
  679. xmlForRoxieSlave.clear().appendf("<RoxieData type=\"None\" val1=\"undefined\" val2=\"undefined\" roxieName=\"%s\" >", compName.str());
  680. else
  681. xmlForRoxieSlave.clear().appendf("<RoxieData type=\"%s\" val1=\"%d\" val2=\"%d\" roxieName=\"%s\" >",
  682. m_roxieAgentRedType.str(),
  683. m_roxieAgentRedChannels, m_roxieAgentRedOffset, compName.str());
  684. if(pInstDetails)
  685. {
  686. StringArray& ipAssignedToComp = pInstDetails->getIpAssigned();
  687. ForEachItemIn(i, ipAssignedToComp)
  688. {
  689. xpath.clear().appendf("./%s/%s/[%s=\"%s\"]", XML_TAG_HARDWARE, XML_TAG_COMPUTER, XML_ATTR_NETADDRESS, ipAssignedToComp.item(i));
  690. IPropertyTree* pHardTemp = pNewEnvTree->queryPropTree(xpath.str());
  691. if(pHardTemp){
  692. xmlForRoxieServer.appendf("<Component name=\"%s\" />", pHardTemp->queryProp("./@name"));
  693. xmlForRoxieSlave.appendf("<Computer name=\"%s\" />", pHardTemp->queryProp("./@name"));
  694. }
  695. }
  696. xmlForRoxieServer.append("</RoxieData>");
  697. xmlForRoxieSlave.append("</RoxieData>");
  698. handleRoxieOperation(pNewEnvTree, "AddRoxieFarm", xmlForRoxieServer.str());
  699. if (!genRoxieOnDemand)
  700. handleRoxieOperation(pNewEnvTree, "RoxieSlaveConfig" ,xmlForRoxieSlave.str());
  701. }
  702. 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);
  703. pNewEnvTree->removeProp(xpath.str());
  704. }
  705. else if(!strcmp(buildSetName, "thor"))
  706. {
  707. //We need only one master
  708. StringBuffer masterIP, xml;
  709. xpath.clear().appendf("./%s/%s/%s", XML_TAG_SOFTWARE, XML_TAG_THORCLUSTER, XML_ATTR_NAME);
  710. compName.clear().append(pNewEnvTree->queryProp(xpath.str()));
  711. if(pInstDetails)
  712. {
  713. StringArray& ipAssignedToComp = pInstDetails->getIpAssigned();
  714. if(!ipAssignedToComp.empty())
  715. masterIP.clear().append(ipAssignedToComp.item(0));
  716. xpath.clear().appendf("./%s/%s[%s=\"%s\"]", XML_TAG_HARDWARE, XML_TAG_COMPUTER, XML_ATTR_NETADDRESS, masterIP.str());
  717. IPropertyTree* pHardTemp = pNewEnvTree->queryPropTree(xpath.str());
  718. if(pHardTemp)
  719. xml.clear().appendf("<ThorData type=\"Master\" name=\"%s\" validateComputers=\"false\" skipExisting=\"false\" > <Computer name=\"%s\" /></ThorData>", compName.str(), pHardTemp->queryProp("./@name"));
  720. handleThorTopologyOp(pNewEnvTree, "Add", xml.str(), msg);
  721. //Now add Slave
  722. xml.clear().appendf("<ThorData type=\"Slave\" name=\"%s\" validateComputers=\"false\" slavesPerNode=\"%d\" skipExisting=\"false\" >", compName.str(), m_thorSlavesPerNode);
  723. unsigned numOfNodes = ipAssignedToComp.ordinality() == 1 || m_thorNodes == m_ipaddress.ordinality()? 0 : 1;
  724. for( ; numOfNodes < ipAssignedToComp.ordinality() ; numOfNodes++)
  725. {
  726. xpath.clear().appendf("./%s/%s[%s=\"%s\"]", XML_TAG_HARDWARE, XML_TAG_COMPUTER, XML_ATTR_NETADDRESS, ipAssignedToComp.item(numOfNodes));
  727. IPropertyTree* pHardTemp = pNewEnvTree->queryPropTree(xpath.str());
  728. if(pHardTemp)
  729. xml.appendf("<Computer name=\"%s\" />", pHardTemp->queryProp("./@name"));
  730. }
  731. xml.append("</ThorData>");
  732. handleThorTopologyOp(pNewEnvTree, "Add" , xml.str(), msg);
  733. }
  734. }
  735. }
  736. void CWizardInputs::getEspBindingInformation(IPropertyTree* pNewEnvTree)
  737. {
  738. StringBuffer xpath, sbDefn, xmlArg, compName, sbNewName;
  739. Owned<IPropertyTreeIterator> espProcessIter = pNewEnvTree->getElements("./"XML_TAG_SOFTWARE"/"XML_TAG_ESPPROCESS);
  740. ForEach(*espProcessIter)
  741. {
  742. IPropertyTree* pEspProcess = &espProcessIter->query();
  743. compName.clear().append(pEspProcess->queryProp(XML_ATTR_NAME));
  744. xpath.clear().appendf("./%s/%s/%s[@processName=\"%s\"]", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET, XML_TAG_ESPSERVICE);
  745. Owned<IPropertyTreeIterator> espServiceIter = pNewEnvTree->getElements(xpath.str());
  746. ForEach (*espServiceIter)
  747. {
  748. IPropertyTree* pEspService = &espServiceIter->query();
  749. if(pEspService)
  750. {
  751. StringBuffer espServiceName;
  752. espServiceName.appendf("my%s", pEspService->queryProp("@name"));
  753. xpath.clear().appendf("./%s/%s[%s=\"%s\"]", XML_TAG_SOFTWARE, XML_TAG_ESPSERVICE, XML_ATTR_NAME, espServiceName.str());
  754. IPropertyTree* pEspServiceInSWTree = pNewEnvTree->queryPropTree(xpath.str());
  755. if(pEspServiceInSWTree)
  756. {
  757. xpath.clear().append("./Properties/@defaultPort");
  758. const char* port = pEspService->queryProp(xpath.str());
  759. xpath.clear().append("./Properties/@defaultResourcesBasedn");
  760. const char* resourceBasedn = pEspService->queryProp(xpath.str());
  761. const char* buildSetName = pEspService->queryProp(XML_ATTR_NAME);
  762. const char* processName = pEspService->queryProp(XML_ATTR_PROCESS_NAME);
  763. StringBuffer buildSetPath;
  764. Owned<IPropertyTree> pSchema = loadSchema(pNewEnvTree->queryPropTree("./Programs/Build[1]"), pEspService, buildSetPath, NULL);
  765. 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());
  766. addEspBindingInformation(xmlArg, pNewEnvTree, sbNewName, NULL, m_cfg, m_service.str());
  767. xpath.clear().appendf("./%s/%s/%s/[%s=\"\"]", XML_TAG_SOFTWARE, XML_TAG_ESPPROCESS, XML_TAG_ESPBINDING, XML_ATTR_SERVICE);
  768. IPropertyTree* pEspBindingInfo = pNewEnvTree->queryPropTree(xpath.str());
  769. pEspBindingInfo->setProp(XML_ATTR_NAME,(espServiceName.toLowerCase()).str());
  770. pEspBindingInfo->setProp(XML_ATTR_SERVICE,(espServiceName.toLowerCase()).str());
  771. pEspBindingInfo->setProp(XML_ATTR_PORT, port );
  772. pEspBindingInfo->setProp("@resourcesBasedn",resourceBasedn);
  773. xpath.clear().appendf("%s/%s[%s=\"%s\"]/Properties", XML_TAG_SOFTWARE, XML_TAG_ESPSERVICE, XML_ATTR_NAME, (espServiceName.toLowerCase()).str());
  774. IPropertyTree* pSvcProps = pNewEnvTree->queryPropTree(xpath.str());
  775. Owned<IPropertyTree> pCompTree = generateTreeFromXsd(pNewEnvTree, pSchema, processName, buildSetName, m_cfg, m_service.str(), true, false, 0);
  776. Owned<IPropertyTreeIterator> i = pSvcProps->getElements("Authenticate");
  777. ForEach(*i)
  778. {
  779. IPropertyTree* pAuthCopy = createPTreeFromIPT(&i->query());
  780. mergeAttributes(pAuthCopy, pCompTree->queryPropTree("Authenticate"));
  781. IPropertyTree* pNewNode = pEspBindingInfo->addPropTree("Authenticate", pAuthCopy);
  782. }
  783. i.setown( pSvcProps->getElements("AuthenticateFeature") );
  784. ForEach(*i)
  785. {
  786. IPropertyTree* pAuthCopy = createPTreeFromIPT(&i->query());
  787. //Adding authentication to true for espbinding.
  788. pAuthCopy->addProp("@authenticate","Yes");
  789. mergeAttributes(pAuthCopy, pCompTree->queryPropTree("AuthenticateFeature"));
  790. IPropertyTree* pNewNode = pEspBindingInfo->addPropTree("AuthenticateFeature", pAuthCopy);
  791. }
  792. i.setown( pSvcProps->getElements("AuthenticateSetting") );
  793. ForEach(*i)
  794. {
  795. IPropertyTree* pAuthCopy = createPTreeFromIPT(&i->query());
  796. mergeAttributes(pAuthCopy, pCompTree->queryPropTree("AuthenticateSetting"));
  797. IPropertyTree* pNewNode = pEspBindingInfo->addPropTree("AuthenticateSetting", pAuthCopy);
  798. }
  799. }
  800. }
  801. }
  802. }
  803. }
  804. void CWizardInputs::addTopology(IPropertyTree* pNewEnvTree)
  805. {
  806. StringBuffer xpath;
  807. if(!pNewEnvTree->hasProp("./"XML_TAG_SOFTWARE"/"XML_TAG_TOPOLOGY))
  808. pNewEnvTree->addPropTree("./"XML_TAG_SOFTWARE"/"XML_TAG_TOPOLOGY, createPTree());
  809. HashIterator sIter(m_compForTopology);
  810. for(sIter.first();sIter.isValid();sIter.next())
  811. {
  812. IMapping &cur = sIter.query();
  813. IPropertyTree* pCluster = createTopologyForComp(pNewEnvTree,(const char *) cur.getKey());
  814. if(pCluster)
  815. pNewEnvTree->addPropTree("./"XML_TAG_SOFTWARE"/"XML_TAG_TOPOLOGY"/Cluster", pCluster);
  816. }
  817. }
  818. IPropertyTree* CWizardInputs::createTopologyForComp(IPropertyTree* pNewEnvTree, const char* component)
  819. {
  820. StringBuffer xmlTag, xpath , compName, clusterStr;
  821. if(!strcmp(component, "roxie"))
  822. xmlTag.clear().append(XML_TAG_ROXIECLUSTER);
  823. else if(!strcmp(component, "thor"))
  824. xmlTag.clear().append(XML_TAG_THORCLUSTER);
  825. else if(!strcmp(component, "hthor"))
  826. xmlTag.clear().append("hthor");
  827. xpath.clear().appendf("./%s/%s[1]/%s", XML_TAG_SOFTWARE, xmlTag.str(), XML_ATTR_NAME);
  828. clusterStr.clear().appendf("<Cluster name=\"%s\" prefix=\"%s\"></Cluster>", component, component);
  829. IPropertyTree* pCluster = createPTreeFromXMLString(clusterStr.str());
  830. if(pCluster)
  831. {
  832. if(pNewEnvTree->hasProp(xpath.str()))
  833. {
  834. IPropertyTree* pComponent = pCluster->addPropTree(xmlTag.str(), createPTree());
  835. pComponent->addProp(XML_ATTR_PROCESS, pNewEnvTree->queryProp(xpath.str()));
  836. }
  837. if(m_compForTopology.find(component) != NULL)
  838. {
  839. StringArray* clusterCompEle = 0;
  840. StringArrayPtr* clusterPair = m_compForTopology.getValue(component);
  841. if(clusterPair)
  842. {
  843. clusterCompEle = (*clusterPair);
  844. for(unsigned i = 0 ; i < clusterCompEle->ordinality() ; i++)
  845. {
  846. const char* eachClusterElem = clusterCompEle->item(i);
  847. xpath.clear().appendf("./%s/%s/%s[%s=\"%s\"]", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET, XML_ATTR_NAME, eachClusterElem);
  848. IPropertyTree* pBuildset = pNewEnvTree->queryPropTree(xpath.str());
  849. if(pBuildset)
  850. {
  851. const char* processName = pBuildset->queryProp(XML_ATTR_PROCESS_NAME);
  852. if(processName && *processName)
  853. {
  854. IPropertyTree* pElement = pCluster->addPropTree(processName,createPTree());
  855. xpath.clear().appendf("./%s/%s[1]/%s", XML_TAG_SOFTWARE, processName, XML_ATTR_NAME);
  856. if(pElement && pNewEnvTree->hasProp(xpath.str()))
  857. pElement->addProp(XML_ATTR_PROCESS, pNewEnvTree->queryProp(xpath.str()));
  858. }
  859. }
  860. }
  861. }
  862. clusterCompEle->kill();
  863. }
  864. return pCluster;
  865. }
  866. else
  867. return NULL;
  868. }
  869. void CWizardInputs::checkForDependencies()
  870. {
  871. StringBuffer xpath;
  872. if(m_buildSetTree)
  873. {
  874. xpath.clear().appendf("./%s/%s/%s", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET);
  875. Owned<IPropertyTreeIterator> buildSetInsts = m_buildSetTree->getElements(xpath.str());
  876. ForEach(*buildSetInsts)
  877. {
  878. IPropertyTree* pBuildSet = &buildSetInsts->query();
  879. const char* buildSetName = pBuildSet->queryProp(XML_ATTR_NAME);
  880. unsigned numOfNodesNeeded = 1;
  881. if((!strcmp(buildSetName,"roxie") && m_roxieNodes == 0 )|| (!strcmp(buildSetName,"thor")&& m_thorNodes == 0)){
  882. numOfNodesNeeded = 0;
  883. m_doNotGenComp.append(buildSetName);
  884. }
  885. if(numOfNodesNeeded == 0 || (m_doNotGenComp.find(buildSetName) != NotFound))
  886. {
  887. if(m_compForTopology.find(buildSetName) != NULL )
  888. m_compForTopology.remove(buildSetName);
  889. checkAndAddDependComponent(buildSetName);
  890. }
  891. }
  892. }
  893. }
  894. void CWizardInputs::checkAndAddDependComponent(const char* key)
  895. {
  896. StringBuffer paramEntry(key);
  897. paramEntry.append("_dependencies");
  898. if(m_algProp)
  899. {
  900. if(m_algProp->hasProp(paramEntry.str()))
  901. {
  902. StringArray sArray;
  903. DelimToStringArray(m_algProp->queryProp(paramEntry.str()), sArray, ";");
  904. ForEachItemIn(x, sArray)
  905. {
  906. if(m_doNotGenComp.find(sArray.item(x)) == NotFound)
  907. {
  908. m_doNotGenComp.append(sArray.item(x));
  909. checkAndAddDependComponent(sArray.item(x));
  910. }
  911. }
  912. }
  913. }
  914. }
  915. unsigned CWizardInputs::getNumOfNodes(const char* compName)
  916. {
  917. if(m_compIpMap.find(compName) != NULL)
  918. {
  919. CInstDetails* pInst = NULL;
  920. pInst = m_compIpMap.getValue(compName);
  921. StringArray& ipArr = pInst->getIpAssigned();
  922. return ipArr.ordinality();
  923. }
  924. return 0;
  925. }
  926. void CWizardInputs::setTopologyParam()
  927. {
  928. if(m_clusterForTopology.ordinality() > 0)
  929. {
  930. StringBuffer topologySec;
  931. ForEachItemIn(x, m_clusterForTopology)
  932. {
  933. topologySec.clear().appendf("%s_topology",m_clusterForTopology.item(x));
  934. const char * elemForCluster = m_algProp->queryProp(topologySec.str());
  935. if(elemForCluster && *elemForCluster)
  936. {
  937. StringArray* compClusterArr = new StringArray();
  938. StringArray clusterElemArr;
  939. DelimToStringArray( elemForCluster, clusterElemArr, ",");
  940. ForEachItemIn(y, clusterElemArr)
  941. compClusterArr->append(clusterElemArr.item(y));
  942. m_compForTopology.setValue(m_clusterForTopology.item(x),compClusterArr);
  943. }
  944. }
  945. }
  946. }
  947. void CWizardInputs::addComponentToSoftware(IPropertyTree* pNewEnvTree, IPropertyTree* pBuildSet)
  948. {
  949. if (!pBuildSet)
  950. return;
  951. StringBuffer xpath, sbNewName;
  952. StringBuffer buildSetPath, compName, assignedIP, sbl;
  953. const char* buildSetName = pBuildSet->queryProp(XML_ATTR_NAME);
  954. const char* xsdFileName = pBuildSet->queryProp(XML_ATTR_SCHEMA);
  955. const char* processName = pBuildSet->queryProp(XML_ATTR_PROCESS_NAME);
  956. StringBuffer deployable = pBuildSet->queryProp("@"TAG_DEPLOYABLE);
  957. unsigned numOfIpNeeded = 1;
  958. if (m_doNotGenComp.find(buildSetName) != NotFound )
  959. return;
  960. if (processName && *processName && buildSetName && * buildSetName && xsdFileName && *xsdFileName)
  961. {
  962. Owned<IPropertyTree> pSchema = loadSchema(m_buildSetTree->queryPropTree("./"XML_TAG_PROGRAMS"/"XML_TAG_BUILD"[1]"), pBuildSet, buildSetPath, NULL);
  963. IPropertyTree* pCompTree = generateTreeFromXsd(pNewEnvTree, pSchema, processName, buildSetName, m_cfg, m_service.str(), false);
  964. sbNewName.clear();
  965. if (strstr(buildSetName ,"my") == NULL && (strcmp(buildSetName, "topology") != 0))
  966. sbNewName.append("my");
  967. addComponentToEnv(pNewEnvTree, buildSetName, sbNewName, pCompTree);
  968. if (!strcmp(processName, XML_TAG_ESPSERVICE) || !strcmp(processName, XML_TAG_PLUGINPROCESS))
  969. processName = buildSetName;
  970. if (strcmp(deployable,"no") != 0)
  971. {
  972. if (m_compOnAllNodes.find(buildSetName) != NotFound)
  973. {
  974. for (unsigned i = 0; i < m_ipaddressSupport.ordinality(); i++)
  975. {
  976. sbl.clear().appendf("s").append(i+1);
  977. assignedIP.clear().append(m_ipaddressSupport.item(i));
  978. addInstanceToTree(pNewEnvTree, assignedIP, processName, buildSetName,sbl.str());
  979. }
  980. for (unsigned i = 0; i < m_ipaddress.ordinality(); i++)
  981. {
  982. sbl.clear().appendf("s").append(m_ipaddressSupport.ordinality() + i+1);
  983. assignedIP.clear().append(m_ipaddress.item(i));
  984. addInstanceToTree(pNewEnvTree, assignedIP, processName, buildSetName,sbl.str());
  985. }
  986. }
  987. else if (numOfIpNeeded > 0)
  988. {
  989. if (!strcmp(buildSetName, "roxie"))
  990. numOfIpNeeded = m_roxieNodes;
  991. else if (!strcmp(buildSetName, "thor"))
  992. {
  993. numOfIpNeeded = m_thorNodes;
  994. if (m_thorNodes < m_ipaddress.ordinality())
  995. numOfIpNeeded += 1;
  996. }
  997. CInstDetails* pInstDetail = getServerIPMap(sbNewName.str(), buildSetName, pNewEnvTree, numOfIpNeeded);
  998. if (pInstDetail)
  999. {
  1000. if (!strcmp(buildSetName, "roxie") || !strcmp(buildSetName, "thor" ))
  1001. {
  1002. addRoxieThorClusterToEnv(pNewEnvTree, pInstDetail, buildSetName);
  1003. if (!strcmp(buildSetName, "roxie") && m_roxieOnDemand)
  1004. addRoxieThorClusterToEnv(pNewEnvTree, pInstDetail, buildSetName, true);
  1005. }
  1006. else
  1007. {
  1008. StringArray& ipArr = pInstDetail->getIpAssigned();
  1009. ForEachItemIn(x, ipArr)
  1010. {
  1011. assignedIP.clear().append(ipArr.item(x));
  1012. addInstanceToTree(pNewEnvTree, assignedIP, processName, buildSetName, "s1");
  1013. }
  1014. }
  1015. }
  1016. }
  1017. }
  1018. }
  1019. }
  1020. StringArray& CWizardInputs::getIpAddrMap(const char* buildSetName)
  1021. {
  1022. if (m_supportNodes == 0)
  1023. return m_ipaddress;
  1024. else
  1025. {
  1026. if (!strcmp(buildSetName, "roxie") || !strcmp(buildSetName, "thor" ))
  1027. return m_ipaddress;
  1028. }
  1029. return m_ipaddressSupport;
  1030. }