installer.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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: 11,
  22. content: Em.Object.create({
  23. cluster: null,
  24. installOptions: null,
  25. hosts: null,
  26. services: null,
  27. slaveComponentHosts: null,
  28. masterComponentHosts: null,
  29. serviceConfigProperties: null,
  30. advancedServiceConfig: null,
  31. configGroups: [],
  32. slaveGroupProperties: null,
  33. stacks: null,
  34. controllerName: 'installerController'
  35. }),
  36. /**
  37. * Wizard properties in local storage, which should be cleaned right after wizard has been finished
  38. */
  39. dbPropertiesToClean: [
  40. 'service',
  41. 'hosts',
  42. 'masterComponentHosts',
  43. 'slaveComponentHosts',
  44. 'cluster',
  45. 'allHostNames',
  46. 'installOptions',
  47. 'allHostNamesPattern',
  48. 'serviceComponents',
  49. 'advancedServiceConfig',
  50. 'clientInfo',
  51. 'selectedServiceNames',
  52. 'serviceConfigGroups',
  53. 'serviceConfigProperties',
  54. 'configsToUpdate',
  55. 'bootStatus',
  56. 'stacksVersions',
  57. 'currentStep',
  58. 'serviceInfo',
  59. 'hostInfo'
  60. ],
  61. init: function () {
  62. this._super();
  63. this.get('isStepDisabled').setEach('value', true);
  64. this.get('isStepDisabled').pushObject(Ember.Object.create({
  65. step: 0,
  66. value: false
  67. }));
  68. },
  69. /**
  70. * redefined connectOutlet method to avoid view loading by unauthorized user
  71. * @param view
  72. * @param content
  73. */
  74. connectOutlet: function(view, content) {
  75. if(App.db.getAuthenticated()) {
  76. this._super(view, content);
  77. }
  78. },
  79. getCluster: function(){
  80. return jQuery.extend({}, this.get('clusterStatusTemplate'));
  81. },
  82. getInstallOptions: function(){
  83. return jQuery.extend({}, this.get('installOptionsTemplate'));
  84. },
  85. getHosts: function(){
  86. return [];
  87. },
  88. /**
  89. * Remove host from model. Used at <code>Confirm hosts(step2)</code> step
  90. * @param hosts Array of hosts, which we want to delete
  91. */
  92. removeHosts: function (hosts) {
  93. var dbHosts = this.getDBProperty('hosts');
  94. hosts.forEach(function (_hostInfo) {
  95. var host = _hostInfo.hostName;
  96. delete dbHosts[host];
  97. });
  98. this.setDBProperty('hosts', dbHosts);
  99. },
  100. /**
  101. * Load confirmed hosts.
  102. * Will be used at <code>Assign Masters(step5)</code> step
  103. */
  104. loadConfirmedHosts: function () {
  105. this.set('content.hosts', this.getDBProperty('hosts') || {});
  106. },
  107. /**
  108. * Load services data. Will be used at <code>Select services(step4)</code> step
  109. */
  110. loadServices: function () {
  111. var servicesInfo = this.getDBProperty('service');
  112. if(servicesInfo && servicesInfo.length) {
  113. servicesInfo.forEach(function (item, index) {
  114. servicesInfo[index] = Em.Object.create(item);
  115. servicesInfo[index].isInstalled = false;
  116. });
  117. this.set('content.services', servicesInfo);
  118. console.log('installerController.loadServices: loaded data ', JSON.stringify(servicesInfo));
  119. console.log('selected services ', servicesInfo.filterProperty('isSelected', true).mapProperty('serviceName'));
  120. } else {
  121. console.log("Failed to load Services");
  122. }
  123. },
  124. /**
  125. * total set of hosts registered to cluster, analog of App.Host model,
  126. * used in Installer wizard until hosts are installed
  127. */
  128. allHosts: function () {
  129. var rawHosts = this.get('content.hosts');
  130. var masterComponents = this.get('content.masterComponentHosts');
  131. var slaveComponents = this.get('content.slaveComponentHosts');
  132. var hosts = [];
  133. masterComponents.forEach(function (component) {
  134. var host = rawHosts[component.hostName];
  135. if (host.hostComponents) {
  136. host.hostComponents.push(Em.Object.create({
  137. componentName: component.component,
  138. displayName: component.display_name
  139. }));
  140. } else {
  141. rawHosts[component.hostName].hostComponents = [
  142. Em.Object.create({
  143. componentName: component.component,
  144. displayName: component.display_name
  145. })
  146. ]
  147. }
  148. });
  149. slaveComponents.forEach(function (component) {
  150. component.hosts.forEach(function (rawHost) {
  151. var host = rawHosts[rawHost.hostName];
  152. if (host.hostComponents) {
  153. host.hostComponents.push(Em.Object.create({
  154. componentName: component.componentName,
  155. displayName: component.displayName
  156. }));
  157. } else {
  158. rawHosts[rawHost.hostName].hostComponents = [
  159. Em.Object.create({
  160. componentName: component.componentName,
  161. displayName: component.displayName
  162. })
  163. ]
  164. }
  165. });
  166. });
  167. for (var hostName in rawHosts) {
  168. var host = rawHosts[hostName];
  169. var disksOverallCapacity = 0;
  170. var diskFree = 0;
  171. host.disk_info.forEach(function (disk) {
  172. disksOverallCapacity += parseFloat(disk.size);
  173. diskFree += parseFloat(disk.available);
  174. });
  175. hosts.pushObject(Em.Object.create({
  176. id: host.name,
  177. ip: host.ip,
  178. osType: host.os_type,
  179. osArch: host.os_arch,
  180. hostName: host.name,
  181. publicHostName: host.name,
  182. cpu: host.cpu,
  183. memory: host.memory,
  184. diskInfo: host.disk_info,
  185. diskTotal: disksOverallCapacity / (1024 * 1024),
  186. diskFree: diskFree / (1024 * 1024),
  187. hostComponents: host.hostComponents
  188. }
  189. ))
  190. }
  191. return hosts;
  192. }.property('content.hosts'),
  193. /**
  194. * Load service components.
  195. */
  196. loadServiceComponentsDb: function () {
  197. var serviceComponents = this.getDBProperty('serviceComponents');
  198. if(serviceComponents && serviceComponents.items && serviceComponents.items.length) {
  199. App.stackServiceComponentMapper.map(serviceComponents);
  200. } else {
  201. console.log("Failed to load Service components");
  202. }
  203. },
  204. stacks: [],
  205. /**
  206. * Load stacks data from server or take exist data from local db
  207. */
  208. loadStacks: function () {
  209. var stacks = App.db.getStacks();
  210. if (stacks && stacks.length) {
  211. var convertedStacks = [];
  212. stacks.forEach(function (stack) {
  213. convertedStacks.pushObject(Ember.Object.create(stack));
  214. });
  215. App.set('currentStackVersion', convertedStacks.findProperty('isSelected').get('name'));
  216. this.set('content.stacks', convertedStacks);
  217. } else {
  218. App.ajax.send({
  219. name: 'wizard.stacks',
  220. sender: this,
  221. success: 'loadStacksSuccessCallback',
  222. error: 'loadStacksErrorCallback'
  223. });
  224. }
  225. },
  226. /**
  227. * Send queries to load versions for each stack
  228. */
  229. loadStacksSuccessCallback: function (data) {
  230. var stacks = data.items;
  231. var result;
  232. this.get('stacks').clear();
  233. stacks.forEach(function (stack) {
  234. App.ajax.send({
  235. name: 'wizard.stacks_versions',
  236. sender: this,
  237. data: {
  238. stackName: stack.Stacks.stack_name
  239. },
  240. success: 'loadStacksVersionsSuccessCallback',
  241. error: 'loadStacksVersionsErrorCallback'
  242. });
  243. }, this);
  244. result = this.get('stacks');
  245. if (!result.length) {
  246. console.log('Error: therea are no active stacks');
  247. } else {
  248. var defaultStackVersion = result.findProperty('name', App.defaultStackVersion);
  249. if (defaultStackVersion) {
  250. defaultStackVersion.set('isSelected', true)
  251. } else {
  252. result.objectAt(0).set('isSelected', true);
  253. }
  254. }
  255. App.db.setStacks(result);
  256. this.set('content.stacks', result);
  257. },
  258. /**
  259. * onError callback for loading stacks data
  260. */
  261. loadStacksErrorCallback: function () {
  262. console.log('Error in loading stacks');
  263. },
  264. /**
  265. * Parse loaded data and create array of stacks objects
  266. */
  267. loadStacksVersionsSuccessCallback: function (data) {
  268. var result = [];
  269. var stackVersions = data.items.filterProperty('Versions.active');
  270. stackVersions.sortProperty('Versions.stack_version').reverse().forEach(function (version) {
  271. /*
  272. * operatingSystems:[
  273. * {
  274. * osType: 'centos5',
  275. * baseUrl: 'http://...',
  276. * originalBaseUrl: 'http://...',
  277. * defaultBaseUrl: 'http://...',
  278. * latestBaseUrl: 'http://...',
  279. * mirrorsList: '';
  280. * },
  281. * {
  282. * osType: 'centos6',
  283. * baseUrl: 'http://...',
  284. * originalBaseUrl: 'http://...',
  285. * defaultBaseUrl: 'http://...',
  286. * latestBaseUrl: 'http://...',
  287. * mirrorsList: '';
  288. * },
  289. * ]
  290. */
  291. var oses = [];
  292. if (version.operatingSystems) {
  293. version.operatingSystems.forEach(function (os) {
  294. if (os.repositories) {
  295. os.repositories.forEach(function (repo) {
  296. var defaultBaseUrl = repo.Repositories.default_base_url || repo.Repositories.base_url;
  297. var latestBaseUrl = repo.Repositories.latest_base_url || defaultBaseUrl;
  298. if (!App.supports.ubuntu && os.OperatingSystems.os_type == 'debian12') return; // @todo: remove after Ubuntu support confirmation
  299. oses.push({
  300. osType: os.OperatingSystems.os_type,
  301. baseUrl: latestBaseUrl,
  302. latestBaseUrl: latestBaseUrl,
  303. originalLatestBaseUrl: latestBaseUrl,
  304. originalBaseUrl: repo.Repositories.base_url,
  305. defaultBaseUrl: defaultBaseUrl,
  306. mirrorsList: repo.Repositories.mirrors_list,
  307. id: os.OperatingSystems.os_type + repo.Repositories.repo_name,
  308. repoId: repo.Repositories.repo_id,
  309. selected: true
  310. });
  311. });
  312. }
  313. });
  314. }
  315. result.push(
  316. Em.Object.create({
  317. name: version.Versions.stack_name + "-" + version.Versions.stack_version,
  318. isSelected: false,
  319. operatingSystems: oses
  320. })
  321. );
  322. }, this);
  323. this.get('stacks').pushObjects(result);
  324. },
  325. /**
  326. * onError callback for loading stacks data
  327. */
  328. loadStacksVersionsErrorCallback: function () {
  329. console.log('Error in loading stacks');
  330. },
  331. /**
  332. * check server version and web client version
  333. */
  334. checkServerClientVersion: function () {
  335. var dfd = $.Deferred();
  336. var self = this;
  337. self.getServerVersion().done(function () {
  338. dfd.resolve();
  339. });
  340. return dfd.promise();
  341. },
  342. getServerVersion: function(){
  343. return App.ajax.send({
  344. name: 'ambari.service.load_server_version',
  345. sender: this,
  346. success: 'getServerVersionSuccessCallback',
  347. error: 'getServerVersionErrorCallback'
  348. });
  349. },
  350. getServerVersionSuccessCallback: function (data) {
  351. var clientVersion = App.get('version');
  352. var serverVersion = (data.RootServiceComponents.component_version).toString();
  353. this.set('ambariServerVersion', serverVersion);
  354. if (clientVersion) {
  355. this.set('versionConflictAlertBody', Em.I18n.t('app.versionMismatchAlert.body').format(serverVersion, clientVersion));
  356. this.set('isServerClientVersionMismatch', clientVersion != serverVersion);
  357. } else {
  358. this.set('isServerClientVersionMismatch', false);
  359. }
  360. },
  361. getServerVersionErrorCallback: function () {
  362. console.log('ERROR: Cannot load Ambari server version');
  363. },
  364. /**
  365. * Save data to model
  366. * @param stepController App.WizardStep4Controller
  367. */
  368. saveServices: function (stepController) {
  369. this.setDBProperty('service', stepController.get('content'));
  370. var serviceNames = stepController.filterProperty('isSelected', true).mapProperty('serviceName');
  371. this.set('content.selectedServiceNames', serviceNames);
  372. this.setDBProperty('selectedServiceNames', serviceNames);
  373. console.log('installerController.saveServices: saved data ', serviceNames);
  374. },
  375. /**
  376. * Save Master Component Hosts data to Main Controller
  377. * @param stepController App.WizardStep5Controller
  378. */
  379. saveMasterComponentHosts: function (stepController) {
  380. var obj = stepController.get('selectedServicesMasters'),
  381. hosts = this.getDBProperty('hosts');
  382. var masterComponentHosts = [];
  383. obj.forEach(function (_component) {
  384. masterComponentHosts.push({
  385. display_name: _component.get('display_name'),
  386. component: _component.get('component_name'),
  387. serviceId: _component.get('serviceId'),
  388. isInstalled: false,
  389. host_id: hosts[_component.get('selectedHost')].id
  390. });
  391. });
  392. console.log("installerController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  393. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  394. this.set('content.masterComponentHosts', masterComponentHosts);
  395. },
  396. /**
  397. * Load master component hosts data for using in required step controllers
  398. */
  399. loadMasterComponentHosts: function () {
  400. var masterComponentHosts = this.getDBProperty('masterComponentHosts'),
  401. hosts = this.getDBProperty('hosts'),
  402. host_names = Em.keys(hosts);
  403. if (Em.isNone(masterComponentHosts)) {
  404. masterComponentHosts = [];
  405. }
  406. else {
  407. masterComponentHosts.forEach(function(component) {
  408. for (var i = 0; i < host_names.length; i++) {
  409. if (hosts[host_names[i]].id === component.host_id) {
  410. component.hostName = host_names[i];
  411. break;
  412. }
  413. }
  414. });
  415. }
  416. this.set("content.masterComponentHosts", masterComponentHosts);
  417. },
  418. /**
  419. * Load master component hosts data for using in required step controllers
  420. */
  421. loadSlaveComponentHosts: function () {
  422. var slaveComponentHosts = this.getDBProperty('slaveComponentHosts'),
  423. hosts = this.getDBProperty('hosts'),
  424. host_names = Em.keys(hosts);
  425. if (!Em.isNone(slaveComponentHosts)) {
  426. slaveComponentHosts.forEach(function(component) {
  427. component.hosts.forEach(function(host) {
  428. for (var i = 0; i < host_names.length; i++) {
  429. if (hosts[host_names[i]].id === host.host_id) {
  430. host.hostName = host_names[i];
  431. break;
  432. }
  433. }
  434. });
  435. });
  436. }
  437. this.set("content.slaveComponentHosts", slaveComponentHosts);
  438. console.log("InstallerController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  439. },
  440. /**
  441. * Load serviceConfigProperties to model
  442. */
  443. loadServiceConfigProperties: function () {
  444. var serviceConfigProperties = this.getDBProperty('serviceConfigProperties');
  445. this.set('content.serviceConfigProperties', serviceConfigProperties);
  446. console.log("InstallerController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  447. this.set('content.advancedServiceConfig', this.getDBProperty('advancedServiceConfig'));
  448. },
  449. /**
  450. * Generate clients list for selected services and save it to model
  451. * @param stepController step4WizardController
  452. */
  453. saveClients: function (stepController) {
  454. var clients = [];
  455. var serviceComponents = App.StackServiceComponent.find();
  456. stepController.get('content').filterProperty('isSelected', true).forEach(function (_service) {
  457. var client = serviceComponents.filterProperty('serviceName', _service.serviceName).findProperty('isClient', true);
  458. if (client) {
  459. clients.pushObject({
  460. component_name: client.get('componentName'),
  461. display_name: client.get('displayName'),
  462. isInstalled: false
  463. });
  464. }
  465. }, this);
  466. this.setDBProperty('clientInfo', clients);
  467. this.set('content.clients', clients);
  468. console.log("InstallerController.saveClients: saved list ", clients);
  469. },
  470. /**
  471. * Save stacks data to local db
  472. * @param stepController step1WizardController
  473. */
  474. saveStacks: function (stepController) {
  475. var stacks = stepController.get('content.stacks');
  476. if (stacks.length) {
  477. App.set('currentStackVersion', stacks.findProperty('isSelected').get('name'));
  478. } else {
  479. App.set('currentStackVersion', App.defaultStackVersion);
  480. }
  481. App.db.setStacks(stacks);
  482. this.set('content.stacks', stacks);
  483. },
  484. /**
  485. * Check validation of the customized local urls
  486. */
  487. checkRepoURL: function () {
  488. var selectedStack = this.get('content.stacks').findProperty('isSelected', true);
  489. selectedStack.set('reload', true);
  490. var nameVersionCombo = selectedStack.name;
  491. var stackName = nameVersionCombo.split('-')[0];
  492. var stackVersion = nameVersionCombo.split('-')[1];
  493. if (selectedStack && selectedStack.operatingSystems) {
  494. this.set('validationCnt', selectedStack.get('operatingSystems').filterProperty('selected', true).length);
  495. this.set('invalidCnt', 0);
  496. selectedStack.operatingSystems.forEach(function (os) {
  497. os.errorTitle = null;
  498. os.errorContent = null;
  499. var verifyBaseUrl = os.skipValidation ? false: true;
  500. if (os.selected ) {
  501. os.validation = 'icon-repeat';
  502. selectedStack.set('reload', !selectedStack.get('reload'));
  503. App.ajax.send({
  504. name: 'wizard.advanced_repositories.valid_url',
  505. sender: this,
  506. data: {
  507. stackName: stackName,
  508. stackVersion: stackVersion,
  509. repoId: os.repoId,
  510. osType: os.osType,
  511. osId: os.id,
  512. data: {
  513. 'Repositories': {
  514. 'base_url': os.baseUrl,
  515. "verify_base_url": verifyBaseUrl
  516. }
  517. }
  518. },
  519. success: 'checkRepoURLSuccessCallback',
  520. error: 'checkRepoURLErrorCallback'
  521. });
  522. }
  523. }, this);
  524. }
  525. },
  526. setInvalidUrlCnt: function () {
  527. var selectedStack = this.get('content.stacks').findProperty('isSelected', true);
  528. selectedStack.set('invalidCnt', this.get('invalidCnt'));
  529. }.observes('invalidCnt'),
  530. /**
  531. * onSuccess callback for check Repo URL.
  532. */
  533. checkRepoURLSuccessCallback: function (response, request, data) {
  534. console.log('Success in check Repo URL. data osType: ' + data.osType );
  535. var selectedStack = this.get('content.stacks').findProperty('isSelected', true);
  536. if (selectedStack && selectedStack.operatingSystems) {
  537. var os = selectedStack.operatingSystems.findProperty('id', data.osId);
  538. os.validation = 'icon-ok';
  539. selectedStack.set('reload', !selectedStack.get('reload'));
  540. this.set('validationCnt', this.get('validationCnt') - 1);
  541. }
  542. },
  543. /**
  544. * onError callback for check Repo URL.
  545. */
  546. checkRepoURLErrorCallback: function (request, ajaxOptions, error, data, params) {
  547. console.log('Error in check Repo URL. The baseURL sent is: ' + data.data);
  548. var selectedStack = this.get('content.stacks').findProperty('isSelected', true);
  549. if (selectedStack && selectedStack.operatingSystems) {
  550. var os = selectedStack.operatingSystems.findProperty('id', params.osId);
  551. os.validation = 'icon-exclamation-sign';
  552. os.errorTitle = request.status + ":" + request.statusText;
  553. os.errorContent = $.parseJSON(request.responseText) ? $.parseJSON(request.responseText).message : "";
  554. selectedStack.set('reload', !selectedStack.get('reload'));
  555. this.set('validationCnt', this.get('validationCnt') - 1);
  556. this.set('invalidCnt', this.get('invalidCnt') + 1);
  557. }
  558. },
  559. /**
  560. * Load data for all steps until <code>current step</code>
  561. */
  562. loadAllPriorSteps: function () {
  563. var step = this.get('currentStep');
  564. switch (step) {
  565. case '10':
  566. case '9':
  567. case '8':
  568. case '7':
  569. this.loadServiceConfigGroups();
  570. this.loadServiceConfigProperties();
  571. case '6':
  572. this.loadSlaveComponentHosts();
  573. this.loadClients();
  574. case '5':
  575. this.loadMasterComponentHosts();
  576. this.loadConfirmedHosts();
  577. case '4':
  578. this.loadServices();
  579. this.loadServiceComponentsDb();
  580. case '3':
  581. this.loadConfirmedHosts();
  582. case '2':
  583. this.load('installOptions');
  584. case '1':
  585. this.loadStacks();
  586. case '0':
  587. this.load('cluster');
  588. }
  589. },
  590. /**
  591. * Clear all temporary data
  592. */
  593. finish: function () {
  594. this.setCurrentStep('0');
  595. this.clearStorageData();
  596. var persists = App.router.get('applicationController').persistKey();
  597. App.router.get('applicationController').postUserPref(persists,true);
  598. },
  599. setStepsEnable: function () {
  600. for (var i = 0; i <= this.totalSteps; i++) {
  601. var step = this.get('isStepDisabled').findProperty('step', i);
  602. if (i <= this.get('currentStep')) {
  603. step.set('value', false);
  604. } else {
  605. step.set('value', true);
  606. }
  607. }
  608. }.observes('currentStep'),
  609. setLowerStepsDisable: function (stepNo) {
  610. for (var i = 0; i < stepNo; i++) {
  611. var step = this.get('isStepDisabled').findProperty('step', i);
  612. step.set('value', true);
  613. }
  614. }
  615. });