installer.js 20 KB

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