step8_controller.js 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629
  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 expression;
  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 'HBASE_REGIONSERVER':
  375. serviceConfig = {
  376. name: 'HBASE',
  377. siteName: 'hbase-site',
  378. domain: 'regionserver-global'
  379. };
  380. break;
  381. default:
  382. serviceConfig = {};
  383. }
  384. return serviceConfig;
  385. },
  386. /**
  387. * Load all info about cluster to <code>clusterInfo</code> variable
  388. */
  389. loadClusterInfo: function () {
  390. //Admin name
  391. var admin = this.rawContent.findProperty('config_name', 'Admin');
  392. admin.config_value = App.db.getLoginName();
  393. console.log("STEP8: the value of content cluster name: " + App.db.getLoginName());
  394. if (admin.config_value) {
  395. this.get('clusterInfo').pushObject(Ember.Object.create(admin));
  396. }
  397. // cluster name
  398. var cluster = this.rawContent.findProperty('config_name', 'cluster');
  399. cluster.config_value = this.get('content.cluster.name');
  400. console.log("STEP8: the value of content cluster name: " + this.get('content.cluster.name'));
  401. this.get('clusterInfo').pushObject(Ember.Object.create(cluster));
  402. //hosts
  403. var masterHosts = this.get('content.masterComponentHosts').mapProperty('hostName').uniq();
  404. var slaveHosts = this.get('content.slaveComponentHosts');
  405. var hostObj = [];
  406. slaveHosts.forEach(function (_hosts) {
  407. hostObj = hostObj.concat(_hosts.hosts);
  408. }, this);
  409. slaveHosts = hostObj.mapProperty('hostName').uniq();
  410. var componentHosts = masterHosts.concat(slaveHosts).uniq();
  411. var totalHosts = App.Host.find().mapProperty('hostName').concat(componentHosts).uniq();
  412. var newHostsCount = totalHosts.length - App.Host.find().content.length;
  413. this.set('totalHosts', totalHosts);
  414. var totalHostsObj = this.rawContent.findProperty('config_name', 'hosts');
  415. totalHostsObj.config_value = totalHosts.length + ' (' + newHostsCount + ' new)';
  416. this.get('clusterInfo').pushObject(Ember.Object.create(totalHostsObj));
  417. //repo
  418. var repoOption = this.get('content.installOption.localRepo');
  419. var repoObj = this.rawContent.findProperty('config_name', 'Repo');
  420. if (repoOption) {
  421. repoObj.config_value = 'Yes';
  422. } else {
  423. repoObj.config_value = 'No';
  424. }
  425. this.get('clusterInfo').pushObject(Ember.Object.create(repoObj));
  426. },
  427. /**
  428. * Load all info about services to <code>services</code> variable
  429. */
  430. loadServices: function () {
  431. var selectedServices = this.get('selectedServices');
  432. this.set('services', selectedServices.mapProperty('serviceName'));
  433. selectedServices.forEach(function (_service) {
  434. console.log('INFO: step8: Name of the service from getService function: ' + _service.serviceName);
  435. var reviewService = this.rawContent.findProperty('config_name', 'services');
  436. var serviceObj = reviewService.config_value.findProperty('service_name', _service.serviceName);
  437. if (serviceObj) {
  438. switch (serviceObj.service_name) {
  439. case 'HDFS':
  440. this.loadHDFS(serviceObj);
  441. break;
  442. case 'MAPREDUCE':
  443. this.loadMapReduce(serviceObj);
  444. break;
  445. case 'HIVE':
  446. this.loadHive(serviceObj);
  447. break;
  448. case 'HBASE':
  449. this.loadHbase(serviceObj);
  450. break;
  451. case 'ZOOKEEPER':
  452. this.loadZk(serviceObj);
  453. break;
  454. case 'OOZIE':
  455. this.loadOozie(serviceObj);
  456. break;
  457. case 'NAGIOS':
  458. this.loadNagios(serviceObj);
  459. break;
  460. case 'GANGLIA':
  461. this.loadGanglia(serviceObj);
  462. break;
  463. case 'HUE':
  464. this.loadHue(serviceObj);
  465. break;
  466. /* case 'PIG':
  467. this.loadPig(serviceObj);
  468. break;
  469. case 'SQOOP':
  470. this.loadSqoop(serviceObj);
  471. break;
  472. */
  473. case 'HCATALOG':
  474. break;
  475. default:
  476. }
  477. }
  478. }, this);
  479. },
  480. /**
  481. * load all info about HDFS service
  482. * @param hdfsObj
  483. */
  484. loadHDFS: function (hdfsObj) {
  485. hdfsObj.get('service_components').forEach(function (_component) {
  486. switch (_component.get('display_name')) {
  487. case 'NameNode':
  488. this.loadNnValue(_component);
  489. break;
  490. case 'SecondaryNameNode':
  491. this.loadSnnValue(_component);
  492. break;
  493. case 'DataNodes':
  494. this.loadDnValue(_component);
  495. break;
  496. default:
  497. }
  498. }, this);
  499. //var
  500. this.get('services').pushObject(hdfsObj);
  501. },
  502. loadNnValue: function (nnComponent) {
  503. var nnHostName = this.get('content.masterComponentHosts').findProperty('display_name', nnComponent.display_name);
  504. nnComponent.set('component_value', nnHostName.hostName);
  505. },
  506. loadSnnValue: function (snnComponent) {
  507. var snnHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'SNameNode');
  508. snnComponent.set('component_value', snnHostName.hostName);
  509. },
  510. loadDnValue: function (dnComponent) {
  511. var dnHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'DataNode');
  512. var totalDnHosts = dnHosts.hosts.length;
  513. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'DATANODE').groups.length;
  514. var groupLabel;
  515. if (totalGroups == 1) {
  516. groupLabel = 'group';
  517. } else {
  518. groupLabel = 'groups';
  519. }
  520. */
  521. dnComponent.set('component_value', totalDnHosts + Em.I18n.t('installer.step8.hosts'));
  522. },
  523. /**
  524. * Load all info about mapReduce service
  525. * @param mrObj
  526. */
  527. loadMapReduce: function (mrObj) {
  528. mrObj.get('service_components').forEach(function (_component) {
  529. switch (_component.get('display_name')) {
  530. case 'JobTracker':
  531. this.loadJtValue(_component);
  532. break;
  533. case 'TaskTrackers':
  534. this.loadTtValue(_component);
  535. break;
  536. default:
  537. }
  538. }, this);
  539. this.get('services').pushObject(mrObj);
  540. },
  541. loadJtValue: function (jtComponent) {
  542. var jtHostName = this.get('content.masterComponentHosts').findProperty('display_name', jtComponent.display_name);
  543. jtComponent.set('component_value', jtHostName.hostName);
  544. },
  545. loadTtValue: function (ttComponent) {
  546. var ttHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'TaskTracker');
  547. var totalTtHosts = ttHosts.hosts.length;
  548. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'TASKTRACKER').groups.length;
  549. var groupLabel;
  550. if (totalGroups == 1) {
  551. groupLabel = 'group';
  552. } else {
  553. groupLabel = 'groups';
  554. }
  555. */
  556. ttComponent.set('component_value', totalTtHosts + Em.I18n.t('installer.step8.hosts'));
  557. },
  558. /**
  559. * Load all info about Hive service
  560. * @param hiveObj
  561. */
  562. loadHive: function (hiveObj) {
  563. hiveObj.get('service_components').forEach(function (_component) {
  564. switch (_component.get('display_name')) {
  565. case 'Hive Metastore':
  566. this.loadHiveMetaStoreValue(_component);
  567. break;
  568. case 'Database':
  569. this.loadHiveDbValue(_component);
  570. break;
  571. default:
  572. }
  573. }, this);
  574. this.get('services').pushObject(hiveObj);
  575. },
  576. loadHiveMetaStoreValue: function (metaStoreComponent) {
  577. var hiveHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'HiveServer2');
  578. metaStoreComponent.set('component_value', hiveHostName.hostName);
  579. },
  580. loadHiveDbValue: function (dbComponent) {
  581. var hiveDb = App.db.getServiceConfigProperties().findProperty('name', 'hive_database');
  582. if (hiveDb.value === 'New MySQL Database') {
  583. dbComponent.set('component_value', 'MySQL (New Database)');
  584. } else if(hiveDb.value === 'Existing MySQL Database'){
  585. var db = App.db.getServiceConfigProperties().findProperty('name', 'hive_existing_mysql_database');
  586. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  587. } else { // existing oracle database
  588. var db = App.db.getServiceConfigProperties().findProperty('name', 'hive_existing_oracle_database');
  589. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  590. }
  591. },
  592. /**
  593. * Load all info about Hbase
  594. * @param hbaseObj
  595. */
  596. loadHbase: function (hbaseObj) {
  597. hbaseObj.service_components.forEach(function (_component) {
  598. switch (_component.display_name) {
  599. case 'Master':
  600. this.loadMasterValue(_component);
  601. break;
  602. case 'RegionServers':
  603. this.loadRegionServerValue(_component);
  604. break;
  605. default:
  606. }
  607. }, this);
  608. this.get('services').pushObject(hbaseObj);
  609. },
  610. loadMasterValue: function (hbaseMaster) {
  611. var hbaseHostName = this.get('content.masterComponentHosts').filterProperty('display_name', 'HBase Master');
  612. if (hbaseHostName.length == 1) {
  613. hbaseMaster.set('component_value', hbaseHostName[0].hostName);
  614. } else {
  615. hbaseMaster.set('component_value', hbaseHostName[0].hostName + Em.I18n.t('installer.step8.other').format(hbaseHostName.length - 1));
  616. }
  617. },
  618. loadRegionServerValue: function (rsComponent) {
  619. var rsHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'RegionServer');
  620. var totalRsHosts = rsHosts.hosts.length;
  621. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'HBASE_REGIONSERVER').groups.length;
  622. var groupLabel;
  623. if (totalGroups == 1) {
  624. groupLabel = 'group';
  625. } else {
  626. groupLabel = 'groups';
  627. } */
  628. rsComponent.set('component_value', totalRsHosts + Em.I18n.t('installer.step8.hosts'));
  629. },
  630. /**
  631. * Load all info about ZooKeeper service
  632. * @param zkObj
  633. */
  634. loadZk: function (zkObj) {
  635. zkObj.get('service_components').forEach(function (_component) {
  636. switch (_component.get('display_name')) {
  637. case 'Servers':
  638. this.loadZkServerValue(_component);
  639. break;
  640. default:
  641. }
  642. }, this);
  643. this.get('services').pushObject(zkObj);
  644. },
  645. loadZkServerValue: function (serverComponent) {
  646. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('display_name', 'ZooKeeper').length;
  647. var hostSuffix;
  648. if (zkHostNames === 1) {
  649. hostSuffix = Em.I18n.t('installer.step8.host');
  650. } else {
  651. hostSuffix = Em.I18n.t('installer.step8.hosts');
  652. }
  653. serverComponent.set('component_value', zkHostNames + ' ' + hostSuffix);
  654. },
  655. /**
  656. * Load all info about Hue services
  657. * @param hueObj
  658. */
  659. loadHue: function (hueObj) {
  660. hueObj.get('service_components').forEach(function (_component) {
  661. switch (_component.get('display_name')) {
  662. case 'Server':
  663. this.loadHueServerValue(_component);
  664. break;
  665. default:
  666. }
  667. }, this);
  668. this.get('services').pushObject(hueObj);
  669. },
  670. loadHueServerValue: function (hueServer) {
  671. var hueServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Hue Server');
  672. hueServer.set('component_value', hueServerName.hostName);
  673. },
  674. /**
  675. * Load all info about Oozie services
  676. * @param oozieObj
  677. */
  678. loadOozie: function (oozieObj) {
  679. oozieObj.get('service_components').forEach(function (_component) {
  680. switch (_component.get('display_name')) {
  681. case 'Server':
  682. this.loadOozieServerValue(_component);
  683. break;
  684. case 'Database':
  685. // TODO: uncomment when ready to integrate with Oozie Database other than Derby
  686. this.loadOozieDbValue(_component);
  687. break;
  688. default:
  689. }
  690. }, this);
  691. this.get('services').pushObject(oozieObj);
  692. },
  693. loadOozieServerValue: function (oozieServer) {
  694. var oozieServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Oozie Server');
  695. oozieServer.set('component_value', oozieServerName.hostName);
  696. },
  697. loadOozieDbValue: function (dbComponent) {
  698. var oozieDb = App.db.getServiceConfigProperties().findProperty('name', 'oozie_database');
  699. if (oozieDb.value === 'New Derby Database'){
  700. var db = App.db.getServiceConfigProperties().findProperty('name', 'oozie_derby_database');
  701. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  702. } else if (oozieDb.value === 'New MySQL Database') {
  703. dbComponent.set('component_value', 'MySQL (New Database)');
  704. } else if(oozieDb.value === 'Existing MySQL Database'){
  705. var db = App.db.getServiceConfigProperties().findProperty('name', 'oozie_existing_mysql_database');
  706. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  707. } else { // existing oracle database
  708. var db = App.db.getServiceConfigProperties().findProperty('name', 'oozie_existing_oracle_database');
  709. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  710. }
  711. },
  712. /**
  713. * Load all info about Nagios service
  714. * @param nagiosObj
  715. */
  716. loadNagios: function (nagiosObj) {
  717. nagiosObj.service_components.forEach(function (_component) {
  718. switch (_component.display_name) {
  719. case 'Server':
  720. this.loadNagiosServerValue(_component);
  721. break;
  722. case 'Administrator':
  723. this.loadNagiosAdminValue(_component);
  724. break;
  725. default:
  726. }
  727. }, this);
  728. this.get('services').pushObject(nagiosObj);
  729. },
  730. loadNagiosServerValue: function (nagiosServer) {
  731. var nagiosServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Nagios Server');
  732. nagiosServer.set('component_value', nagiosServerName.hostName);
  733. },
  734. loadNagiosAdminValue: function (nagiosAdmin) {
  735. var config = this.get('content.serviceConfigProperties');
  736. var adminLoginName = config.findProperty('name', 'nagios_web_login');
  737. var adminEmail = config.findProperty('name', 'nagios_contact');
  738. nagiosAdmin.set('component_value', adminLoginName.value + ' / (' + adminEmail.value + ')');
  739. },
  740. /**
  741. * Load all info about ganglia
  742. * @param gangliaObj
  743. */
  744. loadGanglia: function (gangliaObj) {
  745. gangliaObj.get('service_components').forEach(function (_component) {
  746. switch (_component.get('display_name')) {
  747. case 'Server':
  748. this.loadGangliaServerValue(_component);
  749. break;
  750. default:
  751. }
  752. }, this);
  753. this.get('services').pushObject(gangliaObj);
  754. },
  755. loadGangliaServerValue: function (gangliaServer) {
  756. var gangliaServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Ganglia Collector');
  757. gangliaServer.set('component_value', gangliaServerName.hostName);
  758. },
  759. loadSqoop: function (sqoopObj) {
  760. this.get('services').pushObject(sqoopObj);
  761. },
  762. loadPig: function (pigObj) {
  763. this.get('services').pushObject(pigObj);
  764. },
  765. /**
  766. * Onclick handler for <code>next</code> button
  767. */
  768. submit: function () {
  769. if (this.get('isSubmitDisabled')) {
  770. return;
  771. }
  772. this.set('isSubmitDisabled', true);
  773. // checkpoint the cluster status on the server so that the user can resume from where they left off
  774. switch (this.get('content.controllerName')) {
  775. case 'installerController':
  776. App.clusterStatus.setClusterStatus({
  777. clusterName: this.get('clusterName'),
  778. clusterState: 'CLUSTER_DEPLOY_PREP_2',
  779. wizardControllerName: this.get('content.controllerName'),
  780. localdb: App.db.data
  781. });
  782. break;
  783. case 'addHostController':
  784. App.clusterStatus.setClusterStatus({
  785. clusterName: this.get('clusterName'),
  786. clusterState: 'ADD_HOSTS_DEPLOY_PREP_2',
  787. wizardControllerName: this.get('content.controllerName'),
  788. localdb: App.db.data
  789. });
  790. break;
  791. case 'addServiceController':
  792. App.clusterStatus.setClusterStatus({
  793. clusterName: this.get('clusterName'),
  794. clusterState: 'ADD_SERVICES_DEPLOY_PREP_2',
  795. wizardControllerName: this.get('content.controllerName'),
  796. localdb: App.db.data
  797. });
  798. break;
  799. default:
  800. break;
  801. }
  802. // delete any existing clusters to start from a clean slate
  803. // before creating a new cluster in install wizard
  804. // TODO: modify for multi-cluster support
  805. if (this.get('content.controllerName') == 'installerController') {
  806. var clusterNames = this.getExistingClusterNames();
  807. this.deleteClusters(clusterNames);
  808. }
  809. this.createCluster();
  810. this.createSelectedServices();
  811. this.createConfigurations();
  812. this.createComponents();
  813. this.registerHostsToCluster();
  814. this.createAllHostComponents();
  815. this.createHostOverrideConfigurations();
  816. this.ajaxQueueFinished = function () {
  817. console.log('everything is loaded');
  818. App.router.send('next');
  819. };
  820. this.doNextAjaxCall();
  821. },
  822. /**
  823. * Used in progress bar
  824. */
  825. ajaxQueueLength: function () {
  826. return this.get('ajaxQueue').length;
  827. }.property('ajaxQueue.length'),
  828. /**
  829. * Used in progress bar
  830. */
  831. ajaxQueueLeft: 0,
  832. setAmbariUIDb: function () {
  833. var dbContent = this.get('content.slaveGroupProperties');
  834. var slaveComponentConfig = this.get("slaveComponentConfig");
  835. this.persistKeyValues(slaveComponentConfig.version, dbContent);
  836. this.persistKeyValues('current_version', slaveComponentConfig.version);
  837. },
  838. persistKeyValues: function (key, value) {
  839. var str = "{ '" + key + "' : '" + JSON.stringify(value) + "'}";
  840. var obj = eval("(" + str + ")");
  841. this.ajax({
  842. type: "POST",
  843. url: App.apiPrefix + '/persist',
  844. data: JSON.stringify(obj),
  845. beforeSend: function () {
  846. console.log('BeforeSend: persistKeyValues', obj);
  847. }
  848. });
  849. },
  850. clusterName: function () {
  851. return this.get('content.cluster.name');
  852. }.property('content.cluster.name'),
  853. clusterNames: [],
  854. // returns an array of existing cluster names.
  855. // returns an empty array if there are no existing clusters.
  856. getExistingClusterNames: function () {
  857. var url = App.apiPrefix + '/clusters';
  858. App.ajax.send({
  859. name: 'wizard.step8.existing_cluster_names',
  860. sender: this,
  861. success: 'getExistingClusterNamesSuccessCallBack',
  862. error: 'getExistingClusterNamesErrorCallback'
  863. });
  864. return this.get('clusterNames');
  865. },
  866. getExistingClusterNamesSuccessCallBack: function (data) {
  867. var clusterNames = data.items.mapProperty('Clusters.cluster_name');
  868. console.log("Got existing cluster names: " + clusterNames);
  869. this.set('clusterNames', clusterNames);
  870. },
  871. getExistingClusterNamesErrorCallback: function () {
  872. console.log("Failed to get existing cluster names");
  873. this.set('clusterNames', []);
  874. },
  875. deleteClusters: function (clusterNames) {
  876. clusterNames.forEach(function (clusterName) {
  877. App.ajax.send({
  878. name: 'wizard.step8.delete_cluster',
  879. sender: this,
  880. data: {
  881. name: clusterName
  882. },
  883. success: 'deleteClustersSuccessCallback',
  884. error: 'deleteClustersErrorCallback'
  885. });
  886. });
  887. },
  888. deleteClustersSuccessCallback: function(data, opt) {
  889. console.log('DELETE cluster ' + opt.data.name + ' succeeded');
  890. },
  891. deleteClustersErrorCallback: function(request, ajaxOptions, error, opt) {
  892. console.log('DELETE cluster ' + opt.data.name + ' failed');
  893. },
  894. /**
  895. * The following create* functions are called upon submitting Step 8.
  896. */
  897. createCluster: function () {
  898. if (this.get('content.controllerName') !== 'installerController') {
  899. return false;
  900. }
  901. var clusterName = this.get('clusterName');
  902. var url = App.apiPrefix + '/clusters/' + clusterName;
  903. var stackVersion = (this.get('content.installOptions.localRepo')) ? App.defaultLocalStackVersion : App.defaultStackVersion;
  904. this.ajax({
  905. type: 'POST',
  906. url: url,
  907. data: JSON.stringify({ "Clusters": {"version": stackVersion }}),
  908. beforeSend: function () {
  909. console.log("BeforeSend: createCluster for " + clusterName);
  910. }
  911. });
  912. },
  913. createSelectedServices: function () {
  914. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services';
  915. var data = this.createServiceData();
  916. var httpMethod = 'POST';
  917. if (!data.length) {
  918. return;
  919. }
  920. this.ajax({
  921. type: httpMethod,
  922. url: url,
  923. data: JSON.stringify(data),
  924. beforeSend: function () {
  925. console.log('BeforeSend: createSelectedServices ', data);
  926. }
  927. });
  928. },
  929. createServiceData: function () {
  930. var services = this.get('selectedServices').mapProperty('serviceName');
  931. var data = [];
  932. services.forEach(function (_service) {
  933. data.pushObject({"ServiceInfo": { "service_name": _service }});
  934. }, this);
  935. return data;
  936. },
  937. createComponents: function () {
  938. var serviceComponents = require('data/service_components');
  939. var services = this.get('selectedServices').mapProperty('serviceName');
  940. services.forEach(function (_service) {
  941. var components = serviceComponents.filterProperty('service_name', _service);
  942. var componentsData = components.map(function (_component) {
  943. return { "ServiceComponentInfo": { "component_name": _component.component_name } };
  944. });
  945. // Service must be specified in terms of a query for creating multiple components at the same time.
  946. // See AMBARI-1018.
  947. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services?ServiceInfo/service_name=' + _service;
  948. var data = {
  949. "components": componentsData
  950. }
  951. this.ajax({
  952. type: 'POST',
  953. url: url,
  954. data: JSON.stringify(data),
  955. beforeSend: function () {
  956. console.log('BeforeSend: createComponents for ' + _service, componentsData);
  957. }
  958. });
  959. }, this);
  960. },
  961. registerHostsToCluster: function () {
  962. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts';
  963. var data = this.createRegisterHostData();
  964. if (data.length == 0) {
  965. return;
  966. }
  967. this.ajax({
  968. type: 'POST',
  969. url: url,
  970. data: JSON.stringify(data),
  971. beforeSend: function () {
  972. console.log('BeforeSend: registerHostsToCluster', data);
  973. }
  974. });
  975. },
  976. createRegisterHostData: function () {
  977. var hosts = this.getRegisteredHosts().filterProperty('isInstalled', false);
  978. if (!hosts.length) {
  979. return [];
  980. }
  981. return hosts.map(function (host) {
  982. return {"Hosts": { "host_name": host.hostName}};
  983. });
  984. },
  985. // TODO: review the code for add hosts / add services scenarios...
  986. createAllHostComponents: function () {
  987. var masterHosts = this.get('content.masterComponentHosts');
  988. var slaveHosts = this.get('content.slaveComponentHosts');
  989. var clients = this.get('content.clients');
  990. // note: masterHosts has 'component' vs slaveHosts has 'componentName'
  991. var masterComponents = masterHosts.mapProperty('component').uniq();
  992. masterComponents.forEach(function (component) {
  993. var hostNames = masterHosts.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  994. this.registerHostsToComponent(hostNames, component);
  995. }, this);
  996. slaveHosts.forEach(function (_slave) {
  997. if (_slave.componentName !== 'CLIENT') {
  998. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  999. this.registerHostsToComponent(hostNames, _slave.componentName);
  1000. } else {
  1001. clients.forEach(function (_client) {
  1002. var hostNames = _slave.hosts.mapProperty('hostName');
  1003. switch (_client.component_name) {
  1004. case 'HDFS_CLIENT':
  1005. // install HDFS_CLIENT on HBASE_MASTER, HBASE_REGIONSERVER, and WEBHCAT_SERVER hosts
  1006. masterHosts.filterProperty('component', 'HBASE_MASTER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1007. hostNames.pushObject(_masterHost.hostName);
  1008. }, this);
  1009. masterHosts.filterProperty('component', 'HBASE_REGIONSERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1010. hostNames.pushObject(_masterHost.hostName);
  1011. }, this);
  1012. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1013. hostNames.pushObject(_masterHost.hostName);
  1014. }, this);
  1015. break;
  1016. case 'MAPREDUCE_CLIENT':
  1017. // install MAPREDUCE_CLIENT on HIVE_SERVER, OOZIE_SERVER, NAGIOS_SERVER, and WEBHCAT_SERVER hosts
  1018. masterHosts.filterProperty('component', 'HIVE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1019. hostNames.pushObject(_masterHost.hostName);
  1020. }, this);
  1021. masterHosts.filterProperty('component', 'OOZIE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1022. hostNames.pushObject(_masterHost.hostName);
  1023. }, this);
  1024. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1025. hostNames.pushObject(_masterHost.hostName);
  1026. }, this);
  1027. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1028. hostNames.pushObject(_masterHost.hostName);
  1029. }, this);
  1030. break;
  1031. case 'OOZIE_CLIENT':
  1032. // install OOZIE_CLIENT on NAGIOS_SERVER host
  1033. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1034. hostNames.pushObject(_masterHost.hostName);
  1035. }, this);
  1036. break;
  1037. case 'ZOOKEEPER_CLIENT':
  1038. // install ZOOKEEPER_CLIENT on WEBHCAT_SERVER host
  1039. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1040. hostNames.pushObject(_masterHost.hostName);
  1041. }, this);
  1042. break;
  1043. case 'HIVE_CLIENT':
  1044. //install HIVE client on NAGIOS_SERVER host
  1045. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1046. hostNames.pushObject(_masterHost.hostName);
  1047. }, this);
  1048. masterHosts.filterProperty('component', 'HIVE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1049. hostNames.pushObject(_masterHost.hostName);
  1050. }, this);
  1051. break;
  1052. case 'HCAT':
  1053. // install HCAT (client) on NAGIOS_SERVER host
  1054. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1055. hostNames.pushObject(_masterHost.hostName);
  1056. }, this);
  1057. break;
  1058. }
  1059. hostNames = hostNames.uniq();
  1060. if (_client.isInstalled) {
  1061. //check whether clients are already installed on selected master hosts!!!
  1062. var installedHosts = _slave.hosts.filterProperty('isInstalled', true).mapProperty('hostName');
  1063. installedHosts.forEach(function (host) {
  1064. if (hostNames.contains(host)) {
  1065. hostNames.splice(hostNames.indexOf(host), 1);
  1066. }
  1067. }, this);
  1068. }
  1069. this.registerHostsToComponent(hostNames, _client.component_name);
  1070. }, this);
  1071. }
  1072. }, this);
  1073. // add Ganglia Monitor (Slave) to all hosts if Ganglia service is selected
  1074. var gangliaService = this.get('content.services').filterProperty('isSelected', true).findProperty('serviceName', 'GANGLIA');
  1075. if (gangliaService) {
  1076. var hosts = this.getRegisteredHosts();
  1077. if (gangliaService.get('isInstalled')) {
  1078. hosts = hosts.filterProperty('isInstalled', false);
  1079. }
  1080. if (hosts.length) {
  1081. this.registerHostsToComponent(hosts.mapProperty('hostName'), 'GANGLIA_MONITOR');
  1082. }
  1083. }
  1084. // add MySQL Server if Hive is selected
  1085. var hiveService = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).findProperty('serviceName', 'HIVE');
  1086. if (hiveService) {
  1087. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'MYSQL_SERVER');
  1088. }
  1089. },
  1090. registerHostsToComponent: function (hostNames, componentName) {
  1091. if (hostNames.length == 0) {
  1092. return;
  1093. }
  1094. console.log('registering ' + componentName + ' to ' + JSON.stringify(hostNames));
  1095. // currently we are specifying the predicate as a query string.
  1096. // this can hit a ~4000-character limit in Jetty server.
  1097. // chunk to multiple calls if needed
  1098. // var hostsPredicate = hostNames.map(function (hostName) {
  1099. // return 'Hosts/host_name=' + hostName;
  1100. // }).join('|');
  1101. var queryStrArr = [];
  1102. var queryStr = '';
  1103. hostNames.forEach(function (hostName) {
  1104. queryStr += 'Hosts/host_name=' + hostName + '|';
  1105. if (queryStr.length > 3500) {
  1106. queryStrArr.push(queryStr.slice(0, -1));
  1107. queryStr = '';
  1108. }
  1109. });
  1110. if (queryStr.length > 0) {
  1111. queryStrArr.push(queryStr.slice(0, -1));
  1112. }
  1113. queryStrArr.forEach(function (queryStr) {
  1114. // console.log('creating host components for ' + queryStr);
  1115. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts?' + queryStr;
  1116. var data = {
  1117. "host_components": [
  1118. {
  1119. "HostRoles": {
  1120. "component_name": componentName
  1121. }
  1122. }
  1123. ]
  1124. };
  1125. this.ajax({
  1126. type: 'POST',
  1127. url: url,
  1128. data: JSON.stringify(data),
  1129. beforeSend: function () {
  1130. console.log('BeforeSend: registerHostsToComponent for ' + queryStr + ' and component ' + componentName);
  1131. }
  1132. });
  1133. }, this);
  1134. },
  1135. createConfigurations: function () {
  1136. var selectedServices = this.get('selectedServices');
  1137. if (this.get('content.controllerName') == 'installerController') {
  1138. this.applyConfigurationToSite(this.createGlobalSiteObj());
  1139. this.applyConfigurationToSite(this.createCoreSiteObj());
  1140. this.applyConfigurationToSite(this.createHdfsSiteObj());
  1141. }
  1142. if (selectedServices.someProperty('serviceName', 'MAPREDUCE')) {
  1143. this.applyConfigurationToSite(this.createMrSiteObj());
  1144. if (App.supports.capacitySchedulerUi) {
  1145. this.applyConfigurationToSite(this.createCapacityScheduler());
  1146. this.applyConfigurationToSite(this.createMapredQueueAcls());
  1147. }
  1148. }
  1149. if (selectedServices.someProperty('serviceName', 'HBASE')) {
  1150. this.applyConfigurationToSite(this.createHbaseSiteObj());
  1151. }
  1152. if (selectedServices.someProperty('serviceName', 'OOZIE')) {
  1153. this.applyConfigurationToSite(this.createOozieSiteObj('OOZIE'));
  1154. }
  1155. if (selectedServices.someProperty('serviceName', 'HIVE')) {
  1156. this.applyConfigurationToSite(this.createHiveSiteObj('HIVE'));
  1157. }
  1158. if (selectedServices.someProperty('serviceName', 'WEBHCAT')) {
  1159. this.applyConfigurationToSite(this.createWebHCatSiteObj('WEBHCAT'));
  1160. }
  1161. if (selectedServices.someProperty('serviceName', 'HUE')) {
  1162. this.applyConfigurationToSite(this.createHueSiteObj('HUE'));
  1163. }
  1164. },
  1165. applyConfigurationToSite: function (data) {
  1166. console.log("Inside applyConfigurationToSite");
  1167. var clusterUrl = App.apiPrefix + '/clusters/' + this.get('clusterName');
  1168. var clusterData = {
  1169. Clusters: {
  1170. desired_configs: data
  1171. }
  1172. };
  1173. console.debug("applyConfigurationToSite(Step8): Applying to URL", clusterUrl, " Data:", clusterData);
  1174. this.ajax({
  1175. type: 'PUT',
  1176. url: clusterUrl,
  1177. data: JSON.stringify(clusterData),
  1178. beforeSend: function () {
  1179. console.log("BeforeSend: Updating cluster config for " + clusterData.type);
  1180. }
  1181. });
  1182. },
  1183. createGlobalSiteObj: function () {
  1184. var globalSiteProperties = {};
  1185. //this.get('globals').filterProperty('domain', 'global').forEach(function (_globalSiteObj) {
  1186. this.get('globals').forEach(function (_globalSiteObj) {
  1187. // do not pass any globals whose name ends with _host or _hosts
  1188. if (!/_hosts?$/.test(_globalSiteObj.name)) {
  1189. // append "m" to JVM memory options except for hadoop_heapsize
  1190. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name) && _globalSiteObj.name !== 'hadoop_heapsize') {
  1191. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value + "m";
  1192. } else {
  1193. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value;
  1194. }
  1195. console.log("STEP8: name of the global property is: " + _globalSiteObj.name);
  1196. console.log("STEP8: value of the global property is: " + _globalSiteObj.value);
  1197. }
  1198. if (_globalSiteObj.name == 'java64_home') {
  1199. globalSiteProperties['java64_home'] = this.get('content.installOptions.javaHome');
  1200. }
  1201. this._recordHostOverrideFromObj(_globalSiteObj, 'global', 'version1', this);
  1202. }, this);
  1203. return {"type": "global", "tag": "version1", "properties": globalSiteProperties};
  1204. },
  1205. createCoreSiteObj: function () {
  1206. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  1207. var coreSiteProperties = {};
  1208. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  1209. var isOozieSelected = this.get('selectedServices').someProperty('serviceName', 'OOZIE');
  1210. var oozieUser = this.get('globals').someProperty('name', 'oozie_user') ? this.get('globals').findProperty('name', 'oozie_user').value : null;
  1211. var isHiveSelected = this.get('selectedServices').someProperty('serviceName', 'HIVE');
  1212. var hiveUser = this.get('globals').someProperty('name', 'hive_user') ? this.get('globals').findProperty('name', 'hive_user').value : null;
  1213. var isHcatSelected = this.get('selectedServices').someProperty('serviceName', 'WEBHCAT');
  1214. var hcatUser = this.get('globals').someProperty('name', 'hcat_user') ? this.get('globals').findProperty('name', 'hcat_user').value : null;
  1215. coreSiteObj.forEach(function (_coreSiteObj) {
  1216. 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'))) {
  1217. coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
  1218. this._recordHostOverrideFromObj(_coreSiteObj, 'core-site', 'version1', this);
  1219. }
  1220. console.log("STEP*: name of the property is: " + _coreSiteObj.name);
  1221. console.log("STEP8: value of the property is: " + _coreSiteObj.value);
  1222. }, this);
  1223. return {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  1224. },
  1225. createHdfsSiteObj: function () {
  1226. var hdfsSiteObj = this.get('configs').filterProperty('filename', 'hdfs-site.xml');
  1227. var hdfsProperties = {};
  1228. hdfsSiteObj.forEach(function (_configProperty) {
  1229. hdfsProperties[_configProperty.name] = _configProperty.value;
  1230. this._recordHostOverrideFromObj(_configProperty, 'hdfs-site', 'version1', this);
  1231. console.log("STEP*: name of the property is: " + _configProperty.name);
  1232. console.log("STEP8: value of the property is: " + _configProperty.value);
  1233. }, this);
  1234. return {"type": "hdfs-site", "tag": "version1", "properties": hdfsProperties };
  1235. },
  1236. createHueSiteObj: function () {
  1237. var hueSiteObj = this.get('configs').filterProperty('filename', 'hue-site.xml');
  1238. var hueProperties = {};
  1239. hueSiteObj.forEach(function (_configProperty) {
  1240. hueProperties[_configProperty.name] = _configProperty.value;
  1241. this._recordHostOverrideFromObj(_configProperty, 'hue-site', 'version1', this);
  1242. console.log("STEP*: name of the property is: " + _configProperty.name);
  1243. console.log("STEP8: value of the property is: " + _configProperty.value);
  1244. }, this);
  1245. return {"type": "hue-site", "tag": "version1", "properties": hueProperties };
  1246. },
  1247. createMrSiteObj: function () {
  1248. var configs = this.get('configs').filterProperty('filename', 'mapred-site.xml');
  1249. var mrProperties = {};
  1250. configs.forEach(function (_configProperty) {
  1251. mrProperties[_configProperty.name] = _configProperty.value;
  1252. this._recordHostOverrideFromObj(_configProperty, 'mapred-site', 'version1', this);
  1253. console.log("STEP*: name of the property is: " + _configProperty.name);
  1254. console.log("STEP8: value of the property is: " + _configProperty.value);
  1255. }, this);
  1256. return {type: 'mapred-site', tag: 'version1', properties: mrProperties};
  1257. },
  1258. createCapacityScheduler: function () {
  1259. var configs = this.get('configs').filterProperty('filename', 'capacity-scheduler.xml');
  1260. var csProperties = {};
  1261. configs.forEach(function (_configProperty) {
  1262. csProperties[_configProperty.name] = _configProperty.value;
  1263. this._recordHostOverrideFromObj(_configProperty, 'capacity-scheduler', 'version1', this);
  1264. console.log("STEP*: name of the property is: " + _configProperty.name);
  1265. console.log("STEP8: value of the property is: " + _configProperty.value);
  1266. }, this);
  1267. return {type: 'capacity-scheduler', tag: 'version1', properties: csProperties};
  1268. },
  1269. createMapredQueueAcls: function () {
  1270. var configs = this.get('configs').filterProperty('filename', 'mapred-queue-acls.xml');
  1271. var mqProperties = {};
  1272. configs.forEach(function (_configProperty) {
  1273. mqProperties[_configProperty.name] = _configProperty.value;
  1274. this._recordHostOverrideFromObj(_configProperty, 'mapred-queue-acls', 'version1', this);
  1275. console.log("STEP*: name of the property is: " + _configProperty.name);
  1276. console.log("STEP8: value of the property is: " + _configProperty.value);
  1277. }, this);
  1278. return {type: 'mapred-queue-acls', tag: 'version1', properties: mqProperties};
  1279. },
  1280. createHbaseSiteObj: function () {
  1281. var configs = this.get('configs').filterProperty('filename', 'hbase-site.xml');
  1282. var hbaseProperties = {};
  1283. configs.forEach(function (_configProperty) {
  1284. hbaseProperties[_configProperty.name] = _configProperty.value;
  1285. this._recordHostOverrideFromObj(_configProperty, 'hbase-site', 'version1', this);
  1286. }, this);
  1287. return {type: 'hbase-site', tag: 'version1', properties: hbaseProperties};
  1288. },
  1289. createOozieSiteObj: function (serviceName) {
  1290. var configs = this.get('configs').filterProperty('filename', 'oozie-site.xml');
  1291. var oozieProperties = {};
  1292. configs.forEach(function (_configProperty) {
  1293. oozieProperties[_configProperty.name] = _configProperty.value;
  1294. this._recordHostOverrideFromObj(_configProperty, 'oozie-site', 'version1', this);
  1295. }, this);
  1296. return {type: 'oozie-site', tag: 'version1', properties: oozieProperties};
  1297. },
  1298. createHiveSiteObj: function (serviceName) {
  1299. var configs = this.get('configs').filterProperty('filename', 'hive-site.xml');
  1300. var hiveProperties = {};
  1301. configs.forEach(function (_configProperty) {
  1302. hiveProperties[_configProperty.name] = _configProperty.value;
  1303. this._recordHostOverrideFromObj(_configProperty, 'hive-site', 'version1', this);
  1304. }, this);
  1305. return {type: 'hive-site', tag: 'version1', properties: hiveProperties};
  1306. },
  1307. createWebHCatSiteObj: function (serviceName) {
  1308. var configs = this.get('configs').filterProperty('filename', 'webhcat-site.xml');
  1309. var webHCatProperties = {};
  1310. configs.forEach(function (_configProperty) {
  1311. webHCatProperties[_configProperty.name] = _configProperty.value;
  1312. this._recordHostOverrideFromObj(_configProperty, 'webhcat-site', 'version1', this);
  1313. }, this);
  1314. return {type: 'webhcat-site', tag: 'version1', properties: webHCatProperties};
  1315. },
  1316. getConfigForService: function (serviceName) {
  1317. switch (serviceName) {
  1318. case 'HDFS':
  1319. return {config: {'global': 'version1', 'core-site': 'version1', 'hdfs-site': 'version1'}};
  1320. case 'MAPREDUCE':
  1321. return {config: {'global': 'version1', 'core-site': 'version1', 'mapred-site': 'version1', 'capacity-scheduler': 'version1', 'mapred-queue-acls': 'version1'}};
  1322. case 'HBASE':
  1323. return {config: {'global': 'version1', 'hbase-site': 'version1'}};
  1324. case 'OOZIE':
  1325. return {config: {'global': 'version1', 'oozie-site': 'version1'}};
  1326. case 'HIVE':
  1327. return {config: {'global': 'version1', 'hive-site': 'version1'}};
  1328. case 'WEBHCAT':
  1329. return {config: {'global': 'version1', 'webhcat-site': 'version1'}};
  1330. case 'HUE':
  1331. return {config: {'global': 'version1', 'hue-site': 'version1'}};
  1332. default:
  1333. return {config: {'global': 'version1'}};
  1334. }
  1335. },
  1336. ajaxQueueFinished: function () {
  1337. //do something
  1338. },
  1339. doNextAjaxCall: function () {
  1340. if (this.get('ajaxBusy')) {
  1341. return;
  1342. }
  1343. var queue = this.get('ajaxQueue');
  1344. if (!queue.length) {
  1345. this.ajaxQueueFinished();
  1346. return;
  1347. }
  1348. var first = queue[0];
  1349. this.set('ajaxQueue', queue.slice(1));
  1350. this.set('ajaxQueueLeft', this.get('ajaxQueue').length);
  1351. this.set('ajaxBusy', true);
  1352. console.log('AJAX send ' + first.url);
  1353. $.ajax(first);
  1354. },
  1355. /**
  1356. * Records all the host overrides per site/tag
  1357. */
  1358. _recordHostOverrideFromObj: function(serviceConfigObj, siteName, tagName, self){
  1359. var overrides = serviceConfigObj.overrides;
  1360. if(overrides && overrides.length>0){
  1361. overrides.forEach(function(override){
  1362. override.hosts.forEach(function(host){
  1363. if(!(host in self.savedHostToOverrideSiteToTagMap)){
  1364. self.savedHostToOverrideSiteToTagMap[host] = {};
  1365. }
  1366. if(!(siteName in self.savedHostToOverrideSiteToTagMap[host])){
  1367. self.savedHostToOverrideSiteToTagMap[host][siteName] = {};
  1368. self.savedHostToOverrideSiteToTagMap[host][siteName].map = {};
  1369. }
  1370. var finalTag = tagName + '_' + host;
  1371. console.log("recordHostOverride(): Saving host override for host="+host+", site="+siteName+", tag="+finalTag+", (key,value)=("+serviceConfigObj.name+","+override.value+")");
  1372. self.savedHostToOverrideSiteToTagMap[host][siteName].tagName = finalTag;
  1373. self.savedHostToOverrideSiteToTagMap[host][siteName].map[serviceConfigObj.name] = override.value;
  1374. });
  1375. });
  1376. }
  1377. },
  1378. /**
  1379. * Creates host level overrides for service configuration.
  1380. *
  1381. */
  1382. createHostOverrideConfigurations: function () {
  1383. var singlePUTHostData = [];
  1384. var savedHostSiteArray = [];
  1385. for ( var host in this.savedHostToOverrideSiteToTagMap) {
  1386. for ( var siteName in this.savedHostToOverrideSiteToTagMap[host]) {
  1387. var tagName = this.savedHostToOverrideSiteToTagMap[host][siteName].tagName;
  1388. var map = this.savedHostToOverrideSiteToTagMap[host][siteName].map;
  1389. savedHostSiteArray.push(host + "///" + siteName);
  1390. singlePUTHostData.push({
  1391. RequestInfo: {
  1392. query: 'Hosts/host_name='+host
  1393. },
  1394. Body: {
  1395. Hosts: {
  1396. desired_config: {
  1397. type: siteName,
  1398. tag: tagName,
  1399. properties: map
  1400. }
  1401. }
  1402. }
  1403. });
  1404. }
  1405. }
  1406. console.log("createHostOverrideConfigSites(): PUTting host-overrides. Data=", singlePUTHostData);
  1407. if(singlePUTHostData.length>0){
  1408. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts';
  1409. this.ajax({
  1410. type: 'PUT',
  1411. url: url,
  1412. data: JSON.stringify(singlePUTHostData),
  1413. dataType: 'text',
  1414. beforeSend: function () {
  1415. console.log("createHostOverrideConfigSites() PUT override=", singlePUTHostData);
  1416. }
  1417. });
  1418. }
  1419. },
  1420. /**
  1421. * We need to do a lot of ajax calls async in special order. To do this,
  1422. * generate array of ajax objects and then send requests step by step. All
  1423. * ajax objects are stored in <code>ajaxQueue</code>
  1424. *
  1425. * @param params
  1426. */
  1427. ajax: function (params) {
  1428. if (App.testMode) return;
  1429. var self = this;
  1430. params = jQuery.extend({
  1431. async: true,
  1432. dataType: 'text',
  1433. statusCode: require('data/statusCodes'),
  1434. timeout: App.timeout,
  1435. error: function (request, ajaxOptions, error) {
  1436. console.log('Step8: In Error ');
  1437. // console.log('Step8: Error message is: ' + request.responseText);
  1438. },
  1439. success: function (data) {
  1440. var jsonData = jQuery.parseJSON(data);
  1441. console.log("TRACE: STep8 -> In success function");
  1442. console.log("TRACE: STep8 -> value of the url is: " + params.url);
  1443. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  1444. }
  1445. }, params);
  1446. var success = params.success;
  1447. var error = params.error;
  1448. params.success = function () {
  1449. if (success) {
  1450. success();
  1451. }
  1452. self.set('ajaxBusy', false);
  1453. self.doNextAjaxCall();
  1454. }
  1455. params.error = function (xhr, status, error) {
  1456. var responseText = JSON.parse(xhr.responseText);
  1457. var controller = App.router.get(App.clusterStatus.wizardControllerName);
  1458. controller.registerErrPopup(Em.I18n.t('common.error'), responseText.message);
  1459. self.set('hasErrorOccurred', true);
  1460. // an error will break the ajax call chain and allow submission again
  1461. self.set('isSubmitDisabled', false);
  1462. self.get('ajaxQueue').clear();
  1463. self.set('ajaxBusy', false);
  1464. }
  1465. this.get('ajaxQueue').pushObject(params);
  1466. }
  1467. });