installer.js 21 KB

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