installer.js 21 KB

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