add_controller.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  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.AddHostController = App.WizardController.extend({
  20. name: 'addHostController',
  21. totalSteps: 7,
  22. /**
  23. * Used for hiding back button in wizard
  24. */
  25. hideBackButton: true,
  26. /**
  27. * All wizards data will be stored in this variable
  28. *
  29. * cluster - cluster name
  30. * hosts - hosts, ssh key, repo info, etc.
  31. * services - services list
  32. * hostsInfo - list of selected hosts
  33. * slaveComponentHosts, hostSlaveComponents - info about slave hosts
  34. * masterComponentHosts - info about master hosts
  35. * config??? - to be described later
  36. */
  37. content: Em.Object.create({
  38. cluster: null,
  39. hosts: null,
  40. services: null,
  41. hostsInfo: null,
  42. slaveComponentHosts: null,
  43. masterComponentHosts: null,
  44. serviceConfigProperties: null,
  45. advancedServiceConfig: null,
  46. controllerName: 'addHostController',
  47. isWizard: true
  48. }),
  49. getCluster: function(){
  50. return jQuery.extend(this.get('clusterStatusTemplate'), {
  51. name: App.router.getClusterName()
  52. });
  53. },
  54. showMoreHosts: function () {
  55. var self = this;
  56. App.ModalPopup.show({
  57. header: "Hosts are already part of the cluster and will be ignored",
  58. body: self.get('content.hosts.oldHostNamesMore'),
  59. encodeBody: false,
  60. onPrimary: function () {
  61. this.hide();
  62. },
  63. secondary: null
  64. });
  65. },
  66. /**
  67. * Config for displaying more hosts
  68. * if oldHosts.length more than config.count that configuration will be applied
  69. */
  70. hostDisplayConfig: [
  71. {
  72. count: 0,
  73. delimitery: '<br/>',
  74. popupDelimitery: '<br />'
  75. },
  76. {
  77. count: 10,
  78. delimitery: ', ',
  79. popupDelimitery: '<br />'
  80. },
  81. {
  82. count: 50,
  83. delimitery: ', ',
  84. popupDelimitery: ', '
  85. }
  86. ],
  87. /**
  88. * Load all data for <code>Specify Host(install step2)</code> step
  89. * Data Example:
  90. * {
  91. * hostNames: '',
  92. * manualInstall: false,
  93. * sshKey: '',
  94. * passphrase: '',
  95. * confirmPassphrase: '',
  96. * localRepo: false,
  97. * localRepoPath: ''
  98. * }
  99. */
  100. loadInstallOptions: function () {
  101. if (!this.content.hosts) {
  102. this.content.hosts = Em.Object.create();
  103. }
  104. var hostsInfo = Em.Object.create();
  105. var oldHostNames = App.Host.find().getEach('id');
  106. var k = 10;
  107. var usedConfig = false;
  108. this.get('hostDisplayConfig').forEach(function (config) {
  109. if (oldHostNames.length > config.count) {
  110. usedConfig = config;
  111. }
  112. });
  113. k = usedConfig.count ? usedConfig.count : oldHostNames.length;
  114. var displayedHostNames = oldHostNames.slice(0, k);
  115. hostsInfo.oldHostNames = displayedHostNames.join(usedConfig.delimitery);
  116. if (usedConfig.count) {
  117. var moreHostNames = oldHostNames.slice(k + 1);
  118. hostsInfo.oldHostNamesMore = moreHostNames.join(usedConfig.popupDelimitery);
  119. hostsInfo.showMoreHostsText = "...and %@ more".fmt(moreHostNames.length);
  120. }
  121. hostsInfo.hostNames = App.db.getAllHostNamesPattern() || ''; //empty string if undefined
  122. var installType = App.db.getInstallType();
  123. //false if installType not equals 'manual'
  124. hostsInfo.manualInstall = installType && installType.installType === 'manual' || false;
  125. var softRepo = App.db.getSoftRepo();
  126. if (softRepo && softRepo.repoType === 'local') {
  127. hostsInfo.localRepo = true;
  128. hostsInfo.localRepopath = softRepo.repoPath;
  129. } else {
  130. hostsInfo.localRepo = false;
  131. hostsInfo.localRepoPath = '';
  132. }
  133. hostsInfo.bootRequestId = App.db.getBootRequestId() || null;
  134. hostsInfo.sshKey = '';
  135. hostsInfo.passphrase = '';
  136. hostsInfo.confirmPassphrase = '';
  137. this.set('content.hosts', hostsInfo);
  138. console.log("AddHostController:loadHosts: loaded data ", hostsInfo);
  139. },
  140. /**
  141. * Save data, which user filled, to main controller
  142. * @param stepController App.WizardStep2Controller
  143. */
  144. saveHosts: function (stepController) {
  145. //TODO: put data to content.hosts and only then save it)
  146. //App.db.setBootStatus(false);
  147. App.db.setAllHostNames(stepController.get('hostNameArr').join("\n"));
  148. App.db.setAllHostNamesPattern(stepController.get('hostNames'));
  149. App.db.setBootRequestId(stepController.get('bootRequestId'));
  150. App.db.setHosts(stepController.getHostInfo());
  151. if (stepController.get('manualInstall') === false) {
  152. App.db.setInstallType({installType: 'ambari' });
  153. } else {
  154. App.db.setInstallType({installType: 'manual' });
  155. }
  156. if (stepController.get('localRepo') === false) {
  157. App.db.setSoftRepo({ 'repoType': 'remote', 'repoPath': null});
  158. } else {
  159. App.db.setSoftRepo({ 'repoType': 'local', 'repoPath': stepController.get('localRepoPath') });
  160. }
  161. },
  162. /**
  163. * Remove host from model. Used at <code>Confirm hosts(step2)</code> step
  164. * @param hosts Array of hosts, which we want to delete
  165. */
  166. removeHosts: function (hosts) {
  167. //todo Replace this code with real logic
  168. App.db.removeHosts(hosts);
  169. },
  170. /**
  171. * Save data, which user filled, to main controller
  172. * @param stepController App.WizardStep3Controller
  173. */
  174. saveConfirmedHosts: function (stepController) {
  175. var hostInfo = {};
  176. stepController.get('content.hostsInfo').forEach(function (_host) {
  177. hostInfo[_host.name] = {
  178. name: _host.name,
  179. cpu: _host.cpu,
  180. memory: _host.memory,
  181. bootStatus: _host.bootStatus,
  182. isInstalled: false
  183. };
  184. });
  185. console.log('addHostController:saveConfirmedHosts: save hosts ', hostInfo);
  186. App.db.setHosts(hostInfo);
  187. this.set('content.hostsInfo', hostInfo);
  188. },
  189. /**
  190. * Load confirmed hosts.
  191. * Will be used at <code>Assign Masters(step5)</code> step
  192. */
  193. loadConfirmedHosts: function () {
  194. this.set('content.hostsInfo', App.db.getHosts());
  195. },
  196. /**
  197. * Save data after installation to main controller
  198. * @param stepController App.WizardStep9Controller
  199. */
  200. saveInstalledHosts: function (stepController) {
  201. var hosts = stepController.get('hosts');
  202. var hostInfo = App.db.getHosts();
  203. for (var index in hostInfo) {
  204. var host = hosts.findProperty('name', hostInfo[index].name);
  205. if (host) {
  206. hostInfo[index].status = host.status;
  207. //tasks should be empty because they loads from the server
  208. //hostInfo[index].tasks = host.tasks;
  209. hostInfo[index].message = host.message;
  210. hostInfo[index].progress = host.progress;
  211. }
  212. }
  213. App.db.setHosts(hostInfo);
  214. this.set('content.hostsInfo', hostInfo);
  215. console.log('addHostController:saveInstalledHosts: save hosts ', hostInfo);
  216. },
  217. /**
  218. * Load services data. Will be used at <code>Select services(step4)</code> step
  219. */
  220. loadServices: function () {
  221. var servicesInfo = App.db.getService();
  222. if (!servicesInfo || !servicesInfo.length) {
  223. servicesInfo = require('data/services').slice(0);
  224. servicesInfo.forEach(function (item) {
  225. item.isSelected = App.Service.find().someProperty('id', item.serviceName)
  226. item.isInstalled = item.isSelected;
  227. item.isDisabled = item.isSelected;
  228. });
  229. App.db.setService(servicesInfo);
  230. }
  231. servicesInfo.forEach(function (item, index) {
  232. servicesInfo[index] = Em.Object.create(item);
  233. });
  234. this.set('content.services', servicesInfo);
  235. console.log('AddHostController.loadServices: loaded data ', servicesInfo);
  236. console.log('selected services ', servicesInfo.filterProperty('isSelected', true).filterProperty('isDisabled', false).mapProperty('serviceName'));
  237. },
  238. /**
  239. * Load master component hosts data for using in required step controllers
  240. */
  241. loadMasterComponentHosts: function () {
  242. var masterComponentHosts = App.db.getMasterComponentHosts();
  243. if (!masterComponentHosts) {
  244. masterComponentHosts = [];
  245. App.Component.find().filterProperty('isMaster', true).forEach(function (item) {
  246. masterComponentHosts.push({
  247. component: item.get('componentName'),
  248. hostName: item.get('host.hostName'),
  249. isInstalled: true,
  250. serviceId: item.get('service.id'),
  251. display_name: item.get('displayName')
  252. })
  253. });
  254. App.db.setMasterComponentHosts(masterComponentHosts);
  255. }
  256. this.set("content.masterComponentHosts", masterComponentHosts);
  257. console.log("AddHostController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  258. },
  259. /**
  260. * Save slaveHostComponents to main controller
  261. * @param stepController
  262. */
  263. saveSlaveComponentHosts: function (stepController) {
  264. var hosts = stepController.get('hosts');
  265. var isMrSelected = stepController.get('isMrSelected');
  266. var isHbSelected = stepController.get('isHbSelected');
  267. var dataNodeHosts = [];
  268. var taskTrackerHosts = [];
  269. var regionServerHosts = [];
  270. var clientHosts = [];
  271. hosts.forEach(function (host) {
  272. if (host.get('isDataNode')) {
  273. dataNodeHosts.push({
  274. hostName: host.hostName,
  275. group: 'Default',
  276. isInstalled: host.get('isDataNodeInstalled')
  277. });
  278. }
  279. if (isMrSelected && host.get('isTaskTracker')) {
  280. taskTrackerHosts.push({
  281. hostName: host.hostName,
  282. group: 'Default',
  283. isInstalled: host.get('isTaskTrackerInstalled')
  284. });
  285. }
  286. if (isHbSelected && host.get('isRegionServer')) {
  287. regionServerHosts.push({
  288. hostName: host.hostName,
  289. group: 'Default',
  290. isInstalled: host.get('isRegionServerInstalled')
  291. });
  292. }
  293. if (host.get('isClient')) {
  294. clientHosts.pushObject({
  295. hostName: host.hostName,
  296. group: 'Default',
  297. isInstalled: host.get('isClientInstalled')
  298. });
  299. }
  300. }, this);
  301. var slaveComponentHosts = [];
  302. slaveComponentHosts.push({
  303. componentName: 'DATANODE',
  304. displayName: 'DataNode',
  305. hosts: dataNodeHosts
  306. });
  307. if (isMrSelected) {
  308. slaveComponentHosts.push({
  309. componentName: 'TASKTRACKER',
  310. displayName: 'TaskTracker',
  311. hosts: taskTrackerHosts
  312. });
  313. }
  314. if (isHbSelected) {
  315. slaveComponentHosts.push({
  316. componentName: 'HBASE_REGIONSERVER',
  317. displayName: 'RegionServer',
  318. hosts: regionServerHosts
  319. });
  320. }
  321. slaveComponentHosts.pushObject({
  322. componentName: 'CLIENT',
  323. displayName: 'client',
  324. hosts: clientHosts
  325. });
  326. App.db.setSlaveComponentHosts(slaveComponentHosts);
  327. console.log('addHostController.slaveComponentHosts: saved hosts', slaveComponentHosts);
  328. this.set('content.slaveComponentHosts', slaveComponentHosts);
  329. },
  330. /**
  331. * return slaveComponents bound to hosts
  332. * @return {Array}
  333. */
  334. getSlaveComponentHosts: function () {
  335. var components = [
  336. {
  337. name: 'DATANODE',
  338. service: 'HDFS'
  339. },
  340. {
  341. name: 'TASKTRACKER',
  342. service: 'MAPREDUCE'
  343. },
  344. {
  345. name: 'HBASE_REGIONSERVER',
  346. service: 'HBASE'
  347. }
  348. ];
  349. var result = [];
  350. var services = App.Service.find();
  351. var selectedServices = this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  352. for (var index = 0; index < components.length; index++) {
  353. var comp = components[index];
  354. if (!selectedServices.contains(comp.service)) {
  355. continue;
  356. }
  357. var service = services.findProperty('id', comp.service);
  358. var hosts = [];
  359. service.get('hostComponents').filterProperty('componentName', comp.name).forEach(function (host_component) {
  360. hosts.push({
  361. group: "Default",
  362. hostName: host_component.get('host.id'),
  363. isInstalled: true
  364. });
  365. }, this);
  366. result.push({
  367. componentName: comp.name,
  368. displayName: App.format.role(comp.name),
  369. hosts: hosts,
  370. isInstalled: true
  371. })
  372. }
  373. var clientsHosts = App.HostComponent.find().filterProperty('componentName', 'HDFS_CLIENT');
  374. var hosts = [];
  375. clientsHosts.forEach(function (host_component) {
  376. hosts.push({
  377. group: "Default",
  378. hostName: host_component.get('host.id'),
  379. isInstalled: true
  380. });
  381. }, this);
  382. result.push({
  383. componentName: 'CLIENT',
  384. displayName: 'client',
  385. hosts: hosts,
  386. isInstalled: true
  387. })
  388. return result;
  389. },
  390. /**
  391. * Load master component hosts data for using in required step controllers
  392. */
  393. loadSlaveComponentHosts: function () {
  394. var slaveComponentHosts = App.db.getSlaveComponentHosts();
  395. if (!slaveComponentHosts) {
  396. slaveComponentHosts = this.getSlaveComponentHosts();
  397. }
  398. this.set("content.slaveComponentHosts", slaveComponentHosts);
  399. console.log("AddHostController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  400. },
  401. /**
  402. * Save config properties
  403. * @param stepController Step7WizardController
  404. */
  405. saveServiceConfigProperties: function (stepController) {
  406. var serviceConfigProperties = [];
  407. stepController.get('stepConfigs').forEach(function (_content) {
  408. _content.get('configs').forEach(function (_configProperties) {
  409. var configProperty = {
  410. name: _configProperties.get('name'),
  411. value: _configProperties.get('value'),
  412. service: _configProperties.get('serviceName')
  413. };
  414. serviceConfigProperties.push(configProperty);
  415. }, this);
  416. }, this);
  417. App.db.setServiceConfigProperties(serviceConfigProperties);
  418. this.set('content.serviceConfigProperties', serviceConfigProperties);
  419. },
  420. /**
  421. * Load serviceConfigProperties to model
  422. */
  423. loadServiceConfigProperties: function () {
  424. var serviceConfigProperties = App.db.getServiceConfigProperties();
  425. this.set('content.serviceConfigProperties', serviceConfigProperties);
  426. console.log("AddHostController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  427. },
  428. /**
  429. * Load information about hosts with clients components
  430. */
  431. loadClients: function () {
  432. var clients = App.db.getClientsForSelectedServices();
  433. this.set('content.clients', clients);
  434. console.log("AddHostController.loadClients: loaded list ", clients);
  435. },
  436. dataLoading: function () {
  437. var dfd = $.Deferred();
  438. this.connectOutlet('loading');
  439. var interval = setInterval(function () {
  440. if (App.router.get('clusterController.isLoaded')) {
  441. dfd.resolve();
  442. clearInterval(interval);
  443. }
  444. }, 50);
  445. return dfd.promise();
  446. },
  447. /**
  448. * Generate clients list for selected services and save it to model
  449. * @param stepController step4WizardController
  450. */
  451. saveClients: function () {
  452. var clients = [];
  453. var serviceComponents = require('data/service_components');
  454. var hostComponents = App.HostComponent.find();
  455. this.get('content.services').filterProperty('isSelected', true).forEach(function (_service) {
  456. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  457. if (client) {
  458. clients.pushObject({
  459. component_name: client.component_name,
  460. display_name: client.display_name,
  461. isInstalled: hostComponents.filterProperty('componentName', client.component_name).length > 0
  462. });
  463. }
  464. }, this);
  465. App.db.setClientsForSelectedServices(clients);
  466. this.set('content.clients', clients);
  467. console.log("AddHostController.saveClients: saved list ", clients);
  468. },
  469. /**
  470. * Load data for all steps until <code>current step</code>
  471. */
  472. loadAllPriorSteps: function () {
  473. var step = this.get('currentStep');
  474. switch (step) {
  475. case '8':
  476. case '7':
  477. case '6':
  478. case '5':
  479. case '4':
  480. this.loadServiceConfigProperties();
  481. case '3':
  482. this.loadClients();
  483. this.loadServices();
  484. this.loadMasterComponentHosts();
  485. this.loadSlaveComponentHosts();
  486. this.loadConfirmedHosts();
  487. case '2':
  488. this.loadServices();
  489. this.loadConfirmedHosts();
  490. case '1':
  491. this.loadInstallOptions();
  492. case '0':
  493. this.load('cluster');
  494. }
  495. },
  496. loadAdvancedConfigs: function () {
  497. this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName').forEach(function (_serviceName) {
  498. this.loadAdvancedConfig(_serviceName);
  499. }, this);
  500. },
  501. /**
  502. * Generate serviceProperties save it to localdata
  503. * called form stepController step6WizardController
  504. */
  505. loadAdvancedConfig: function (serviceName) {
  506. var self = this;
  507. var url = (App.testMode) ? '/data/wizard/stack/hdp/version01/' + serviceName + '.json' : App.apiPrefix + '/stacks/HDP/version/1.2.0/services/' + serviceName; // TODO: get this url from the stack selected by the user in Install Options page
  508. var method = 'GET';
  509. $.ajax({
  510. type: method,
  511. url: url,
  512. async: false,
  513. dataType: 'text',
  514. timeout: App.timeout,
  515. success: function (data) {
  516. var jsonData = jQuery.parseJSON(data);
  517. console.log("TRACE: Step6 submit -> In success function for the loadAdvancedConfig call");
  518. console.log("TRACE: Step6 submit -> value of the url is: " + url);
  519. var serviceComponents = jsonData.properties;
  520. serviceComponents.setEach('serviceName', serviceName);
  521. var configs;
  522. if (App.db.getAdvancedServiceConfig()) {
  523. configs = App.db.getAdvancedServiceConfig();
  524. } else {
  525. configs = [];
  526. }
  527. configs = configs.concat(serviceComponents);
  528. self.set('content.advancedServiceConfig', configs);
  529. App.db.setAdvancedServiceConfig(configs);
  530. console.log('TRACE: servicename: ' + serviceName);
  531. },
  532. error: function (request, ajaxOptions, error) {
  533. console.log("TRACE: STep6 submit -> In error function for the loadAdvancedConfig call");
  534. console.log("TRACE: STep6 submit-> value of the url is: " + url);
  535. console.log("TRACE: STep6 submit-> error code status is: " + request.status);
  536. console.log('Step6 submit: Error message is: ' + request.responseText);
  537. },
  538. statusCode: require('data/statusCodes')
  539. });
  540. },
  541. /**
  542. * Remove all loaded data.
  543. * Created as copy for App.router.clearAllSteps
  544. */
  545. clearAllSteps: function () {
  546. this.clearHosts();
  547. //todo it)
  548. },
  549. /**
  550. * Clear all temporary data
  551. */
  552. finish: function () {
  553. this.setCurrentStep('1');
  554. App.db.setService(undefined); //not to use this data at AddService page
  555. App.db.setHosts(undefined);
  556. App.db.setMasterComponentHosts(undefined);
  557. App.db.setSlaveComponentHosts(undefined);
  558. App.db.setCluster(undefined);
  559. App.router.get('updateController').updateAll();
  560. }
  561. });