wizardInputs.cpp 49 KB

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