wizardInputs.cpp 51 KB

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