step8_controller.js 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.WizardStep8Controller = Em.Controller.extend({
  20. name: 'wizardStep8Controller',
  21. rawContent: require('data/review_configs'),
  22. totalHosts: [],
  23. clusterInfo: [],
  24. services: [],
  25. configs: [],
  26. globals: [],
  27. ajaxQueue: [],
  28. configMapping: require('data/config_mapping').all(),
  29. slaveComponentConfig: null,
  30. isSubmitDisabled: false,
  31. hasErrorOccurred: false,
  32. servicesInstalled: false,
  33. /**
  34. * During page save time, we set the host overrides to the server.
  35. * The new host -> site:tag map is stored below. This will be
  36. * useful during save, to update the host's host components. Also,
  37. * it will be useful in deletion of overrides.
  38. *
  39. * Example:
  40. * {
  41. * 'hostname1': {
  42. * 'global': {
  43. * 'tagName': 'tag3187261938_hostname1',
  44. * 'map': {
  45. * 'hadoop_heapsize': '2048m'
  46. * }
  47. * }
  48. * }
  49. * }
  50. *
  51. * @see loadedHostToOverrideSiteToTagMap
  52. */
  53. savedHostToOverrideSiteToTagMap: {},
  54. selectedServices: function () {
  55. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false);
  56. }.property('content.services').cacheable(),
  57. clearStep: function () {
  58. this.get('services').clear();
  59. this.get('configs').clear();
  60. this.get('globals').clear();
  61. this.get('clusterInfo').clear();
  62. this.set('servicesInstalled', false);
  63. },
  64. loadStep: function () {
  65. console.log("TRACE: Loading step8: Review Page");
  66. this.clearStep();
  67. this.loadGlobals();
  68. this.loadConfigs();
  69. this.loadClusterInfo();
  70. this.loadServices();
  71. this.set('isSubmitDisabled', false);
  72. },
  73. loadGlobals: function () {
  74. var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
  75. if (globals.someProperty('name', 'hive_database')) {
  76. var hiveDb = globals.findProperty('name', 'hive_database');
  77. var hiveDbType = {name: 'hive_database_type', value: 'mysql'};
  78. var hiveJdbcDriver = {name: 'hive_jdbc_driver'};
  79. if (hiveDb.value === 'New MySQL Database') {
  80. if (globals.someProperty('name', 'hive_ambari_host')) {
  81. globals.findProperty('name', 'hive_ambari_host').name = 'hive_hostname';
  82. hiveDbType.value = 'mysql';
  83. hiveJdbcDriver.value = 'com.mysql.jdbc.Driver';
  84. }
  85. globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_host'));
  86. globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_database'));
  87. globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_host'));
  88. globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_database'));
  89. } else if (hiveDb.value === 'Existing MySQL Database'){
  90. globals.findProperty('name', 'hive_existing_mysql_host').name = 'hive_hostname';
  91. hiveDbType.value = 'mysql';
  92. hiveJdbcDriver.value = 'com.mysql.jdbc.Driver';
  93. globals = globals.without(globals.findProperty('name', 'hive_ambari_host'));
  94. globals = globals.without(globals.findProperty('name', 'hive_ambari_database'));
  95. globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_host'));
  96. globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_database'));
  97. } else{ //existing oracle database
  98. globals.findProperty('name', 'hive_existing_oracle_host').name = 'hive_hostname';
  99. hiveDbType.value = 'oracle';
  100. hiveJdbcDriver.value = 'oracle.jdbc.driver.OracleDriver';
  101. globals = globals.without(globals.findProperty('name', 'hive_ambari_host'));
  102. globals = globals.without(globals.findProperty('name', 'hive_ambari_database'));
  103. globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_host'));
  104. globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_database'));
  105. }
  106. globals.push(hiveDbType);
  107. globals.push(hiveJdbcDriver);
  108. }
  109. if (globals.someProperty('name', 'oozie_database')) {
  110. var oozieDb = globals.findProperty('name', 'oozie_database');
  111. var oozieDbType = {name:'oozie_database_type'};
  112. var oozieJdbcDriver = {name: 'oozie_jdbc_driver'};
  113. var oozieJPAServcieURL = {name: 'oozie_JPAService_url'};
  114. if (oozieDb.value === 'New Derby Database'){
  115. oozieDbType.value = 'derby';
  116. oozieJdbcDriver.value = 'org.apache.derby.jdbc.EmbeddedDriver';
  117. oozieJPAServcieURL.value = '${oozie.data.dir}/${oozie.db.schema.name}-db;create=true';
  118. globals = globals.without(globals.findProperty('name', 'oozie_ambari_host'));
  119. globals = globals.without(globals.findProperty('name', 'oozie_ambari_database'));
  120. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_host'));
  121. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_database'));
  122. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_host'));
  123. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_database'));
  124. }else if (oozieDb.value === 'New MySQL Database') {
  125. if (globals.someProperty('name', 'oozie_ambari_host')) {
  126. globals.findProperty('name', 'oozie_ambari_host').name = 'oozie_hostname';
  127. oozieDbType.value = 'mysql';
  128. oozieJdbcDriver.value = 'com.mysql.jdbc.Driver';
  129. oozieJPAServcieURL.value = '//'+ globals.findProperty('name','oozie_hostname').value +'/' + globals.findProperty('name','oozie_database_name').value +'?createDatabaseIfNotExist=true';
  130. }
  131. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_host'));
  132. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_database'));
  133. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_host'));
  134. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_database'));
  135. globals = globals.without(globals.findProperty('name', 'oozie_derby_database'));
  136. } else if (oozieDb.value === 'Existing MySQL Database'){
  137. globals.findProperty('name', 'oozie_existing_mysql_host').name = 'oozie_hostname';
  138. oozieDbType.value = 'mysql';
  139. oozieJdbcDriver.value = 'com.mysql.jdbc.Driver';
  140. oozieJPAServcieURL.value = '//'+ globals.findProperty('name','oozie_hostname').value +'/' + globals.findProperty('name','oozie_database_name').value +'?createDatabaseIfNotExist=true';
  141. globals = globals.without(globals.findProperty('name', 'oozie_ambari_host'));
  142. globals = globals.without(globals.findProperty('name', 'oozie_ambari_database'));
  143. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_host'));
  144. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_database'));
  145. globals = globals.without(globals.findProperty('name', 'oozie_derby_database'));
  146. } else{ //existing oracle database
  147. globals.findProperty('name', 'oozie_existing_oracle_host').name = 'oozie_hostname';
  148. oozieDbType.value = 'oracle';
  149. oozieJdbcDriver.value = 'oracle.jdbc.driver.OracleDriver';
  150. oozieJPAServcieURL.value = '//'+ globals.findProperty('name','oozie_hostname').value +'/'+ globals.findProperty('name','oozie_database_name').value +'?createDatabaseIfNotExist=true';
  151. globals = globals.without(globals.findProperty('name', 'oozie_ambari_host'));
  152. globals = globals.without(globals.findProperty('name', 'oozie_ambari_database'));
  153. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_host'));
  154. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_database'));
  155. globals = globals.without(globals.findProperty('name', 'oozie_derby_database'));
  156. }
  157. globals.push(oozieDbType);
  158. globals.push(oozieJdbcDriver);
  159. globals.push(oozieJPAServcieURL);
  160. }
  161. this.set('globals', globals);
  162. },
  163. loadConfigs: function () {
  164. //storedConfigs contains custom configs as well
  165. var serviceConfigProperties = this.get('content.serviceConfigProperties').filterProperty('id', 'site property');
  166. serviceConfigProperties.forEach(function(_config){
  167. _config.value = (typeof _config.value === "boolean") ? _config.value.toString() : _config.value;
  168. });
  169. var storedConfigs = serviceConfigProperties.filterProperty('value');
  170. var uiConfigs = this.loadUiSideConfigs();
  171. this.set('configs', storedConfigs.concat(uiConfigs));
  172. },
  173. loadUiSideConfigs: function () {
  174. var uiConfig = [];
  175. var configs = this.get('configMapping').filterProperty('foreignKey', null);
  176. configs.forEach(function (_config) {
  177. var valueWithOverrides = this.getGlobConfigValueWithOverrides(_config.templateName, _config.value, _config.name);
  178. uiConfig.pushObject({
  179. "id": "site property",
  180. "name": _config.name,
  181. "value": valueWithOverrides.value,
  182. "filename": _config.filename,
  183. "overrides": valueWithOverrides.overrides
  184. });
  185. }, this);
  186. var dependentConfig = this.get('configMapping').filterProperty('foreignKey');
  187. dependentConfig.forEach(function (_config) {
  188. this.setConfigValue(uiConfig, _config);
  189. uiConfig.pushObject({
  190. "id": "site property",
  191. "name": _config.name,
  192. "value": _config.value,
  193. "filename": _config.filename
  194. });
  195. }, this);
  196. return uiConfig;
  197. },
  198. getRegisteredHosts: function () {
  199. var allHosts = this.get('content.hosts');
  200. var hosts = [];
  201. for (var hostName in allHosts) {
  202. if (allHosts[hostName].bootStatus == 'REGISTERED') {
  203. allHosts[hostName].hostName = allHosts[hostName].name;
  204. hosts.pushObject(allHosts[hostName]);
  205. }
  206. }
  207. return hosts;
  208. },
  209. /**
  210. * Set all site property that are derived from other puppet-variable
  211. * @return {
  212. * value: '...',
  213. * overrides: {
  214. * 'value1': [h1, h2],
  215. * 'value2': [h3]
  216. * }
  217. * }
  218. */
  219. getGlobConfigValueWithOverrides: function (templateName, expression, name) {
  220. var express = expression.match(/<(.*?)>/g);
  221. var value = expression;
  222. if (express == null) {
  223. return { value : expression, overrides: []}; // if site property do not map any global property then return the value
  224. }
  225. var overrideHostToValue = {};
  226. express.forEach(function (_express) {
  227. //console.log("The value of template is: " + _express);
  228. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  229. if (this.get('globals').someProperty('name', templateName[index])) {
  230. //console.log("The name of the variable is: " + this.get('content.serviceConfigProperties').findProperty('name', templateName[index]).name);
  231. var globalObj = this.get('globals').findProperty('name', templateName[index]);
  232. var globValue = globalObj.value;
  233. // Hack for templeton.zookeeper.hosts
  234. var preReplaceValue = null;
  235. if (value !== null) { // if the property depends on more than one template name like <templateName[0]>/<templateName[1]> then don't proceed to the next if the prior is null or not found in the global configs
  236. preReplaceValue = value;
  237. value = this._replaceConfigValues(name, _express, value, globValue);
  238. }
  239. if(globalObj.overrides!=null){
  240. globalObj.overrides.forEach(function(override){
  241. var ov = override.value;
  242. var hostsArray = override.hosts;
  243. hostsArray.forEach(function(host){
  244. if(!(host in overrideHostToValue)){
  245. overrideHostToValue[host] = this._replaceConfigValues(name, _express, preReplaceValue, ov);
  246. }else{
  247. overrideHostToValue[host] = this._replaceConfigValues(name, _express, overrideHostToValue[host], ov);
  248. }
  249. }, this);
  250. }, this);
  251. }
  252. } else {
  253. /*
  254. console.log("ERROR: The variable name is: " + templateName[index]);
  255. console.log("ERROR: mapped config from configMapping file has no corresponding variable in " +
  256. "content.serviceConfigProperties. Two possible reasons for the error could be: 1) The service is not selected. " +
  257. "and/OR 2) The service_config metadata file has no corresponding global var for the site property variable");
  258. */
  259. value = null;
  260. }
  261. }, this);
  262. var valueWithOverrides = {
  263. value: value,
  264. overrides: []
  265. };
  266. var overrideValueToHostMap = {};
  267. if(!jQuery.isEmptyObject(overrideHostToValue)){
  268. for(var host in overrideHostToValue){
  269. var hostVal = overrideHostToValue[host];
  270. if(!(hostVal in overrideValueToHostMap)){
  271. overrideValueToHostMap[hostVal] = [];
  272. }
  273. overrideValueToHostMap[hostVal].push(host);
  274. }
  275. }
  276. for(var val in overrideValueToHostMap){
  277. valueWithOverrides.overrides.push({
  278. value: val,
  279. hosts: overrideValueToHostMap[val]
  280. });
  281. }
  282. return valueWithOverrides;
  283. },
  284. _replaceConfigValues: function (name, express, value, globValue) {
  285. if (name === "templeton.zookeeper.hosts" || name === 'hbase.zookeeper.quorum') {
  286. // globValue is an array of ZooKeeper Server hosts
  287. var zooKeeperPort = '2181';
  288. if (name === "templeton.zookeeper.hosts") {
  289. var zooKeeperServers = globValue.map(function (item) {
  290. return item + ':' + zooKeeperPort;
  291. }).join(',');
  292. value = value.replace(express, zooKeeperServers);
  293. } else {
  294. value = value.replace(express, globValue.join(','));
  295. }
  296. } else {
  297. value = value.replace(express, globValue);
  298. }
  299. return value;
  300. },
  301. /**
  302. * Set all site property that are derived from other site-properties
  303. */
  304. setConfigValue: function (uiConfig, config) {
  305. if (config.value == null) {
  306. return;
  307. }
  308. var fkValue = config.value.match(/<(foreignKey.*?)>/g);
  309. if (fkValue) {
  310. fkValue.forEach(function (_fkValue) {
  311. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  312. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  313. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  314. config.value = config.value.replace(_fkValue, globalValue);
  315. } else if (this.get('content.serviceConfigProperties').someProperty('name', config.foreignKey[index])) {
  316. var globalValue;
  317. if (this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value === '') {
  318. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).defaultValue;
  319. } else {
  320. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value;
  321. }
  322. config.value = config.value.replace(_fkValue, globalValue);
  323. }
  324. }, this);
  325. }
  326. if (fkValue = config.name.match(/<(foreignKey.*?)>/g)) {
  327. fkValue.forEach(function (_fkValue) {
  328. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  329. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  330. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  331. config.name = config.name.replace(_fkValue, globalValue);
  332. } else if (this.get('content.serviceConfigProperties').someProperty('name', config.foreignKey[index])) {
  333. var globalValue;
  334. if (this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value === '') {
  335. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).defaultValue;
  336. } else {
  337. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value;
  338. }
  339. config.name = config.name.replace(_fkValue, globalValue);
  340. }
  341. }, this);
  342. }
  343. //For properties in the configMapping file having foreignKey and templateName properties.
  344. var templateValue = config.value.match(/<(templateName.*?)>/g);
  345. if (templateValue) {
  346. templateValue.forEach(function (_value) {
  347. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  348. if (this.get('globals').someProperty('name', config.templateName[index])) {
  349. var globalValue = this.get('globals').findProperty('name', config.templateName[index]).value;
  350. config.value = config.value.replace(_value, globalValue);
  351. } else {
  352. config.value = null;
  353. }
  354. }, this);
  355. }
  356. },
  357. getServiceInfo: function (componentName) {
  358. var serviceConfig;
  359. switch (componentName) {
  360. case 'DATANODE':
  361. serviceConfig = {
  362. name: 'HDFS',
  363. siteName: 'hdfs-site',
  364. domain: 'datanode-global'
  365. };
  366. break;
  367. case 'TASKTRACKER':
  368. serviceConfig = {
  369. name: 'MAPREDUCE',
  370. siteName: 'mapred-site',
  371. domain: 'tasktracker-global'
  372. };
  373. break;
  374. case 'NODEMANAGER':
  375. serviceConfig = {
  376. name: 'YARN',
  377. siteName: 'yarn-site',
  378. domain: 'nodemanager-global'
  379. };
  380. break;
  381. case 'HBASE_REGIONSERVER':
  382. serviceConfig = {
  383. name: 'HBASE',
  384. siteName: 'hbase-site',
  385. domain: 'regionserver-global'
  386. };
  387. break;
  388. default:
  389. serviceConfig = {};
  390. }
  391. return serviceConfig;
  392. },
  393. /**
  394. * Load all info about cluster to <code>clusterInfo</code> variable
  395. */
  396. loadClusterInfo: function () {
  397. //Admin name
  398. var admin = this.rawContent.findProperty('config_name', 'Admin');
  399. admin.config_value = App.db.getLoginName();
  400. console.log("STEP8: the value of content cluster name: " + App.db.getLoginName());
  401. if (admin.config_value) {
  402. this.get('clusterInfo').pushObject(Ember.Object.create(admin));
  403. }
  404. // cluster name
  405. var cluster = this.rawContent.findProperty('config_name', 'cluster');
  406. cluster.config_value = this.get('content.cluster.name');
  407. console.log("STEP8: the value of content cluster name: " + this.get('content.cluster.name'));
  408. this.get('clusterInfo').pushObject(Ember.Object.create(cluster));
  409. //hosts
  410. var masterHosts = this.get('content.masterComponentHosts').mapProperty('hostName').uniq();
  411. var slaveHosts = this.get('content.slaveComponentHosts');
  412. var hostObj = [];
  413. slaveHosts.forEach(function (_hosts) {
  414. hostObj = hostObj.concat(_hosts.hosts);
  415. }, this);
  416. slaveHosts = hostObj.mapProperty('hostName').uniq();
  417. var componentHosts = masterHosts.concat(slaveHosts).uniq();
  418. var totalHosts = App.Host.find().mapProperty('hostName').concat(componentHosts).uniq();
  419. var newHostsCount = totalHosts.length - App.Host.find().content.length;
  420. this.set('totalHosts', totalHosts);
  421. var totalHostsObj = this.rawContent.findProperty('config_name', 'hosts');
  422. totalHostsObj.config_value = totalHosts.length + ' (' + newHostsCount + ' new)';
  423. this.get('clusterInfo').pushObject(Ember.Object.create(totalHostsObj));
  424. //repo
  425. var repoOption = this.get('content.installOptions.localRepo');
  426. var repoObj = this.rawContent.findProperty('config_name', 'Repo');
  427. if (repoOption) {
  428. repoObj.config_value = 'Yes';
  429. } else {
  430. repoObj.config_value = 'No';
  431. }
  432. this.get('clusterInfo').pushObject(Ember.Object.create(repoObj));
  433. },
  434. /**
  435. * Load all info about services to <code>services</code> variable
  436. */
  437. loadServices: function () {
  438. var selectedServices = this.get('selectedServices');
  439. this.set('services', selectedServices.mapProperty('serviceName'));
  440. selectedServices.forEach(function (_service) {
  441. console.log('INFO: step8: Name of the service from getService function: ' + _service.serviceName);
  442. var reviewService = this.rawContent.findProperty('config_name', 'services');
  443. var serviceObj = reviewService.config_value.findProperty('service_name', _service.serviceName);
  444. if (serviceObj) {
  445. switch (serviceObj.service_name) {
  446. case 'HDFS':
  447. this.loadHDFS(serviceObj);
  448. break;
  449. case 'MAPREDUCE':
  450. this.loadMapReduce(serviceObj);
  451. break;
  452. case 'MAPREDUCEv2':
  453. this.loadMapReduce2(serviceObj);
  454. break;
  455. case 'YARN':
  456. this.loadYARN(serviceObj);
  457. break;
  458. case 'HIVE':
  459. this.loadHive(serviceObj);
  460. break;
  461. case 'HBASE':
  462. this.loadHbase(serviceObj);
  463. break;
  464. case 'ZOOKEEPER':
  465. this.loadZk(serviceObj);
  466. break;
  467. case 'OOZIE':
  468. this.loadOozie(serviceObj);
  469. break;
  470. case 'NAGIOS':
  471. this.loadNagios(serviceObj);
  472. break;
  473. case 'GANGLIA':
  474. this.loadGanglia(serviceObj);
  475. break;
  476. case 'HUE':
  477. this.loadHue(serviceObj);
  478. break;
  479. /* case 'TEZ':
  480. break;
  481. case 'PIG':
  482. this.loadPig(serviceObj);
  483. break;
  484. case 'SQOOP':
  485. this.loadSqoop(serviceObj);
  486. break;
  487. */
  488. case 'HCATALOG':
  489. break;
  490. default:
  491. }
  492. }
  493. }, this);
  494. },
  495. /**
  496. * load all info about HDFS service
  497. * @param hdfsObj
  498. */
  499. loadHDFS: function (hdfsObj) {
  500. hdfsObj.get('service_components').forEach(function (_component) {
  501. switch (_component.get('display_name')) {
  502. case 'NameNode':
  503. this.loadNnValue(_component);
  504. break;
  505. case 'SecondaryNameNode':
  506. this.loadSnnValue(_component);
  507. break;
  508. case 'DataNodes':
  509. this.loadDnValue(_component);
  510. break;
  511. default:
  512. }
  513. }, this);
  514. //var
  515. this.get('services').pushObject(hdfsObj);
  516. },
  517. loadNnValue: function (nnComponent) {
  518. var nnHostName = this.get('content.masterComponentHosts').findProperty('display_name', nnComponent.display_name);
  519. nnComponent.set('component_value', nnHostName.hostName);
  520. },
  521. loadSnnValue: function (snnComponent) {
  522. var snnHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'SNameNode');
  523. snnComponent.set('component_value', snnHostName.hostName);
  524. },
  525. loadDnValue: function (dnComponent) {
  526. var dnHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'DataNode');
  527. var totalDnHosts = dnHosts.hosts.length;
  528. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'DATANODE').groups.length;
  529. var groupLabel;
  530. if (totalGroups == 1) {
  531. groupLabel = 'group';
  532. } else {
  533. groupLabel = 'groups';
  534. }
  535. */
  536. dnComponent.set('component_value', totalDnHosts + Em.I18n.t('installer.step8.hosts'));
  537. },
  538. /**
  539. * Load all info about mapReduce service
  540. * @param mrObj
  541. */
  542. loadMapReduce: function (mrObj) {
  543. mrObj.get('service_components').forEach(function (_component) {
  544. switch (_component.get('display_name')) {
  545. case 'JobTracker':
  546. this.loadJtValue(_component);
  547. break;
  548. case 'TaskTrackers':
  549. this.loadTtValue(_component);
  550. break;
  551. default:
  552. }
  553. }, this);
  554. this.get('services').pushObject(mrObj);
  555. },
  556. loadMapReduce2: function(mrObj){
  557. mrObj.get('service_components').forEach(function (_component) {
  558. switch (_component.get('display_name')) {
  559. case 'History Server':
  560. _component.set('component_value', this.get('content.masterComponentHosts').findProperty('component', 'HISTORYSERVER').hostName);
  561. break;
  562. }
  563. }, this);
  564. this.get('services').pushObject(mrObj);
  565. },
  566. loadYARN: function(mrObj){
  567. mrObj.get('service_components').forEach(function (_component) {
  568. switch (_component.get('display_name')) {
  569. case 'Node Manager':
  570. this.loadNMValue(_component);
  571. break;
  572. case 'Resource Manager':
  573. _component.set('component_value', this.get('content.masterComponentHosts').findProperty('component', 'RESOURCEMANAGER').hostName);
  574. break;
  575. }
  576. }, this);
  577. this.get('services').pushObject(mrObj);
  578. },
  579. loadNMValue: function (nmComponent) {
  580. var nmHosts = this.get('content.slaveComponentHosts').findProperty('componentName', 'NODEMANAGER');
  581. nmComponent.set('component_value', nmHosts.hosts.length + Em.I18n.t('installer.step8.hosts'));
  582. },
  583. loadJtValue: function (jtComponent) {
  584. var jtHostName = this.get('content.masterComponentHosts').findProperty('display_name', jtComponent.display_name);
  585. jtComponent.set('component_value', jtHostName.hostName);
  586. },
  587. loadTtValue: function (ttComponent) {
  588. var ttHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'TaskTracker');
  589. var totalTtHosts = ttHosts.hosts.length;
  590. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'TASKTRACKER').groups.length;
  591. var groupLabel;
  592. if (totalGroups == 1) {
  593. groupLabel = 'group';
  594. } else {
  595. groupLabel = 'groups';
  596. }
  597. */
  598. ttComponent.set('component_value', totalTtHosts + Em.I18n.t('installer.step8.hosts'));
  599. },
  600. /**
  601. * Load all info about Hive service
  602. * @param hiveObj
  603. */
  604. loadHive: function (hiveObj) {
  605. hiveObj.get('service_components').forEach(function (_component) {
  606. switch (_component.get('display_name')) {
  607. case 'Hive Metastore':
  608. this.loadHiveMetaStoreValue(_component);
  609. break;
  610. case 'Database':
  611. this.loadHiveDbValue(_component);
  612. break;
  613. default:
  614. }
  615. }, this);
  616. this.get('services').pushObject(hiveObj);
  617. },
  618. loadHiveMetaStoreValue: function (metaStoreComponent) {
  619. var hiveHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'HiveServer2');
  620. metaStoreComponent.set('component_value', hiveHostName.hostName);
  621. },
  622. loadHiveDbValue: function (dbComponent) {
  623. var hiveDb = App.db.getServiceConfigProperties().findProperty('name', 'hive_database');
  624. if (hiveDb.value === 'New MySQL Database') {
  625. dbComponent.set('component_value', 'MySQL (New Database)');
  626. } else if(hiveDb.value === 'Existing MySQL Database'){
  627. var db = App.db.getServiceConfigProperties().findProperty('name', 'hive_existing_mysql_database');
  628. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  629. } else { // existing oracle database
  630. var db = App.db.getServiceConfigProperties().findProperty('name', 'hive_existing_oracle_database');
  631. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  632. }
  633. },
  634. /**
  635. * Load all info about Hbase
  636. * @param hbaseObj
  637. */
  638. loadHbase: function (hbaseObj) {
  639. hbaseObj.service_components.forEach(function (_component) {
  640. switch (_component.display_name) {
  641. case 'Master':
  642. this.loadMasterValue(_component);
  643. break;
  644. case 'RegionServers':
  645. this.loadRegionServerValue(_component);
  646. break;
  647. default:
  648. }
  649. }, this);
  650. this.get('services').pushObject(hbaseObj);
  651. },
  652. loadMasterValue: function (hbaseMaster) {
  653. var hbaseHostName = this.get('content.masterComponentHosts').filterProperty('display_name', 'HBase Master');
  654. if (hbaseHostName.length == 1) {
  655. hbaseMaster.set('component_value', hbaseHostName[0].hostName);
  656. } else {
  657. hbaseMaster.set('component_value', hbaseHostName[0].hostName + Em.I18n.t('installer.step8.other').format(hbaseHostName.length - 1));
  658. }
  659. },
  660. loadRegionServerValue: function (rsComponent) {
  661. var rsHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'RegionServer');
  662. var totalRsHosts = rsHosts.hosts.length;
  663. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'HBASE_REGIONSERVER').groups.length;
  664. var groupLabel;
  665. if (totalGroups == 1) {
  666. groupLabel = 'group';
  667. } else {
  668. groupLabel = 'groups';
  669. } */
  670. rsComponent.set('component_value', totalRsHosts + Em.I18n.t('installer.step8.hosts'));
  671. },
  672. /**
  673. * Load all info about ZooKeeper service
  674. * @param zkObj
  675. */
  676. loadZk: function (zkObj) {
  677. zkObj.get('service_components').forEach(function (_component) {
  678. switch (_component.get('display_name')) {
  679. case 'Servers':
  680. this.loadZkServerValue(_component);
  681. break;
  682. default:
  683. }
  684. }, this);
  685. this.get('services').pushObject(zkObj);
  686. },
  687. loadZkServerValue: function (serverComponent) {
  688. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('display_name', 'ZooKeeper').length;
  689. var hostSuffix;
  690. if (zkHostNames === 1) {
  691. hostSuffix = Em.I18n.t('installer.step8.host');
  692. } else {
  693. hostSuffix = Em.I18n.t('installer.step8.hosts');
  694. }
  695. serverComponent.set('component_value', zkHostNames + ' ' + hostSuffix);
  696. },
  697. /**
  698. * Load all info about Hue services
  699. * @param hueObj
  700. */
  701. loadHue: function (hueObj) {
  702. hueObj.get('service_components').forEach(function (_component) {
  703. switch (_component.get('display_name')) {
  704. case 'Server':
  705. this.loadHueServerValue(_component);
  706. break;
  707. default:
  708. }
  709. }, this);
  710. this.get('services').pushObject(hueObj);
  711. },
  712. loadHueServerValue: function (hueServer) {
  713. var hueServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Hue Server');
  714. hueServer.set('component_value', hueServerName.hostName);
  715. },
  716. /**
  717. * Load all info about Oozie services
  718. * @param oozieObj
  719. */
  720. loadOozie: function (oozieObj) {
  721. oozieObj.get('service_components').forEach(function (_component) {
  722. switch (_component.get('display_name')) {
  723. case 'Server':
  724. this.loadOozieServerValue(_component);
  725. break;
  726. case 'Database':
  727. // TODO: uncomment when ready to integrate with Oozie Database other than Derby
  728. this.loadOozieDbValue(_component);
  729. break;
  730. default:
  731. }
  732. }, this);
  733. this.get('services').pushObject(oozieObj);
  734. },
  735. loadOozieServerValue: function (oozieServer) {
  736. var oozieServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Oozie Server');
  737. oozieServer.set('component_value', oozieServerName.hostName);
  738. },
  739. loadOozieDbValue: function (dbComponent) {
  740. var oozieDb = App.db.getServiceConfigProperties().findProperty('name', 'oozie_database');
  741. if (oozieDb.value === 'New Derby Database'){
  742. var db = App.db.getServiceConfigProperties().findProperty('name', 'oozie_derby_database');
  743. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  744. } else if (oozieDb.value === 'New MySQL Database') {
  745. dbComponent.set('component_value', 'MySQL (New Database)');
  746. } else if(oozieDb.value === 'Existing MySQL Database'){
  747. var db = App.db.getServiceConfigProperties().findProperty('name', 'oozie_existing_mysql_database');
  748. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  749. } else { // existing oracle database
  750. var db = App.db.getServiceConfigProperties().findProperty('name', 'oozie_existing_oracle_database');
  751. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  752. }
  753. },
  754. /**
  755. * Load all info about Nagios service
  756. * @param nagiosObj
  757. */
  758. loadNagios: function (nagiosObj) {
  759. nagiosObj.service_components.forEach(function (_component) {
  760. switch (_component.display_name) {
  761. case 'Server':
  762. this.loadNagiosServerValue(_component);
  763. break;
  764. case 'Administrator':
  765. this.loadNagiosAdminValue(_component);
  766. break;
  767. default:
  768. }
  769. }, this);
  770. this.get('services').pushObject(nagiosObj);
  771. },
  772. loadNagiosServerValue: function (nagiosServer) {
  773. var nagiosServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Nagios Server');
  774. nagiosServer.set('component_value', nagiosServerName.hostName);
  775. },
  776. loadNagiosAdminValue: function (nagiosAdmin) {
  777. var config = this.get('content.serviceConfigProperties');
  778. var adminLoginName = config.findProperty('name', 'nagios_web_login');
  779. var adminEmail = config.findProperty('name', 'nagios_contact');
  780. nagiosAdmin.set('component_value', adminLoginName.value + ' / (' + adminEmail.value + ')');
  781. },
  782. /**
  783. * Load all info about ganglia
  784. * @param gangliaObj
  785. */
  786. loadGanglia: function (gangliaObj) {
  787. gangliaObj.get('service_components').forEach(function (_component) {
  788. switch (_component.get('display_name')) {
  789. case 'Server':
  790. this.loadGangliaServerValue(_component);
  791. break;
  792. default:
  793. }
  794. }, this);
  795. this.get('services').pushObject(gangliaObj);
  796. },
  797. loadGangliaServerValue: function (gangliaServer) {
  798. var gangliaServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Ganglia Collector');
  799. gangliaServer.set('component_value', gangliaServerName.hostName);
  800. },
  801. loadSqoop: function (sqoopObj) {
  802. this.get('services').pushObject(sqoopObj);
  803. },
  804. loadPig: function (pigObj) {
  805. this.get('services').pushObject(pigObj);
  806. },
  807. /**
  808. * Onclick handler for <code>next</code> button
  809. */
  810. submit: function () {
  811. if (this.get('isSubmitDisabled')) {
  812. return;
  813. }
  814. this.set('isSubmitDisabled', true);
  815. // checkpoint the cluster status on the server so that the user can resume from where they left off
  816. switch (this.get('content.controllerName')) {
  817. case 'installerController':
  818. App.clusterStatus.setClusterStatus({
  819. clusterName: this.get('clusterName'),
  820. clusterState: 'CLUSTER_DEPLOY_PREP_2',
  821. wizardControllerName: this.get('content.controllerName'),
  822. localdb: App.db.data
  823. });
  824. break;
  825. case 'addHostController':
  826. App.clusterStatus.setClusterStatus({
  827. clusterName: this.get('clusterName'),
  828. clusterState: 'ADD_HOSTS_DEPLOY_PREP_2',
  829. wizardControllerName: this.get('content.controllerName'),
  830. localdb: App.db.data
  831. });
  832. break;
  833. case 'addServiceController':
  834. App.clusterStatus.setClusterStatus({
  835. clusterName: this.get('clusterName'),
  836. clusterState: 'ADD_SERVICES_DEPLOY_PREP_2',
  837. wizardControllerName: this.get('content.controllerName'),
  838. localdb: App.db.data
  839. });
  840. break;
  841. default:
  842. break;
  843. }
  844. // delete any existing clusters to start from a clean slate
  845. // before creating a new cluster in install wizard
  846. // TODO: modify for multi-cluster support
  847. if (this.get('content.controllerName') == 'installerController' && (!App.testMode)) {
  848. var clusterNames = this.getExistingClusterNames();
  849. this.deleteClusters(clusterNames);
  850. }
  851. this.createCluster();
  852. this.createSelectedServices();
  853. this.createConfigurations();
  854. this.createComponents();
  855. this.registerHostsToCluster();
  856. this.createAllHostComponents();
  857. this.createHostOverrideConfigurations();
  858. this.ajaxQueueFinished = function () {
  859. console.log('everything is loaded');
  860. App.router.send('next');
  861. };
  862. this.doNextAjaxCall();
  863. },
  864. /**
  865. * Used in progress bar
  866. */
  867. ajaxQueueLength: function () {
  868. return this.get('ajaxQueue').length;
  869. }.property('ajaxQueue.length'),
  870. /**
  871. * Used in progress bar
  872. */
  873. ajaxQueueLeft: 0,
  874. setAmbariUIDb: function () {
  875. var dbContent = this.get('content.slaveGroupProperties');
  876. var slaveComponentConfig = this.get("slaveComponentConfig");
  877. this.persistKeyValues(slaveComponentConfig.version, dbContent);
  878. this.persistKeyValues('current_version', slaveComponentConfig.version);
  879. },
  880. persistKeyValues: function (key, value) {
  881. var str = "{ '" + key + "' : '" + JSON.stringify(value) + "'}";
  882. var obj = eval("(" + str + ")");
  883. this.ajax({
  884. type: "POST",
  885. url: App.apiPrefix + '/persist',
  886. data: JSON.stringify(obj),
  887. beforeSend: function () {
  888. console.log('BeforeSend: persistKeyValues', obj);
  889. }
  890. });
  891. },
  892. clusterName: function () {
  893. return this.get('content.cluster.name');
  894. }.property('content.cluster.name'),
  895. clusterNames: [],
  896. // returns an array of existing cluster names.
  897. // returns an empty array if there are no existing clusters.
  898. getExistingClusterNames: function () {
  899. var url = App.apiPrefix + '/clusters';
  900. App.ajax.send({
  901. name: 'wizard.step8.existing_cluster_names',
  902. sender: this,
  903. success: 'getExistingClusterNamesSuccessCallBack',
  904. error: 'getExistingClusterNamesErrorCallback'
  905. });
  906. return this.get('clusterNames');
  907. },
  908. getExistingClusterNamesSuccessCallBack: function (data) {
  909. var clusterNames = data.items.mapProperty('Clusters.cluster_name');
  910. console.log("Got existing cluster names: " + clusterNames);
  911. this.set('clusterNames', clusterNames);
  912. },
  913. getExistingClusterNamesErrorCallback: function () {
  914. console.log("Failed to get existing cluster names");
  915. this.set('clusterNames', []);
  916. },
  917. deleteClusters: function (clusterNames) {
  918. clusterNames.forEach(function (clusterName) {
  919. App.ajax.send({
  920. name: 'wizard.step8.delete_cluster',
  921. sender: this,
  922. data: {
  923. name: clusterName
  924. },
  925. success: 'deleteClustersSuccessCallback',
  926. error: 'deleteClustersErrorCallback'
  927. });
  928. }, this);
  929. },
  930. deleteClustersSuccessCallback: function(data, opt, params) {
  931. console.log('DELETE cluster ' + params.name + ' succeeded');
  932. },
  933. deleteClustersErrorCallback: function(request, ajaxOptions, error, opt) {
  934. console.log('DELETE cluster failed');
  935. },
  936. /**
  937. * The following create* functions are called upon submitting Step 8.
  938. */
  939. createCluster: function () {
  940. if (this.get('content.controllerName') !== 'installerController') {
  941. return false;
  942. }
  943. var clusterName = this.get('clusterName');
  944. var url = App.apiPrefix + '/clusters/' + clusterName;
  945. var stackVersion = (this.get('content.installOptions.localRepo')) ? App.defaultLocalStackVersion : App.currentStackVersion;
  946. this.ajax({
  947. type: 'POST',
  948. url: url,
  949. data: JSON.stringify({ "Clusters": {"version": stackVersion }}),
  950. beforeSend: function () {
  951. console.log("BeforeSend: createCluster for " + clusterName);
  952. }
  953. });
  954. },
  955. createSelectedServices: function () {
  956. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services';
  957. var data = this.createServiceData();
  958. var httpMethod = 'POST';
  959. if (!data.length) {
  960. return;
  961. }
  962. this.ajax({
  963. type: httpMethod,
  964. url: url,
  965. data: JSON.stringify(data),
  966. beforeSend: function () {
  967. console.log('BeforeSend: createSelectedServices ', data);
  968. }
  969. });
  970. },
  971. createServiceData: function () {
  972. var services = this.get('selectedServices').mapProperty('serviceName');
  973. var data = [];
  974. services.forEach(function (_service) {
  975. data.pushObject({"ServiceInfo": { "service_name": _service }});
  976. }, this);
  977. return data;
  978. },
  979. createComponents: function () {
  980. var serviceComponents = require('data/service_components');
  981. var services = this.get('selectedServices').mapProperty('serviceName');
  982. services.forEach(function (_service) {
  983. var components = serviceComponents.filterProperty('service_name', _service);
  984. var componentsData = components.map(function (_component) {
  985. return { "ServiceComponentInfo": { "component_name": _component.component_name } };
  986. });
  987. // Service must be specified in terms of a query for creating multiple components at the same time.
  988. // See AMBARI-1018.
  989. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services?ServiceInfo/service_name=' + _service;
  990. var data = {
  991. "components": componentsData
  992. }
  993. this.ajax({
  994. type: 'POST',
  995. url: url,
  996. data: JSON.stringify(data),
  997. beforeSend: function () {
  998. console.log('BeforeSend: createComponents for ' + _service, componentsData);
  999. }
  1000. });
  1001. }, this);
  1002. },
  1003. registerHostsToCluster: function () {
  1004. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts';
  1005. var data = this.createRegisterHostData();
  1006. if (data.length == 0) {
  1007. return;
  1008. }
  1009. this.ajax({
  1010. type: 'POST',
  1011. url: url,
  1012. data: JSON.stringify(data),
  1013. beforeSend: function () {
  1014. console.log('BeforeSend: registerHostsToCluster', data);
  1015. }
  1016. });
  1017. },
  1018. createRegisterHostData: function () {
  1019. var hosts = this.getRegisteredHosts().filterProperty('isInstalled', false);
  1020. if (!hosts.length) {
  1021. return [];
  1022. }
  1023. return hosts.map(function (host) {
  1024. return {"Hosts": { "host_name": host.hostName}};
  1025. });
  1026. },
  1027. // TODO: review the code for add hosts / add services scenarios...
  1028. createAllHostComponents: function () {
  1029. var masterHosts = this.get('content.masterComponentHosts');
  1030. var slaveHosts = this.get('content.slaveComponentHosts');
  1031. var clients = this.get('content.clients');
  1032. // note: masterHosts has 'component' vs slaveHosts has 'componentName'
  1033. var masterComponents = masterHosts.mapProperty('component').uniq();
  1034. masterComponents.forEach(function (component) {
  1035. var hostNames = masterHosts.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  1036. this.registerHostsToComponent(hostNames, component);
  1037. }, this);
  1038. slaveHosts.forEach(function (_slave) {
  1039. if (_slave.componentName !== 'CLIENT') {
  1040. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  1041. this.registerHostsToComponent(hostNames, _slave.componentName);
  1042. } else {
  1043. clients.forEach(function (_client) {
  1044. var hostNames = _slave.hosts.mapProperty('hostName');
  1045. switch (_client.component_name) {
  1046. case 'HDFS_CLIENT':
  1047. // install HDFS_CLIENT on HBASE_MASTER, HBASE_REGIONSERVER, and WEBHCAT_SERVER hosts
  1048. masterHosts.filterProperty('component', 'HBASE_MASTER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1049. hostNames.pushObject(_masterHost.hostName);
  1050. }, this);
  1051. masterHosts.filterProperty('component', 'HBASE_REGIONSERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1052. hostNames.pushObject(_masterHost.hostName);
  1053. }, this);
  1054. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1055. hostNames.pushObject(_masterHost.hostName);
  1056. }, this);
  1057. break;
  1058. case 'MAPREDUCE_CLIENT':
  1059. // install MAPREDUCE_CLIENT on HIVE_SERVER, OOZIE_SERVER, NAGIOS_SERVER, and WEBHCAT_SERVER hosts
  1060. masterHosts.filterProperty('component', 'HIVE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1061. hostNames.pushObject(_masterHost.hostName);
  1062. }, this);
  1063. masterHosts.filterProperty('component', 'OOZIE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1064. hostNames.pushObject(_masterHost.hostName);
  1065. }, this);
  1066. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1067. hostNames.pushObject(_masterHost.hostName);
  1068. }, this);
  1069. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1070. hostNames.pushObject(_masterHost.hostName);
  1071. }, this);
  1072. break;
  1073. case 'OOZIE_CLIENT':
  1074. // install OOZIE_CLIENT on NAGIOS_SERVER host
  1075. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1076. hostNames.pushObject(_masterHost.hostName);
  1077. }, this);
  1078. break;
  1079. case 'ZOOKEEPER_CLIENT':
  1080. // install ZOOKEEPER_CLIENT on WEBHCAT_SERVER host
  1081. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1082. hostNames.pushObject(_masterHost.hostName);
  1083. }, this);
  1084. break;
  1085. case 'HIVE_CLIENT':
  1086. //install HIVE client on NAGIOS_SERVER host
  1087. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1088. hostNames.pushObject(_masterHost.hostName);
  1089. }, this);
  1090. masterHosts.filterProperty('component', 'HIVE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1091. hostNames.pushObject(_masterHost.hostName);
  1092. }, this);
  1093. break;
  1094. case 'HCAT':
  1095. // install HCAT (client) on NAGIOS_SERVER host
  1096. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1097. hostNames.pushObject(_masterHost.hostName);
  1098. }, this);
  1099. break;
  1100. }
  1101. hostNames = hostNames.uniq();
  1102. if (_client.isInstalled) {
  1103. //check whether clients are already installed on selected master hosts!!!
  1104. var installedHosts = _slave.hosts.filterProperty('isInstalled', true).mapProperty('hostName');
  1105. installedHosts.forEach(function (host) {
  1106. if (hostNames.contains(host)) {
  1107. hostNames.splice(hostNames.indexOf(host), 1);
  1108. }
  1109. }, this);
  1110. }
  1111. this.registerHostsToComponent(hostNames, _client.component_name);
  1112. }, this);
  1113. }
  1114. }, this);
  1115. // add Ganglia Monitor (Slave) to all hosts if Ganglia service is selected
  1116. var gangliaService = this.get('content.services').filterProperty('isSelected', true).findProperty('serviceName', 'GANGLIA');
  1117. if (gangliaService) {
  1118. var hosts = this.getRegisteredHosts();
  1119. if (gangliaService.get('isInstalled')) {
  1120. hosts = hosts.filterProperty('isInstalled', false);
  1121. }
  1122. if (hosts.length) {
  1123. this.registerHostsToComponent(hosts.mapProperty('hostName'), 'GANGLIA_MONITOR');
  1124. }
  1125. }
  1126. // add MySQL Server if Hive is selected
  1127. var hiveService = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).findProperty('serviceName', 'HIVE');
  1128. if (hiveService) {
  1129. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'MYSQL_SERVER');
  1130. }
  1131. },
  1132. registerHostsToComponent: function (hostNames, componentName) {
  1133. if (hostNames.length == 0) {
  1134. return;
  1135. }
  1136. console.log('registering ' + componentName + ' to ' + JSON.stringify(hostNames));
  1137. // currently we are specifying the predicate as a query string.
  1138. // this can hit a ~4000-character limit in Jetty server.
  1139. // chunk to multiple calls if needed
  1140. // var hostsPredicate = hostNames.map(function (hostName) {
  1141. // return 'Hosts/host_name=' + hostName;
  1142. // }).join('|');
  1143. var queryStrArr = [];
  1144. var queryStr = '';
  1145. hostNames.forEach(function (hostName) {
  1146. queryStr += 'Hosts/host_name=' + hostName + '|';
  1147. if (queryStr.length > 3500) {
  1148. queryStrArr.push(queryStr.slice(0, -1));
  1149. queryStr = '';
  1150. }
  1151. });
  1152. if (queryStr.length > 0) {
  1153. queryStrArr.push(queryStr.slice(0, -1));
  1154. }
  1155. queryStrArr.forEach(function (queryStr) {
  1156. // console.log('creating host components for ' + queryStr);
  1157. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts?' + queryStr;
  1158. var data = {
  1159. "host_components": [
  1160. {
  1161. "HostRoles": {
  1162. "component_name": componentName
  1163. }
  1164. }
  1165. ]
  1166. };
  1167. this.ajax({
  1168. type: 'POST',
  1169. url: url,
  1170. data: JSON.stringify(data),
  1171. beforeSend: function () {
  1172. console.log('BeforeSend: registerHostsToComponent for ' + queryStr + ' and component ' + componentName);
  1173. }
  1174. });
  1175. }, this);
  1176. },
  1177. createConfigurations: function () {
  1178. var selectedServices = this.get('selectedServices');
  1179. if (this.get('content.controllerName') == 'installerController') {
  1180. this.applyConfigurationToSite(this.createGlobalSiteObj());
  1181. this.applyConfigurationToSite(this.createCoreSiteObj());
  1182. this.applyConfigurationToSite(this.createHdfsSiteObj());
  1183. }
  1184. if (selectedServices.someProperty('serviceName', 'MAPREDUCE')) {
  1185. this.applyConfigurationToSite(this.createMrSiteObj());
  1186. if (App.supports.capacitySchedulerUi) {
  1187. this.applyConfigurationToSite(this.createCapacityScheduler());
  1188. this.applyConfigurationToSite(this.createMapredQueueAcls());
  1189. }
  1190. }
  1191. if (selectedServices.someProperty('serviceName', 'MAPREDUCEv2')) {
  1192. this.applyConfigurationToSite(this.createMrSiteObj());
  1193. if (App.supports.capacitySchedulerUi) {
  1194. this.applyConfigurationToSite(this.createMapredQueueAcls());
  1195. }
  1196. }
  1197. if (selectedServices.someProperty('serviceName', 'YARN')) {
  1198. this.applyConfigurationToSite(this.createYarnSiteObj());
  1199. if (App.supports.capacitySchedulerUi) {
  1200. this.applyConfigurationToSite(this.createCapacityScheduler());
  1201. }
  1202. }
  1203. if (selectedServices.someProperty('serviceName', 'HBASE')) {
  1204. this.applyConfigurationToSite(this.createHbaseSiteObj());
  1205. }
  1206. if (selectedServices.someProperty('serviceName', 'OOZIE')) {
  1207. this.applyConfigurationToSite(this.createOozieSiteObj('OOZIE'));
  1208. }
  1209. if (selectedServices.someProperty('serviceName', 'HIVE')) {
  1210. this.applyConfigurationToSite(this.createHiveSiteObj('HIVE'));
  1211. }
  1212. if (selectedServices.someProperty('serviceName', 'WEBHCAT')) {
  1213. this.applyConfigurationToSite(this.createWebHCatSiteObj('WEBHCAT'));
  1214. }
  1215. if (selectedServices.someProperty('serviceName', 'HUE')) {
  1216. this.applyConfigurationToSite(this.createHueSiteObj('HUE'));
  1217. }
  1218. },
  1219. applyConfigurationToSite: function (data) {
  1220. console.log("Inside applyConfigurationToSite");
  1221. var clusterUrl = App.apiPrefix + '/clusters/' + this.get('clusterName');
  1222. var clusterData = {
  1223. Clusters: {
  1224. desired_configs: data
  1225. }
  1226. };
  1227. console.debug("applyConfigurationToSite(Step8): Applying to URL", clusterUrl, " Data:", clusterData);
  1228. this.ajax({
  1229. type: 'PUT',
  1230. url: clusterUrl,
  1231. data: JSON.stringify(clusterData),
  1232. beforeSend: function () {
  1233. console.log("BeforeSend: Updating cluster config for " + clusterData.type);
  1234. }
  1235. });
  1236. },
  1237. createGlobalSiteObj: function () {
  1238. var globalSiteProperties = {};
  1239. //this.get('globals').filterProperty('domain', 'global').forEach(function (_globalSiteObj) {
  1240. this.get('globals').forEach(function (_globalSiteObj) {
  1241. // do not pass any globals whose name ends with _host or _hosts
  1242. if (!/_hosts?$/.test(_globalSiteObj.name)) {
  1243. // append "m" to JVM memory options except for hadoop_heapsize
  1244. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name) && _globalSiteObj.name !== 'hadoop_heapsize') {
  1245. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value + "m";
  1246. } else {
  1247. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value;
  1248. }
  1249. console.log("STEP8: name of the global property is: " + _globalSiteObj.name);
  1250. console.log("STEP8: value of the global property is: " + _globalSiteObj.value);
  1251. }
  1252. if (_globalSiteObj.name == 'java64_home') {
  1253. globalSiteProperties['java64_home'] = this.get('content.installOptions.javaHome');
  1254. }
  1255. this._recordHostOverrideFromObj(_globalSiteObj, 'global', 'version1', this);
  1256. }, this);
  1257. // we don't expose gmond_user to the user; it needs to be the same as gmetad_user
  1258. globalSiteProperties['gmond_user'] = globalSiteProperties['gmetad_user'];
  1259. return {"type": "global", "tag": "version1", "properties": globalSiteProperties};
  1260. },
  1261. createCoreSiteObj: function () {
  1262. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  1263. var coreSiteProperties = {};
  1264. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  1265. var isOozieSelected = this.get('selectedServices').someProperty('serviceName', 'OOZIE');
  1266. var oozieUser = this.get('globals').someProperty('name', 'oozie_user') ? this.get('globals').findProperty('name', 'oozie_user').value : null;
  1267. var isHiveSelected = this.get('selectedServices').someProperty('serviceName', 'HIVE');
  1268. var hiveUser = this.get('globals').someProperty('name', 'hive_user') ? this.get('globals').findProperty('name', 'hive_user').value : null;
  1269. var isHcatSelected = this.get('selectedServices').someProperty('serviceName', 'WEBHCAT');
  1270. var hcatUser = this.get('globals').someProperty('name', 'hcat_user') ? this.get('globals').findProperty('name', 'hcat_user').value : null;
  1271. coreSiteObj.forEach(function (_coreSiteObj) {
  1272. if ((isOozieSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + oozieUser + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + oozieUser + '.groups')) && (isHiveSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + hiveUser + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + hiveUser + '.groups')) && (isHcatSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + hcatUser + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + hcatUser + '.groups'))) {
  1273. coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
  1274. this._recordHostOverrideFromObj(_coreSiteObj, 'core-site', 'version1', this);
  1275. }
  1276. console.log("STEP*: name of the property is: " + _coreSiteObj.name);
  1277. console.log("STEP8: value of the property is: " + _coreSiteObj.value);
  1278. }, this);
  1279. return {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  1280. },
  1281. createHdfsSiteObj: function () {
  1282. var hdfsSiteObj = this.get('configs').filterProperty('filename', 'hdfs-site.xml');
  1283. var hdfsProperties = {};
  1284. hdfsSiteObj.forEach(function (_configProperty) {
  1285. hdfsProperties[_configProperty.name] = _configProperty.value;
  1286. this._recordHostOverrideFromObj(_configProperty, 'hdfs-site', 'version1', this);
  1287. console.log("STEP*: name of the property is: " + _configProperty.name);
  1288. console.log("STEP8: value of the property is: " + _configProperty.value);
  1289. }, this);
  1290. return {"type": "hdfs-site", "tag": "version1", "properties": hdfsProperties };
  1291. },
  1292. createHueSiteObj: function () {
  1293. var hueSiteObj = this.get('configs').filterProperty('filename', 'hue-site.xml');
  1294. var hueProperties = {};
  1295. hueSiteObj.forEach(function (_configProperty) {
  1296. hueProperties[_configProperty.name] = _configProperty.value;
  1297. this._recordHostOverrideFromObj(_configProperty, 'hue-site', 'version1', this);
  1298. console.log("STEP*: name of the property is: " + _configProperty.name);
  1299. console.log("STEP8: value of the property is: " + _configProperty.value);
  1300. }, this);
  1301. return {"type": "hue-site", "tag": "version1", "properties": hueProperties };
  1302. },
  1303. createMrSiteObj: function () {
  1304. var configs = this.get('configs').filterProperty('filename', 'mapred-site.xml');
  1305. var mrProperties = {};
  1306. configs.forEach(function (_configProperty) {
  1307. mrProperties[_configProperty.name] = _configProperty.value;
  1308. this._recordHostOverrideFromObj(_configProperty, 'mapred-site', 'version1', this);
  1309. console.log("STEP*: name of the property is: " + _configProperty.name);
  1310. console.log("STEP8: value of the property is: " + _configProperty.value);
  1311. }, this);
  1312. return {type: 'mapred-site', tag: 'version1', properties: mrProperties};
  1313. },
  1314. createYarnSiteObj: function () {
  1315. var configs = this.get('configs').filterProperty('filename', 'yarn-site.xml');
  1316. var mrProperties = {};
  1317. configs.forEach(function (_configProperty) {
  1318. mrProperties[_configProperty.name] = _configProperty.value;
  1319. this._recordHostOverrideFromObj(_configProperty, 'mapred-site', 'version1', this);
  1320. console.log("STEP*: name of the property is: " + _configProperty.name);
  1321. console.log("STEP8: value of the property is: " + _configProperty.value);
  1322. }, this);
  1323. return {type: 'yarn-site', tag: 'version1', properties: mrProperties};
  1324. },
  1325. createCapacityScheduler: function () {
  1326. var configs = this.get('configs').filterProperty('filename', 'capacity-scheduler.xml');
  1327. var csProperties = {};
  1328. configs.forEach(function (_configProperty) {
  1329. csProperties[_configProperty.name] = _configProperty.value;
  1330. this._recordHostOverrideFromObj(_configProperty, 'capacity-scheduler', 'version1', this);
  1331. console.log("STEP*: name of the property is: " + _configProperty.name);
  1332. console.log("STEP8: value of the property is: " + _configProperty.value);
  1333. }, this);
  1334. return {type: 'capacity-scheduler', tag: 'version1', properties: csProperties};
  1335. },
  1336. createMapredQueueAcls: function () {
  1337. var configs = this.get('configs').filterProperty('filename', 'mapred-queue-acls.xml');
  1338. var mqProperties = {};
  1339. configs.forEach(function (_configProperty) {
  1340. mqProperties[_configProperty.name] = _configProperty.value;
  1341. this._recordHostOverrideFromObj(_configProperty, 'mapred-queue-acls', 'version1', this);
  1342. console.log("STEP*: name of the property is: " + _configProperty.name);
  1343. console.log("STEP8: value of the property is: " + _configProperty.value);
  1344. }, this);
  1345. return {type: 'mapred-queue-acls', tag: 'version1', properties: mqProperties};
  1346. },
  1347. createHbaseSiteObj: function () {
  1348. var configs = this.get('configs').filterProperty('filename', 'hbase-site.xml');
  1349. var hbaseProperties = {};
  1350. configs.forEach(function (_configProperty) {
  1351. hbaseProperties[_configProperty.name] = _configProperty.value;
  1352. this._recordHostOverrideFromObj(_configProperty, 'hbase-site', 'version1', this);
  1353. }, this);
  1354. return {type: 'hbase-site', tag: 'version1', properties: hbaseProperties};
  1355. },
  1356. createOozieSiteObj: function (serviceName) {
  1357. var configs = this.get('configs').filterProperty('filename', 'oozie-site.xml');
  1358. var oozieProperties = {};
  1359. configs.forEach(function (_configProperty) {
  1360. oozieProperties[_configProperty.name] = _configProperty.value;
  1361. this._recordHostOverrideFromObj(_configProperty, 'oozie-site', 'version1', this);
  1362. }, this);
  1363. var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
  1364. if (globals.someProperty('name', 'oozie_database')) {
  1365. var oozieDb = globals.findProperty('name', 'oozie_database');
  1366. var oozieHost = null;
  1367. if(globals.someProperty('name', 'oozie_hostname')){
  1368. oozieHost = globals.findProperty('name', 'oozie_hostname').value;
  1369. }
  1370. var oozieDbName = globals.findProperty('name', 'oozie_database_name').value;
  1371. if (oozieDb.value === 'New Derby Database'){
  1372. oozieProperties["oozie.service.JPAService.jdbc.url"] = "jdbc:derby:${oozie.data.dir}/${oozie.db.schema.name}-db;create=true";
  1373. oozieProperties["oozie.service.JPAService.jdbc.driver"] = "org.apache.derby.jdbc.EmbeddedDriver";
  1374. }else if (oozieDb.value === 'New MySQL Database') {
  1375. oozieProperties["oozie.service.JPAService.jdbc.url"] = "jdbc:mysql://" + oozieHost + "/" + oozieDbName + "?createDatabaseIfNotExist=true";
  1376. oozieProperties["oozie.service.JPAService.jdbc.driver"] = "com.mysql.jdbc.Driver";
  1377. } else if (oozieDb.value === 'Existing MySQL Database'){
  1378. oozieProperties["oozie.service.JPAService.jdbc.url"] = "jdbc:mysql://" + oozieHost + "/" + oozieDbName + "?createDatabaseIfNotExist=true";
  1379. oozieProperties["oozie.service.JPAService.jdbc.driver"] = "com.mysql.jdbc.Driver";
  1380. } else{ //existing oracle database
  1381. oozieProperties["oozie.service.JPAService.jdbc.url"] = "jdbc:oracle://" + oozieHost + "/" + oozieDbName + "?createDatabaseIfNotExist=true";
  1382. oozieProperties["oozie.service.JPAService.jdbc.driver"] = "oracle.jdbc.driver.OracleDriver";
  1383. }
  1384. //set oozie username and password
  1385. oozieProperties["oozie.service.JPAService.jdbc.username"] = globals.findProperty('name', 'oozie_metastore_user_name').value;
  1386. oozieProperties["oozie.service.JPAService.jdbc.password"] = globals.findProperty('name', 'oozie_metastore_user_passwd').value;
  1387. }
  1388. return {type: 'oozie-site', tag: 'version1', properties: oozieProperties};
  1389. },
  1390. createHiveSiteObj: function (serviceName) {
  1391. var configs = this.get('configs').filterProperty('filename', 'hive-site.xml');
  1392. var hiveProperties = {};
  1393. configs.forEach(function (_configProperty) {
  1394. hiveProperties[_configProperty.name] = _configProperty.value;
  1395. this._recordHostOverrideFromObj(_configProperty, 'hive-site', 'version1', this);
  1396. }, this);
  1397. var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
  1398. if (globals.someProperty('name', 'hive_database')) {
  1399. var hiveDb = globals.findProperty('name', 'hive_database');
  1400. var hiveHost = globals.findProperty('name', 'hive_hostname').value;
  1401. var hiveDbName = globals.findProperty('name', 'hive_database_name').value;
  1402. if (hiveDb.value === 'New MySQL Database') {
  1403. hiveProperties["javax.jdo.option.ConnectionURL"] = "jdbc:mysql://"+ hiveHost + "/" + hiveDbName + "?createDatabaseIfNotExist=true";
  1404. hiveProperties["javax.jdo.option.ConnectionDriverName"] = "com.mysql.jdbc.Driver";
  1405. } else if (hiveDb.value === 'Existing MySQL Database'){
  1406. hiveProperties["javax.jdo.option.ConnectionURL"] = "jdbc:mysql://"+ hiveHost + "/" + hiveDbName + "?createDatabaseIfNotExist=true";
  1407. hiveProperties["javax.jdo.option.ConnectionDriverName"] = "com.mysql.jdbc.Driver";
  1408. } else{ //existing oracle database
  1409. hiveProperties["javax.jdo.option.ConnectionURL"] = "jdbc:oracle://"+ hiveHost + "/" + hiveDbName + "?createDatabaseIfNotExist=true";
  1410. hiveProperties["javax.jdo.option.ConnectionDriverName"] = "oracle.jdbc.driver.OracleDriver";
  1411. }
  1412. }
  1413. return {type: 'hive-site', tag: 'version1', properties: hiveProperties};
  1414. },
  1415. createWebHCatSiteObj: function (serviceName) {
  1416. var configs = this.get('configs').filterProperty('filename', 'webhcat-site.xml');
  1417. var webHCatProperties = {};
  1418. configs.forEach(function (_configProperty) {
  1419. webHCatProperties[_configProperty.name] = _configProperty.value;
  1420. this._recordHostOverrideFromObj(_configProperty, 'webhcat-site', 'version1', this);
  1421. }, this);
  1422. return {type: 'webhcat-site', tag: 'version1', properties: webHCatProperties};
  1423. },
  1424. getConfigForService: function (serviceName) {
  1425. switch (serviceName) {
  1426. case 'HDFS':
  1427. return {config: {'global': 'version1', 'core-site': 'version1', 'hdfs-site': 'version1'}};
  1428. case 'MAPREDUCE':
  1429. return {config: {'global': 'version1', 'core-site': 'version1', 'mapred-site': 'version1', 'capacity-scheduler': 'version1', 'mapred-queue-acls': 'version1'}};
  1430. case 'MAPREDUCEv2':
  1431. return {config: {'global': 'version1', 'core-site': 'version1', 'mapred-site': 'version1', 'mapred-queue-acls': 'version1'}};
  1432. case 'YARN':
  1433. return {config: {'global': 'version1', 'yarn-site': 'version1', 'capacity-scheduler': 'version1'}};
  1434. case 'HBASE':
  1435. return {config: {'global': 'version1', 'hbase-site': 'version1'}};
  1436. case 'OOZIE':
  1437. return {config: {'global': 'version1', 'oozie-site': 'version1'}};
  1438. case 'HIVE':
  1439. return {config: {'global': 'version1', 'hive-site': 'version1'}};
  1440. case 'WEBHCAT':
  1441. return {config: {'global': 'version1', 'webhcat-site': 'version1'}};
  1442. case 'HUE':
  1443. return {config: {'global': 'version1', 'hue-site': 'version1'}};
  1444. default:
  1445. return {config: {'global': 'version1'}};
  1446. }
  1447. },
  1448. ajaxQueueFinished: function () {
  1449. //do something
  1450. },
  1451. doNextAjaxCall: function () {
  1452. if (this.get('ajaxBusy')) {
  1453. return;
  1454. }
  1455. var queue = this.get('ajaxQueue');
  1456. if (!queue.length) {
  1457. this.ajaxQueueFinished();
  1458. return;
  1459. }
  1460. var first = queue[0];
  1461. this.set('ajaxQueue', queue.slice(1));
  1462. this.set('ajaxQueueLeft', this.get('ajaxQueue').length);
  1463. this.set('ajaxBusy', true);
  1464. console.log('AJAX send ' + first.url);
  1465. $.ajax(first);
  1466. },
  1467. /**
  1468. * Records all the host overrides per site/tag
  1469. */
  1470. _recordHostOverrideFromObj: function(serviceConfigObj, siteName, tagName, self){
  1471. var overrides = serviceConfigObj.overrides;
  1472. if(overrides && overrides.length>0){
  1473. overrides.forEach(function(override){
  1474. override.hosts.forEach(function(host){
  1475. if(!(host in self.savedHostToOverrideSiteToTagMap)){
  1476. self.savedHostToOverrideSiteToTagMap[host] = {};
  1477. }
  1478. if(!(siteName in self.savedHostToOverrideSiteToTagMap[host])){
  1479. self.savedHostToOverrideSiteToTagMap[host][siteName] = {};
  1480. self.savedHostToOverrideSiteToTagMap[host][siteName].map = {};
  1481. }
  1482. var finalTag = tagName + '_' + host;
  1483. console.log("recordHostOverride(): Saving host override for host="+host+", site="+siteName+", tag="+finalTag+", (key,value)=("+serviceConfigObj.name+","+override.value+")");
  1484. self.savedHostToOverrideSiteToTagMap[host][siteName].tagName = finalTag;
  1485. self.savedHostToOverrideSiteToTagMap[host][siteName].map[serviceConfigObj.name] = override.value;
  1486. });
  1487. });
  1488. }
  1489. },
  1490. /**
  1491. * Creates host level overrides for service configuration.
  1492. *
  1493. */
  1494. createHostOverrideConfigurations: function () {
  1495. var singlePUTHostData = [];
  1496. var savedHostSiteArray = [];
  1497. for ( var host in this.savedHostToOverrideSiteToTagMap) {
  1498. for ( var siteName in this.savedHostToOverrideSiteToTagMap[host]) {
  1499. var tagName = this.savedHostToOverrideSiteToTagMap[host][siteName].tagName;
  1500. var map = this.savedHostToOverrideSiteToTagMap[host][siteName].map;
  1501. savedHostSiteArray.push(host + "///" + siteName);
  1502. singlePUTHostData.push({
  1503. RequestInfo: {
  1504. query: 'Hosts/host_name='+host
  1505. },
  1506. Body: {
  1507. Hosts: {
  1508. desired_config: {
  1509. type: siteName,
  1510. tag: tagName,
  1511. properties: map
  1512. }
  1513. }
  1514. }
  1515. });
  1516. }
  1517. }
  1518. console.log("createHostOverrideConfigSites(): PUTting host-overrides. Data=", singlePUTHostData);
  1519. if(singlePUTHostData.length>0){
  1520. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts';
  1521. this.ajax({
  1522. type: 'PUT',
  1523. url: url,
  1524. data: JSON.stringify(singlePUTHostData),
  1525. dataType: 'text',
  1526. beforeSend: function () {
  1527. console.log("createHostOverrideConfigSites() PUT override=", singlePUTHostData);
  1528. }
  1529. });
  1530. }
  1531. },
  1532. /**
  1533. * We need to do a lot of ajax calls async in special order. To do this,
  1534. * generate array of ajax objects and then send requests step by step. All
  1535. * ajax objects are stored in <code>ajaxQueue</code>
  1536. *
  1537. * @param params
  1538. */
  1539. ajax: function (params) {
  1540. if (App.testMode) return;
  1541. var self = this;
  1542. params = jQuery.extend({
  1543. async: true,
  1544. dataType: 'text',
  1545. statusCode: require('data/statusCodes'),
  1546. timeout: App.timeout,
  1547. error: function (request, ajaxOptions, error) {
  1548. console.log('Step8: In Error ');
  1549. // console.log('Step8: Error message is: ' + request.responseText);
  1550. },
  1551. success: function (data) {
  1552. var jsonData = jQuery.parseJSON(data);
  1553. console.log("TRACE: STep8 -> In success function");
  1554. console.log("TRACE: STep8 -> value of the url is: " + params.url);
  1555. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  1556. }
  1557. }, params);
  1558. var success = params.success;
  1559. var error = params.error;
  1560. params.success = function () {
  1561. if (success) {
  1562. success();
  1563. }
  1564. self.set('ajaxBusy', false);
  1565. self.doNextAjaxCall();
  1566. }
  1567. params.error = function (xhr, status, error) {
  1568. var responseText = JSON.parse(xhr.responseText);
  1569. var controller = App.router.get(App.clusterStatus.wizardControllerName);
  1570. controller.registerErrPopup(Em.I18n.t('common.error'), responseText.message);
  1571. self.set('hasErrorOccurred', true);
  1572. // an error will break the ajax call chain and allow submission again
  1573. self.set('isSubmitDisabled', false);
  1574. self.get('ajaxQueue').clear();
  1575. self.set('ajaxBusy', false);
  1576. }
  1577. this.get('ajaxQueue').pushObject(params);
  1578. }
  1579. });