installer.js 20 KB

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