add_controller.js 19 KB

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