wizardInputs.cpp 50 KB

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