wizardInputs.cpp 43 KB

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