wizardInputs.cpp 43 KB

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