add_controller.js 20 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.AddServiceController = Em.Controller.extend({
  20. name: 'addServiceController',
  21. /**
  22. * All wizards data will be stored in this variable
  23. *
  24. * cluster - cluster name
  25. * hosts - hosts, ssh key, repo info, etc.
  26. * services - services list
  27. * hostsInfo - list of selected hosts
  28. * slaveComponentHosts, hostSlaveComponents - info about slave hosts
  29. * masterComponentHosts - info about master hosts
  30. * config??? - to be described later
  31. */
  32. content: Em.Object.create({
  33. cluster: null,
  34. hosts: null,
  35. services: null,
  36. hostsInfo: null,
  37. slaveComponentHosts: null,
  38. hostSlaveComponents: null,
  39. masterComponentHosts: null,
  40. serviceConfigProperties: null,
  41. advancedServiceConfig: null,
  42. controllerName: 'addServiceController'
  43. }),
  44. /**
  45. * Used for hiding back button in wizard
  46. */
  47. hideBackButton: true,
  48. isStepDisabled: [],
  49. totalSteps: 9,
  50. init: function () {
  51. this.isStepDisabled.pushObject(Ember.Object.create({
  52. step: 1,
  53. value: false
  54. }));
  55. for (var i = 2; i <= this.totalSteps; i++) {
  56. this.isStepDisabled.pushObject(Ember.Object.create({
  57. step: i,
  58. value: true
  59. }));
  60. }
  61. },
  62. setStepsEnable: function () {
  63. for (var i = 2; i <= this.totalSteps; i++) {
  64. var step = this.get('isStepDisabled').findProperty('step', i);
  65. if (i <= this.get('currentStep')) {
  66. step.set('value', false);
  67. } else {
  68. step.set('value', true);
  69. }
  70. }
  71. }.observes('currentStep'),
  72. /**
  73. * Return current step of Add Host Wizard
  74. */
  75. currentStep: function () {
  76. return App.get('router').getWizardCurrentStep('addService');
  77. }.property(),
  78. clusters: null,
  79. /**
  80. * Set current step to new value.
  81. * Method moved from App.router.setInstallerCurrentStep
  82. * @param currentStep
  83. * @param completed
  84. */
  85. setCurrentStep: function (currentStep, completed) {
  86. App.db.setWizardCurrentStep('addService', currentStep, completed);
  87. this.set('currentStep', currentStep);
  88. },
  89. isStep1: function () {
  90. return this.get('currentStep') == 1;
  91. }.property('currentStep'),
  92. isStep2: function () {
  93. return this.get('currentStep') == 2;
  94. }.property('currentStep'),
  95. isStep3: function () {
  96. return this.get('currentStep') == 3;
  97. }.property('currentStep'),
  98. isStep4: function () {
  99. return this.get('currentStep') == 4;
  100. }.property('currentStep'),
  101. isStep5: function () {
  102. return this.get('currentStep') == 5;
  103. }.property('currentStep'),
  104. isStep6: function () {
  105. return this.get('currentStep') == 6;
  106. }.property('currentStep'),
  107. isStep7: function () {
  108. return this.get('currentStep') == 7;
  109. }.property('currentStep'),
  110. gotoStep: function (step) {
  111. if (this.get('isStepDisabled').findProperty('step', step).get('value') === false) {
  112. App.router.send('gotoStep' + step);
  113. }
  114. },
  115. gotoStep1: function () {
  116. this.gotoStep(1);
  117. },
  118. gotoStep2: function () {
  119. this.gotoStep(2);
  120. },
  121. gotoStep3: function () {
  122. this.gotoStep(3);
  123. },
  124. gotoStep4: function () {
  125. this.gotoStep(4);
  126. },
  127. gotoStep5: function () {
  128. this.gotoStep(5);
  129. },
  130. gotoStep6: function () {
  131. this.gotoStep(6);
  132. },
  133. gotoStep7: function () {
  134. this.gotoStep(7);
  135. },
  136. /**
  137. * Load clusterInfo(step1) to model
  138. */
  139. loadClusterInfo: function(){
  140. var cStatus = App.db.getClusterStatus() || {status: "", isCompleted: false};
  141. var cluster = {
  142. name: App.db.getClusterName() || "",
  143. status: cStatus.status,
  144. isCompleted: cStatus.isCompleted
  145. };
  146. this.set('content.cluster', cluster);
  147. console.log("AddServiceController:loadClusterInfo: loaded data ", cluster);
  148. },
  149. /**
  150. * save status of the cluster. This is called from step8 and step9 to persist install and start requestId
  151. * @param clusterStatus object with status, isCompleted, requestId, isInstallError and isStartError field.
  152. */
  153. saveClusterStatus: function (clusterStatus) {
  154. this.set('content.cluster', clusterStatus);
  155. App.db.setClusterStatus(clusterStatus);
  156. },
  157. /**
  158. * Temporary function for wizardStep9, before back-end integration
  159. */
  160. setInfoForStep9: function () {
  161. var hostInfo = App.db.getHosts();
  162. for (var index in hostInfo) {
  163. hostInfo[index].status = "pending";
  164. hostInfo[index].message = 'Information';
  165. hostInfo[index].progress = '0';
  166. }
  167. App.db.setHosts(hostInfo);
  168. },
  169. /**
  170. * Load confirmed hosts.
  171. * Will be used at <code>Assign Masters(step5)</code> step
  172. */
  173. loadConfirmedHosts: function(){
  174. var hosts = App.db.getHosts();
  175. if(!hosts){
  176. var hosts = {};
  177. App.Host.find().forEach(function(item){
  178. hosts[item.get('id')] = {
  179. name: item.get('id'),
  180. cpu: item.get('cpu'),
  181. memory: item.get('memory'),
  182. bootStatus: "success",
  183. isInstalled: true
  184. };
  185. });
  186. }
  187. this.set('content.hostsInfo', hosts);
  188. console.log('AddServiceController.loadConfirmedHosts: loaded hosts', hosts);
  189. },
  190. /**
  191. * Save data after installation to main controller
  192. * @param stepController App.WizardStep9Controller
  193. */
  194. saveInstalledHosts: function (stepController) {
  195. var hosts = stepController.get('hosts');
  196. var hostInfo = App.db.getHosts();
  197. for (var index in hostInfo) {
  198. hostInfo[index].status = "pending";
  199. var host = hosts.findProperty('name', hostInfo[index].name);
  200. if (host) {
  201. hostInfo[index].status = host.status;
  202. hostInfo[index].message = host.message;
  203. hostInfo[index].progress = host.progress;
  204. }
  205. }
  206. App.db.setHosts(hostInfo);
  207. this.set('content.hostsInfo', hostInfo);
  208. console.log('AddServiceController:saveInstalledHosts: save hosts ', hostInfo);
  209. },
  210. /**
  211. * Remove all data for hosts
  212. */
  213. clearHosts: function () {
  214. var hosts = this.get('content').get('hosts');
  215. if (hosts) {
  216. hosts.hostNames = '';
  217. hosts.manualInstall = false;
  218. hosts.localRepo = '';
  219. hosts.localRepopath = '';
  220. hosts.sshKey = '';
  221. hosts.passphrase = '';
  222. hosts.confirmPassphrase = '';
  223. }
  224. App.db.setHosts(null);
  225. App.db.setAllHostNames(null);
  226. },
  227. /**
  228. * Load services data. Will be used at <code>Select services(step4)</code> step
  229. */
  230. loadServices: function () {
  231. var servicesInfo = App.db.getService();
  232. if(!servicesInfo){
  233. servicesInfo = require('data/mock/services').slice(0);
  234. servicesInfo.forEach(function(item, index){
  235. servicesInfo[index].isSelected = App.Service.find().someProperty('id', item.serviceName);
  236. servicesInfo[index].isDisabled = servicesInfo[index].isSelected;
  237. servicesInfo[index].isInstalled = servicesInfo[index].isSelected;
  238. });
  239. }
  240. servicesInfo.forEach(function (item, index) {
  241. servicesInfo[index] = Em.Object.create(item);
  242. });
  243. this.set('content.services', servicesInfo);
  244. console.log('AddServiceController.loadServices: loaded data ', servicesInfo);
  245. console.log('selected services ', servicesInfo.filterProperty('isSelected', true).filterProperty('isDisabled', false).mapProperty('serviceName'));
  246. },
  247. /**
  248. * Save data to model
  249. * @param stepController App.WizardStep4Controller
  250. */
  251. saveServices: function (stepController) {
  252. var serviceNames = [];
  253. App.db.setService(stepController.get('content'));
  254. console.log('AddServiceController.saveServices: saved data', stepController.get('content'));
  255. stepController.filterProperty('isSelected', true).filterProperty('isInstalled', false).forEach(function (item) {
  256. serviceNames.push(item.serviceName);
  257. });
  258. this.set('content.selectedServiceNames', serviceNames);
  259. App.db.setSelectedServiceNames(serviceNames);
  260. console.log('AddServiceController.selectedServiceNames:', serviceNames);
  261. },
  262. /**
  263. * Save Master Component Hosts data to Main Controller
  264. * @param stepController App.WizardStep5Controller
  265. */
  266. saveMasterComponentHosts: function (stepController) {
  267. var obj = stepController.get('selectedServicesMasters');
  268. var masterComponentHosts = [];
  269. var installedComponents = App.Component.find();
  270. obj.forEach(function (_component) {
  271. masterComponentHosts.push({
  272. display_name: _component.display_name,
  273. component: _component.component_name,
  274. hostName: _component.selectedHost,
  275. isInstalled: installedComponents.someProperty('componentName', _component.component_name)
  276. });
  277. });
  278. console.log("AddServiceController.saveMasterComponentHosts: saved hosts ", masterComponentHosts);
  279. App.db.setMasterComponentHosts(masterComponentHosts);
  280. this.set('content.masterComponentHosts', masterComponentHosts);
  281. },
  282. /**
  283. * Load master component hosts data for using in required step controllers
  284. */
  285. loadMasterComponentHosts: function () {
  286. var masterComponentHosts = App.db.getMasterComponentHosts();
  287. if(!masterComponentHosts){
  288. masterComponentHosts = [];
  289. App.Component.find().filterProperty('isMaster', true).forEach(function(item){
  290. masterComponentHosts.push({
  291. component: item.get('componentName'),
  292. hostName: item.get('host.hostName'),
  293. isInstalled: true
  294. })
  295. });
  296. }
  297. this.set("content.masterComponentHosts", masterComponentHosts);
  298. console.log("AddServiceController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  299. },
  300. /**
  301. * Save slaveHostComponents to main controller
  302. * @param stepController
  303. */
  304. saveSlaveComponentHosts: function (stepController) {
  305. var hosts = stepController.get('hosts');
  306. var isMrSelected = stepController.get('isMrSelected');
  307. var isHbSelected = stepController.get('isHbSelected');
  308. App.db.setHostSlaveComponents(hosts);
  309. console.log('addServiceController.hostSlaveComponents: saved hosts', hosts);
  310. this.set('content.hostSlaveComponents', hosts);
  311. var dataNodeHosts = [];
  312. var taskTrackerHosts = [];
  313. var regionServerHosts = [];
  314. var clientHosts = [];
  315. var installedComponents = App.Component.find();
  316. hosts.forEach(function (host) {
  317. if (host.get('isDataNode')) {
  318. dataNodeHosts.push({
  319. hostName: host.hostName,
  320. group: 'Default',
  321. isInstalled: installedComponents.someProperty('componentName', 'DATANODE')
  322. });
  323. }
  324. if (isMrSelected && host.get('isTaskTracker')) {
  325. taskTrackerHosts.push({
  326. hostName: host.hostName,
  327. group: 'Default',
  328. isInstalled: installedComponents.someProperty('componentName', 'TASKTRACKER')
  329. });
  330. }
  331. if (isHbSelected && host.get('isRegionServer')) {
  332. regionServerHosts.push({
  333. hostName: host.hostName,
  334. group: 'Default',
  335. isInstalled: installedComponents.someProperty('componentName', 'HBASE_REGIONSERVER')
  336. });
  337. }
  338. if (host.get('isClient')) {
  339. clientHosts.pushObject({
  340. hostName: host.hostName,
  341. group: 'Default',
  342. isInstalled: installedComponents.someProperty('componentName', 'CLIENT')
  343. });
  344. }
  345. }, this);
  346. var slaveComponentHosts = [];
  347. slaveComponentHosts.push({
  348. componentName: 'DATANODE',
  349. displayName: 'DataNode',
  350. hosts: dataNodeHosts
  351. });
  352. if (isMrSelected) {
  353. slaveComponentHosts.push({
  354. componentName: 'TASKTRACKER',
  355. displayName: 'TaskTracker',
  356. hosts: taskTrackerHosts
  357. });
  358. }
  359. if (isHbSelected) {
  360. slaveComponentHosts.push({
  361. componentName: 'HBASE_REGIONSERVER',
  362. displayName: 'RegionServer',
  363. hosts: regionServerHosts
  364. });
  365. }
  366. slaveComponentHosts.pushObject({
  367. componentName: 'CLIENT',
  368. displayName: 'client',
  369. hosts: clientHosts
  370. });
  371. App.db.setSlaveComponentHosts(slaveComponentHosts);
  372. console.log('addServiceController.slaveComponentHosts: saved hosts', slaveComponentHosts);
  373. this.set('content.slaveComponentHosts', slaveComponentHosts);
  374. },
  375. /**
  376. * Load master component hosts data for using in required step controllers
  377. */
  378. loadSlaveComponentHosts: function () {
  379. var slaveComponentHosts = App.db.getSlaveComponentHosts();
  380. this.set("content.slaveComponentHosts", slaveComponentHosts);
  381. console.log("AddServiceController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  382. var hostSlaveComponents = App.db.getHostSlaveComponents();
  383. this.set('content.hostSlaveComponents', hostSlaveComponents);
  384. console.log("AddServiceController.loadSlaveComponentHosts: loaded hosts ", hostSlaveComponents);
  385. },
  386. /**
  387. * Save config properties
  388. * @param stepController Step7WizardController
  389. */
  390. saveServiceConfigProperties: function (stepController) {
  391. var serviceConfigProperties = [];
  392. stepController.get('stepConfigs').forEach(function (_content) {
  393. _content.get('configs').forEach(function (_configProperties) {
  394. var configProperty = {
  395. name: _configProperties.get('name'),
  396. value: _configProperties.get('value'),
  397. service: _configProperties.get('serviceName')
  398. };
  399. serviceConfigProperties.push(configProperty);
  400. }, this);
  401. }, this);
  402. App.db.setServiceConfigProperties(serviceConfigProperties);
  403. this.set('content.serviceConfigProperties', serviceConfigProperties);
  404. },
  405. /**
  406. * Load serviceConfigProperties to model
  407. */
  408. loadServiceConfigProperties: function () {
  409. var serviceConfigProperties = App.db.getServiceConfigProperties();
  410. this.set('content.serviceConfigProperties', serviceConfigProperties);
  411. console.log("AddServiceController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  412. },
  413. /**
  414. * Load information about hosts with clients components
  415. */
  416. loadClients: function(){
  417. var clients = App.db.getClientsForSelectedServices();
  418. this.set('content.clients', clients);
  419. console.log("AddServiceController.loadClients: loaded list ", clients);
  420. },
  421. /**
  422. * Generate clients list for selected services and save it to model
  423. * @param stepController step4WizardController
  424. */
  425. saveClients: function(stepController){
  426. var clients = [];
  427. var serviceComponents = require('data/service_components');
  428. stepController.get('content').filterProperty('isSelected',true).forEach(function (_service) {
  429. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  430. if (client) {
  431. clients.pushObject({
  432. component_name: client.component_name,
  433. display_name: client.display_name
  434. });
  435. }
  436. }, this);
  437. App.db.setClientsForSelectedServices(clients);
  438. this.set('content.clients', clients);
  439. console.log("AddServiceController.saveClients: saved list ", clients);
  440. },
  441. /**
  442. * Load data for all steps until <code>current step</code>
  443. */
  444. loadAllPriorSteps: function () {
  445. var step = this.get('currentStep');
  446. switch (step) {
  447. case '6':
  448. case '5':
  449. this.loadClusterInfo();
  450. case '4':
  451. this.loadServiceConfigProperties();
  452. case '3':
  453. this.loadClients();
  454. this.loadSlaveComponentHosts();
  455. case '2':
  456. this.loadMasterComponentHosts();
  457. this.loadConfirmedHosts();
  458. case '1':
  459. this.loadServices();
  460. }
  461. },
  462. loadAdvancedConfigs: function () {
  463. App.db.getSelectedServiceNames().forEach(function (_serviceName) {
  464. this.loadAdvancedConfig(_serviceName);
  465. }, this);
  466. },
  467. /**
  468. * Generate serviceProperties save it to localdata
  469. * called form stepController step6WizardController
  470. */
  471. loadAdvancedConfig: function (serviceName) {
  472. var self = this;
  473. var url = (App.testMode) ? '/data/wizard/stack/hdp/version01/' + serviceName + '.json' : '/api/stacks/HDP/version/1.2.0/services/' + serviceName; // TODO: get this url from the stack selected by the user in Install Options page
  474. var method = 'GET';
  475. $.ajax({
  476. type: method,
  477. url: url,
  478. async: false,
  479. dataType: 'text',
  480. timeout: 5000,
  481. success: function (data) {
  482. var jsonData = jQuery.parseJSON(data);
  483. console.log("TRACE: Step6 submit -> In success function for the loadAdvancedConfig call");
  484. console.log("TRACE: Step6 submit -> value of the url is: " + url);
  485. var serviceComponents = jsonData.properties;
  486. serviceComponents.setEach('serviceName', serviceName);
  487. var configs;
  488. if (App.db.getAdvancedServiceConfig()) {
  489. configs = App.db.getAdvancedServiceConfig();
  490. } else {
  491. configs = [];
  492. }
  493. configs = configs.concat(serviceComponents);
  494. self.set('content.advancedServiceConfig', configs);
  495. App.db.setAdvancedServiceConfig(configs);
  496. console.log('TRACE: servicename: ' + serviceName);
  497. },
  498. error: function (request, ajaxOptions, error) {
  499. console.log("TRACE: STep6 submit -> In error function for the loadAdvancedConfig call");
  500. console.log("TRACE: STep6 submit-> value of the url is: " + url);
  501. console.log("TRACE: STep6 submit-> error code status is: " + request.status);
  502. console.log('Step6 submit: Error message is: ' + request.responseText);
  503. },
  504. statusCode: require('data/statusCodes')
  505. });
  506. },
  507. /**
  508. * Generate clients list for selected services and save it to model
  509. * @param stepController step8WizardController or step9WizardController
  510. */
  511. installServices: function () {
  512. var self = this;
  513. var clusterName = this.get('content.cluster.name');
  514. var url = (App.testMode) ? '/data/wizard/deploy/poll_1.json' : '/api/clusters/' + clusterName + '/services?state=INIT';
  515. var method = (App.testMode) ? 'GET' : 'PUT';
  516. var data = '{"ServiceInfo": {"state": "INSTALLED"}}';
  517. $.ajax({
  518. type: method,
  519. url: url,
  520. data: data,
  521. async: false,
  522. dataType: 'text',
  523. timeout: 5000,
  524. success: function (data) {
  525. var jsonData = jQuery.parseJSON(data);
  526. var installSartTime = new Date().getTime();
  527. console.log("TRACE: STep8 -> In success function for the installService call");
  528. console.log("TRACE: STep8 -> value of the url is: " + url);
  529. if (jsonData) {
  530. var requestId = jsonData.href.match(/.*\/(.*)$/)[1];
  531. console.log('requestId is: ' + requestId);
  532. var clusterStatus = {
  533. status: 'PENDING',
  534. requestId: requestId,
  535. isInstallError: false,
  536. isCompleted: false,
  537. installStartTime: installSartTime
  538. };
  539. self.saveClusterStatus(clusterStatus);
  540. } else {
  541. console.log('ERROR: Error occurred in parsing JSON data');
  542. }
  543. },
  544. error: function (request, ajaxOptions, error) {
  545. console.log("TRACE: STep8 -> In error function for the installService call");
  546. console.log("TRACE: STep8 -> value of the url is: " + url);
  547. console.log("TRACE: STep8 -> error code status is: " + request.status);
  548. console.log('Step8: Error message is: ' + request.responseText);
  549. var clusterStatus = {
  550. status: 'PENDING',
  551. isInstallError: true,
  552. isCompleted: false
  553. };
  554. self.saveClusterStatus(clusterStatus);
  555. },
  556. statusCode: require('data/statusCodes')
  557. });
  558. },
  559. /**
  560. * Remove all loaded data.
  561. * Created as copy for App.router.clearAllSteps
  562. */
  563. clearAllSteps: function () {
  564. this.clearHosts();
  565. //todo it)
  566. }
  567. });