step8_controller.js 61 KB

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