wizardInputs.cpp 46 KB

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